Exemple #1
0
 /**
  * Update rewrite rules if possible
  */
 public function admin_init()
 {
     if (!AjaxBase::is_ajax() && current_user_can('manage_options')) {
         if (!empty($this->classes)) {
             $rewrites = '';
             foreach ($this->classes as $class_name) {
                 $rewrites .= $this->get_prefix($class_name);
             }
             $rewrites = md5($rewrites);
             if (get_option('rewrite_rules') && $this->rewrite_md5 != $rewrites) {
                 flush_rewrite_rules();
                 $last_updated = current_time('timestamp');
                 update_option($this->option_name, $last_updated);
                 update_option($this->rewrite_md5_name, $rewrites);
                 $message = sprintf($this->__('Rewrite rules updated. Last modified date is %s'), date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $last_updated));
                 add_action('admin_notices', function () use($message) {
                     printf('<div class="updated"><p>%s</p></div>', $message);
                 });
             }
         }
     }
 }
Exemple #2
0
 /**
  * Register ajax actions
  */
 public function ajax_register()
 {
     if (AjaxBase::is_ajax()) {
         foreach ($this->ajax_controllers as $class_name) {
             /** @var AjaxBase $instance */
             $instance = $class_name::get_instance();
             $instance->register();
         }
     }
 }