Example #1
0
 /**
  * Return an instance of this class.
  *
  * @since     1.0.0
  *
  * @return    object    A single instance of this class.
  */
 public static function get_instance()
 {
     // If the single instance hasn't been set, set it now.
     if (null == self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
 /**
  * Initialize the plugin by loading admin scripts & styles and adding a settings page and menu.
  *
  * @since     1.0.0
  */
 private function __construct()
 {
     /**
      * Call $plugin_slug from public plugin class
      */
     $plugin = Mark_Posts::get_instance();
     $this->plugin_slug = $plugin->get_plugin_slug();
     $get_mark_posts_setup = get_option('mark_posts_settings');
     // Load admin style sheet and JavaScript
     add_action('admin_enqueue_scripts', array($this, 'mark_posts_enqueue_admin_styles'));
     add_action('admin_enqueue_scripts', array($this, 'mark_posts_enqueue_admin_scripts'));
     // Add the options page and menu item
     add_action('admin_menu', array($this, 'mark_posts_add_plugin_admin_menu'));
     /**
      * Add dashboard
      *
      * @since    1.0.8
      */
     if (isset($get_mark_posts_setup['mark_posts_dashboard'])) {
         $mark_posts_dashboard = $get_mark_posts_setup['mark_posts_dashboard'];
         if (!empty($mark_posts_dashboard)) {
             add_action('wp_dashboard_setup', array($this, 'mark_posts_dashboard_widget'));
         }
     }
     // Add an action link pointing to the options page
     $plugin_basename = plugin_basename(plugin_dir_path(__DIR__) . $this->plugin_slug . '.php');
     add_filter('plugin_action_links_' . $plugin_basename, array($this, 'mark_posts_add_action_links'));
     // Add quick edit and bulk edit actions
     add_action('bulk_edit_custom_box', array($this, 'mark_posts_display_quickedit_box'), 10, 2);
     add_action('quick_edit_custom_box', array($this, 'mark_posts_display_quickedit_box'), 10, 2);
     // Add JavaScript for quick edit and bulk edit actions
     add_action('admin_print_scripts-edit.php', array($this, 'mark_posts_edit_scripts'), 10, 2);
     // Add metabox
     add_action('add_meta_boxes', array($this, 'mark_posts_add_meta_box'));
     // Save action for metabox
     add_action('save_post', array($this, 'mark_posts_save'));
     // Save action for quick edit
     add_action('save_post', array($this, 'mark_posts_save_quick_edit'), 10, 2);
     // Save action for bulk edit
     add_action('wp_ajax_mark_posts_save_bulk_edit', array($this, 'mark_posts_save_bulk_edit'));
     // Trash action
     add_action('trash_post', array($this, 'mark_posts_trash'), 1, 1);
     // Delete action
     add_action('delete_post', array($this, 'mark_posts_delete'), 10);
     /**
      * Custom admin post columns (custom post types only)
      *
      * @since    1.0.0
      */
     $mark_posts_posttypes = $get_mark_posts_setup['mark_posts_posttypes'];
     foreach ($mark_posts_posttypes as $post_type) {
         add_filter('manage_' . $post_type . '_posts_columns', array($this, 'mark_posts_column_head'), 10, 2);
         add_action('manage_' . $post_type . '_posts_custom_column', array($this, 'mark_posts_column_content'), 10, 2);
     }
 }