/** * <label for="[+name+]" class="cctm_label cctm_textarea_label" id="cctm_label_[+name+]">[+label+]</label> * <textarea name="[+name+]" class="cctm_textarea" id="[+name+]" [+extra+]>[+value+]</textarea> * * @param string $current_value current value for this field. * @return string */ public function get_edit_field_instance($current_value) { $this->id = str_replace(array('[', ']', ' '), '_', $this->name); $fieldtpl = ''; $wrappertpl = ''; // Multi-versions if ($this->is_repeatable) { $fieldtpl = CCTM::load_tpl(array('fields/elements/' . $this->name . '.tpl', 'fields/elements/_' . $this->type . '_multi.tpl')); $wrappertpl = CCTM::load_tpl(array('fields/wrappers/' . $this->name . '.tpl', 'fields/wrappers/_' . $this->type . '_multi.tpl')); $this->i = 0; $values = $this->get_value($current_value, 'to_array'); foreach ($values as $v) { $this->value = htmlspecialchars(html_entity_decode($v), ENT_QUOTES); $this->content .= CCTM::parse($fieldtpl, $this->get_props()); $this->i = $this->i + 1; } } else { $fieldtpl = CCTM::load_tpl(array('fields/elements/' . $this->name . '.tpl', 'fields/elements/_' . $this->type . '.tpl', 'fields/elements/_default.tpl')); $wrappertpl = CCTM::load_tpl(array('fields/wrappers/' . $this->name . '.tpl', 'fields/wrappers/_' . $this->type . '.tpl', 'fields/wrappers/_default.tpl')); $this->value = htmlspecialchars($this->get_value($current_value, 'to_string'), ENT_QUOTES); $this->content = CCTM::parse($fieldtpl, $this->get_props()); } // wrap it. $this->add_label = __('Add', CCTM_TXTDOMAIN); return CCTM::parse($wrappertpl, $this->get_props()); }
/** * Apply the filter. * * @param mixed input * @param mixed optional arguments * @return mixed */ public function filter($input, $options = null) { $output = ' <style> div.cctm_code { border: solid 1px blue; font-size: 1.3 em; color: blue; margin: 10px; padding:10px; background: #FFFFB3 } #cctm_help { border:1px solid black; background-color: lightyellow; width: 90%; margin: 10px; padding: 10px; } h2.cctm_h2 { font-size:25px; line-height:32px; margin-bottom: 10px; } h3.cctm_h3 { font-size:18px; line-height:25px; margin-top: 20px; } </style> <div id="cctm_help"> <h2 class="cctm_h2">' . __('Output Filter Help', CCTM_TXTDOMAIN) . '</h2> <p>' . __('This help page was generated by <a href="http://code.google.com/p/wordpress-custom-content-type-manager/wiki/OutputFilters">Custom Content Type Manager</a> to demonstrate the use of the available Output Filters. For samples of template files, see the CCTM menus in the WordPress manager.', CCTM_TXTDOMAIN) . '</p>'; $filters = CCTM::get_available_helper_classes('filters', true); // print_r($filters); exit; foreach ($filters as $filter => $file) { //if( CCTM::include_output_filter_class($filter) ) { if ($Obj = CCTM::load_object($filter, 'filters')) { /* $filter_name = CCTM::filter_prefix . $filter; $Obj = new $filter_name(); */ $output .= sprintf('<h3 class="cctm_h3">%s (%s)</h3> <p>%s -- [<a href="%s" target="_new">%s</a>]</p> <strong>%s</strong>:<br/> <div class="cctm_code"> %s </div> ', $Obj->get_name(), $filter, $Obj->get_description(), $Obj->get_url(), __('More info', CCTM_TXTDOMAIN), __('Example', CCTM_TXTDOMAIN), highlight_string($Obj->get_example('myfield', $filter), true)); } else { $output .= sprintf(__('File not found for %s output filter: %s', CCTM_TXTDOMAIN), '<strong>' . $filter . '</strong>', $file) . '<br/>'; } } return $output . '</div>'; }
/** * Apply the filter. * * @param mixed $input, usually a string representing a JSON-encoded array, but a real PHP array is ok too. * @param string $options optional arguments, to_array accepts the name of an Output Filter * @return mixed */ public function filter($input, $options = null) { $the_array = $this->to_array($input); // Apply secondary optional filter to each item in the array. if ($options && is_scalar($options)) { foreach ($the_array as &$item) { $item = CCTM::filter($item, $options); } } return $the_array; }
/** * See Issue http://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=138 * and this one: http://keighl.com/2010/04/switching-visualhtml-modes-with-tinymce/ * * @param string $current_value current value for this field. * @return string */ public function get_edit_field_instance($current_value) { $this->id = str_replace(array('[', ']', ' '), '_', $this->name); $wrappertpl = CCTM::load_tpl(array('fields/wrappers/' . $this->name . '.tpl', 'fields/wrappers/_' . $this->type . '.tpl', 'fields/wrappers/_default.tpl')); $settings = array(); $settings['editor_class'] = $this->class; $settings['textarea_name'] = $this->name_prefix . $this->name; // see http://nacin.com/tag/wp_editor/ ob_start(); wp_editor($current_value, $this->id_prefix . $this->id, $settings); $this->content = ob_get_clean(); $this->add_label = __('Add', CCTM_TXTDOMAIN); return CCTM::parse($wrappertpl, $this->get_props()); }
/** * Nonces exist in the $_POST array using the key named like this: * conroller_name + _nonce. The nonce is always named "ajax_nonce". * WARNING: The response returned by the ajax-controllers *must* be wrapped in * some kind of HTML tag, otherwise you can't use jQuery('#target_id').html(x) * to write it. * * @param string $name of the method being called * @param mixed $args sent to that method */ public function __call($name, $args) { if (!isset($this->controllers[$name])) { CCTM::log(sprintf(__('Invalid Ajax controller: %s', CCTM_TXTDOMAIN), "<em>{$name}</em>"), __FILE__, __LINE__); die(sprintf(__('Invalid Ajax controller: %s', CCTM_TXTDOMAIN), "<em>{$name}</em>")); } $nonce = CCTM::get_value($_REQUEST, $name . '_nonce'); if (!wp_verify_nonce($nonce, 'ajax_nonce')) { CCTM::log(sprintf(__('Invalid nonce for %s', CCTM_TXTDOMAIN), "<em>{$name}</em>"), __FILE__, __LINE__); die(sprintf(__('Invalid nonce for %s', CCTM_TXTDOMAIN), "<em>{$name}</em>")); } include $this->controllers[$name]; exit; }
/** * * * @param string $current_value * @return string */ public function get_edit_field_instance($current_value) { $this->is_checked = ''; $current_value = $this->get_value($current_value, 'to_string'); if ($current_value == $this->checked_value) { $this->is_checked = 'checked="checked"'; } $fieldtpl = CCTM::load_tpl(array('fields/elements/' . $this->name . '.tpl', 'fields/elements/_' . $this->type . '.tpl', 'fields/elements/_default.tpl')); $wrappertpl = CCTM::load_tpl(array('fields/wrappers/' . $this->name . '.tpl', 'fields/wrappers/_' . $this->type . '.tpl', 'fields/wrappers/_default.tpl')); $this->id = str_replace(array('[', ']', ' '), '_', $this->name); $this->value = htmlspecialchars($this->checked_value); $this->content = CCTM::parse($fieldtpl, $this->get_props()); return CCTM::parse($wrappertpl, $this->get_props()); }
/** * Apply the filter. * * @param mixed input: an integer, an array of integers, or a JSON string representing an array of integers. * @param string optional formatting tpl * @return mixed */ public function filter($input, $options = null) { $required_functions = array('getimagesize', 'imagecreatefromjpeg', 'imagecreatefromgif', 'imagecreatefrompng'); foreach ($required_functions as $f) { if (!function_exists($f)) { return sprintf(__('Missing required function %s'), '<code>' . $f . '</code>'); } } require_once CCTM_PATH . '/includes/SummarizePosts.php'; require_once CCTM_PATH . '/includes/GetPostsQuery.php'; $tpl = '<div class="cctm_gallery" id="cctm_gallery_[+i+]"><img height="[+height+]" width="[+width+]" src="[+guid+]" title="[+post_title+]" alt="[+alt+]" class="cctm_image" id="cctm_image_[+i+]"/></div>'; if (!empty($options)) { $tpl = $options; } if (empty($input)) { return ''; } $inputs = $this->to_array($input); $Q = new GetPostsQuery(); $Q->set_include_hidden_fields(true); // We can't use $Q->get_posts() because MySQL will return results in an arbitrary order. boo. $output = ''; $i = 1; foreach ($inputs as $image_id) { $r = $Q->get_post($image_id); // Translate $r['post_title'] = __($r['post_title']); $r['post_content'] = __($r['post_content']); $r['post_excerpt'] = __($r['post_excerpt']); $image_info = getimagesize($r['guid']); $image_type = $image_info[2]; if ($image_type == IMAGETYPE_JPEG) { $this_image = imagecreatefromjpeg($r['guid']); } elseif ($image_type == IMAGETYPE_GIF) { $this_image = imagecreatefromgif($r['guid']); } elseif ($image_type == IMAGETYPE_PNG) { $this_image = imagecreatefrompng($r['guid']); } if (isset($r['_wp_attachment_image_alt'])) { $r['alt'] = $r['_wp_attachment_image_alt']; } $r['i'] = $i; $r['width'] = imagesx($this_image); $r['height'] = imagesy($this_image); $output .= CCTM::parse($tpl, $r); $i++; } return $output; }
/** * Apply the filter. * * @param mixed user id or an array of them * @param mixed optional formatting string * @return mixed */ public function filter($input, $options = null) { $tpl = '<div class="cctm_userinfo" id="cctm_user_[+ID+]">[+user_nicename+]: [+user_email+]</div>'; if (!empty($options)) { $tpl = $options; } $inputs = $this->to_array($input); $output = ''; foreach ($inputs as $input) { $input = (int) $input; // Retrieve from CCTM request cache? (this caches data for a single request) // we cache the userdata array, keyed to a user ID if (isset(CCTM::$cache['userinfo'][$input])) { $output .= CCTM::parse($tpl, CCTM::$cache['userinfo'][$input]); continue; } global $wpdb; $userdata = array(); $query = $wpdb->prepare("SELECT ID, user_login, user_nicename, user_email, \n\t\t\t\tuser_url, user_registered, user_activation_key, user_status, \n\t\t\t\tdisplay_name FROM " . $wpdb->prefix . "users WHERE ID = %s", $input); $results = $wpdb->get_results($query, ARRAY_A); // No data for this user? if (!isset($results[0])) { CCTM::$cache['userinfo'][$input] = array(); // blank: prevents multiple queries continue; // $output .= CCTM::parse($tpl, $userdata); // ??? should we??? } // shift off the first (and only) result $userdata = $results[0]; // Get metadata $query = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "usermeta WHERE user_id = %s", $input); $results = $wpdb->get_results($query, ARRAY_A); // No metadata (don't know how'd you get here, but just in case...) if (empty($results)) { CCTM::$cache['userinfo'][$input] = $userdata; $output .= CCTM::parse($tpl, $userdata); continue; // next user... } foreach ($results as $r) { $userdata[$r['meta_key']] = $r['meta_value']; } CCTM::$cache['userinfo'][$input] = $userdata; $output .= CCTM::parse($tpl, $userdata); } return $output; }
/** * Apply the filter. * * @param mixed input: a single post ID or an array of them * @param string formatting string OR clickable title * @return mixed */ public function filter($input, $options = null) { $output = ''; // Gotta set the default here due to how print_custom_field calls get_custom_field if (empty($options)) { $options = '<a href="[+permalink+]" title="[+post_title+]">[+post_title+]</a>'; } elseif (strpos($options, '[+') === false) { $options = '<a href="[+permalink+]" title="[+post_title+]">' . $options . '</a>'; } $input = $this->to_array($input); if (empty($input)) { return ''; } $output = ''; if ($this->is_array_input) { foreach ($input as &$item) { if ($item) { //$post = get_post($item); if (!is_numeric($item)) { $item = sprintf(__('Invalid input. %s operates on post IDs only.', CCTM_TXTDOMAIN), 'to_link'); continue; } $post = get_post_complete($item); if (!is_array($post)) { $item = __('Referenced post not found.', CCTM_TXTDOMAIN); continue; } $link_text = $post['post_title']; $item = CCTM::parse($options, $post); } } return implode(', ', $input); } else { if (!is_numeric($input[0])) { return sprintf(__('Invalid input. %s operates on post IDs only.', CCTM_TXTDOMAIN), 'to_link'); } $post = get_post_complete($input[0]); if (!is_array($post)) { return _e('Referenced post not found.', CCTM_TXTDOMAIN); } return CCTM::parse($options, $post); } }
/** * Convert a post id to an array represent the post and all its data. * * @param mixed integer post_id or an array of post_id's * @param string optional field name to return OR a formatting string with [+placeholders+] * @return mixed */ public function filter($input, $options = null) { $input = $this->to_array($input); if ($options && is_scalar($options)) { $output = ''; } else { $output = array(); } if (empty($input)) { return false; } if ($this->is_array_input) { foreach ($input as $k => $item) { $item = (int) $item; $post = get_post_complete($item); if ($options && is_scalar($options)) { if (isset($post[$options])) { $output .= $post[$options]; } else { $output .= CCTM::parse($options, $post); } } else { $output[] = $post; } } return $output; } else { $input = (int) $input[0]; if ($options && is_scalar($options)) { $post = get_post_complete($input); if (isset($post[$options])) { return $post[$options]; } return CCTM::parse($options, $post); } else { return get_post_complete($input); } } }
/** * Format an array of values. * * @param mixed $input, e.g. a json_encoded array like '["cat","dog","bird"]' OR a real PHP array, e.g. array('cat','dog','bird') * @param mixed $options (optional)formatting parameters * @return string */ public function filter($input, $options = null) { $array = $this->to_array($input); // Return an empty string if the input is empty: // http://wordpress.org/support/topic/plugin-custom-content-type-manager-displaying-custom-fields-in-conditional-tags?replies=4#post-2537738 if (empty($array)) { return ''; } if (!empty($options) && is_array($options)) { $out = ''; // format each value if (isset($options[0])) { foreach ($array as $k => $v) { $hash['key'] = $k; $hash['value'] = $v; $out .= CCTM::parse($options[0], $hash); } } else { // ??? user supplied an associative array for options??? return __('Options array in incorrect format!', CCTM_TXTDOMAIN); } // wrap the output if (isset($options[1])) { $hash['content'] = $out; return CCTM::parse($options[1], $hash); } } elseif (!empty($options) && !is_array($options)) { //foreach ( $array as $i => $item ) { // $array[$i] = htmlspecialchars($item); // we apply this //} if ($this->_is_assoc($array)) { $array = array_values($array); } return implode($options, $array); } else { return implode(', ', $array); } }
/** * Apply the filter. * * @param mixed input * @param mixed optional arguments defining how to wrap the input * @return mixed */ public function filter($input, $options = null) { $inputs = $this->to_array($input); $output = ''; foreach ($inputs as $input) { if (empty($options) || empty($input)) { $output .= $input; } elseif (is_array($options)) { $before = ''; $after = ''; if (isset($options[0])) { $before = $options[0]; } if (isset($options[1])) { $after = $options[1]; } $output .= $before . $input . $after; } else { $output .= CCTM::parse($options, array('content' => $input)); } } return $output; }
function test_get_relation() { CCTM::$post_id = 77; $rel = get_relation('poster_image'); $this->assertTrue($rel['ID'] == 120); }
/** * Validate custom fields on a post that's already been saved. * * @param string $post_type * @param array $full_post array of all submitted values * @return boolean : true if valid, false if there were errors */ public static function validate_fields($post_type, $full_post) { $custom_fields = self::_get_custom_fields($post_type); $validation_errors = array(); foreach ($custom_fields as $field_name) { if (!isset(CCTM::$data['custom_field_defs'][$field_name]['type'])) { continue; } $field_type = CCTM::$data['custom_field_defs'][$field_name]['type']; if ($FieldObj = CCTM::load_object($field_type, 'fields')) { $FieldObj->set_props(CCTM::$data['custom_field_defs'][$field_name]); $value = ''; if (isset($full_post[$field_name])) { $value = $full_post[$field_name]; } // Check for empty json arrays, e.g. [""], convert them to empty PHP array() $value_copy = ''; if ($FieldObj->is_repeatable) { $value_copy = $FieldObj->get_value($value, 'to_array'); if (is_array($value_copy)) { foreach ($value_copy as $k => $v) { if (empty($v)) { unset($value_copy[$k]); } } } } else { $value_copy = $FieldObj->get_value($value, 'to_string'); } // Is this field required? OR did validation fail? if ($FieldObj->required) { if (is_array($value_copy) && empty($value_copy) || !is_array($value_copy) && !strlen(trim($value_copy))) { CCTM::$post_validation_errors[$FieldObj->name] = sprintf(__('The %s field is required.', CCTM_TXTDOMAIN), $FieldObj->label); } elseif (!is_array($value_copy) && !strlen(trim($value_copy))) { CCTM::$post_validation_errors[$FieldObj->name] = sprintf(__('The %s field is required.', CCTM_TXTDOMAIN), $FieldObj->label); } } elseif ((!empty($value_copy) || $value_copy == '0') && isset($FieldObj->validator) && !empty($FieldObj->validator)) { $Validator = CCTM::load_object($FieldObj->validator, 'validators'); if (isset(CCTM::$data['custom_field_defs'][$field_name]['validator_options'])) { $Validator->set_options(CCTM::$data['custom_field_defs'][$field_name]['validator_options']); } $Validator->set_subject($FieldObj->label); $Validator->set_options($FieldObj->validator_options); if (is_array($value_copy)) { foreach ($value_copy as $i => $val) { $value_copy[$i] = $Validator->validate($val); } } else { $value_copy = $Validator->validate($value_copy); } if (!empty($Validator->error_msg)) { CCTM::$post_validation_errors[$FieldObj->name] = $Validator->get_error_msg(); } } } else { // error! Can't include the field class. WTF did you do to get here? } } if (empty(CCTM::$post_validation_errors)) { return true; } else { return false; } }
$hash['post_parent'] = __('Parent', CCTM_TXTDOMAIN); $hash['post_type'] = __('Post Type', CCTM_TXTDOMAIN); $hash['add_to_post'] = __('Add to Post', CCTM_TXTDOMAIN); $hash['add_to_post_and_close'] = __('Add to Post and Close', CCTM_TXTDOMAIN); //$hash['filter'] = __('Filter', CCTM_TXTDOMAIN); //$hash['show_all'] = __('Show All', CCTM_TXTDOMAIN); $hash['content'] = ''; // And the items //$results = array(); foreach ($results as $r) { $r['name'] = $raw_fieldname; $r['preview'] = __('Preview', CCTM_TXTDOMAIN); $r['select'] = __('Select', CCTM_TXTDOMAIN); $r['field_id'] = $raw_fieldname; $r['thumbnail_url'] = CCTM::get_thumbnail($r['ID']); // Translate stuff (issue 279) $r['post_title'] = __($r['post_title']); $r['post_content'] = __($r['post_content']); $r['post_excerpt'] = __($r['post_excerpt']); $hash['content'] .= CCTM::parse($item_tpl, $r); } $d['content'] .= CCTM::parse($wrapper_tpl, $hash); $d['content'] .= '<div class="cctm_pagination_links">' . $Q->get_pagination_links() . '</div>'; if (isset($_POST['wrap_thickbox'])) { print CCTM::load_view('templates/thickbox.php', $d); } else { //print CCTM::load_view('templates/thickbox_inner.php', $d); print $d['content']; } exit; /*EOF*/
/** * Generate a form. This is the main event. * * @param array (optional) $search_by specify which parameters you want to search by * @param array (optional) $existing_values to populate the form e.g. from $_POST. * @return string HTML form. */ public function generate($search_by = array(), $existing_values = array()) { foreach ($existing_values as $k => $v) { $this->Q->{$k} = $v; // to __set() on GetPostsQuery } $this->values = $this->Q->args; // from GetPostsQuery static $instantiation_count = 0; // used to generate a unique CSS for every form on the page $instantiation_count++; $this->placeholders['form_number'] = $instantiation_count; // Default CSS stuff if (!isset($this->placeholders['css'])) { $dir = dirname(dirname(__FILE__)); $this->set_css($dir . '/css/searchform.css'); } // Defaults if (!empty($search_by)) { // override $this->search_by = $search_by; } // Override to our EVERYTHING search. if ($search_by === true) { $this->search_by = $this->search_by_everything; } $output = ''; $this->placeholders['content'] = ''; // Each part of the form is generated by component functions that correspond // exactly to the $search_by arguments. foreach ($this->search_by as $p) { $function_name = '_' . $p; if (method_exists($this, $function_name)) { $this->placeholders[$p] = $this->{$function_name}(); // Keep the main 'content' bit populated: the content is the sum total of all generated elements. $this->placeholders['content'] .= $this->placeholders[$p]; } else { $this->placeholders[$p] = $this->__call($p, array()); // Keep the main 'content' bit populated. $this->placeholders['content'] .= $this->placeholders[$p]; $this->errors['invalid_searchby_parameter'] = sprintf(__('Possible invalid search_by parameter:'), "<em>{$p}</em>"); } } // Get help // $all_placeholders = array_keys($this->placeholders); $all_placeholders = array(); foreach ($this->placeholders as $key => $tmp) { $all_placeholders[$key] = "[+{$key}+]"; } $this->placeholders['nonce'] = $this->get_nonce_field(); // this won't show via [+help+] $this->placeholders['help'] = implode(', ', $all_placeholders); // Two passes. $this->form_tpl = CCTM::parse($this->form_tpl, $this->placeholders, true); $out = CCTM::parse($this->form_tpl, $this->placeholders); $this->stop_time = microtime(true); return $out; }
<div class="container"> <div class="row"> <div class="col-xs-10 col-xs-offset-1"> <div class="bike-shot"> <div class="bike-shot-ft"> <img src="<?php print_custom_field('photoImage'); ?> " alt="<?php the_title(); ?> " class="top show"/> <?php $array_of_images = get_custom_field('uploadsGallery:to_array'); foreach ($array_of_images as $img_id) { print CCTM::filter($img_id, 'to_image_tag'); } ?> </div> </div> </div> </div> <div class="row"> <div class="col-xs-10 col-xs-offset-1 col-md-8 col-md-offset-2 pre-text"> <?php if ($array_of_images) { ?> <div class="bike-shot-thumbs"></div> <?php } else { ?>
/** * Everything when creating a new post type must be filtered here. * * Problems with: * hierarchical * rewrite_with_front * * This is janky... sorta doesn't work how it's supposed when combined with save_post_type_settings(). * * * @param mixed $raw unsanitized $_POST data * @return mixed filtered $_POST data (only white-listed are passed thru to output) */ public static function sanitize_post_type_def($raw) { $sanitized = array(); unset($raw['custom_content_type_mgr_create_new_content_type_nonce']); unset($raw['custom_content_type_mgr_edit_content_type_nonce']); $raw = CCTM::striptags_deep($raw); // WP always adds slashes: see http://kovshenin.com/archives/wordpress-and-magic-quotes/ $raw = CCTM::stripslashes_deep($raw); // Handle unchecked checkboxes if (empty($raw['cctm_hierarchical_custom'])) { $sanitized['cctm_hierarchical_custom'] = ''; } if (empty($raw['cctm_hierarchical_includes_drafts'])) { $sanitized['cctm_hierarchical_includes_drafts'] = ''; } if (empty($raw['cctm_hierarchical_post_types'])) { $sanitized['cctm_hierarchical_post_types'] = array(); } if (!isset($raw['cctm_custom_columns_enabled'])) { $sanitized['cctm_custom_columns_enabled'] = 0; } if (!isset($raw['cctm_enable_right_now'])) { $sanitized['cctm_enable_right_now'] = 0; } // This will be empty if no "supports" items are checked. if (!empty($raw['supports'])) { $sanitized['supports'] = $raw['supports']; unset($raw['supports']); } else { $sanitized['supports'] = array(); } if (!empty($raw['taxonomies'])) { $sanitized['taxonomies'] = $raw['taxonomies']; } else { // do this so this will take precedence when you merge the existing array with the new one in the save_post_type_settings() function. $sanitized['taxonomies'] = array(); } // You gotta unset arrays if you want the foreach thing below to work. unset($raw['taxonomies']); // Temporary thing... ???? unset($sanitized['rewrite_slug']); // The main event // We grab everything except stuff that begins with '_', then override specific $keys as needed. foreach ($raw as $key => $value) { if (!preg_match('/^_.*/', $key)) { $sanitized[$key] = CCTM::get_value($raw, $key); } } // Specific overrides below: $sanitized['description'] = strip_tags($raw['description']); // post_type is the only required field $sanitized['post_type'] = CCTM::get_value($raw, 'post_type'); $sanitized['post_type'] = strtolower($sanitized['post_type']); $sanitized['post_type'] = preg_replace('/[^a-z0-9_\\-]/', '_', $sanitized['post_type']); $sanitized['post_type'] = substr($sanitized['post_type'], 0, 20); // Our form passes integers and strings, but WP req's literal booleans, // so we do some type-casting here to ensure literal booleans. $sanitized['public'] = (bool) CCTM::get_value($raw, 'public'); $sanitized['rewrite_with_front'] = (bool) CCTM::get_value($raw, 'rewrite_with_front'); $sanitized['show_ui'] = (bool) CCTM::get_value($raw, 'show_ui'); $sanitized['public'] = (bool) CCTM::get_value($raw, 'public'); $sanitized['show_in_nav_menus'] = (bool) CCTM::get_value($raw, 'show_in_nav_menus'); $sanitized['can_export'] = (bool) CCTM::get_value($raw, 'can_export'); $sanitized['use_default_menu_icon'] = (bool) CCTM::get_value($raw, 'use_default_menu_icon'); $sanitized['hierarchical'] = (bool) CCTM::get_value($raw, 'hierarchical'); $sanitized['include_in_search'] = (bool) CCTM::get_value($raw, 'include_in_search'); $sanitized['publicly_queryable'] = (bool) CCTM::get_value($raw, 'publicly_queryable'); $sanitized['include_in_rss'] = (bool) CCTM::get_value($raw, 'include_in_rss'); $sanitized['map_meta_cap'] = (bool) CCTM::get_value($raw, 'map_meta_cap'); $sanitized['show_in_admin_bar'] = (bool) CCTM::get_value($raw, 'show_in_admin_bar'); if (empty($sanitized['has_archive'])) { $sanitized['has_archive'] = false; } else { $sanitized['has_archive'] = true; } // *facepalm*... Special handling req'd here for menu_position because 0 // is handled differently than a literal null. if ((int) CCTM::get_value($raw, 'menu_position')) { $sanitized['menu_position'] = (int) CCTM::get_value($raw, 'menu_position', null); } else { $sanitized['menu_position'] = null; } $sanitized['show_in_menu'] = CCTM::get_value($raw, 'show_in_menu'); $sanitized['cctm_show_in_menu'] = CCTM::get_value($raw, 'cctm_show_in_menu'); // menu_icon... the user will lose any custom Menu Icon URL if they save with this checked! // TODO: let this value persist. if ($sanitized['use_default_menu_icon']) { unset($sanitized['menu_icon']); // === null; } if (empty($sanitized['query_var'])) { $sanitized['query_var'] = false; } // Cleaning up the labels if (empty($sanitized['label'])) { $sanitized['label'] = ucfirst($sanitized['post_type']); } if (empty($sanitized['labels']['singular_name'])) { $sanitized['labels']['singular_name'] = ucfirst($sanitized['post_type']); } if (empty($sanitized['labels']['add_new'])) { $sanitized['labels']['add_new'] = __('Add New'); } if (empty($sanitized['labels']['add_new_item'])) { $sanitized['labels']['add_new_item'] = __('Add New') . ' ' . ucfirst($sanitized['post_type']); } if (empty($sanitized['labels']['edit_item'])) { $sanitized['labels']['edit_item'] = __('Edit') . ' ' . ucfirst($sanitized['post_type']); } if (empty($sanitized['labels']['new_item'])) { $sanitized['labels']['new_item'] = __('New') . ' ' . ucfirst($sanitized['post_type']); } if (empty($sanitized['labels']['view_item'])) { $sanitized['labels']['view_item'] = __('View') . ' ' . ucfirst($sanitized['post_type']); } if (empty($sanitized['labels']['search_items'])) { $sanitized['labels']['search_items'] = __('Search') . ' ' . ucfirst($sanitized['labels']['menu_name']); } if (empty($sanitized['labels']['not_found'])) { $sanitized['labels']['not_found'] = sprintf(__('No %s found', CCTM_TXTDOMAIN), strtolower($raw['labels']['menu_name'])); } if (empty($sanitized['labels']['not_found_in_trash'])) { $sanitized['labels']['not_found_in_trash'] = sprintf(__('No %s found in trash', CCTM_TXTDOMAIN), strtolower($raw['labels']['menu_name'])); } if (empty($sanitized['labels']['parent_item_colon'])) { $sanitized['labels']['parent_item_colon'] = __('Parent Page'); } // Rewrites. TODO: make this work like the built-in post-type permalinks switch ($sanitized['permalink_action']) { case '/%postname%/': $sanitized['rewrite'] = true; break; case 'Custom': $sanitized['rewrite']['slug'] = $raw['rewrite_slug']; $sanitized['rewrite']['with_front'] = isset($raw['rewrite_with_front']) ? (bool) $raw['rewrite_with_front'] : false; break; case 'Off': default: $sanitized['rewrite'] = false; } return $sanitized; }
can be adjusted allows you to open up certain criteria for user selection. This file should ONLY populate the CCTM::$post_selector array, and the valid keys should be valid arguments to the GetPostsQuery::get_posts() function: CCTM::$post_selector['post_type'] = 'attachment'; CCTM::$post_selector['post_mime_type'] = 'image'; // ... etc... See http://code.google.com/p/wordpress-summarize-posts/wiki/get_posts e.g. DO NOT OVERWRITE THIS FILE DIRECTLY! Instead, create a copy of this file inside wp-content/uploads/cctm/post_selector/ -- this ensures that your custom modications are preserved in a place that will not be overwritten by the WordPress update process. ------------------------------------------------------------------------------*/ CCTM::$post_selector['search_columns'] = array('post_title', 'post_content'); CCTM::$post_selector['post_status'] = array('publish', 'inherit'); CCTM::$post_selector['orderby'] = 'ID'; CCTM::$post_selector['order'] = 'DESC'; CCTM::$post_selector['limit'] = 10; CCTM::$post_selector['paginate'] = 1; CCTM::$search_by = array(); CCTM::$search_by[] = 'post_type'; CCTM::$search_by[] = 'post_status'; CCTM::$search_by[] = 'taxonomy'; CCTM::$search_by[] = 'taxonomy_term'; CCTM::$search_by[] = 'post_parent'; CCTM::$search_by[] = 'meta_key'; CCTM::$search_by[] = 'meta_value'; /*EOF*/
$data = array(); $data['i'] = md5(uniqid()); // we just need a unique identifier for each row element $data['name'] = ''; $data['label'] = ''; $data['type'] = ''; $data['field_types'] = ''; $data['name_class'] = ''; // 'cctm_validation_error'; // 1. User has specified a desired field type if ($desired_field_type) { $elements = CCTM::get_available_helper_classes('fields'); foreach ($elements as $field_type => $file) { if ($FieldObj = CCTM::load_object($field_type, 'fields')) { $is_selected = ''; if ($desired_field_type == $field_type) { $is_selected = ' selected="selected"'; } $data['field_types'] .= '<option value="' . $field_type . '"' . $is_selected . '>' . $FieldObj->get_name() . '</option>'; } else { // Form element not found. Did someone move a custom class file? } } print CCTM::load_view('tr_bulk.php', $data); } elseif ($post_type || $post_ids) { // Search the database } else { printf('<div class="error"><table><tr><td><img src="%s/images/warning-icon.png" height="44" width="50"/></td><td><p>%s</p></td></tr></table></div>', CCTM_URL, __('Invalid selection.', CCTM_TXTDOMAIN)); return; } /*EOF*/
add_action('save_post', 'StandardizedCustomFields::save_custom_fields', 1, 2); //! TODO: register this action conditionally // Customize the page-attribute box for custom page hierarchies add_filter('wp_dropdown_pages', 'StandardizedCustomFields::customized_hierarchical_post_types', 100, 1); // FUTURE: Highlght which themes are CCTM-compatible (if any) // add_filter('theme_action_links', 'CCTM::highlight_cctm_compatible_themes'); add_action('admin_notices', 'CCTM::print_warnings'); // Used to modify the large post icon add_action('in_admin_header', 'StandardizedCustomFields::print_admin_header'); // Handle Custom Columns: this is only relevant for the edit.php?post_type=xxxx pages (i.e. the list view) if (substr($_SERVER['SCRIPT_NAME'], strrpos($_SERVER['SCRIPT_NAME'], '/') + 1) == 'edit.php') { $post_type = CCTM::get_value($_GET, 'post_type'); if (isset(CCTM::$data['post_type_defs'][$post_type]['cctm_custom_columns_enabled']) && CCTM::$data['post_type_defs'][$post_type]['cctm_custom_columns_enabled'] == 1 && isset(CCTM::$data['post_type_defs'][$post_type]['cctm_custom_columns']) && !empty(CCTM::$data['post_type_defs'][$post_type]['cctm_custom_columns'])) { require_once 'includes/CCTM_Columns.php'; require_once 'includes/functions.php'; CCTM::$Columns = new CCTM_Columns(); CCTM::$Columns->post_type = $post_type; // Draw the column headers add_filter("manage_{$post_type}_posts_columns", array(CCTM::$Columns, $post_type)); // Handle the data in each cell add_action('manage_posts_custom_column', array(CCTM::$Columns, 'populate_custom_column_data')); add_action('manage_pages_custom_column', array(CCTM::$Columns, 'populate_custom_column_data')); // Forces custom post types to sort correctly add_filter('posts_orderby', 'CCTM::order_posts'); add_filter('posts_join', 'CCTM::posts_join'); } } add_filter('media_upload_tabs', 'CCTM::customize_upload_tabs'); } // Enable archives for custom post types //add_filter('request', 'CCTM::request_filter');
if ($counter == 2 || $counter == 1) { $fluidClasses = 'col-xs-12 col-sm-6 col-md-6 col-lg-6'; } else { $fluidClasses = 'col-xs-12 col-sm-6 col-md-4 col-lg-4'; } ?> <div class="case <?php echo $fluidClasses; ?> "> <a href="<?php echo get_permalink(); ?> "><?php echo CCTM::filter(get_post_meta(get_the_ID(), 'slider_image', true), 'to_image_tag', 'overview-img'); ?> </a> <a href="<?php echo get_permalink(); ?> "> <p class="related-title-white"><?php print_custom_field('overview_title'); ?> <span><?php print_custom_field('overview_subtitle'); ?> </span></p> </a> </div>
/** * * * @param mixed $current_value current value for this field. * @return string */ public function get_edit_field_instance($current_value) { $this->id = str_replace(array('[', ']', ' '), '_', $this->name); $fieldtpl = ''; $wrappertpl = ''; // Figure out which tpls to load if (in_array($this->date_format, array('yyyy-mm-dd hh:mm:ss', 'mm/dd/yy hh:mm', 'mm/dd/yy hh:mm am'))) { $this->datetype = 'datetime'; } elseif (in_array($this->date_format, array('show24Hours: true, step: 10', 'show24Hours: true, step: 15', 'show24Hours: true, step: 30', 'show24Hours: false, step: 10', 'show24Hours: false, step: 15', 'show24Hours: false, step: 30'))) { $this->datetype = 'time'; } else { $this->datetype = 'date'; } // Multi-version of the field if ($this->is_repeatable) { $fieldtpl = CCTM::load_tpl(array('fields/elements/' . $this->name . '.tpl', 'fields/elements/_' . $this->datetype . '_multi.tpl')); $wrappertpl = CCTM::load_tpl(array('fields/wrappers/' . $this->name . '.tpl', 'fields/wrappers/_' . $this->datetype . '_multi.tpl', 'fields/wrappers/_text_multi.tpl')); $this->i = 0; $values = $this->get_value($current_value, 'to_array'); //die(print_r($values,true)); $this->content = ''; foreach ($values as $v) { $this->value = htmlspecialchars(html_entity_decode($v)); $this->content .= CCTM::parse($fieldtpl, $this->get_props()); $this->i = $this->i + 1; } } else { $fieldtpl = CCTM::load_tpl(array('fields/elements/' . $this->name . '.tpl', 'fields/elements/_' . $this->datetype . '.tpl', 'fields/elements/_default.tpl')); $wrappertpl = CCTM::load_tpl(array('fields/wrappers/' . $this->name . '.tpl', 'fields/wrappers/_' . $this->datetype . '.tpl', 'fields/wrappers/_default.tpl')); $this->value = htmlspecialchars(html_entity_decode($this->get_value($current_value, 'to_string'))); $this->content = CCTM::parse($fieldtpl, $this->get_props()); } $this->add_label = __('Add', CCTM_TXTDOMAIN); return CCTM::parse($wrappertpl, $this->get_props()); }
continue; // skip } ?> <div class="cctm_element_wrapper" id="custom_field_wrapper_taxonomy_<?php print $t->name; ?> "> <input type="checkbox" name="taxonomies[]" class="cctm_checkbox" id="taxonomy_<?php print $t->name; ?> " value="<?php print $t->name; ?> " <?php print CCTM::is_checked($data['def']['taxonomies'], $t->name); ?> /> <label for="taxonomy_<?php print $t->name; ?> " class="cctm_label cctm_checkbox_label" id="cctm_label_taxonomies[]"><?php print $t->labels->name; ?> </label> </div> <?php } ?> </div>
/** * Note that the HTML in $option_html should match the JavaScript version of * the same HTML in js/dropdown.js (see the append_dropdown_option() function). * I couldn't think of a clean way to do this, but the fundamental problem is * that both PHP and JS need to draw the same HTML into this form: * PHP draws it when an existing definition is *edited*, whereas JS draws it * when you dynamically *create* new dropdown options. * * @param array $def nested array of existing definition. * @return string */ public function get_edit_field_definition($def) { // Standard $out = $this->format_standard_fields($def, false); $is_checked = ''; $is_sql_checked = ''; $readonly_str = ' readonly="readonly"'; if (isset($def['use_key_values']) && $def['use_key_values']) { $is_checked = 'checked="checked"'; $readonly_str = ''; } if (isset($def['is_sql']) && $def['is_sql']) { $is_sql_checked = 'checked="checked"'; } // Options $out .= ' <div class="postbox"> <div class="handlediv" title="Click to toggle"><br /></div> <h3 class="hndle"><span>' . __('Options', CCTM_TXTDOMAIN) . '</span></h3> <div class="inside"> <table><tr><td width="600" style="vertical-align:top">'; // Use Key => Value Pairs? (if not, the simple usage is simple options) $out .= ' <input type="hidden" name="use_key_values" value="0"/> <div class="' . self::wrapper_css_class . '" id="use_key_values_wrapper"> <label for="use_key_values" class="cctm_label cctm_checkbox_label" id="use_key_values_label">' . __('Distinct options/values?', CCTM_TXTDOMAIN) . '</label> <br /> <input type="checkbox" name="use_key_values" class="cctm_checkbox" id="use_key_values" value="1" onclick="javascript:toggle_readonly();" ' . $is_checked . '/> <span>' . $this->descriptions['use_key_values'] . '</span> </div>'; // OPTIONS $option_cnt = 0; if (isset($def['options'])) { $option_cnt = count($def['options']); } // using the parse function because this got too crazy with escaping single quotes $hash = array(); $hash['option_cnt'] = $option_cnt; $hash['delete'] = __('Delete'); $hash['options'] = __('Options', CCTM_TXTDOMAIN); $hash['values'] = __('Stored Values', CCTM_TXTDOMAIN); $hash['add_option'] = __('Add Option', CCTM_TXTDOMAIN); $hash['set_as_default'] = __('Set as Default', CCTM_TXTDOMAIN); $tpl = ' <script type="text/javascript"> jQuery(function() { jQuery( "#dropdown_options2" ).sortable(); // jQuery( "#dropdown_options2" ).disableSelection(); }); </script> <table id="dropdown_options"> <thead> <td scope="col" id="sorter" class="" style=""> </td> <td width="200"><label for="options" class="cctm_label cctm_select_label" id="cctm_label_options">[+options+]</label></td> <td width="200"><label for="options" class="cctm_label cctm_select_label" id="cctm_label_options">[+values+]</label></td> <td> <span class="button" onclick="javascript:append_dropdown_option(\'dropdown_options\',\'[+delete+]\',\'[+set_as_default+]\',\'[+option_cnt+]\');">[+add_option+]</span> </td> </thead> <tbody id="dropdown_options2">'; $out .= CCTM::parse($tpl, $hash); // this html should match up with the js html in dropdown.js $option_html = ' <tr id="%s"> <td><span class="ui-icon ui-icon-arrowthick-2-n-s"></span></td> <td><input type="text" name="options[]" id="option_%s" value="%s"/></td> <td><input type="text" name="values[]" id="value_%s" value="%s" class="possibly_gray"' . $readonly_str . '/></td> <td><span class="button" onclick="javascript:remove_html(\'%s\');">%s</span> <span class="button" onclick="javascript:set_as_default(\'%s\');">%s</span></td> </tr>'; $opt_i = 0; // used to uniquely ID options. if (!empty($def['options']) && is_array($def['options'])) { $opt_cnt = count($def['options']); for ($i = 0; $i < $opt_cnt; $i++) { // just in case the array isn't set $option_txt = ''; if (isset($def['options'][$i])) { $option_txt = htmlspecialchars(trim($def['options'][$i])); } $value_txt = ''; if (isset($def['values'][$i])) { $value_txt = htmlspecialchars(trim($def['values'][$i])); } $option_css_id = 'cctm_dropdown_option' . $opt_i; $out .= sprintf($option_html, $option_css_id, $opt_i, $option_txt, $opt_i, $value_txt, $option_css_id, __('Delete'), $opt_i, __('Set as Default')); $opt_i = $opt_i + 1; } } $out .= ' </tbody> </table>'; // close id="dropdown_options" // Display as Radio Button or as Dropdown? $out .= '<div class="' . self::wrapper_css_class . '" id="display_type_wrapper"> <label class="cctm_label cctm_checkbox_label" id="display_type_label">' . __('How should the field display?', CCTM_TXTDOMAIN) . '</label> <br /> <input type="radio" name="display_type" class="cctm_radio" id="display_type_dropdown" value="dropdown" ' . CCTM::is_radio_selected('dropdown', CCTM::get_value($this->props, 'display_type', 'dropdown')) . '/> <label for="display_type_dropdown" class="cctm_label cctm_radio_label" id="display_type_dropdown_label">' . __('Dropdown', CCTM_TXTDOMAIN) . '</label><br /> <input type="radio" name="display_type" class="cctm_radio" id="display_type_radio" value="radio" ' . CCTM::is_radio_selected('radio', CCTM::get_value($this->props, 'display_type', 'dropdown')) . '/> <label for="display_type_radio" class="cctm_label cctm_radio_label" id="display_type_radio_label">' . __('Radio Button', CCTM_TXTDOMAIN) . '</label><br /> </div>'; // Secondary Input options $out .= '</td><td style="vertical-align:top"> <label class="cctm_label cctm_textarea_label" id="advanced_label">' . __('Alternate Input', CCTM_TXTDOMAIN) . '</label> <span>' . __('Use this input if you want to options in bulk. Separate options and values using double-pipes "||" with the visible option on the left, the corresponding value to be stored on the right (if present). You may also enter a valid MySQL query. This field overrides other inputs!', CCTM_TXTDOMAIN) . '</span><br/> <textarea name="alternate_input" id="alternate_input" cols="50" rows="10">' . CCTM::get_value($def, 'alternate_input') . '</textarea>'; // Execute as MySQL? $out .= '<div class="' . self::wrapper_css_class . '" id="is_sql_wrapper"> <input type="hidden" name="is_sql" value="0"/> <input type="checkbox" name="is_sql" class="cctm_checkbox" id="is_sql" value="1"' . $is_sql_checked . '/> <label for="is_sql" class="cctm_label cctm_checkbox_label" id="is_sql_label">' . __('Execute as a MySQL query?', CCTM_TXTDOMAIN) . '</label> <span>' . __('Select up to 2 columns: the 1st column will be the visible label and the 2nd column (if present) will represent the value stored in the database. Use [+table_prefix+] instead of hard-coding your WordPress database table prefix.', CCTM_TXTDOMAIN) . '</span> </div>'; $out .= ' </td></tr></table> </div><!-- /inside --> </div><!-- /postbox -->'; // Validations / Required $out .= $this->format_validators($def, false); // Output Filter $out .= $this->format_available_output_filters($def); return $out; }
/** * Process the $args to something GetPostsQuery. */ function widget($args, $instance) { // Avoid placing empty widgets if (!isset($instance['post_id']) || empty($instance['post_id'])) { return; } require_once CCTM_PATH . '/includes/GetPostsQuery.php'; $post_id = (int) $instance['post_id']; $Q = new GetPostsQuery(); $post = $Q->get_post($post_id); $post['post_content'] = do_shortcode(wpautop($post['post_content'])); $output = $args['before_widget']; if (isset($instance['override_title']) && $instance['override_title'] == 1) { $title = $instance['title']; } else { $title = $post['post_title']; // default is to use the post's title } if (!empty($title)) { $output .= $args['before_title'] . $title . $args['after_title']; } if (!empty($instance['formatting_string'])) { $output .= CCTM::parse($instance['formatting_string'], $post); } else { $output .= $post['post_content']; } $output .= $args['after_widget']; print $output; }
if (isset($GLOBALS['wp_post_types'][$post_type]->cap->edit_posts)) { $cap = $GLOBALS['wp_post_types'][$post_type]->cap->edit_posts; } if (!current_user_can($cap)) { die('<pre>You do not have permission to do that.</pre>'); } require_once CCTM_PATH . '/includes/GetPostsQuery.php'; //print '<div>'. print_r($_POST, true).'</div>'; $post_id = CCTM::get_value($_POST, 'post_id'); $target_id = CCTM::get_value($_POST, 'target_id'); // Will be either the single or the multi, depending. $tpl = ''; $tpl = CCTM::load_tpl('widgets/post_item.tpl'); // Just in case... if (empty($tpl)) { print '<p>' . __('Formatting template not found!', CCTM_TXTDOMAIN) . '</p>'; return; } $Q = new GetPostsQuery(); $post = $Q->get_post($post_id); $post['edit_selected_post_label'] = __('Edit Selected Post', CCTM_TXTDOMAIN); $post_type = $post['post_type']; $post['post_icon'] = CCTM::get_thumbnail($post_id); if ($post_type == 'attachment') { $post['edit_url'] = get_admin_url('', 'media.php') . "?attachment_id={$post_id}&action=edit"; } else { $post['edit_url'] = get_admin_url('', 'post.php') . "?post={$post_id}&action=edit"; } $post['target_id'] = $target_id; print CCTM::parse($tpl, $post); /*EOF*/
private static function _set_post_type_form_definition() { $def = array(); $def['post_type']['name'] = 'post_type'; $def['post_type']['label'] = __('Name', CCTM::txtdomain) . ' *'; $def['post_type']['value'] = ''; $def['post_type']['extra'] = ''; $def['post_type']['description'] = __('Unique singular name to identify this post type in the database, e.g. "movie","book". This 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>. The name should be lowercase with only letters and underscores. This name cannot be changed!', CCTM::txtdomain); $def['post_type']['type'] = 'text'; $def['post_type']['sort_param'] = 1; $def['singular_label']['name'] = 'singular_label'; $def['singular_label']['label'] = __('Singular Label', CCTM::txtdomain); $def['singular_label']['value'] = ''; $def['singular_label']['extra'] = ''; $def['singular_label']['description'] = __('Human readable single instance of this content type, e.g. "Post"', CCTM::txtdomain); $def['singular_label']['type'] = 'text'; $def['singular_label']['sort_param'] = 2; $def['label']['name'] = 'label'; $def['label']['label'] = __('Menu Label (Plural)', CCTM::txtdomain); $def['label']['value'] = ''; $def['label']['extra'] = ''; $def['label']['description'] = __('Plural name used in the admin menu, e.g. "Posts"', CCTM::txtdomain); $def['label']['type'] = 'text'; $def['label']['sort_param'] = 3; $def['description']['name'] = 'description'; $def['description']['label'] = __('Description', CCTM::txtdomain); $def['description']['value'] = ''; $def['description']['extra'] = ''; $def['description']['description'] = ''; $def['description']['type'] = 'textarea'; $def['description']['sort_param'] = 4; $def['show_ui']['name'] = 'show_ui'; $def['show_ui']['label'] = __('Show Admin User Interface', CCTM::txtdomain); $def['show_ui']['value'] = '1'; $def['show_ui']['extra'] = ''; $def['show_ui']['description'] = __('Should this post type be visible on the back-end?', CCTM::txtdomain); $def['show_ui']['type'] = 'checkbox'; $def['show_ui']['sort_param'] = 5; $def['capability_type']['name'] = 'capability_type'; $def['capability_type']['label'] = __('Capability Type', CCTM::txtdomain); $def['capability_type']['value'] = 'post'; $def['capability_type']['extra'] = ''; $def['capability_type']['description'] = __('The post type to use for checking read, edit, and delete capabilities. Default: "post"', CCTM::txtdomain); $def['capability_type']['type'] = 'text'; $def['capability_type']['sort_param'] = 6; $def['public']['name'] = 'public'; $def['public']['label'] = __('Public', CCTM::txtdomain); $def['public']['value'] = '1'; $def['public']['extra'] = ''; $def['public']['description'] = __('Should these posts be visible on the front-end?', CCTM::txtdomain); $def['public']['type'] = 'checkbox'; $def['public']['sort_param'] = 7; $def['hierarchical']['name'] = 'hierarchical'; $def['hierarchical']['label'] = __('Hierarchical', CCTM::txtdomain); $def['hierarchical']['value'] = ''; $def['hierarchical']['extra'] = ''; $def['hierarchical']['description'] = __('Allows parent to be specified (Page Attributes should be checked)', CCTM::txtdomain); $def['hierarchical']['type'] = 'checkbox'; $def['hierarchical']['sort_param'] = 8; $def['supports_title']['name'] = 'supports[]'; $def['supports_title']['id'] = 'supports_title'; $def['supports_title']['label'] = __('Title', CCTM::txtdomain); $def['supports_title']['value'] = 'title'; $def['supports_title']['checked_value'] = 'title'; $def['supports_title']['extra'] = ''; $def['supports_title']['description'] = __('Post Title', CCTM::txtdomain); $def['supports_title']['type'] = 'checkbox'; $def['supports_title']['sort_param'] = 20; $def['supports_editor']['name'] = 'supports[]'; $def['supports_editor']['id'] = 'supports_editor'; $def['supports_editor']['label'] = __('Content', CCTM::txtdomain); $def['supports_editor']['value'] = 'editor'; $def['supports_editor']['checked_value'] = 'editor'; $def['supports_editor']['extra'] = ''; $def['supports_editor']['description'] = __('Main content block.', CCTM::txtdomain); $def['supports_editor']['type'] = 'checkbox'; $def['supports_editor']['sort_param'] = 21; $def['supports_author']['name'] = 'supports[]'; $def['supports_author']['id'] = 'supports_author'; $def['supports_author']['label'] = __('Author', CCTM::txtdomain); $def['supports_author']['value'] = ''; $def['supports_author']['checked_value'] = 'author'; $def['supports_author']['extra'] = ''; $def['supports_author']['description'] = __('Track the author.', CCTM::txtdomain); $def['supports_author']['type'] = 'checkbox'; $def['supports_author']['sort_param'] = 22; $def['supports_thumbnail']['name'] = 'supports[]'; $def['supports_thumbnail']['id'] = 'supports_thumbnail'; $def['supports_thumbnail']['label'] = __('Thumbnail', CCTM::txtdomain); $def['supports_thumbnail']['value'] = ''; $def['supports_thumbnail']['checked_value'] = 'thumbnail'; $def['supports_thumbnail']['extra'] = ''; $def['supports_thumbnail']['description'] = __('Featured image (the activetheme must also support post-thumbnails)', CCTM::txtdomain); $def['supports_thumbnail']['type'] = 'checkbox'; $def['supports_thumbnail']['sort_param'] = 23; $def['supports_excerpt']['name'] = 'supports[]'; $def['supports_excerpt']['id'] = 'supports_excerpt'; $def['supports_excerpt']['label'] = __('Excerpt', CCTM::txtdomain); $def['supports_excerpt']['value'] = ''; $def['supports_excerpt']['checked_value'] = 'excerpt'; $def['supports_excerpt']['extra'] = ''; $def['supports_excerpt']['description'] = __('Small summary field.', CCTM::txtdomain); $def['supports_excerpt']['type'] = 'checkbox'; $def['supports_excerpt']['sort_param'] = 24; $def['supports_trackbacks']['name'] = 'supports[]'; $def['supports_trackbacks']['id'] = 'supports_trackbacks'; $def['supports_trackbacks']['label'] = __('Trackbacks', CCTM::txtdomain); $def['supports_trackbacks']['value'] = ''; $def['supports_trackbacks']['checked_value'] = 'trackbacks'; $def['supports_trackbacks']['extra'] = ''; $def['supports_trackbacks']['description'] = ''; $def['supports_trackbacks']['type'] = 'checkbox'; $def['supports_trackbacks']['sort_param'] = 25; $def['supports_custom-fields']['name'] = 'supports[]'; $def['supports_custom-fields']['id'] = 'supports_custom-fields'; $def['supports_custom-fields']['label'] = __('Supports Custom Fields', CCTM::txtdomain); $def['supports_custom-fields']['value'] = ''; $def['supports_custom-fields']['checked_value'] = 'custom-fields'; $def['supports_custom-fields']['extra'] = ''; $def['supports_custom-fields']['description'] = ''; $def['supports_custom-fields']['type'] = 'checkbox'; $def['supports_custom-fields']['sort_param'] = 26; $def['supports_comments']['name'] = 'supports[]'; $def['supports_comments']['id'] = 'supports_comments'; $def['supports_comments']['label'] = __('Enable Comments', CCTM::txtdomain); $def['supports_comments']['value'] = ''; $def['supports_comments']['checked_value'] = 'comments'; $def['supports_comments']['extra'] = ''; $def['supports_comments']['description'] = ''; $def['supports_comments']['type'] = 'checkbox'; $def['supports_comments']['sort_param'] = 27; $def['supports_revisions']['name'] = 'supports[]'; $def['supports_revisions']['id'] = 'supports_revisions'; $def['supports_revisions']['label'] = __('Store Revisions', CCTM::txtdomain); $def['supports_revisions']['value'] = ''; $def['supports_revisions']['checked_value'] = 'revisions'; $def['supports_revisions']['extra'] = ''; $def['supports_revisions']['description'] = ''; $def['supports_revisions']['type'] = 'checkbox'; $def['supports_revisions']['sort_param'] = 28; $def['supports_page-attributes']['name'] = 'supports[]'; $def['supports_page-attributes']['id'] = 'supports_page-attributes'; $def['supports_page-attributes']['label'] = __('Enable Page Attributes', CCTM::txtdomain); $def['supports_page-attributes']['value'] = ''; $def['supports_page-attributes']['checked_value'] = 'page-attributes'; $def['supports_page-attributes']['extra'] = ''; $def['supports_page-attributes']['description'] = __('(template and menu order; hierarchical must be checked)', CCTM::txtdomain); $def['supports_page-attributes']['type'] = 'checkbox'; $def['supports_page-attributes']['sort_param'] = 29; $def['menu_position']['name'] = 'menu_position'; $def['menu_position']['label'] = __('Menu Position', CCTM::txtdomain); $def['menu_position']['value'] = ''; $def['menu_position']['extra'] = ''; $def['menu_position']['description'] = sprintf('%1$s <ul style="margin-left:40px;"> <li><strong>5</strong> - %2$s</li> <li><strong>10</strong> - %3$s</li> <li><strong>20</strong> - %4$s</li> <li><strong>60</strong> - %5$s</li> <li><strong>100</strong> - %6$s</li> </ul>', __('This setting determines where this post type should appear in the left-hand admin menu. Default: null (below Comments)', CCTM::txtdomain), __('below Posts', CCTM::txtdomain), __('below Media', CCTM::txtdomain), __('below Posts', CCTM::txtdomain), __('below Pages', CCTM::txtdomain), __('below first separator', CCTM::txtdomain), __('below second separator', CCTM::txtdomain)); $def['menu_position']['type'] = 'text'; $def['menu_position']['sort_param'] = 30; $def['menu_icon']['name'] = 'menu_icon'; $def['menu_icon']['label'] = __('Menu Icon', CCTM::txtdomain); $def['menu_icon']['value'] = ''; $def['menu_icon']['extra'] = ''; $def['menu_icon']['description'] = __('Menu icon URL.', CCTM::txtdomain); $def['menu_icon']['type'] = 'text'; $def['menu_icon']['sort_param'] = 31; $def['use_default_menu_icon']['name'] = 'use_default_menu_icon'; $def['use_default_menu_icon']['label'] = __('Use Default Menu Icon', CCTM::txtdomain); $def['use_default_menu_icon']['value'] = '1'; $def['use_default_menu_icon']['extra'] = ''; $def['use_default_menu_icon']['description'] = __('If checked, your post type will use the posts icon', CCTM::txtdomain); $def['use_default_menu_icon']['type'] = 'checkbox'; $def['use_default_menu_icon']['sort_param'] = 32; $def['rewrite_slug']['name'] = 'rewrite_slug'; $def['rewrite_slug']['label'] = __('Rewrite Slug', CCTM::txtdomain); $def['rewrite_slug']['value'] = ''; $def['rewrite_slug']['extra'] = ''; $def['rewrite_slug']['description'] = __("Prepend posts with this slug - defaults to post type's name", CCTM::txtdomain); $def['rewrite_slug']['type'] = 'text'; $def['rewrite_slug']['sort_param'] = 35; $def['rewrite_with_front']['name'] = 'rewrite_with_front'; $def['rewrite_with_front']['label'] = __('Rewrite with Permalink Front', CCTM::txtdomain); $def['rewrite_with_front']['value'] = '1'; $def['rewrite_with_front']['extra'] = ''; $def['rewrite_with_front']['description'] = __("Allow permalinks to be prepended with front base - defaults to checked", CCTM::txtdomain); $def['rewrite_with_front']['type'] = 'checkbox'; $def['rewrite_with_front']['sort_param'] = 35; $def['rewrite']['name'] = 'permalink_action'; $def['rewrite']['label'] = __('Permalink Action', CCTM::txtdomain); $def['rewrite']['value'] = 'Off'; $def['rewrite']['options'] = array('Off', '/%postname%/'); // ,'Custom'), $def['rewrite']['extra'] = ''; $def['rewrite']['description'] = sprintf('%1$s <ul style="margin-left:20px;"> <li><strong>Off</strong> - %2$s</li> <li><strong>/%postname%/</strong> - %3$s</li> <!--li><strong>Custom</strong> - Evaluate the contents of slug</li--> <ul>', __('Use permalink rewrites for this post_type? Default: Off', CCTM::txtdomain), __('URLs for custom post_types will always look like: http://site.com/?post_type=book&p=39 even if the rest of the site is using a different permalink structure.', CCTM::txtdomain), __('You MUST use the custom permalink structure: "/%postname%/". Other formats are <strong>not</strong> supported. Your URLs will look like http://site.com/movie/star-wars/', CCTM::txtdomain)); $def['rewrite']['type'] = 'dropdown'; $def['rewrite']['sort_param'] = 37; $def['query_var']['name'] = 'query_var'; $def['query_var']['label'] = __('Query Variable', CCTM::txtdomain); $def['query_var']['value'] = ''; $def['query_var']['extra'] = ''; $def['query_var']['description'] = __('(optional) Name of the query var to use for this post type. E.g. "movie" would make for URLs like http://site.com/?movie=star-wars. If blank, the default structure is http://site.com/?post_type=movie&p=18', CCTM::txtdomain); $def['query_var']['type'] = 'text'; $def['query_var']['sort_param'] = 38; $def['can_export']['name'] = 'can_export'; $def['can_export']['label'] = __('Can Export', CCTM::txtdomain); $def['can_export']['value'] = '1'; $def['can_export']['extra'] = ''; $def['can_export']['description'] = __('Can this post_type be exported.', CCTM::txtdomain); $def['can_export']['type'] = 'checkbox'; $def['can_export']['sort_param'] = 40; $def['show_in_nav_menus']['name'] = 'show_in_nav_menus'; $def['show_in_nav_menus']['label'] = __('Show in Nav Menus', CCTM::txtdomain); $def['show_in_nav_menus']['value'] = '1'; $def['show_in_nav_menus']['extra'] = ''; $def['show_in_nav_menus']['description'] = __('Whether post_type is available for selection in navigation menus. Default: value of public argument', CCTM::txtdomain); $def['show_in_nav_menus']['type'] = 'checkbox'; $def['show_in_nav_menus']['sort_param'] = 40; self::$post_type_form_definition = $def; }
// Remove the primary definition unset(CCTM::$data['metabox_defs'][$id]); // Remove the map_field_metabox for each post-type so any fields point to the default. // See: https://code.google.com/p/wordpress-custom-content-type-manager/wiki/DataStructures $defs = self::get_post_type_defs(); foreach ($defs as $pt => $d) { if (isset($d['map_field_metabox']) && in_array($id, array_values($d['map_field_metabox']))) { foreach ($d['map_field_metabox'] as $cf => $mb) { if ($mb == $id) { $defs[$pt]['map_field_metabox'][$cf] = 'default'; } } } } self::$data['post_type_defs'] = $defs; update_option(self::db_key, self::$data); $msg = '<div class="updated"><p>' . sprintf(__('The Metabox %s has been deleted', CCTM_TXTDOMAIN), "<em>{$id}</em>") . '</p></div>'; self::set_flash($msg); include CCTM_PATH . '/controllers/list_post_types.php'; return; } $data['content'] = '<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 Metabox. Any fields that have been assigned to this Metabox will be moved into the default Metabox. This will not delete any of your custom fields, but it may make your admin pages to become disorganized.', CCTM_TXTDOMAIN), "<em>{$id}</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/Metaboxes" title="Deleting a Metabox" target="_blank"> <img src="' . CCTM_URL . '/images/question-mark.gif" width="16" height="16" /> </a> </p></div>'; $data['content'] = CCTM::load_view('basic_form.php', $data); print CCTM::load_view('templates/default.php', $data); /*EOF*/
} if (isset($new_data['custom_field_defs'][$fieldname])) { $fieldname++; } if (isset($new_data['custom_field_defs'][$fieldname])) { $fieldname++; } $custom_fields_this_post_type[] = $fieldname; $field_def['name'] = $fieldname; $new_data['custom_field_defs'][$fieldname] = $field_def; } $data[$post_type]['custom_fields'] = $custom_fields_this_post_type; // Alert users to the fact that they may have to change their templates!!! if ($fieldname != $original_fieldname) { $msg = sprintf(__("You may have to change your template for the %s post_type! Any instances of get_custom_field('%s') or print_custom_field('%s') in the single-%s.php file should be replaced with get_custom_field('%s') or print_custom_field('%s'). You may also use the 'Custom Fields-->Merge' command to merge field definitions.", CCTM_TXTDOMAIN), $post_type, $original_fieldname, $original_fieldname, $post_type, $fieldname, $fieldname); CCTM::register_warning($msg); // update database global $wpdb; $wpdb->prepare("UPDATE \n {$wpdb->postmeta} postmeta INNER JOIN {$wpdb->posts} posts\n SET postmeta.meta_key = %s\n WHERE\n posts.post_type = %s \n AND\n postmeta.meta_key = %s", $fieldname, $post_type, $original_fieldname); } } } // post_type loop $new_data['post_type_defs'] = $data; //print_r($new_data); exit; update_option(self::db_key, $new_data); // stick it in the db self::$data = $new_data; // and stick it in memory just to be sure delete_option('custom_content_types_mgr_data'); // legacy pre 0.9.4