53 add_action(
'after_setup_theme', array( $this,
'after_setup_theme' ) );
56 add_action(
'wp', array( $this,
'wp' ) );
57 add_action(
'wp_head', array( $this,
'wp_head' ) );
58 add_action(
'wp_footer', array( $this,
'wp_footer' ) );
61 add_filter(
'body_class', array( $this,
'_body_class' ) );
64 add_action(
'wp_enqueue_scripts', array( $this,
'wp_enqueue_scripts' ) );
67 add_action(
'template_redirect', array( $this,
'template_redirect' ) );
68 add_filter(
'template_include', array( $this,
'template_include' ) );
87 if ( !is_null( $this->plugin ) ) {
88 $classes[] = sprintf(
' %s-body', $this->plugin->slug );
201 const DEFINES =
'wpx-defines.php';
210 public $__version =
'1.1.1';
247 public $javascriptURL;
286 private $_wpxThemeClassLoadingPath;
307 public function __construct( $file, $setup =
false ) {
309 if (
false == $setup ) {
310 $this->setup = $setup =
new WPDKThemeSetup();
312 $this->setup = apply_filters(
'wpdk_theme_setup-' . $file, $setup );
315 $this->_wpxThemeClassLoadingPath = array();
316 spl_autoload_extensions(
'.php' );
317 spl_autoload_register( array( $this,
'autoloadEnvironment' ) );
320 $this->path = trailingslashit( dirname( $file ) );
321 $this->classesPath = $this->path .
'classes/';
324 $this->url = trailingslashit( get_template_directory_uri() );
325 $this->assetsURL = $this->url .
'assets/';
326 $this->cssURL = $this->assetsURL .
'css/';
327 $this->imagesURL = $this->assetsURL .
'images/';
328 $this->javascriptURL = $this->assetsURL .
'js/';
330 $theme_key = basename( dirname( $file ) );
331 $theme_directories = search_theme_directories();
333 $theme_file = $theme_directories[$theme_key][
'theme_file'];
334 $theme_root = $theme_directories[$theme_key][
'theme_root'];
337 $this->theme =
new WP_Theme( $theme_key, $theme_root );
340 $defines = trailingslashit( dirname( $file ) ) . self::DEFINES;
341 if ( file_exists( $defines ) ) {
342 require_once( $defines );
346 if ( method_exists( $this,
'registerClasses' ) ) {
347 $this->registerClasses();
351 add_action(
'admin_init', array( $this,
'admin_init' ) );
354 add_action(
'init', array( $this,
'_init' ) );
357 add_action(
'init', array( $this,
'init_theme' ) );
360 add_action(
'init', array( $this,
'init_shortcode' ) );
364 add_action(
'init', array( $this,
'ajax' ) );
368 add_action(
'after_setup_theme', array( $this,
'_after_setup_theme' ) );
369 add_action(
'after_setup_theme', array( $this,
'after_setup_theme' ) );
372 add_action(
'wp_enqueue_scripts', array( $this,
'wp_enqueue_scripts' ) );
375 add_action(
'wp_head', array( $this,
'_wp_head' ), 0 );
376 add_action(
'wp_head', array( $this,
'wp_head' ) );
379 add_action(
'wp_footer', array( $this,
'wp_footer' ) );
382 add_filter(
'body_class', array( $this,
'_body_classes' ) );
385 add_filter(
'image_size_names_choose', array( $this,
'image_size_names_choose' ) );
394 public function _init()
397 if( $this->setup->autoload_text_domain ) {
398 load_theme_textdomain( $this->theme->get(
'TextDomain' ), trailingslashit( TEMPLATEPATH ) . $this->theme->get(
'DomainPath' ) );
402 if ( $this->setup->cleanup_wp_head ) {
403 remove_action(
'wp_head',
'feed_links_extra', 3 );
404 remove_action(
'wp_head',
'feed_links', 2 );
405 remove_action(
'wp_head',
'rsd_link' );
406 remove_action(
'wp_head',
'wlwmanifest_link' );
407 remove_action(
'wp_head',
'index_rel_link' );
408 remove_action(
'wp_head',
'parent_post_rel_link', 10, 0 );
409 remove_action(
'wp_head',
'start_post_rel_link', 10, 0 );
410 remove_action(
'wp_head',
'adjacent_posts_rel_link_wp_head', 10, 0 );
411 remove_action(
'wp_head',
'wp_generator' );
420 public function _after_setup_theme()
423 if ( !is_admin() && $this->setup->hide_admin_bar ) {
424 show_admin_bar(
false );
428 if ( !empty( $this->setup->theme_support ) ) {
429 $theme_supports = (array)$this->setup->theme_support;
430 foreach ( $theme_supports as $args => $theme_support ) {
431 if ( !is_numeric( $args ) && is_array( $theme_support ) ) {
432 add_theme_support( $args, $theme_support );
435 add_theme_support( $theme_support );
441 if ( !empty( $this->setup->image_sizes ) ) {
442 foreach ( $this->setup->image_sizes as $key => $size ) {
443 $size = array_merge( $size, array( 0, 0,
false ) );
444 list( $w, $h, $crop ) = $size;
445 add_image_size( $key, $w, $h, is_null( $crop ) ?
false : $crop );
450 if ( !empty( $this->setup->post_thumbnail_size ) ) {
451 list( $w, $h, $crop ) = $this->setup->post_thumbnail_size;
452 set_post_thumbnail_size( $w, $h, is_null( $crop ) ?
false : $crop );
456 if ( !empty( $this->setup->nav_menus ) ) {
457 register_nav_menus( $this->setup->nav_menus );
461 if ( !empty( $this->setup->sidebars ) ) {
462 foreach ( $this->setup->sidebars as $sidebar ) {
463 if ( is_array( $sidebar ) ) {
464 register_sidebar( $sidebar );
470 if ( !empty( $this->setup->editor_styles ) ) {
471 add_editor_style( $this->setup->editor_styles );
480 public function admin_init()
487 if ( !is_user_logged_in() ) {
492 if ( !empty( $this->setup->disable_admin_for_roles ) ) {
497 if ( !empty( $this->setup->disable_admin_if_user_has_not_caps ) ) {
499 $roles = $this->setup->disable_admin_if_user_has_not_caps;
500 if ( !empty( $roles ) && is_array( $roles ) ) {
501 foreach ( $roles as $role ) {
502 if ( ( $pass = current_user_can( $role ) ) ) {
507 elseif ( !empty( $roles ) && is_string( $roles ) ) {
508 $pass = current_user_can( $roles );
521 public function init_theme() {
530 public function init_shortcode() {
539 public function ajax() {
550 public function after_setup_theme() {
551 die( __METHOD__ .
' must be override in your subclass' );
559 public function wp_enqueue_scripts() {
568 public function _wp_head()
570 if ( !empty( $this->setup->normalize_css ) ) {
571 wp_enqueue_style(
'normalize', WPDK_URI_CSS .
'normalize.css', array(), WPDK_VERSION );
574 if ( !empty( $this->setup->theme_js ) ) {
575 wp_enqueue_script(
'wpdk-theme', WPDK_URI_JAVASCRIPT .
'wpdk-theme.js', array(), WPDK_VERSION );
584 public function wp_head()
594 public function wp_footer()
604 public function _body_classes( $classes )
606 if ( !empty( $this->setup->body_classes ) ) {
607 if ( is_string( $this->setup->body_classes ) ) {
608 $classes[] = $this->setup->body_classes;
610 elseif ( is_array( $this->setup->body_classes ) ) {
611 $classes = array_merge( $classes, $this->setup->body_classes );
614 return array_unique( $classes );
626 public function image_size_names_choose( $sizes )
628 if ( !empty( $this->setup->image_sizes ) ) {
629 foreach ( $this->setup->image_sizes as $key => $size ) {
630 $size = array_merge( $size, array( 0, 0, 0, 0 ) );
631 list( $w, $h, $crop, $label ) = $size;
632 $sizes[$key] = empty( $label ) ? $key : $label;
655 public function registerAutoloadClass( $sLoadingPath, $mClassName =
'' ) {
658 if ( is_string( $sLoadingPath ) && is_string( $mClassName ) && !empty( $mClassName ) ) {
659 $sClassNameLowerCased = strtolower( $mClassName );
660 $this->_wpxThemeClassLoadingPath[$sClassNameLowerCased] = $sLoadingPath;
664 elseif ( is_array( $sLoadingPath ) ) {
665 foreach ( $sLoadingPath as $path => $classes ) {
666 if ( is_string( $classes ) ) {
667 $class_name = strtolower( $classes );
668 $this->_wpxThemeClassLoadingPath[$class_name] = $path;
672 elseif ( is_array( $classes ) ) {
673 foreach ( $classes as $class_name ) {
674 $class_name = strtolower( $class_name );
675 $this->_wpxThemeClassLoadingPath[$class_name] = $path;
694 public function autoloadEnvironment( $sClassName ) {
697 $sClassNameLowerCased = strtolower( $sClassName );
698 if ( isset( $this->_wpxThemeClassLoadingPath[$sClassNameLowerCased] ) ) {
699 require_once( $this->_wpxThemeClassLoadingPath[$sClassNameLowerCased] );
716 class WPDKThemeSetup {
731 public $disable_admin_for_roles = array();
749 public $disable_admin_if_user_has_not_caps = array();
768 public $cleanup_wp_head =
true;
774 public $autoload_text_domain =
true;
783 public $hide_admin_bar =
true;
796 public $theme_support = array();
811 public $image_sizes = array();
823 public $post_thumbnail_size = array();
837 public $nav_menus = array();
875 public $sidebars = array();
884 public $body_classes = array();
893 public $editor_styles = array();
902 public $theme_js =
true;
912 public $theme_css =
true;
921 public $normalize_css =
true;
930 public function __construct()