public function setup_custom_taxonomy() { global $wp_rewrite; do_action('setup_custom_taxonomy'); $prev_installed_taxonomies = get_option('installed_taxonomies'); $installed_taxonomies = array_keys($this->taxonomy_handlers); $has_new_taxonomies = false; foreach ($this->taxonomy_handlers as $handler) { $args = array('hierarchical' => $handler->get_taxonomy_is_hierarchical(), 'label' => $handler->get_taxonomy_label_plural(), 'query_var' => $handler->get_taxonomy_query_var(), 'rewrite' => $handler->get_taxonomy_rewrite()); if (false !== ($callback = $handler->get_taxonomy_update_count_callback())) { $args['update_count_callback'] = $callback; } register_taxonomy($handler->get_taxonomy_name(), $handler->get_object_types(), $args); if (version_compare(get_wp_version(), '3.0-dev', '<') && $handler->get_taxonomy_is_hierarchical()) { add_action('admin_menu', array($handler, 'register_management_page')); } } }
public function setup_custom_taxonomy() { do_action('setup_custom_taxonomy'); foreach ($this->taxonomy_handlers as $handler) { $args = array('hierarchical' => (bool) $handler->get_taxonomy_is_hierarchical(), 'label' => $handler->get_taxonomy_label_plural(), 'query_var' => $handler->get_taxonomy_query_var(), 'rewrite' => $handler->get_taxonomy_rewrite(), 'show_ui' => $handler->get_taxonomy_show_ui(), 'manage_cap' => $handler->get_taxonomy_manage_cap(), 'edit_cap' => $handler->get_taxonomy_edit_cap(), 'delete_cap' => $handler->get_taxonomy_delete_cap(), 'assign_cap' => $handler->get_taxonomy_assign_cap()); if (false !== ($callback = $handler->get_taxonomy_update_count_callback())) { $args['update_count_callback'] = $callback; } register_taxonomy($handler->get_taxonomy_name(), $handler->get_object_types(), $args); if (version_compare(get_wp_version(), '3.0-dev', '<')) { if ($handler->get_taxonomy_is_hierarchical()) { add_action('admin_menu', array($handler, 'register_management_page')); } if (in_array('page', $handler->get_object_types())) { add_action('do_meta_boxes', array($handler, 'add_page_taxonomy_support'), 10, 2); } } } }
function create_archive() { global $wpdb; $archives_id = $wpdb->get_var("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_wp_page_template' AND meta_value = 'page-archives.php' LIMIT 1"); $archives_page = array(); $archives_page['ID'] = $archives_id; $archives_page['post_content'] = __('Do not edit this page', 'k2_domain'); $archives_page['post_excerpt'] = __('Do not edit this page', 'k2_domain'); $archives_page['post_title'] = __('Archives', 'k2_domain'); $archives_page['post_name'] = 'archives'; if (get_wp_version() < 2.1) { // WP 2.0 $archives_page['post_status'] = 'static'; } else { // WP 2.1+ $archives_page['post_status'] = 'publish'; $archives_page['post_type'] = 'page'; } $archives_page['page_template'] = 'page-archives.php'; wp_insert_post($archives_page); }
/** * Registers the rewrite rules for the content_type with the system. * */ public function add_rewrite_rules() { if ($this->get_type_publicly_queryable()) { global $wp_rewrite; $permastructure = $this->get_type_permastructure(); $structure = $permastructure['structure']; $front = substr($structure, 0, strpos($structure, '%')); $type_query_var = $this->get_type_query_var(); $structure = str_replace('%identifier%', $permastructure['identifier'], $structure); $rewrite_rules = $wp_rewrite->generate_rewrite_rules($structure, EP_NONE, true, true, true, true, true); //build a rewrite rule from just the identifier if it is the first token preg_match('/%.+?%/', $permastructure['structure'], $tokens); if ($tokens[0] == '%identifier%') { $rewrite_rules = array_merge($wp_rewrite->generate_rewrite_rules($front . $permastructure['identifier'] . '/'), $rewrite_rules); $rewrite_rules[$front . $permastructure['identifier'] . '/?$'] = 'index.php?paged=1'; } foreach ($rewrite_rules as $regex => $redirect) { if (strpos($redirect, 'attachment=') === false) { //don't set the post_type for attachments $redirect .= '&post_type=' . $this->get_content_type(); } if (0 < preg_match_all('@\\$([0-9])@', $redirect, $matches)) { for ($i = 0; $i < count($matches[0]); $i++) { $redirect = str_replace($matches[0][$i], '$matches[' . $matches[1][$i] . ']', $redirect); } } if (version_compare(get_wp_version(), '3.0-dev', '>=') && $type_query_var) { $redirect = str_replace('name=', $type_query_var . '=', $redirect); } add_rewrite_rule($regex, $redirect, 'top'); } } }
/** * This calls the stetup_custom_content action which should be * used to registers any child plugins via register_custom_content_type() * * Runs on 'init' action */ public function setup_custom_content() { global $wp_rewrite; //child plugins should hook into this action to register their handler do_action('setup_custom_content'); if (!count($this->content_handlers)) { return; } //check if new post_types were added. $prev_installed_post_types = get_option('installed_post_types'); $installed_post_types = array_keys($this->content_handlers); $has_new_types = false; if (!is_array($prev_installed_post_types) || count(array_diff($installed_post_types, $prev_installed_post_types)) > 0) { $has_new_types = true; } foreach ($this->content_handlers as $handler) { $handler->add_base_hooks(); $handler->add_custom_hooks(); $args = array('labels' => $handler->get_type_labels(), 'publicly_queryable' => (bool) $handler->get_type_publicly_queryable(), 'exclude_from_search' => (bool) $handler->get_type_exclude_from_search(), 'public' => (bool) $handler->get_type_is_public(), 'hierarchical' => (bool) $handler->get_type_is_hierarchical(), 'capability_type' => $handler->get_type_capability_type(), 'supports' => $handler->get_type_supports(), 'rewrite' => $handler->get_type_rewrite(), 'query_var' => $handler->get_type_query_var(), 'show_ui' => (bool) $handler->get_type_show_ui(), 'has_archive' => (bool) $handler->get_type_has_archive(), 'menu_position' => (int) $handler->get_type_menu_position()); if ($edit_link = $handler->get_type_edit_link()) { $args['_edit_link'] = $edit_link; } register_post_type($handler->get_content_type(), $args); if (!function_exists('wpcom_is_vip')) { $handler->add_rewrite_rules(); } } if (version_compare(get_wp_version(), '3.0-dev', '<')) { add_filter('query_vars', array($this, 'query_vars'), 10, 1); add_action('parse_request', array($this, 'parse_request'), 10, 1); } //template handling /** * @todo remove if http://core.trac.wordpress.org/attachment/ticket/9674/9674.18.diff is merged */ add_filter("single_template", array($this, 'single_template'), 10, 1); add_filter("date_template", array($this, 'date_template'), 10, 1); add_filter("search_template", array($this, 'search_template'), 10, 1); add_filter("index_template", array($this, 'index_template'), 10, 1); add_filter("home_template", array($this, 'index_template'), 10, 1); //flush the rewrite rules if new content_types were added if ($has_new_types && !function_exists('wpcom_is_vip')) { $wp_rewrite->flush_rules(); update_option('installed_post_types', $installed_post_types); } }
/** * Form for editing a taxonomy * * @param Dynamic_Taxonomy_Handler $taxonomy */ private function edit_taxonomy_form($taxonomy, $add = true) { ?> <?php if (!empty($_REQUEST['notice'])) { ?> <div id="message" class="updated fade"><p><strong><?php echo stripslashes($_REQUEST['notice']); ?> </strong></div> <?php } ?> <form method="post" action="<?php $this->get_edit_taxonomy_url($taxonomy->get_taxonomy_name()); ?> "> <?php if ($add) { ?> <input type="hidden" name="action" value="add_taxonomy" /> <?php wp_nonce_field('add_taxonomy', '_wpnonce'); ?> <?php } else { ?> <input type="hidden" name="action" value="edit_taxonomy" /> <?php wp_nonce_field('edit_taxonomy', '_wpnonce'); ?> <input type="hidden" name="orig_taxonomy" value="<?php echo esc_attr($taxonomy->get_taxonomy_name()); ?> " /> <?php } ?> <h3><?php _e('General Settings'); ?> </h3> <table class="form-table"> <tr valign="top"> <th scope="row"><label for="taxonomy_name"><?php _e('Taxonomy (required)'); ?> </label></th> <td> <input type="text" class="regular-text code" id="taxonomy_name" name="taxonomy_name" value="<?php echo esc_attr($taxonomy->get_taxonomy_name()); ?> "<?php echo $add ? '' : ' readonly="readonly"'; ?> /> <span class="description"><?php _e('This will be used to identify this taxonomy in the database. This must be unique.'); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><label for="taxonomy"><?php _e('Label'); ?> </label></th> <td> <input type="text" class="regular-text code" id="label" name="settings[label]" value="<?php echo esc_attr($taxonomy->get_taxonomy_label()); ?> " /> </td> </tr> <tr valign="top"> <th scope="row"><label for="taxonomy"><?php _e('Label Plural'); ?> </label></th> <td> <input type="text" class="regular-text code" id="label_plural" name="settings[label_plural]" value="<?php echo esc_attr($taxonomy->get_taxonomy_label_plural()); ?> " /> </td> </tr> <?php if (version_compare(get_wp_version(), '3.0-dev', '>=')) { ?> <tr valign="top"> <th scope="row"><?php _e('Is Hierarchical?'); ?> </th> <td> <label for="hierarchical_yes"><?php echo 'Yes'; ?> </label> <input type="radio" id="hierarchical" name="settings[hierarchical]" value="1"<?php echo $taxonomy->get_taxonomy_is_hierarchical() ? ' checked="checked"' : ''; ?> /> <label for="hierarchical_no"><?php echo 'No'; ?> </label> <input type="radio" id="hierarchical" name="settings[hierarchical]" value="0"<?php echo !$taxonomy->get_taxonomy_is_hierarchical() ? ' checked="checked"' : ''; ?> /> <span class="description"><?php _e('Will terms in this taxonomy have categorical structure?'); ?> </span> </td> </tr> <?php } ?> </table> <h3><?php _e('General Settings'); ?> </h3> <table class="form-table"> <tr valign="top"> <th scope="row"><?php _e('Related Object Types'); ?> </th> <td> <?php foreach (get_post_types(null, 'objects') as $post_type) { ?> <?php if (isset($post_type->public) && $post_type->public || in_array($post_type->name, array('post', 'page', 'attachment'))) { ?> <input type="checkbox" id="object_types_<?php echo esc_attr($post_type->name); ?> " name="object_types[]" value="<?php echo esc_attr($post_type->name); ?> "<?php echo $taxonomy->supports_post_type($post_type->name) ? ' checked="checked"' : ''; ?> /> <label for="object_types_<?php echo esc_attr($post_type->name); ?> "><?php echo $post_type->name; ?> </label> <br /> <?php } ?> <?php } ?> </td> </tr> </table> <p class="submit"><input type="submit" name="submit" value="<?php esc_attr_e('Submit'); ?> " class="button-secondary" /></p> </form> <?php }
<?php include dirname(dirname(__FILE__)) . '/config.php'; $url = 'http://wordpress.org/download/counter/?ajaxupdate=1&time=' . time(); $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); $count = curl_exec($ch); curl_close($ch); $version = get_wp_version(); $count = str_replace('.', '', $count); $count = str_replace(',', '', $count); if ($count || $count == 0) { try { $dbh = new PDO($dsn, $user, $password); $sql = "INSERT INTO downloads (\n\t\t\tversion,\n\t\t\tcount,\n\t\t\tdate_gmt) VALUES (\n\t\t\t:version,\n\t\t\t:count,\n\t\t\tUTC_TIMESTAMP())"; $stmt = $dbh->prepare($sql); $stmt->bindParam(':version', $version, PDO::PARAM_STR); $stmt->bindParam(':count', $count, PDO::PARAM_INT); $stmt->execute(); } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); } }
/** * Handles adding of content_types before any content is rendered. * */ public function on_load_add_content_type_page() { if (!current_user_can('manage_content_types')) { wp_die("You do not have sufficient permissions to access this page"); } $action = !empty($_POST['action']) ? $_POST['action'] : ''; $nonce = !empty($_POST['_wpnonce']) ? $_POST['_wpnonce'] : ''; switch ($action) { case 'add_content_type': if (wp_verify_nonce($nonce, 'add_content_type')) { if (!empty($_POST['content_type'])) { $content_type = $_POST['content_type']; $content_handler = new Dynamic_Content_Handler($content_type, $_POST); $content_type = $this->add_content_handler($content_handler); if (!is_wp_error($content_type)) { $add_url = admin_url('post-new.php?post_type=' . $content_type); if (version_compare(get_wp_version(), '3.0-dev', '<')) { $add_url = CP_Custom_Content_Core::GetInstance()->get_add_custom_content_url($content_type); } $notice = sprintf(__("The content type of '{$content_type}' has been created. <a href=\"%s\">Add one now.</a>"), esc_attr($add_url)); wp_redirect($this->get_edit_content_type_url($content_type, array('notice' => $notice))); exit; } else { $_REQUEST['notice'] = $content_type->get_error_message(); } } } break; } }
/** * Called from CP_Custom_Content_Core::setup_custom_content * This should be used to add any * */ public final function add_base_hooks() { //add permastruct handling if (version_compare(get_wp_version(), '3.0-dev', '>=')) { add_filter('post_type_link', array($this, 'post_link'), 10, 3); } else { add_filter('post_link', array($this, 'post_link'), 10, 3); } }
along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ if (!function_exists('get_wp_version')) { /** * Returns the current WordPress version. This is used to avoid the constant use of globals. * * @return string */ function get_wp_version() { global $wp_version; return $wp_version; } } if (!version_compare(get_wp_version(), '2.9', '>=')) { trigger_error('CMS Press requires WP version 2.9 or higher', E_USER_NOTICE); return; } define('CP_BASE_DIR', dirname(__FILE__)); define('CP_BASE_URL', str_replace(str_replace('\\', '/', ABSPATH), site_url() . '/', str_replace('\\', '/', dirname(__FILE__)))); require_once CP_BASE_DIR . '/cp-custom-content/legacy/legacy.php'; /** * Core files */ require_once CP_BASE_DIR . '/cp-custom-content/cp-custom-content-core.php'; require_once CP_BASE_DIR . '/cp-custom-taxonomy/cp-custom-taxonomy-core.php'; CP_Custom_Content_Core::Initialize(); CP_Custom_Taxonomy_Core::Initialize(); /** * Add dynamic content type handler(s)
/** * Renders the form for editing a content type * * @param Dynamic_Content_Handler $content_handler */ private function edit_content_type_form($content_handler, $add = true) { if (!empty($_REQUEST['notice'])) { ?> <div id="message" class="updated fade"><p><strong><?php echo stripslashes($_REQUEST['notice']); ?> </strong></div><?php } $permastructure = $content_handler->get_type_permastructure(); if (empty($permastructure['identifier'])) { $perma_identifier = $content_handler->get_content_type(); if (!$add) { $permalink_warnings[] = __("Warning: Content Type Identifier should not be empty."); } } else { $perma_identifier = $permastructure['identifier']; } if (empty($permastructure['structure'])) { $perma_structure = '%identifier%' . get_option('permalink_structure'); } else { $perma_structure = $permastructure['structure']; if (!$add && false === strpos($perma_structure, '%identifier%')) { $permalink_warnings[] = __("Warning: The permalink structure must contain the %identifier% term."); } if (false !== strpos($perma_structure, '%tag%') || false !== strpos($perma_structure, '%category%')) { $permalink_warnings[] = __("Warning: The user of the %tag% or %category% tags is not currently supported by cms-press."); } } ?> <?php if (isset($permalink_warnings) && count($permalink_warnings)) { ?> <?php foreach ($permalink_warnings as $permalink_warning) { ?> <?php if (!empty($_REQUEST['notice'])) { ?> <div class="updated"><p><strong><?php echo stripslashes($permalink_warning); ?> </strong></div> <?php } ?> <?php } ?> <?php } ?> <form method="post" action="<?php $this->get_edit_content_type_url($content_handler->get_content_type()); ?> "> <?php if ($add) { ?> <input type="hidden" name="action" value="add_content_type" /> <?php wp_nonce_field('add_content_type', '_wpnonce'); ?> <?php } else { ?> <input type="hidden" name="action" value="edit_content_type" /> <?php wp_nonce_field('edit_content_type', '_wpnonce'); ?> <input type="hidden" name="orig_content_type" value="<?php echo esc_attr($content_handler->get_content_type()); ?> " /> <?php } ?> <h3><?php _e('General Settings'); ?> </h3> <table class="form-table"> <tr valign="top"> <th scope="row"><label for="content_type"><?php _e('Content Type (required)'); ?> </label></th> <td> <input type="text" class="regular-text code" id="content_type" name="content_type" value="<?php echo esc_attr($content_handler->get_content_type()); ?> "<?php echo $add ? '' : ' readonly="readonly"'; ?> /> <span class="description"><?php _e('This will be used to identify this content type in the database. This must be unique.'); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><label for="content_type"><?php _e('Label'); ?> </label></th> <td> <input type="text" class="regular-text code" id="label" name="label" value="<?php echo esc_attr($content_handler->get_type_label()); ?> " /> </td> </tr> <tr valign="top"> <th scope="row"><label for="content_type"><?php _e('Label Plural'); ?> </label></th> <td> <input type="text" class="regular-text code" id="label_plural" name="label_plural" value="<?php echo esc_attr($content_handler->get_type_label_plural()); ?> " /> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Display in admin menu?'); ?> </th> <td> <label for="public_yes"><?php echo 'Yes'; ?> </label> <input type="radio" id="public" name="public" value="1"<?php echo $content_handler->get_type_is_public() ? ' checked="checked"' : ''; ?> /> <label for="public_no"><?php echo 'No'; ?> </label> <input type="radio" id="public" name="public" value="0"<?php echo !$content_handler->get_type_is_public() ? ' checked="checked"' : ''; ?> /> <span class="description"><?php _e('This should almost always be Yes.'); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><label for="menu_position"><?php echo 'menu_position'; ?> </label></th> <td> <input type="text" class="regular-text code" id="menu_position" name="menu_position" value="<?php echo esc_attr($content_handler->get_type_menu_position()); ?> " /> <span class="description"><?php echo '5 - below Posts 10 - below Media 15 - below Links 20 - below Pages 25 - below comments '; ?> </span> </td> </tr> <?php /* @todo leaving these out for now <tr valign="top"> <th scope="row"><?php _e('Is Hierarchical?'); ?></th> <td> <label for="hierarchical_yes"><?php echo ('Yes') ?></label> <input type="radio" id="hierarchical" name="hierarchical" value="1"<?php echo $content_handler->get_type_is_hierarchical() ? ' checked="checked"' : ''?> /> <label for="hierarchical_no"><?php echo ('No') ?></label> <input type="radio" id="hierarchical" name="hierarchical" value="0"<?php echo !$content_handler->get_type_is_hierarchical() ? ' checked="checked"' : ''?> /> <span class="description"><?php _e('Will the URL to the content be based on parent child relationships?.')?></span> </td> </tr> */ ?> <?php if (version_compare(get_wp_version(), '3.0-dev', '>=')) { ?> <tr valign="top"> <th scope="row"><label for="capability_type"><?php _e('Capability Type'); ?> </label></th> <td> <input type="text" class="regular-text code" id="capability_type" name="capability_type" value="<?php echo esc_attr($content_handler->get_type_capability_type()); ?> " /> </td> </tr> <?php } ?> <tr valign="top"> <th scope="row"><?php _e('Is Publicly Queryable?'); ?> </th> <td> <label for="publicly_queryable_yes"><?php echo 'Yes'; ?> </label> <input type="radio" id="publicly_queryable" name="publicly_queryable" value="1"<?php echo $content_handler->get_type_publicly_queryable() ? ' checked="checked"' : ''; ?> /> <label for="publicly_queryable_no"><?php echo 'No'; ?> </label> <input type="radio" id="publicly_queryable" name="publicly_queryable" value="0"<?php echo !$content_handler->get_type_publicly_queryable() ? ' checked="checked"' : ''; ?> /> <span class="description"><?php _e('Can this post_type be accessed via URL?'); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Exclude from search results?'); ?> </th> <td> <label for="exclude_from_search_yes"><?php echo 'Yes'; ?> </label> <input type="radio" id="exclude_from_search" name="exclude_from_search" value="1"<?php echo $content_handler->get_type_exclude_from_search() ? ' checked="checked"' : ''; ?> /> <label for="exclude_from_search_no"><?php echo 'No'; ?> </label> <input type="radio" id="exclude_from_search" name="exclude_from_search" value="0"<?php echo !$content_handler->get_type_exclude_from_search() ? ' checked="checked"' : ''; ?> /> <span class="description"><?php _e('Should this content be excluded in search results?'); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><?php echo 'has_archive?'; ?> </th> <td> <label for="has_archive_yes"><?php echo 'Yes'; ?> </label> <input type="radio" id="has_archive" name="has_archive" value="1"<?php echo $content_handler->get_type_has_archive() ? ' checked="checked"' : ''; ?> /> <label for="has_archive_no"><?php echo 'No'; ?> </label> <input type="radio" id="has_archive" name="has_archive" value="0"<?php echo !$content_handler->get_type_has_archive() ? ' checked="checked"' : ''; ?> /> <span class="description"><?php echo 'Use custom_post_type_archives?'; ?> </span> </td> </tr> </table> <br /> <h3><?php _e('Permalink Structure'); ?> </h3> <p><span class="description">This only applies to Content Types that are Publicly Queryable.</span></p> <table class="form-table"> <tr valign="top"> <th scope="row"><label for="permastructure_identifier"><?php _e('Content Type Identifier'); ?> </label></th> <td> <input type="text" class="regular-text code" id="permastructure_identifier" name="permastructure[identifier]" value="<?php echo esc_attr($perma_identifier); ?> "/> <span class="description"><?php _e('This will be used in the permalink structure to identify this content type. This should be unique per content type.'); ?> </span> </td> <tr valign="top"> <th scope="row"><label for="permastructure_structure"><?php _e('Permalink Structure'); ?> </label></th> <td> <input type="text" class="regular-text code" id="permastructure_structure" name="permastructure[structure]" value="<?php echo esc_attr($perma_structure); ?> "/> <span class="description"><?php _e('This will be custom URL structure for this content type. These follow WP\'s normal <a href="http://codex.wordpress.org/Using_Permalinks">permalink tags</a>, but must also include the content type \'%identifier%\'.'); ?> </span> <br /> <span class="description"> Allowed tags: %year%, %monthnum%, %day%, %hour%, %minute%, %second%, %postname%, %post_id%, </span> </td> </tr> </tr> </table> <br /> <h3><?php _e('Supported Features'); ?> </h3> <table class="form-table"> <?php $standard_features = $this->get_standard_features(); ?> <?php $supported_features = $content_handler->get_type_supports(); ?> <?php foreach ($standard_features as $feature_key => $feature) { ?> <tr valign="top"> <th scope="row"><label for="supports_<?php echo $feature_key; ?> "><?php echo $feature['label']; ?> </label></th> <td> <input type="checkbox" id="supports_<?php echo $feature_key; ?> " name="supports[]" value="<?php echo $feature_key; ?> "<?php echo in_array($feature_key, $supported_features) ? ' checked="checked"' : ''; ?> /> <?php if (!empty($feature['description'])) { ?> <span class="description"><?php echo $feature['description']; ?> </span> <?php } ?> </td> </tr> <?php } ?> </table> <p class="submit"><input type="submit" name="submit" value="<?php esc_attr_e('Submit'); ?> " class="button-secondary" /></p> </form> <?php }