Пример #1
0
 public static function init()
 {
     self::$cache_base_key = theme_functions::$iden;
     add_action('advanced_settings', __CLASS__ . '::display_backend');
     add_action('wp_ajax_' . __CLASS__, __CLASS__ . '::process');
     /**
      * When update menu
      */
     add_filter('pre_set_theme_mod_nav_menu_locations', function ($return) {
         self::delete_keys('nav-menu');
         return $return;
     });
     /**
      * When update widget
      */
     add_filter('widget_update_callback', function ($instance) {
         self::delete_keys('dynamic-sidebar');
         return $instance;
     });
     /**
      * When update option for widget
      */
     add_action('update_option_sidebars_widgets', function () {
         self::delete_keys('dynamic-sidebar');
     });
     /**
      * when post delete
      */
     add_action('delete_post', function ($post_id) {
         $post = self::get_post($post_id);
         if ($post->type !== 'page') {
             return;
         }
         $caches = (array) wp_cache_get('pages_by_path');
         if (isset($caches[$post->post_name])) {
             unset($caches[$post->post_name]);
             wp_cache_set('pages_by_path', $caches);
         }
     });
     /**
      * when post save
      */
     add_action('save_post', function ($post_id) {
         $post = self::get_post($post_id);
         if ($post->type !== 'page') {
             return;
         }
         $caches = (array) wp_cache_get('pages_by_path');
         if (!isset($caches[$post->post_name])) {
             $caches[$post->post_name] = $post_id;
             wp_cache_set('pages_by_path', $caches);
         }
     });
 }