SHARE
TWEET

Untitled

a guest Mar 21st, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. class Temaclass
  3. {
  4.     private function actionAfterSetup($function)
  5.     {
  6.         add_action('after_setup_theme', function() use ($function) {
  7.             $function();
  8.         });
  9.     }
  10.     private function actionEnqueueScripts($function)
  11.     {
  12.         add_action('wp_enqueue_scripts', function() use ($function){
  13.             $function();
  14.         });
  15.     }
  16.     public function __construct()
  17.     {
  18.         $this->addSupport('title-tag')
  19.              ->addSupport('custom-logo')
  20.              ->addSupport('post-thumbnails')
  21.              ->addSupport('customize-selective-refresh-widgets')
  22.              ->addSupport('html5', [
  23.                  'search-form',
  24.                  'comment-form',
  25.                  'comment-list',
  26.                  'gallery',
  27.                  'caption'
  28.              ])
  29.              ->addStyle('theme-styles', get_stylesheet_uri())
  30.              ->addCommentScript();
  31.     }
  32.     public function addSupport($feature, $options = null)
  33.     {
  34.         $this->actionAfterSetup(function() use ($feature, $options) {
  35.             if ($options){
  36.                 add_theme_support($feature, $options);
  37.             } else {
  38.                 add_theme_support($feature);
  39.             }
  40.         });
  41.         return $this;
  42.     }
  43.     public function removeSupport($feature)
  44.     {
  45.         $this->actionAfterSetup(function() use ($feature){
  46.             remove_theme_support($feature);
  47.         });
  48.         return $this;
  49.     }
  50.     public function loadTextDomain($domain, $path = false)
  51.     {
  52.         $this->actionAfterSetup(function() use ($domain, $path){
  53.             load_theme_textdomain($domain, $path);
  54.         });
  55.         return $this;
  56.     }
  57.     public function addImageSize($name, $width = 0, $height = 0, $crop = false)
  58.     {
  59.         $this->actionAfterSetup(function() use ($name, $width, $height, $crop){
  60.             add_image_size($name, $width, $height, $crop);
  61.         });
  62.         return $this;
  63.     }
  64.     public function removeImageSize($name)
  65.     {
  66.         $this->actionAfterSetup(function() use ($name){
  67.             remove_image_size($name);
  68.         });
  69.         return $this;
  70.     }
  71.     public function addStyle($handle,  $src = '',  $deps = array(), $ver = false, $media = 'all')
  72.     {
  73.         $this->actionEnqueueScripts(function() use ($handle, $src, $deps, $ver, $media){
  74.             wp_enqueue_style($handle,  $src,  $deps, $ver, $media);
  75.         });
  76.         return $this;
  77.     }
  78.     public function addScript($handle,  $src = '',  $deps = array(), $ver = false, $in_footer = false)
  79.     {
  80.         $this->actionEnqueueScripts(function() use ($handle, $src, $deps, $ver, $in_footer){
  81.             wp_enqueue_script($handle,  $src,  $deps, $ver, $in_footer);
  82.         });
  83.         return $this;
  84.     }
  85.     public function addCommentScript()
  86.     {
  87.         $this->actionEnqueueScripts(function(){
  88.             if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  89.                 wp_enqueue_script( 'comment-reply' );
  90.             }
  91.         });
  92.         return $this;
  93.     }
  94.     public function removeStyle($handle)
  95.     {
  96.         $this->actionEnqueueScripts(function() use ($handle){
  97.             wp_dequeue_style($handle);
  98.             wp_deregister_style($handle);
  99.         });
  100.         return $this;
  101.     }
  102.     public function removeScript($handle)
  103.     {
  104.         $this->actionEnqueueScripts(function() use ($handle){
  105.             wp_dequeue_script($handle);
  106.             wp_deregister_script($handle);  
  107.         });
  108.         return $this;
  109.     }
  110.     public function addNavMenus($locations = array())
  111.     {
  112.         $this->actionAfterSetup(function() use ($locations){
  113.             register_nav_menus($locations);
  114.         });
  115.         return $this;
  116.     }
  117.     public function addNavMenu($location, $description)
  118.     {
  119.         $this->actionAfterSetup(function() use ($location, $description){
  120.             register_nav_menu($location, $description);
  121.         });
  122.         return $this;
  123.     }
  124.     public function removeNavMenu($location){
  125.         $this->actionAfterSetup(function() use ($location){
  126.        unregister_nav_menu($location);
  127.         });
  128.         return $this;
  129.     }
  130. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top