/wordpress/wp-content/plugins/custom-content-type-manager/includes/CCTM.php
PHP | 1875 lines | 1117 code | 227 blank | 531 comment | 187 complexity | b0e73917690e62458f7fb3e62d090865 MD5 | raw file
Possible License(s): Apache-2.0, AGPL-1.0, GPL-2.0, GPL-3.0, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- <?php
- /*------------------------------------------------------------------------------
- CCTM = Custom Content Type Manager
- This is the main class for the Custom Content Type Manager plugin.
- This class handles the creation and management of custom post-types (also
- referred to as 'content-types'). It requires the FormGenerator.php,
- StandardizedCustomFields.php, and the CCTMtests.php files/classes to work.
- Post Thumbnails support is post-type specific:
- http://markjaquith.wordpress.com/2009/12/23/new-in-wordpress-2-9-post-thumbnail-images/
- ------------------------------------------------------------------------------*/
- class CCTM {
- // Name of this plugin
- const name = 'Custom Content Type Manager';
-
- // Required versions (referenced in the CCTMtest class).
- const wp_req_ver = '3.0.1';
- const php_req_ver = '5.2.6';
- const mysql_req_ver = '4.1.2';
- // Used to uniquely identify an option_name in the wp_options table
- // ALL data describing the post types and their custom fields lives there.
- // DELETE FROM `wp_options` WHERE option_name='custom_content_types_mgr_data';
- // would clean out everything this plugin knows.
- const db_key = 'custom_content_types_mgr_data';
- // Used to uniquely identify this plugin's menu page in the WP manager
- const admin_menu_slug = 'cctm';
- // These parameters identify where in the $_GET array we can find the values
- // and how URLs are constructed, e.g. some-admin-page.php?a=123&pt=xyz
- const action_param = 'a';
- const post_type_param = 'pt';
- const FormElement_classname_prefix = 'CCTM_';
-
- // Data object stored in the wp_options table representing all primary data
- // for post_types and custom fields
- public static $data = array();
-
- // integer iterator used to uniquely identify groups of field definitions for
- // CSS and $_POST variables
- public static $def_i = 0;
- // Where are the icons for custom images stored?
- // TODO: let the users select their own dir in their own directory
- public static $custom_field_icons_dir;
- // Built-in post-types that can have custom fields, but cannot be deleted.
- public static $built_in_post_types = array('post', 'page');
- // Names that are off-limits for custom post types b/c they're already used by WP
- public static $reserved_post_types = array('post', 'page', 'attachment', 'revision'
- , 'nav_menu', 'nav_menu_item');
- // Custom field names are not allowed to use the same names as any column in wp_posts
- public static $reserved_field_names = array('ID', 'post_author', 'post_date', 'post_date_gmt',
- 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status',
- 'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt',
- 'post_content_filtered', 'post_parent', 'guid', 'menu_order', 'post_type', 'post_mime_type',
- 'comment_count');
- // Future-proofing: post-type names cannot begin with 'wp_'
- // See: http://codex.wordpress.org/Custom_Post_Types
- // FUTURE: List any other reserved prefixes here (if any)
- public static $reserved_prefixes = array('wp_');
- public static $Errors; // used to store WP_Error object (FUTURE TODO)
- /*------------------------------------------------------------------------------
- This var stores the big definition for the forms that allow users to define
- custom post-types. The form is generated in a way so that when it is posted, it
- can be easily passed to WP's register_post_type() function.
- We populate the value via the setter function, _set_post_type_form_definition(),
- but we do not have a getter. Since we are lazy, and PHP doesn't require
- getters/setters, we would have forgone the setter function if possible, but we
- had to use a setter simply to avoid the PHP syntax errors that would have
- errupted had we tried something like this:
- public $myvar = array( 'val' => __('somevalue') );
- That fails because we can't use the __() function nakedly when declaring a class
- variable. :(
- ------------------------------------------------------------------------------*/
- public static $post_type_form_definition = array();
- /*------------------------------------------------------------------------------
- This array defines the form used for all new custom field definitions.
- The variable is populated via a setter: _set_custom_field_def_template() for
- the same reason as the $post_type_form_definition var above (see above).
- See the _page_manage_custom_fields() function for when and how these forms
- are used and handled.
- ------------------------------------------------------------------------------*/
- public static $custom_field_def_template = array();
- //! Private Functions
- //------------------------------------------------------------------------------
- /**
- * Geared to be backwards compatible with CCTM versions prior to 0.8.8 where
- * custom field defs were stored in numbered arrays instead of keyed off of their
- * unique names.
- *
- * @param mixed $data: full data structure
- * @param string $post_type: the name of this post_type
- * @param string $field_name: the name of the field whose data you want
- * @return array associative array representing a field definition for $field_name
- */
- private static function _get_field_data($data, $post_type, $field_name) {
- if ( empty($data) || empty($data[$post_type]) || empty($data[$post_type]['custom_fields']))
- {
- return array();
- }
- foreach ( $data[$post_type]['custom_fields'] as $tmp => $def )
- {
- if ( $def['name'] == $field_name )
- {
- return $def;
- }
- }
- return array(); // gave up
- }
-
- /*------------------------------------------------------------------------------
- Generate HTML portion of our manage custom fields form. This is in distinction
- to the JS portion of the form, which uses a slightly different format.
- self::$def_i is used to track the definition #. All 5 output fields will use
- the same $def_i number to identify their place in the $_POST array.
- INPUT: $custom_field_defs (mixed) an array of hashes, each hash describing
- a custom field.
- Array
- (
- [1] => Array
- (
- [label] => Rating
- [name] => rating
- [description] => MPAA rating
- [type] => dropdown
- [options] => Array
- (
- [0] => G
- [1] => PG
- [2] => PG-13
- )
- [sort_param] =>
- )
- )
- OUTPUT: An HTML form, length depends on the # of field defs.
- * @return unknown
- */
- private static function _get_field_type_icons() {
- $icons = array();
- if ($handle = opendir(CCTM_PATH.'/images/custom-fields/')) {
- while (false !== ($file = readdir($handle))) {
- if ( !preg_match('/^\./', $file) && preg_match('/\.png$/i', $file) ) {
- $icons[] = $file;
- }
- }
- closedir($handle);
- }
- $output = '';
- $tpl = CCTM_PATH.'/tpls/settings/icon.tpl';
- if ( file_exists($tpl) ) {
- $tpl = file_get_contents($tpl);
- }
- foreach ( $icons as $img ) {
- $output .= FormGenerator::parse($tpl, array('title'=> $img, 'src'=> CCTM_URL.'/images/icons/default/'.$img) );
- }
- return $output;
- }
- //------------------------------------------------------------------------------
- /**
- *
- *
- * @return unknown
- */
- private static function _get_post_type_icons() {
- $icons = array();
- if ($handle = opendir(CCTM_PATH.'/images/icons/default')) {
- while (false !== ($file = readdir($handle))) {
- if ( !preg_match('/^\./', $file) ) {
- $icons[] = $file;
- }
- }
- closedir($handle);
- }
- $output = '';
- $tpl = CCTM_PATH.'/tpls/settings/icon.tpl';
- if ( file_exists($tpl) ) {
- $tpl = file_get_contents($tpl);
- }
- foreach ( $icons as $img ) {
- $output .= FormGenerator::parse($tpl, array('title'=> $img, 'src'=> CCTM_URL.'/images/icons/default/'.$img) );
- }
- return $output;
- }
- /*------------------------------------------------------------------------------
- Designed to safely retrieve scalar elements out of a hash. Don't use this
- if you have a more deeply nested object (e.g. an array of arrays).
- INPUT:
- $hash : an associative array, e.g. array('animal' => 'Cat');
- $key : the key to search for in that array, e.g. 'animal'
- $default (optional) : value to return if the value is not set. Default=''
- OUTPUT: either safely escaped value from the hash or the default value
- ------------------------------------------------------------------------------*/
- /**
- *
- *
- * @param unknown $hash
- * @param unknown $key
- * @param unknown $default (optional)
- * @return unknown
- */
- private static function _get_value($hash, $key, $default='') {
- if ( !isset($hash[$key]) ) {
- return $default;
- }
- else {
- if ( is_array($hash[$key]) ) {
- return $hash[$key];
- }
- // Warning: stripslashes was added to avoid some weird behavior
- else {
- return esc_html(stripslashes($hash[$key]));
- }
- }
- }
- //------------------------------------------------------------------------------
- /**
- SYNOPSIS: checks the custom content data array to see if $post_type exists.
- The $data array is structured something like this:
- $data = array(
- 'movie' => array('name'=>'movie', ... ),
- 'book' => array('name'=>'book', ... ),
- ...
- );
- So we can just check the keys of the main array to see if the post type exists.
- Built-in post types 'page' and 'post' are considered valid (i.e. existing) by
- default, even if they haven't been explicitly defined for use by this plugin
- so long as the 2nd argument, $search_built_ins, is not overridden to false.
- *
- *
- * @param string $post_type the lowercase database slug identifying a post type.
- * @param boolean $search_built_ins (optional) whether or not to search inside the
- $built_in_post_types array.
- * @return boolean indicating whether this is a valid post-type
- */
- private static function _is_existing_post_type($post_type, $search_built_ins=true) {
-
- // If there is no existing data, check against the built-ins
- if ( empty(self::$data) && $search_built_ins ) {
- return in_array($post_type, self::$built_in_post_types);
- }
- // If there's no existing $data and we omit the built-ins...
- elseif ( empty(self::$data) && !$search_built_ins ) {
- return false;
- }
- // Check to see if we've stored this $post_type before
- elseif ( array_key_exists($post_type, self::$data) ) {
- return true;
- }
- // Check the built-ins
- elseif ( $search_built_ins && in_array($post_type, self::$built_in_post_types) ) {
- return true;
- }
- else {
- return false;
- }
- }
- //! Links
- //------------------------------------------------------------------------------
- /**
- *
- *
- * @param string $post_type
- * @return unknown
- */
- private static function _link_activate($post_type) {
- return sprintf(
- '<a href="?page=%s&%s=6&%s=%s" title="%s">%s</a>'
- , self::admin_menu_slug
- , self::action_param
- , self::post_type_param
- , $post_type
- , __('Activate this content type', CCTM_TXTDOMAIN)
- , __('Activate', CCTM_TXTDOMAIN)
- );
- }
- //------------------------------------------------------------------------------
- /**
- * $tpl = sprintf(
- * '<li><a href="?page=%s&%s=9&%s=%s&type=[+field_type+]" title="[+title+]">
- * <img src="[+icon_src+]" class="cctm-field-icon" id="cctm-field-icon-[+field_type+]"/>
- * <br/>[+label+]</a>
- * </li>'
- *
- * @param string $post_type
- * @return unknown
- */
- private static function _link_create_custom_field($post_type) {
- $output = '<ul id="cctm-field-type-selector">';
- $tpl = sprintf(
- '<li><a href="?page=%s&%s=9&%s=%s&type=[+field_type+]" title="[+title+]">
- <img src="[+icon_src+]" class="cctm-field-icon" id="cctm-field-icon-[+field_type+]"/>
- </a>
- <!-- a href="?page=%s&%s=9&%s=%s&type=[+field_type+]" class="button" title="[+title+]">[+label+]</a-->
- </li>'
- , self::admin_menu_slug
- , self::action_param
- , self::post_type_param
- , $post_type
- , self::admin_menu_slug
- , self::action_param
- , self::post_type_param
- , $post_type
- );
- foreach ( self::$custom_field_def_template['type']['options'] as $field_type ) {
- $hash = array();
- $hash['icon_src'] = self::get_custom_icons_src_dir() . $field_type.'.png';
- // Use the default image if necessary
- if (!@fclose(@fopen($hash['icon_src'], 'r'))) {
- $hash['icon_src'] = self::get_custom_icons_src_dir() . 'default.png';
- }
- $hash['field_type'] = $field_type;
- $hash['label'] = ucfirst($field_type);
- $hash['title'] = sprintf( __('Create a %s custom field', CCTM_TXTDOMAIN), $field_type );
- $output .= FormGenerator::parse($tpl, $hash);
- }
- return $output . '</ul>';
- }
- //------------------------------------------------------------------------------
- /**
- *
- *
- * @param string $post_type
- * @return unknown
- */
- private static function _link_deactivate($post_type) {
- return sprintf(
- '<a href="?page=%s&%s=7&%s=%s" title="%s">%s</a>'
- , self::admin_menu_slug
- , self::action_param
- , self::post_type_param
- , $post_type
- , __('Deactivate this content type', CCTM_TXTDOMAIN)
- , __('Deactivate', CCTM_TXTDOMAIN)
- );
- }
- //------------------------------------------------------------------------------
- /**
- *
- *
- * @param string $post_type
- * @return unknown
- */
- private static function _link_delete($post_type) {
- return sprintf(
- '<a href="?page=%s&%s=3&%s=%s" title="%s">%s</a>'
- , self::admin_menu_slug
- , self::action_param
- , self::post_type_param
- , $post_type
- , __('Delete this content type', CCTM_TXTDOMAIN)
- , __('Delete', CCTM_TXTDOMAIN)
- );
- }
- //------------------------------------------------------------------------------
- /**
- * Delete all custom fields for the given post_type
- *
- * @param string $post_type
- * @return string
- */
- private static function _link_reset_all_custom_fields($post_type) {
- return sprintf(
- '<a href="?page=%s&%s=12&%s=%s" title="%s" class="button">%s</a>'
- , self::admin_menu_slug
- , self::action_param
- , self::post_type_param
- , $post_type
- , __('Delete all custom field definitions for this post type', CCTM_TXTDOMAIN)
- , __('Reset Custom Fields', CCTM_TXTDOMAIN)
- );
- }
- ///------------------------------------------------------------------------------
- /**
- *
- *
- * @param string $post_type a post_type known to CCTM (not necessarily currently registered)
- * @return string HTML link for managing the custom fields
- */
- private static function _link_manage_custom_fields($post_type) {
- return sprintf(
- '<a href="?page=%s&%s=4&%s=%s" title="%s">%s</a>'
- , self::admin_menu_slug
- , self::action_param
- , self::post_type_param
- , $post_type
- , __('Manage Custom Fields for this content type', CCTM_TXTDOMAIN)
- , __('Manage Custom Fields', CCTM_TXTDOMAIN)
- );
- }
- //------------------------------------------------------------------------------
- /**
- *
- *
- * @param string $post_type a post_type known to CCTM (not necessarily currently registered)
- * @return string HTML link to edit a post_type
- */
- private static function _link_edit($post_type) {
- return sprintf(
- '<a href="?page=%s&%s=2&%s=%s" title="%s">%s</a>'
- , self::admin_menu_slug
- , self::action_param
- , self::post_type_param
- , $post_type
- , __('Edit this content type', CCTM_TXTDOMAIN )
- , __('Edit', CCTM_TXTDOMAIN)
- );
- }
- //------------------------------------------------------------------------------
- /**
- *
- *
- * @param string $post_type
- * @return unknown
- */
- private static function _link_view_sample_templates($post_type) {
- return sprintf('<a href="?page=%s&%s=8&%s=%s" title="%s">%s</a>'
- , self::admin_menu_slug
- , self::action_param
- , self::post_type_param
- , $post_type
- , __('View Sample Templates for this content type', CCTM_TXTDOMAIN )
- , __('View Sample Templates', CCTM_TXTDOMAIN)
- );
- }
- //! Pages
- //------------------------------------------------------------------------------
- /**
- * Manager Page -- called by page_main_controller()
- * Activating a post type will cause it to show up in the WP menus and its custom
- * fields will be managed.
- * @param string $post_type
- */
- private static function _page_activate_post_type($post_type) {
- // Validate post type
- if (!self::_is_existing_post_type($post_type) ) {
- self::_page_display_error();
- return;
- }
- self::$data[$post_type]['is_active'] = 1;
- update_option( self::db_key, self::$data );
- $msg = '
- <div class="updated">
- <p>'
- . sprintf( __('The %s post_type has been activated.', CCTM_TXTDOMAIN), '<em>'.$post_type.'</em>')
- . '</p>
- </div>';
- self::set_flash($msg);
- // Often, PHP scripts use the header() function to refresh a page, but
- // WP has already claimed those, so we use a JavaScript refresh instead.
- // Refreshing the page ensures that active post types are added to menus.
- $msg = '
- <script type="text/javascript">
- window.location.replace("?page='.self::admin_menu_slug.'");
- </script>';
- print $msg;
- }
- //------------------------------------------------------------------------------
- /**
- Edit a custom field. This is a bit complicated, but it doesn't involve JS like
- the previous version did.
- *
- *
- * @param string $post_type
- * @param string $field_name
- */
- private static function _page_create_custom_field($post_type, $field_type) {
- if ( !self::_is_existing_post_type($post_type, true ) ) {
- self::_page_display_error();
- return;
- }
-
- // Page variables
- $heading = __('Create Field', CCTM_TXTDOMAIN);
-
- $action_name = 'custom_content_type_mgr_create_new_custom_field';
- $nonce_name = 'custom_content_type_mgr_create_new_custom_field_nonce';
- $success_msg = sprintf('<div class="updated"><p>%s</p></div>'
- , sprintf(__('A custom field for %s has been created.', CCTM_TXTDOMAIN)
- , '<em>'.$post_type.'</em>'));
-
- $field_data = array(); // Data object we will save
-
- self::include_form_element_class($field_type); // This will die on errors
-
- $field_type_name = self::FormElement_classname_prefix.$field_type;
- $FieldObj = new $field_type_name(); // Instantiate the field element
-
- // Save if submitted...
- if ( !empty($_POST) && check_admin_referer($action_name, $nonce_name) ) {
- // A little cleanup before we handoff to save_field_filter
- unset($_POST[ $nonce_name ]);
- unset($_POST['_wp_http_referer']);
- // Validate and sanitize any submitted data
- $field_data = $FieldObj->save_field_filter($_POST, $post_type);
- $field_data['type'] = $field_type; // same effect as adding a hidden field
-
- $FieldObj->props = $field_data; // This is how we repopulate data in the create forms
- // Any errors?
- if ( !empty($FieldObj->errors) ) {
- $msg = $FieldObj->format_errors();
- }
- // Save;
- else {
- $field_name = $field_data['name'];
- self::$data[$post_type]['custom_fields'][$field_name] = $field_data;
- update_option( self::db_key, self::$data );
- unset($_POST);
- self::set_flash($success_msg);
- self::_page_show_custom_fields($post_type);
- return;
- }
- }
- // this should change to get_edit_field_definition() if it's an edit.
- $fields = $FieldObj->get_create_field_definition();
- $submit_link = $tpl = sprintf(
- '?page=%s&%s=9&%s=%s&type=%s'
- , self::admin_menu_slug
- , self::action_param
- , self::post_type_param
- , $post_type
- , $field_type
- );
-
- $icon = $FieldObj->get_icon();
-
- include 'pages/custom_field.php';
- }
-
-
- //------------------------------------------------------------------------------
- /**
- * Edit a custom field. This is a bit complicated, but it doesn't involve JS like
- * the previous version did.
- *
- * @param string $post_type
- * @param string $field_name uniquely identifies this field inside this post_type
- */
- //! Working here...
- private static function _page_edit_custom_field($post_type, $field_name) {
-
- if ( !self::_is_existing_post_type($post_type, true ) ) {
- self::_page_display_error();
- return;
- }
-
- $field_data = array(); // Data object we will save
- // For compatibility with versions prior to 0.8.8, we iterate through
- if ( !empty(self::$data[$post_type]['custom_fields']) ) {
- foreach (self::$data[$post_type]['custom_fields'] as $k => $def )
- {
- $custom_fields_array[] = $def['name'];
- if ($def['name'] == $field_name) {
- $field_data = $def; // Data object we will save
- }
- }
- }
-
- if ( !in_array($field_name, $custom_fields_array) ) {
- $msg = '<p>'. __('Invalid custom field.', CCTM_TXTDOMAIN)
- . '</p>';
- $msg .= sprintf(
- '<a href="?page=%s&%s=4&%s=%s" title="%s" class="button">%s</a>'
- , self::admin_menu_slug
- , self::action_param
- , self::post_type_param
- , $post_type
- , __('Manage Custom Fields for this content type', CCTM_TXTDOMAIN)
- , __('Back', CCTM_TXTDOMAIN)
- );
- wp_die( $msg );
- }
-
- $field_type = $field_data['type'];
-
- // Page variables
- $heading = __('Create Field', CCTM_TXTDOMAIN);
-
- $action_name = 'custom_content_type_mgr_create_new_custom_field';
- $nonce_name = 'custom_content_type_mgr_create_new_custom_field_nonce';
- $success_msg = sprintf('<div class="updated"><p>%s</p></div>'
- , sprintf(__('The %s custom field has been edited.', CCTM_TXTDOMAIN)
- , '<em>'.$post_type.'</em>'));
-
-
- self::include_form_element_class($field_type); // This will die on errors
-
- $field_type_name = self::FormElement_classname_prefix.$field_type;
- $FieldObj = new $field_type_name(); // Instantiate the field element
- //
- $FieldObj->props = $field_data;
- // THIS is what keys us off to the fact that we're EDITING a field:
- // the logic in FormElement->save_field_filter() ensures we don't overwrite other fields.
- // This attribute is nuked by the time we get down to line 691 or so.
- $FieldObj->original_name = $field_name;
-
- // Save if submitted...
- if ( !empty($_POST) && check_admin_referer($action_name, $nonce_name) ) {
- // A little cleanup before we handoff to save_field_filter
- unset($_POST[ $nonce_name ]);
- unset($_POST['_wp_http_referer']);
- // Validate and sanitize any submitted data
- $field_data = $FieldObj->save_field_filter($_POST, $post_type);
- $field_data['type'] = $field_type; // same effect as adding a hidden field
-
- $FieldObj->props = $field_data;
- // Any errors?
- if ( !empty($FieldObj->errors) ) {
- $msg = $FieldObj->format_errors();
- }
- // Save;
- else {
- // Unset the old field if the name changed ($field_name is passed via $_GET)
- if ($field_name != $field_data['name']) {
- unset(self::$data[$post_type]['custom_fields'][$field_name]);
- }
- self::$data[$post_type]['custom_fields'][ $field_data['name'] ] = $field_data;
- update_option( self::db_key, self::$data );
- unset($_POST);
- self::set_flash($success_msg);
- self::_page_show_custom_fields($post_type);
- return;
- }
- }
- $fields = $FieldObj->get_edit_field_definition($field_data);
- $submit_link = $tpl = sprintf(
- '?page=%s&%s=9&%s=%s&type=%s'
- , self::admin_menu_slug
- , self::action_param
- , self::post_type_param
- , $post_type
- , $field_type
- );
-
- include 'pages/custom_field.php';
- }
- //------------------------------------------------------------------------------
- /**
- * Manager Page -- called by page_main_controller()
- * Create a new post type
- */
- private static function _page_create_new_post_type() {
- self::_set_post_type_form_definition();
- // Variables for our template
- $page_header = __('Create Custom Content Type', CCTM_TXTDOMAIN);
- $fields = '';
- $action_name = 'custom_content_type_mgr_create_new_content_type';
- $nonce_name = 'custom_content_type_mgr_create_new_content_type_nonce';
- $submit = __('Create New Content Type', CCTM_TXTDOMAIN);
- $msg = '';
- $def = self::$post_type_form_definition;
- // Save data if it was properly submitted
- if ( !empty($_POST) && check_admin_referer($action_name, $nonce_name) ) {
- $sanitized_vals = self::_sanitize_post_type_def($_POST);
- $error_msg = self::_post_type_name_has_errors($sanitized_vals, true);
- if ( empty($error_msg) ) {
- self::_save_post_type_settings($sanitized_vals);
- $msg = '
- <div class="updated">
- <p>'
- . sprintf( __('The content type %s has been created', CCTM_TXTDOMAIN), '<em>'.$sanitized_vals['post_type'].'</em>')
- . '</p>
- </div>';
- self::set_flash($msg);
- self::_page_show_all_post_types();
- return;
- }
- else {
- //! Error: see issue 17: http://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=37
- // This won't work bc the location in the $_POST array does not match the location in the $def. This needs a _post_to_def() function.. mostly direct throughput, but we'd have to identify the array inputs and walk through them specifically.
- // This is for repopulating the form
- foreach ( $def as $node_id => &$d ) {
- $d['value'] = self::_get_value($sanitized_vals, $d['name']);
- }
- $msg = "<div class='error'>$error_msg</div>";
- }
- }
- //
- foreach ($def as $pt => &$d) {
- $d['raw_name'] = $pt;
- }
- $fields = FormGenerator::generate($def, 'css-friendly');
- $mgr_tpl_file = CCTM_PATH.'/tpls/settings/edit_post_type.tpl';
- if ( file_exists($mgr_tpl_file) ) {
- $tpl = file_get_contents($mgr_tpl_file);
- FormGenerator::$placeholders['icons'] = self::_get_post_type_icons();
- FormGenerator::$placeholders['CCTM_URL'] = CCTM_URL;
- $fields = FormGenerator::parse($tpl, FormGenerator::$placeholders);
- }
- include 'pages/basic_form.php';
- }
- /*------------------------------------------------------------------------------
- Manager Page -- called by page_main_controller()
- Deactivate a post type. This will remove custom post types from the WP menus;
- deactivation stops custom fields from being standardized in built-in and custom
- post types
- ------------------------------------------------------------------------------*/
- /**
- *
- *
- * @param string $post_type
- */
- private static function _page_deactivate_post_type($post_type) {
- // Validate post type
- if (!self::_is_existing_post_type($post_type) ) {
- self::_page_display_error();
- return;
- }
- // Variables for our template
- $style = '';
- $page_header = sprintf( __('Deactivate Content Type %s', CCTM_TXTDOMAIN), $post_type );
- $fields = '';
- $action_name = 'custom_content_type_mgr_deactivate_content_type';
- $nonce_name = 'custom_content_type_mgr_deactivate_content_type_nonce';
- $submit = __('Deactivate', CCTM_TXTDOMAIN);
- // If properly submitted, Proceed with deleting the post type
- if ( !empty($_POST) && check_admin_referer($action_name, $nonce_name) ) {
- // get current values from database
- self::$data[$post_type]['is_active'] = 0;
- update_option( self::db_key, self::$data );
- $msg = '<div class="updated"><p>'
- . sprintf( __('The %s content type has been deactivated.', CCTM_TXTDOMAIN), $post_type )
- . '</p></div>';
- self::set_flash($msg);
- // A JavaScript refresh ensures that inactive post types are removed from the menus.
- $msg = '
- <script type="text/javascript">
- window.location.replace("?page='.self::admin_menu_slug.'");
- </script>';
- print $msg;
- return;
- }
- $msg = '<div class="error">
- <img src="'.CCTM_URL.'/images/warning-icon.png" width="50" height="44" style="float:left; padding:10px;"/>
- <p>'
- . sprintf( __('You are about to deactivate the %s post type.', CCTM_TXTDOMAIN ), "<strong>$post_type</strong>")
- .'</p>';
- // If it's a custom post type, we include some additional info.
- if ( !in_array($post_type, self::$built_in_post_types) ) {
- $msg .= '<p>'
- . sprintf( __('Deactivation does not delete anything, but it does make %s posts unavailable to the outside world. %s will be removed from the administration menus and you will no longer be able to edit them using the WordPress manager.', CCTM_TXTDOMAIN), "<strong>$post_type</strong>", "<strong>$post_type</strong>" )
- .'</p>';
- }
- $post_cnt_obj = wp_count_posts($post_type);
- $msg .= '<p>'
- . sprintf( __('This would affect %1$s published %2$s posts.'
- , CCTM_TXTDOMAIN), '<strong>'.$post_cnt_obj->publish.'</strong>'
- , "<strong>$post_type</strong>")
- .'</p>';
- $msg .= '<p>'.__('Are you sure you want to do this?', CCTM_TXTDOMAIN).'
- <a href="http://code.google.com/p/wordpress-custom-content-type-manager/wiki/DeactivatePostType" title="deactivating a content type" target="_blank">
- <img src="'.CCTM_URL.'/images/question-mark.gif" width="16" height="16" />
- </a>
- </p>
- </div>';
- include 'pages/basic_form.php';
- }
- //------------------------------------------------------------------------------
- /**
- * called by page_main_controller()
- *
- * @param string $post_type
- * @param null
- */
- private static function _page_delete_custom_field($post_type, $field) {
- // We can't delete built-in post types
- if (!self::_is_existing_post_type($post_type, false ) ) {
- self::_page_display_error();
- return;
- }
- $custom_fields_array = array();
- #print_r($data[$post_type]['custom_fields']); exit;
- // For compatibility with versions prior to 0.8.8, we iterate through
- if ( !empty(self::$data[$post_type]['custom_fields']) ) {
- foreach (self::$data[$post_type]['custom_fields'] as $k => $def )
- {
- $custom_fields_array[] = $def['name'];
- }
- # $custom_fields_array = array_keys($data[$post_type]['custom_fields']);
- }
- if ( !in_array($field, $custom_fields_array) ) {
- $msg = '<p>'. __('Invalid custom field.', CCTM_TXTDOMAIN)
- . '</p>';
- $msg .= sprintf(
- '<a href="?page=%s&%s=4&%s=%s" title="%s" class="button">%s</a>'
- , self::admin_menu_slug
- , self::action_param
- , self::post_type_param
- , $post_type
- , __('Manage Custom Fields for this content type', CCTM_TXTDOMAIN)
- , __('Back', CCTM_TXTDOMAIN)
- );
- wp_die( $msg );
- }
- $nonce = self::_get_value($_GET, '_wpnonce');
- if (! wp_verify_nonce($nonce, 'cctm_delete_field') ) {
- die( __('Invalid request.', CCTM_TXTDOMAIN ) );
- }
- else {
- // Again, for compatibility with versions prior to 0.8.8, we do not assume that the
- // field names exist as keys inside of 'custom_fields' (there could be int keys)
- foreach (self::$data[$post_type]['custom_fields'] as $k => $def ) {
- if ($def['name'] == $field) {
- unset(self::$data[$post_type]['custom_fields'][$k]);
- }
- }
-
-
- update_option( self::db_key, self::$data );
- $msg = '<div class="updated"><p>'
- .sprintf( __('The %s custom field has been deleted', CCTM_TXTDOMAIN), "<em>$field</em>")
- . '</p></div>';
- self::set_flash($msg);
- unset($_POST);
- self::_page_show_custom_fields($post_type);
- return;
- }
- }
- //------------------------------------------------------------------------------
- /**
- * Manager Page -- called by page_main_controller()
- * This is only a valid page for custom post types.
- * @param string $post_type
- * @return null
- */
- private static function _page_delete_post_type($post_type) {
- // We can't delete built-in post types
- if (!self::_is_existing_post_type($post_type, false ) ) {
- self::_page_display_error();
- return;
- }
- // Variables for our template
- $style = '';
- $page_header = sprintf( __('Delete Content Type: %s', CCTM_TXTDOMAIN), $post_type );
- $fields = '';
- $action_name = 'custom_content_type_mgr_delete_content_type';
- $nonce_name = 'custom_content_type_mgr_delete_content_type_nonce';
- $submit = __('Delete', CCTM_TXTDOMAIN);
- // If properly submitted, Proceed with deleting the post type
- if ( !empty($_POST) && check_admin_referer($action_name, $nonce_name) ) {
- unset(self::$data[$post_type]); // <-- Delete this node of the data structure
- update_option( self::db_key, self::$data );
- $msg = '<div class="updated"><p>'
- .sprintf( __('The post type %s has been deleted', CCTM_TXTDOMAIN), "<em>$post_type</em>")
- . '</p></div>';
- self::set_flash($msg);
- self::_page_show_all_post_types();
- return;
- }
- $msg = '<div class="error">
- <img src="'.CCTM_URL.'/images/warning-icon.png" width="50" height="44" style="float:left; padding:10px;"/>
- <p>'
- . sprintf( __('You are about to delete the %s post type. This will remove all of its settings from the database, but this will NOT delete any rows from the wp_posts table. However, without a custom post type defined for those rows, they will be essentially invisible to WordPress.', CCTM_TXTDOMAIN), "<em>$post_type</em>" )
- .'</p>'
- . '<p>'.__('Are you sure you want to do this?', CCTM_TXTDOMAIN).'
- <a href="http://code.google.com/p/wordpress-custom-content-type-manager/wiki/DeletePostType" title="Deleting a content type" target="_blank">
- <img src="'.CCTM_URL.'/images/question-mark.gif" width="16" height="16" />
- </a>
- </p></div>';
- include 'pages/basic_form.php';
- }
- //------------------------------------------------------------------------------
- /**
- * Manager Page -- called by page_main_controller()
- * Returned on errors. Future: accept an argument identifying an error
- * @param string $msg_id identifies the error.
- */
- private static function _page_display_error($msg_id='invalid_post_type') {
- $msg = '';
- switch ($msg_id) {
- case 'invalid_field_name':
- $msg = '<p>'. __('Invalid field name.', CCTM_TXTDOMAIN)
- . '</p><a class="button" href="?page='
- .self::admin_menu_slug.'">'. __('Back', CCTM_TXTDOMAIN). '</a>';
- break;
- default:
- $msg = '<p>'. __('Invalid post type.', CCTM_TXTDOMAIN)
- . '</p><a class="button" href="?page='
- .self::admin_menu_slug.'">'. __('Back', CCTM_TXTDOMAIN). '</a>';
- }
- wp_die( $msg );
- }
- //------------------------------------------------------------------------------
- /**
- * Manager Page -- called by page_main_controller()
- * Edit an existing post type. Changing the unique post-type identifier (i.e. name)
- * is not allowed.
- * @param string $post_type
- */
- private static function _page_edit_post_type($post_type) {
- // We can't edit built-in post types
- if (!self::_is_existing_post_type($post_type, false ) ) {
- self::_page_display_error();
- return;
- }
- self::_set_post_type_form_definition($post_type);
- // Variables for our template (TODO: register this instead of this cheap inline trick)
- $style = '';
- $page_header = __('Edit Content Type: ') . $post_type;
- $fields = '';
- $action_name = 'custom_content_type_mgr_edit_content_type';
- $nonce_name = 'custom_content_type_mgr_edit_content_type_nonce';
- $submit = __('Save', CCTM_TXTDOMAIN);
- $msg = ''; // Any validation errors
- $def = self::$post_type_form_definition;
- $def['post_type']['type'] = 'readonly';
- $def['post_type']['description'] = __('The name of the post-type cannot be changed. The name may show up in your URLs, e.g. ?movie=star-wars. This will also make a new theme file available, starting with prefix named "single-", e.g. <strong>single-movie.php</strong>.', CCTM_TXTDOMAIN);
- // Save data if it was properly submitted
- if ( !empty($_POST) && check_admin_referer($action_name, $nonce_name) ) {
- $sanitized_vals = self::_sanitize_post_type_def($_POST);
- //print_r($sanitized_vals); exit;
- $error_msg = self::_post_type_name_has_errors($sanitized_vals);
- if ( empty($error_msg) ) {
- self::_save_post_type_settings($sanitized_vals);
- $msg .= '<div class="updated"><p>'
- . sprintf( __('Settings for %s have been updated.', CCTM_TXTDOMAIN )
- , '<em>'.$sanitized_vals['post_type'].'</em>')
- .'</p></div>';
- self::set_flash($msg);
- $msg = '
- <script type="text/javascript">
- window.location.replace("?page='.self::admin_menu_slug.'");
- </script>';
- print $msg;
- return;
- }
- else {
- // This is for repopulating the form
- $def = self::_populate_form_def_from_data($def, $sanitized_vals);
- $msg = "<div class='error'>$error_msg</div>";
- }
- }
- //
- foreach ($def as $pt => &$d) {
- $d['raw_name'] = $pt;
- }
- // Populate the form $def with values from the database
- $def = self::_populate_form_def_from_data($def, self::$data[$post_type]);
- $fields = FormGenerator::generate($def, 'css-friendly');
- $mgr_tpl_file = CCTM_PATH.'/tpls/settings/edit_post_type.tpl';
- if ( file_exists($mgr_tpl_file) ) {
- $tpl = file_get_contents($mgr_tpl_file);
- FormGenerator::$placeholders['icons'] = self::_get_post_type_icons();
- FormGenerator::$placeholders['CCTM_URL'] = CCTM_URL;
- // print_r(FormGenerator::$placeholders);
- $fields = FormGenerator::parse($tpl, FormGenerator::$placeholders);
- }
- include 'pages/basic_form.php';
- }
- //------------------------------------------------------------------------------
- /**
- Manager Page -- called by page_main_controller()
- Deletes all custom field definitions for a given post_type.
- * @param string $post_type
- */
- private static function _page_reset_all_custom_fields($post_type) {
- // We can't delete built-in post types
- if (!self::_is_existing_post_type($post_type, true ) ) {
- self::_page_display_error();
- return;
- }
- // Variables for our template
- $style = '';
- $page_header = sprintf( __('Reset custom field definitions for post type %s', CCTM_TXTDOMAIN), $post_type );
- $fields = '';
- $action_name = 'custom_content_type_mgr_delete_all_custom_fields';
- $nonce_name = 'custom_content_type_mgr_delete_all_custom_fields';
- $submit = __('Reset', CCTM_TXTDOMAIN);
- // If properly submitted, Proceed with deleting the post type
- if ( !empty($_POST) && check_admin_referer($action_name, $nonce_name) ) {
- unset(self::$data[$post_type]['custom_fields']); // <-- Delete this node of the data structure
- update_option( self::db_key, self::$data );
- $msg = '<div class="updated"><p>'
- .sprintf( __('All custom field definitions for the %s post type have been deleted', CCTM_TXTDOMAIN), "<em>$post_type</em>")
- . '</p></div>';
- self::set_flash($msg);
- self::_page_show_custom_fields($post_type, true);
- return;
- }
- $msg = '<div class="error">
- <img src="'.CCTM_URL.'/images/warning-icon.png" width="50" height="44" style="float:left; padding:10px;"/>
- <p>'
- . sprintf( __('You are about to delete all custom field definitions for the %s post type. This will not delete any data from the wp_postmeta table, but it will make any custom fields invisible to WordPress users on the front and back end.', CCTM_TXTDOMAIN), "<em>$post_type</em>" )
- .'</p>'
- . '<p>'.__('Are you sure you want to do this?', CCTM_TXTDOMAIN).'</p></div>';
- // The URL nec. to take the "Cancel" button back to this page.
- $cancel_target_url = '?page='.self::admin_menu_slug . '&'.self::action_param .'=4&'.self::post_type_param.'='.$post_type;
-
- include 'pages/basic_form.php';
- }
- //------------------------------------------------------------------------------
- /**
- * Manager Page -- called by page_main_controller()
- * List all post types (default page)
- */
- private static function _page_show_all_post_types() {
- $msg = self::get_flash();
- $customized_post_types = array();
- $displayable_types = array();
- $displayable_types = array();
- if ( !empty(self::$data) ) {
- $customized_post_types = array_keys(self::$data);
- }
- $displayable_types = array_merge(self::$built_in_post_types , $customized_post_types);
- $displayable_types = array_unique($displayable_types);
- $row_data = '';
- $tpl = file_get_contents(CCTM_PATH.'/tpls/settings/post_type_tr.tpl');
- foreach ( $displayable_types as $post_type ) {
- $hash = array(); // populated for the tpl
- $hash['post_type'] = $post_type;
- // Get our links
- $deactivate = self::_link_deactivate($post_type);
- $edit_link = self::_link_edit($post_type);
- $manage_custom_fields = self::_link_manage_custom_fields($post_type);
- $view_templates = self::_link_view_sample_templates($post_type);
- $hash['edit_manage_view_links'] = $edit_link . ' | '. $manage_custom_fields . ' | ' . $view_templates;
- if ( isset(self::$data[$post_type]['is_active']) && !empty(self::$data[$post_type]['is_active']) ) {
- $hash['class'] = 'active';
- $hash['activate_deactivate_delete_links'] = '<span class="deactivate">'.$deactivate.'</span>';
- $is_active = true;
- }
- else {
- $hash['class'] = 'inactive';
- $hash['activate_deactivate_delete_links'] = '<span class="activate">'
- . self::_link_activate($post_type) . ' | </span>'
- . '<span class="delete">'. self::_link_delete($post_type).'</span>';
- $is_active = false;
- }
- // Built-in post types use a canned description and override a few other behaviors
- if ( in_array($post_type, self::$built_in_post_types) ) {
- $hash['description'] = __('Built-in post type.', CCTM_TXTDOMAIN);
- $hash['edit_manage_view_links'] = $manage_custom_fields . ' | ' . $view_templates;
- if (!$is_active) {
- $hash['activate_deactivate_delete_links'] = '<span class="activate">'
- . self::_link_activate($post_type) . '</span>';
- }
- }
- // Whereas users define the description for custom post types
- else {
- $hash['description'] = self::_get_value(self::$data[$post_type], 'description');
- }
- // Images
- $hash['icon'] = '';
- switch ($post_type) {
- case 'post':
- $hash['icon'] = '<img src="'. CCTM_URL . '/images/icons/default/post.png' . '" width="15" height="15"/>';
- break;
- case 'page':
- $hash['icon'] = '<img src="'. CCTM_URL . '/images/icons/default/page.png' . '" width="14" height="16"/>';
- break;
- default:
- //print_r($data[$post_type]); exit;
- if ( !empty(self::$data[$post_type]['menu_icon']) && !self::$data[$post_type]['use_default_menu_icon'] ) {
- $hash['icon'] = '<img src="'. self::$data[$post_type]['menu_icon'] . '" />';
- }
- break;
- }
- $row_data .= FormGenerator::parse($tpl, $hash);
- }
- include 'pages/default.php';
- }
- //------------------------------------------------------------------------------
- /**
- * Manager Page -- called by page_main_controller()
- * Show what a single page for this custom post-type might look like. This is
- * me throwing a bone to template editors and creators.
- *
- * I'm using a tpl and my parse() function because I have to print out sample PHP
- * code and it's too much of a pain in the ass to include PHP without it executing.
- *
- * @param string $post_type
- */
- private static function _page_sample_template($post_type) {
- // Validate post type
- if (!self::_is_existing_post_type($post_type) ) {
- self::_page_display_error();
- return;
- }
- $current_theme_name = get_current_theme();
- $current_theme_path = get_stylesheet_directory();
- $hash = array();
- $tpl = file_get_contents( CCTM_PATH.'/tpls/samples/single_post.tpl');
- $tpl = htmlentities($tpl);
- $single_page_msg = sprintf( __('WordPress supports a custom theme file for each registered post-type (content-type). Copy the text below into a file named <strong>%s</strong> and save it into your active theme.', CCTM_TXTDOMAIN)
- , 'single-'.$post_type.'.php'
- );
- $single_page_msg .= sprintf( __('You are currently using the %1$s theme. Save the file into the %2$s directory.', CCTM_TXTDOMAIN)
- , '<strong>'.$current_theme_name.'</strong>'
- , '<strong>'.$current_theme_path.'</strong>'
- );
- $def = array();
- if ( isset(self::$data[$post_type]['custom_fields']) ) {
- $def = self::$data[$post_type]['custom_fields'];
- }
- //print_r($data[$post_type]); exit;
- // built-in content types don't verbosely display what they display
- /* Array
- (
- [product] => Array
- (
- [supports] => Array
- (
- [0] => title
- [1] => editor
- [2] => author
- [3] => thumbnail
- [4] => excerpt
- [5] => trackbacks
- [6] => custom-fields
- )
- */
- // print_r($data); exit;
- // Check the TYPE of custom field to handle image and relation custom fields.
- // title, author, thumbnail, excerpt
- $custom_fields_str = '';
- $builtin_fields_str = '';
- $comments_str = '';
- // Built-in Fields
- if ( is_array(self::$data[$post_type]['supports']) ) {
- if ( in_array('title', self::$data[$post_type]['supports']) ) {
- $builtin_fields_str .= "\n\t<h1><?php the_title(); ?></h1>\n";
- }
- if ( in_array('editor', self::$data[$post_type]['supports']) ) {
- $builtin_fields_str .= "\n\t\t<?php the_content(); ?>\n";
- }
- if ( in_array('author', self::$data[$post_type]['supports']) ) {
- $builtin_fields_str .= "\n\t\t<?php the_author(); ?>\n";
- }
- if ( in_array('thumbnail', self::$data[$post_type]['supports']) ) {
- $builtin_fields_str .= "\n\t\t<?php the_post_thumbnail(); ?>\n";
- }
- if ( in_array('excerpt', self::$data[$post_type]['supports']) ) {
- $builtin_fields_str .= "\n\t\t<?php the_excerpt(); ?>\n";
- }
- if ( in_array('comments', self::$data[$post_type]['supports']) ) {
- $comments_str .= "\n\t\t<?php comments_template(); ?>\n";
- }
- }
- // Custom fields
- foreach ( $def as $d ) {
- switch ($d['type']) {
- case 'media':
- $custom_fields_str .= "\t\t<?php /* http://codex.wordpress.org/Function_Reference/wp_get_attachment_image */ ?>\n";
- $custom_fields_str .= sprintf("\t\t<strong>%s:</strong> <?php print wp_get_attachment_image( get_custom_field('%s'), 'full'); ?><br />\n", $d['label'], $d['name']);
- case 'text':
- default:
- $custom_fields_str .= sprintf("\t\t<strong>%s:</strong> <?php print_custom_field('%s'); ?><br />\n", $d['label'], $d['name']);
- }
- }
- // Populate placeholders
- $hash['post_type'] = $post_type;
- $hash['built_in_fields'] = $builtin_fields_str;
- $hash['custom_fields'] = $custom_fields_str;
- $hash['comments'] = $comments_str;
- $single_page_sample_code = StandardizedCustomFields::parse($tpl, $hash);
- // Manager Page Sample CSS
- $manager_page_css_msg = '';
- $manager_page_sample_css = '';
- $manager_page_css_msg .= sprintf( __('You can customize the forms in the manager by adding the following CSS declarations to your in your theme\'s %s file.', CCTM_TXTDOMAIN)
- , '<strong>editor-style.css</strong>' );
- $manager_page_css_msg .= sprintf( __('You can override the style definitions in %s', CCTM_TXTDOMAIN)
- , '<strong>'.CCTM_PATH.'/css/posts.css</strong>');
- // or in your theme's editor-style.css file.
- // FormGenerator::element_wrapper_id_prefix
- foreach ( $def as $d ) {
- $manager_page_sample_css .= sprintf("/* The div that wraps the %s field */\n#%s%s {\n\n}\n\n/* Style the input for the %s field */\n#%s%s {\n\n}\n\n"
- , $d['name']
- , FormGenerator::element_wrapper_id_prefix
- , $d['name']
- , $d['name']
- , StandardizedCustomFields::field_name_prefix
- , $d['name']
- );
- }
- // Manager Page HTML examples;
- // post-new.php?post_type=%s
- $manager_page_html_msg = '';
- $manager_page_sample_html = '';
- /*
- <div class="formgenerator_element_wrapper" id="custom_field_id_sample_img">
- <span class="formgenerator_label formgenerator_media_label" id="formgenerator_label_custom_content_sample_img">Sample Image (sample_img)</span>
- <input type="hidden" id="custom_content_sample_img" name="custom_content_sample_img" />
- </div>
- A <div> wraps each custom field. Its class is "formgenerator_element_wrapper" and its id is the field name prefixed by "custom_field_id_"
- Labels for each field are wrapped with their own <span>. Each <span> uses 2 classes: a general one for all generated labels, and another specific to the field type (text, checkbox, etc).
- */
- $manager_page_html_msg .= __('You can create custom manager templates for the users who will be creating new content.', CCTM_TXTDOMAIN) . ' ';
- $manager_page_html_msg .= sprintf( __('Create a file named %s in the %s directory.', CCTM_TXTDOMAIN)
- , '<strong>'.$post_type.'.tpl</strong>'
- , '<strong>'.CCTM_PATH.'/tpls/manager/</strong>'
- );
- foreach ( $def as $d ) {
- unset($d['default_value']); // this should not be publicly available.
- $manager_page_sample_html .= sprintf( "<!-- Sample HTML for %s field-->\n", $d['name']);
- $manager_page_sample_html .= "<!-- [+".$d['name']."+] will generate field in its entirety -->\n";
- $manager_page_sample_html .= "<!-- Individual placeholders follow: -->\n";
- foreach ($d as $k => $v) {
- $manager_page_sample_html .= '[+'.$d['name'].'.'.$k.'+]'. "\n";
- }
- $manager_page_sample_html .= "\n";
- //! FUTURE: TODO: Give more complete examples.
- /*
- switch ( $d['type'] )
- {
- case 'checkbox':
- $output_this_field .= self::_get_checkbox_element($field_def);
- break;
- case 'dropdown':
- $output_this_field .= self::_get_dropdown_element($field_def);
- break;
- case 'media':
- $output_this_field .= self::_get_media_element($field_def);
- break;
- case 'readonly':
- $output_this_field .= self::_get_readonly_element($field_def);
- break;
- case 'relation':
- $output_this_field .= self::_get_relation_element($field_def);
- break;
- case 'textarea':
- $output_this_field .= self::_get_textarea_element($field_def);
- break;
- case 'wysiwyg':
- $output_this_field .= self::_get_wysiwyg_element($field_def);
- break;
- case 'text':
- default:
- $output_this_field .= self::_get_text_element($field_def);
- break;
- }
- */
- }
- if ( empty($def) ) {
- $manager_page_sample_css = sprintf( '/* %s %s */'
- , __('There are no custom fields defined this post type.', CCTM_TXTDOMAIN)
- , "($post_type)"
- );
- $manager_page_sample_html = sprintf( '<!-- %s %s -->'
- , __('There are no custom fields defined this post type.', CCTM_TXTDOMAIN)
- , "($post_type)"
- );
- }
- include 'pages/sample_template.php';
- }
- //------------------------------------------------------------------------------
- /**
- * Manager Page -- called by page_main_controller()
- * Manage custom fields for any post type, built-in or custom.
- * @param string $post_type
- * @param boolen $reset true only if we've just reset all custom fields
- */
- private static function _page_show_custom_fields($post_type, $reset=false) {
- // Validate post type
- if (!self::_is_existing_post_type($post_type) ) {
- self::_page_display_error();
- …
Large files files are truncated, but you can click here to view the full file