/**
  * Initialize the plugin by loading admin scripts & styles and adding a
  * settings page and menu.
  *
  * @since     1.0
  */
 private function __construct()
 {
     /*
      * Call $plugin_slug from public plugin class.
      *
      */
     $plugin = add_post_type_instructions::get_instance();
     $this->plugin_slug = $plugin->get_plugin_slug();
     // Add the options page
     require_once plugin_dir_path(__FILE__) . 'includes/settings.php';
     // Add the menu item.
     add_action('admin_menu', array($this, 'add_plugin_admin_menu'));
     // Add an action link pointing to the options page.
     $plugin_basename = plugin_basename(plugin_dir_path(realpath(dirname(__FILE__))) . 'add-post-type-instructions.php');
     add_filter('plugin_action_links_' . $plugin_basename, array($this, 'add_action_links'));
     // Fire functions
     add_action('admin_print_styles', array($this, 'is_edit_page'));
     add_action('edit_form_top', array($this, 'add_content_above_title'));
     add_action('edit_form_after_title', array($this, 'add_content_above_editor'));
     add_filter('default_content', array($this, 'change_editor_content'));
     add_action('admin_head', array($this, 'change_publish_metabox_content'));
     add_action('admin_head', array($this, 'change_author_metabox_content'));
     add_filter('admin_post_thumbnail_html', array($this, 'change_thumbnail_metabox_content'));
     add_action('admin_head', array($this, 'change_excerpt_metabox_content'));
     add_action('admin_head', array($this, 'change_trackbacks_metabox_content'));
     add_action('admin_head', array($this, 'change_customfields_metabox_content'));
     add_action('admin_head', array($this, 'change_comments_metabox_content'));
     add_action('admin_head', array($this, 'change_discussion_metabox_content'));
     add_action('admin_head', array($this, 'change_revisions_metabox_content'));
     add_action('admin_head', array($this, 'change_pageattributes_metabox_content'));
     add_action('admin_head', array($this, 'change_categories_metabox_content'));
     add_action('admin_head', array($this, 'change_tags_metabox_content'));
     add_action('admin_head', array($this, 'change_postformats_metabox_content'));
     add_action('admin_head', array($this, 'change_slug_metabox_content'));
 }
예제 #2
0
 /**
  * Registering the Sections, Fields, and Settings.
  *
  * This function is registered with the 'admin_init' hook.
  */
 public function admin_init()
 {
     $plugin = add_post_type_instructions::get_instance();
     $post_types = $plugin->supported_post_types();
     $defaults = array('top' => '', 'instruction' => '', 'editor' => '', 'publish' => '', 'author' => '', 'thumbnail' => '', 'excerpt' => '', 'trackbacks' => '', 'custom-fields' => '', 'comments' => '', 'discussion' => '', 'revisions' => '', 'page-attributes' => '', 'categories' => '', 'tags' => '', 'post-formats' => '', 'slug' => '');
     foreach ($post_types as $pt) {
         $post_object = get_post_type_object($pt);
         $section = $this->plugin_slug . '_' . $pt;
         if (false == get_option($section)) {
             add_option($section, apply_filters($section . '_default_settings', $defaults));
         }
         $args = array($section, get_option($section));
         add_settings_section($pt, sprintf(__('Set instructional content for all %s', $this->plugin_slug), $post_object->labels->name), '', $section);
         if (post_type_supports($pt, 'title')) {
             add_settings_field('top_check', __('Above Title Field:', $this->plugin_slug), array($this, 'top_check_callback'), $section, $pt, $args);
             add_settings_field('top', __('', $this->plugin_slug), array($this, 'top_callback'), $section, $pt, $args);
         }
         add_settings_field('instruction_check', __('Above WYSIWYG Editor:', $this->plugin_slug), array($this, 'instruction_check_callback'), $section, $pt, $args);
         add_settings_field('instruction', __('', $this->plugin_slug), array($this, 'instruction_callback'), $section, $pt, $args);
         if (post_type_supports($pt, 'editor')) {
             add_settings_field('editor_check', __('WYSIWYG Content:', $this->plugin_slug), array($this, 'editor_check_callback'), $section, $pt, $args);
             add_settings_field('editor', __('', $this->plugin_slug), array($this, 'editor_callback'), $section, $pt, $args);
         }
         add_settings_field('publish_check', __('Publish Metabox:', $this->plugin_slug), array($this, 'publish_check_callback'), $section, $pt, $args);
         add_settings_field('publish', __('', $this->plugin_slug), array($this, 'publish_callback'), $section, $pt, $args);
         if (post_type_supports($pt, 'author')) {
             add_settings_field('author_check', __('Author Metabox:', $this->plugin_slug), array($this, 'author_check_callback'), $section, $pt, $args);
             add_settings_field('author', __('', $this->plugin_slug), array($this, 'author_callback'), $section, $pt, $args);
         }
         if (post_type_supports($pt, 'thumbnail')) {
             add_settings_field('thumbnail_check', __('Featured Image Metabox:', $this->plugin_slug), array($this, 'thumbnail_check_callback'), $section, $pt, $args);
             add_settings_field('thumbnail', __('', $this->plugin_slug), array($this, 'thumbnail_callback'), $section, $pt, $args);
         }
         if (post_type_supports($pt, 'excerpt')) {
             add_settings_field('excerpt_check', __('Excerpt Metabox:', $this->plugin_slug), array($this, 'excerpt_check_callback'), $section, $pt, $args);
             add_settings_field('excerpt', __('', $this->plugin_slug), array($this, 'excerpt_callback'), $section, $pt, $args);
         }
         if (post_type_supports($pt, 'trackbacks')) {
             add_settings_field('trackbacks_check', __('Trackbacks Metabox:', $this->plugin_slug), array($this, 'trackbacks_check_callback'), $section, $pt, $args);
             add_settings_field('trackbacks', __('', $this->plugin_slug), array($this, 'trackbacks_callback'), $section, $pt, $args);
         }
         if (post_type_supports($pt, 'custom-fields')) {
             add_settings_field('customfields_check', __('Custom Fields Metabox:', $this->plugin_slug), array($this, 'customfields_check_callback'), $section, $pt, $args);
             add_settings_field('customfields', __('', $this->plugin_slug), array($this, 'customfields_callback'), $section, $pt, $args);
         }
         if (post_type_supports($pt, 'comments')) {
             add_settings_field('comments_check', __('Comments Metabox:', $this->plugin_slug), array($this, 'comments_check_callback'), $section, $pt, $args);
             add_settings_field('comments', __('', $this->plugin_slug), array($this, 'comments_callback'), $section, $pt, $args);
             add_settings_field('discussion_check', __('Discussion Metabox:', $this->plugin_slug), array($this, 'discussion_check_callback'), $section, $pt, $args);
             add_settings_field('discussion', __('', $this->plugin_slug), array($this, 'discussion_callback'), $section, $pt, $args);
         }
         if (post_type_supports($pt, 'revisions')) {
             add_settings_field('revisions_check', __('Revisions Metabox:', $this->plugin_slug), array($this, 'revisions_check_callback'), $section, $pt, $args);
             add_settings_field('revisions', __('', $this->plugin_slug), array($this, 'revisions_callback'), $section, $pt, $args);
         }
         if (post_type_supports($pt, 'page-attributes')) {
             add_settings_field('pageattributes_check', __('Page Attributes Metabox:', $this->plugin_slug), array($this, 'pageattributes_check_callback'), $section, $pt, $args);
             add_settings_field('pageattributes', __('', $this->plugin_slug), array($this, 'pageattributes_callback'), $section, $pt, $args);
         }
         if (!($pt == 'page')) {
             if (is_object_in_taxonomy($pt, 'category')) {
                 add_settings_field('categories_check', __('Categories Metabox:', $this->plugin_slug), array($this, 'categories_check_callback'), $section, $pt, $args);
                 add_settings_field('categories', __('', $this->plugin_slug), array($this, 'categories_callback'), $section, $pt, $args);
             }
             if (is_object_in_taxonomy($pt, 'post_tag')) {
                 add_settings_field('tags_check', __('Tags Metabox:', $this->plugin_slug), array($this, 'tags_check_callback'), $section, $pt, $args);
                 add_settings_field('tags', __('', $this->plugin_slug), array($this, 'tags_callback'), $section, $pt, $args);
             }
             // custom taxonomies
             if (post_type_supports($pt, 'post-formats')) {
                 add_settings_field('postformats_check', __('Post Format Metabox:', $this->plugin_slug), array($this, 'postformats_check_callback'), $section, $pt, $args);
                 add_settings_field('postformats', __('', $this->plugin_slug), array($this, 'postformats_callback'), $section, $pt, $args);
             }
         }
         add_settings_field('slug_check', __('Slug Metabox:', $this->plugin_slug), array($this, 'slug_check_callback'), $section, $pt, $args);
         add_settings_field('slug', __('', $this->plugin_slug), array($this, 'slug_callback'), $section, $pt, $args);
         register_setting($section, $section);
     }
 }
예제 #3
0
?>

<!-- Create a header in the default WordPress 'wrap' container -->
<div class="wrap">

	<div id="icon-themes" class="icon32"></div>
	<h2><?php 
echo esc_html(get_admin_page_title()) . ' Settings';
?>
</h2>
	<?php 
// settings_errors();
?>

	<?php 
$plugin = add_post_type_instructions::get_instance();
$post_types = $plugin->supported_post_types();
if (isset($_GET['tab'])) {
    $active_tab = $_GET['tab'];
} else {
    $active_tab = isset($post_types[0]) ? $post_types[0] : '';
}
?>

	<h2 class="nav-tab-wrapper">
		<?php 
foreach ($post_types as $pt) {
    ?>
		<a href="?page=<?php 
    echo $plugin->get_plugin_slug();
    ?>
 /**
  * Return an instance of this class.
  *
  * @since     1.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;
 }