示例#1
0
 /**
  * Registers the custom post type
  *
  * @mvc Controller
  */
 public static function create_post_type()
 {
     if (!post_type_exists(POST_TYPE_SLUG)) {
         $post_type_params = self::get_post_type_params();
         $post_type = register_post_type(POST_TYPE_SLUG, $post_type_params);
         // CPT columns (Ohad Raz Class)
         $post_columns = new CPT_columns(POST_TYPE_SLUG, true);
         // $post_columns->_column_orderby( (object) array('orderby' => 'date') );
         $post_columns->add_column('cb', array('label' => __(''), 'type' => 'cb'));
         $post_columns->add_column('post_thumb', array('label' => __(''), 'type' => 'thumb', 'size' => array('50,50')));
         $post_columns->add_column('title', array('label' => __('title'), 'type' => 'native', 'sortable' => true));
         $post_columns->add_column('custom_tax_id', array('label' => __('OSmedia video category'), 'type' => 'custom_tax', 'taxonomy' => TAG_SLUG));
         $post_columns->add_column('tags', array('label' => __('tag'), 'type' => 'tags'));
         $post_columns->add_column('comments', array('label' => __('comments'), 'type' => 'comments'));
         $post_columns->add_column('date', array('label' => __('date'), 'type' => 'date', 'sortable' => true));
         if (is_wp_error($post_type)) {
             add_notice(__METHOD__ . ' error: ' . $post_type->get_error_message(), 'error');
         }
     }
 }
 /**
  * Initialize the plugin by loading admin scripts & styles and adding a
  * settings page and menu.
  *
  * @since     1.0.0
  */
 private function __construct()
 {
     /*
      * @TODO :
      *
      * - Uncomment following lines if the admin class should only be available for super admins
      */
     /* if( ! is_super_admin() ) {
     	  return;
     	  } */
     /*
      * Call $plugin_slug from public plugin class.
      *
      * @TODO:
      *
      * - Rename "Plugin_Name" to the name of your initial plugin class
      *
      */
     $plugin = Plugin_Name::get_instance();
     $this->plugin_slug = $plugin->get_plugin_slug();
     $this->plugin_name = $plugin->get_plugin_name();
     $this->version = $plugin->get_plugin_version();
     $this->cpts = $plugin->get_cpts();
     // Load admin style sheet and JavaScript.
     add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_styles'));
     add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'));
     // Load admin style in dashboard for the At glance widget
     add_action('admin_head-index.php', array($this, 'enqueue_admin_styles'));
     // At Glance Dashboard widget for your cpts
     add_filter('dashboard_glance_items', array($this, 'cpt_dashboard_support'), 10, 1);
     // Add the options page and menu item.
     add_action('admin_menu', array($this, 'add_plugin_admin_menu'));
     //Add bubble notification for cpt pending
     add_action('admin_menu', array($this, 'pending_cpt_bubble'), 999);
     // Add an action link pointing to the options page.
     $plugin_basename = plugin_basename(plugin_dir_path(realpath(dirname(__FILE__))) . $this->plugin_slug . '.php');
     add_filter('plugin_action_links_' . $plugin_basename, array($this, 'add_action_links'));
     /*
      * CMB 2 for metabox and many other cool things!
      * https://github.com/WebDevStudios/CMB2
      * Also CMB2 Shortcode support 
      * Check on the repo for the example and documentation 
      * https://github.com/jtsternberg/Shortcode_Button
      */
     require_once plugin_dir_path(__FILE__) . '/includes/CMB2/init.php';
     require_once plugin_dir_path(__FILE__) . '/includes/CMB2-Shortcode/shortcode-button.php';
     /*
      * Add metabox
      */
     add_action('cmb2_init', array($this, 'cmb_demo_metaboxes'));
     /*
      * Define custom functionality.
      *
      * Read more about actions and filters:
      * http://codex.wordpress.org/Plugin_API#Hooks.2C_Actions_and_Filters
      */
     add_action('@TODO', array($this, 'action_method_name'));
     add_filter('@TODO', array($this, 'filter_method_name'));
     //Add the export settings method
     add_action('admin_init', array($this, 'settings_export'));
     //Add the import settings method
     add_action('admin_init', array($this, 'settings_import'));
     /*
      * Debug mode
      */
     require_once plugin_dir_path(__FILE__) . 'includes/debug.php';
     $debug = new Pn_Debug($this);
     $debug->log(__('Plugin Loaded', $this->plugin_slug));
     /*
      * Load Wp_Contextual_Help for the help tabs
      */
     add_filter('wp_contextual_help_docs_dir', array($this, 'help_docs_dir'));
     add_filter('wp_contextual_help_docs_url', array($this, 'help_docs_url'));
     if (!class_exists('WP_Contextual_Help')) {
         require_once plugin_dir_path(__FILE__) . 'includes/WP-Contextual-Help/wp-contextual-help.php';
     }
     add_action('init', array($this, 'contextual_help'));
     /*
      * Load Wp_Admin_Notice for the notices in the backend
      * 
      * First parameter the HTML, the second is the css class
      */
     if (!class_exists('WP_Admin_Notice')) {
         require_once plugin_dir_path(__FILE__) . 'includes/WP-Admin-Notice/WP_Admin_Notice.php';
     }
     new WP_Admin_Notice(__('Updated Messages'), 'updated');
     new WP_Admin_Notice(__('Error Messages'), 'error');
     /*
      * Load PointerPlus for the Wp Pointer
      * 
      * Unique paramter is the prefix
      */
     if (!class_exists('PointerPlus')) {
         require_once plugin_dir_path(__FILE__) . 'includes/PointerPlus/class-pointerplus.php';
     }
     $pointerplus = new PointerPlus(array('prefix' => $this->plugin_slug));
     //With this you can reset all the pointer with your prefix
     //$pointerplus->reset_pointer();
     add_filter('pointerplus_list', array($this, 'custom_initial_pointers'), 10, 2);
     /*
      * Load CPT_Columns
      * 
      * Check the file for example
      */
     require_once plugin_dir_path(__FILE__) . 'includes/CPT_Columns.php';
     $post_columns = new CPT_columns('demo');
     $post_columns->add_column('cmb2_field', array('label' => __('CMB2 Field'), 'type' => 'post_meta', 'meta_key' => '_demo_' . $this->plugin_slug . '_text', 'orderby' => 'meta_value', 'sortable' => true, 'prefix' => "<b>", 'suffix' => "</b>", 'def' => "Not defined", 'order' => "-1"));
 }