/**
  * Returns the Singleton instance.
  *
  * @since 1.0.0
  * @access public
  * @static
  *
  * @return Attachment_Taxonomies The Singleton class instance.
  */
 public static function instance()
 {
     if (null === self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
示例#2
0
                    continue;
                }
                if (is_dir($dir . '/' . $file)) {
                    if (in_array($file, $valid_subdirs, true)) {
                        $subdirs[] = $dir . '/' . $file;
                    }
                } elseif ('.php' === substr($file, -4)) {
                    require_once $dir . '/' . $file;
                }
            }
            @closedir($inc_dir);
            foreach ($subdirs as $subdir) {
                $this->autoload_manual($subdir);
            }
        }
    }
    public function get_path($rel_path)
    {
        return plugin_dir_path(__FILE__) . $this->base_path_relative . ltrim($rel_path, '/');
    }
    public function get_url($rel_path)
    {
        return plugin_dir_url(__FILE__) . $this->base_path_relative . ltrim($rel_path, '/');
    }
    private function get_subdirs()
    {
        return array('admin' => 'admin', 'tab' => 'tabs', 'subtab' => 'subtabs', 'api' => 'api', 'endpoint' => 'endpoints');
    }
}
Attachment_Taxonomies::instance();
 public function test_remove_taxonomy()
 {
     $status = Attachment_Taxonomies::instance()->remove_taxonomy('attachment_category');
     $this->assertTrue($status);
 }
 /**
  * Enqueues the plugin's JavaScript file.
  *
  * The script handles attachment taxonomies through Backbone, allowing filtering by and managing
  * these taxonomies through the media library and media modal.
  *
  * This method is hooked into the `wp_enqueue_media` action.
  *
  * @since 1.0.0
  * @access public
  */
 public function enqueue_script()
 {
     if (!$this->has_taxonomies()) {
         return;
     }
     $taxonomies = array();
     $all_items = array();
     $filter_by_item = array();
     foreach ($this->get_taxonomies('objects') as $taxonomy_slug => $taxonomy) {
         if (!$taxonomy->query_var) {
             continue;
         }
         $js_slug = $this->make_js_slug($taxonomy_slug);
         $taxonomies[] = $this->prepare_taxonomy_for_js($taxonomy_slug, $taxonomy);
         $all_items[$js_slug] = $taxonomy->labels->all_items;
         $filter_by_item[$js_slug] = $this->get_filter_by_label($taxonomy);
     }
     $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
     wp_enqueue_script('attachment-taxonomies', Attachment_Taxonomies::instance()->get_url('assets/dist/js/library' . $min . '.js'), array('jquery', 'media-views'), Attachment_Taxonomies::VERSION, true);
     wp_localize_script('attachment-taxonomies', '_attachment_taxonomies', array('data' => $taxonomies, 'l10n' => array('all' => $all_items, 'filterBy' => $filter_by_item)));
 }