/** * 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 = post_type_requirements_checklist::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__))) . 'post-type-requirements-checklist.php'); add_filter('plugin_action_links_' . $plugin_basename, array($this, 'add_action_links')); // Fire functions add_action('admin_enqueue_scripts', array($this, 'is_edit_page')); add_action('post_submitbox_misc_actions', array($this, 'insert_publish_metabox_checklist')); }
?> <!-- 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 = post_type_requirements_checklist::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(); ?>
/** * Registering the Sections, Fields, and Settings. * * This function is registered with the 'admin_init' hook. */ public function admin_init() { $plugin = post_type_requirements_checklist::get_instance(); $post_types = $plugin->supported_post_types(); $defaults = array('title' => '', 'editor' => '', 'thumbnail' => '', 'excerpt' => '', 'categories' => '', 'tags' => '', 'customtaxonomies' => '', 'customfields' => ''); 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)); // CONTENT REQUIREMENTS // section add_settings_section($pt, __('Default Content Requirements', 'aptrc') . ':', '', $section); // title field if (post_type_supports($pt, 'title')) { add_settings_field('title_check', __('Title', 'aptrc') . ':', array($this, 'title_check_callback'), $section, $pt, $args); } // wysiwyg editor if (post_type_supports($pt, 'editor')) { add_settings_field('editor_check', __('WYSIWYG Editor', 'aptrc') . ':', array($this, 'editor_check_callback'), $section, $pt, $args); } // featured image if (post_type_supports($pt, 'thumbnail')) { add_settings_field('thumbnail_check', __('Featured Image', 'aptrc') . ':', array($this, 'thumbnail_check_callback'), $section, $pt, $args); } // excerpt if (post_type_supports($pt, 'excerpt')) { add_settings_field('excerpt_check', __('Excerpt', 'aptrc') . ':', array($this, 'excerpt_check_callback'), $section, $pt, $args); } // TAXONOMY REQUIREMENTS if ('page' != $pt) { // pages don't have taxonomies $objtaxs = get_object_taxonomies($pt); if (!($objtaxs == null)) { // section add_settings_section('tax_' . $pt, '<hr>' . __('Taxonomy Requirements', 'aptrc') . ':', '', $section); // taxonomy tip add_settings_field('CatTagTip', '', array($this, 'CatTagTip'), $section, 'tax_' . $pt, $args); } } // category if (is_object_in_taxonomy($pt, 'category')) { add_settings_field('categories_check', __('Categories', 'aptrc') . ':', array($this, 'categories_check_callback'), $section, 'tax_' . $pt, $args); // minimum add_settings_field('categories_dropdown', '', array($this, 'categories_dropdown_callback'), $section, 'tax_' . $pt, $args); // maximum add_settings_field('categories_max_dropdown', '', array($this, 'categories_max_dropdown_callback'), $section, 'tax_' . $pt, $args); } // tag if (is_object_in_taxonomy($pt, 'post_tag')) { add_settings_field('tags_check', __('Tags', 'aptrc') . ':', array($this, 'tags_check_callback'), $section, 'tax_' . $pt, $args); // minimum add_settings_field('tags_dropdown', '', array($this, 'tags_dropdown_callback'), $section, 'tax_' . $pt, $args); // maximum add_settings_field('tags_max_dropdown', '', array($this, 'tags_max_dropdown_callback'), $section, 'tax_' . $pt, $args); } // CUSTOM TAXONOMIES // get all taxonomies in a post type $argums = array('public' => true, '_builtin' => false); $outputs = 'names'; // or objects $operators = 'and'; // 'and' or 'or' $taxonomy_names = get_taxonomies($argums, $outputs, $operators); $x = '1'; foreach ($taxonomy_names as $tn) { // get that taxonomy's objects (so we can output the label later for plural name) $thingargums = array('name' => $tn); $thingoutputs = 'objects'; // or names $things = get_taxonomies($thingargums, $thingoutputs); foreach ($things as $thing) { if (is_object_in_taxonomy($pt, $tn)) { // categories are hierarchical if (is_taxonomy_hierarchical($tn)) { add_settings_field('hierarchical_check_' . $x, $thing->label . ' <span>(' . __('category', 'aptrc') . '):</span>', array($this, 'hierarchical_check_callback_' . $x), $section, 'tax_' . $pt, $args); // minimum add_settings_field('hierarchical_dropdown_' . $x, '', array($this, 'hierarchical_dropdown_callback_' . $x), $section, 'tax_' . $pt, $args); // maximum add_settings_field('hierarchical_max_dropdown_' . $x, '', array($this, 'hierarchical_max_dropdown_callback_' . $x), $section, 'tax_' . $pt, $args); } else { add_settings_field('flat_check' . $x, $thing->label . ' <span>(' . __('tag', 'aptrc') . '):</span>', array($this, 'flat_check_callback_' . $x), $section, 'tax_' . $pt, $args); // minimum add_settings_field('flat_dropdown' . $x, '', array($this, 'flat_dropdown_callback_' . $x), $section, 'tax_' . $pt, $args); // maximum add_settings_field('flat_max_dropdown_' . $x, '', array($this, 'flat_max_dropdown_callback_' . $x), $section, 'tax_' . $pt, $args); } } } $x++; // advance } // * @since 2.3 // CUSTOM FIELD REQUIREMENTS /* // get a random post from this post type (we're still in the post type loop) $field_post_args = array( 'post_type' => $pt, // look in our post type (from the loop) 'posts_per_page' => 1, // get a random post (should have custom fields for our post type) ); $id_ptrc_posts = get_posts( $field_post_args ); foreach ( $id_ptrc_posts as $post ) { $custom_post_id = $post->ID; // get our random post's ID $getFieldsCustom = get_post_custom_values( $key = '', $post_id = $custom_post_id ); // get array of custom fields in this post type * sort of * // trim key values that are internal to WP unset( $getFieldsCustom['_edit_lock'] ); unset( $getFieldsCustom['_edit_last'] ); // unset( $getFieldsCustom['_mini_post'] ); unset( $getFieldsCustom['_thumbnail_id'] ); if ( !( $getFieldsCustom == null ) ) { // if our post type has any custom fields... // section add_settings_section( 'fields_' . $pt, '<hr>' . __( 'Custom Field Requirements', 'aptrc' ) .':', '', $section ); // custom fields tip add_settings_field( 'FieldsTip', __( '', 'aptrc' ), array( $this, 'FieldsTip' ), $section, 'fields_' . $pt, $args ); foreach ( $getFieldsCustom as $ptrc_cf ) { add_settings_field( 'fields' . $ptrc_cf, __( $ptrc_cf . ':', 'aptrc' ), array( $this, '' . $ptrc_cf ), $section, 'fields_' . $pt, $args ); } } } */ // section add_settings_section('3rdparty' . $pt, '<hr>' . __('3rd Party Plugin Support', 'aptrc') . ':', '', $section); // * @since 2.3 // 3RD PARTY PLUGIN SUPPORT // WP SEO by Yoast if (class_exists('WPSEO_Utils')) { // focus keyword add_settings_field('yoastseo_focus_keyword', __('WordPress SEO by Yoast', 'aptrc') . ':', array($this, 'yoastseo_focus_keyword_callback'), $section, '3rdparty' . $pt, $args); // meta description add_settings_field('yoastseo_meta_description', '', array($this, 'yoastseo_meta_description_callback'), $section, '3rdparty' . $pt, $args); } // All In One SEO if (class_exists('All_in_One_SEO_Pack')) { // title add_settings_field('allinone_title', __('All In One SEO Pack', 'aptrc') . ':', array($this, 'allinone_title_callback'), $section, '3rdparty' . $pt, $args); // description add_settings_field('allinone_description', '', array($this, 'allinone_description_callback'), $section, '3rdparty' . $pt, $args); // keywords add_settings_field('allinone_keywords', '', array($this, 'allinone_keywords_callback'), $section, '3rdparty' . $pt, $args); } register_setting($section, $section); } }
/** * 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; }