/** * Load initial Content Types data for plugin * * @return void */ function load_data() { /* Get setting options. If empty return an array */ $options = get_site_option(DR_OPTIONS_NAME) ? get_site_option(DR_OPTIONS_NAME) : array(); // Check whether post types are loaded if (!post_type_exists('directory_listing')) { $directory_listing_default = array('can_export' => true, 'capability_type' => 'listing', 'description' => 'Directory Listing post type.', 'has_archive' => 'listings', 'hierarchical' => false, 'map_meta_cap' => true, 'menu_position' => '', 'public' => true, 'query_var' => true, 'rewrite' => array('slug' => 'listing', 'with_front' => false), 'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'custom-fields', 'comments', 'revisions'), 'labels' => array('name' => __('Listings', DR_TEXT_DOMAIN), 'singular_name' => __('Listing', DR_TEXT_DOMAIN), 'add_new' => __('Add New', DR_TEXT_DOMAIN), 'add_new_item' => __('Add New Listing', DR_TEXT_DOMAIN), 'edit_item' => __('Edit Listing', DR_TEXT_DOMAIN), 'new_item' => __('New Listing', DR_TEXT_DOMAIN), 'view_item' => __('View Listing', DR_TEXT_DOMAIN), 'search_items' => __('Search Listings', DR_TEXT_DOMAIN), 'not_found' => __('No listings found', DR_TEXT_DOMAIN), 'not_found_in_trash' => __('No listings found in trash', DR_TEXT_DOMAIN))); //Update custom post types if (is_network_admin()) { $ct_custom_post_types = get_site_option('ct_custom_post_types'); $ct_custom_post_types['directory_listing'] = $directory_listing_default; update_site_option('ct_custom_post_types', $ct_custom_post_types); } else { $ct_custom_post_types = get_option('ct_custom_post_types'); $ct_custom_post_types['directory_listing'] = $directory_listing_default; update_option('ct_custom_post_types', $ct_custom_post_types); } // Update post types and delete tmp options flush_network_rewrite_rules(); } /* Check whether taxonomies data is loaded */ if (!taxonomy_exists('listing_tag')) { $listing_tags_default = array(); $listing_tags_default['object_type'] = array('directory_listing'); $listing_tags_default['args'] = array('public' => true, 'hierarchical' => false, 'rewrite' => array('slug' => 'listings-tag', 'with_front' => false, 'hierarchical' => false), 'query_var' => true, 'capabilities' => array('assign_terms' => 'edit_listings'), 'labels' => array('name' => __('Listing Tags', DR_TEXT_DOMAIN), 'singular_name' => __('Listing Tag', DR_TEXT_DOMAIN), 'search_items' => __('Search Listing Tags', DR_TEXT_DOMAIN), 'popular_items' => __('Popular Listing Tags', DR_TEXT_DOMAIN), 'all_items' => __('All Listing Tags', DR_TEXT_DOMAIN), 'edit_item' => __('Edit Listing Tag', DR_TEXT_DOMAIN), 'update_item' => __('Update Listing Tag', DR_TEXT_DOMAIN), 'add_new_item' => __('Add New Listing Tag', DR_TEXT_DOMAIN), 'new_item_name' => __('New Listing Tag Name', DR_TEXT_DOMAIN), 'add_or_remove_items' => __('Add or remove listing tags', DR_TEXT_DOMAIN), 'choose_from_most_used' => __('Choose from the most used listing tags', DR_TEXT_DOMAIN), 'separate_items_with_commas' => __('Separate listing tags with commas', DR_TEXT_DOMAIN))); if (is_network_admin()) { $ct_custom_taxonomies = get_site_option('ct_custom_taxonomies'); $ct_custom_taxonomies['listing_tag'] = $listing_tags_default; update_site_option('ct_custom_taxonomies', $ct_custom_taxonomies); } else { $ct_custom_taxonomies = get_option('ct_custom_taxonomies'); $ct_custom_taxonomies['listing_tag'] = $listing_tags_default; update_option('ct_custom_taxonomies', $ct_custom_taxonomies); } // Update post types and delete tmp options flush_network_rewrite_rules(); } if (!taxonomy_exists('listing_category')) { $listing_category_default = array(); $listing_category_default['object_type'] = array('directory_listing'); $listing_category_default['args'] = array('public' => true, 'hierarchical' => true, 'rewrite' => array('slug' => 'listings-category', 'with_front' => false, 'hierarchical' => true), 'query_var' => true, 'capabilities' => array('assign_terms' => 'edit_listings'), 'labels' => array('name' => __('Listing Categories', DR_TEXT_DOMAIN), 'singular_name' => __('Listing Category', DR_TEXT_DOMAIN), 'search_items' => __('Search Listing Categories', DR_TEXT_DOMAIN), 'popular_items' => __('Popular Listing Categories', DR_TEXT_DOMAIN), 'all_items' => __('All Listing Categories', DR_TEXT_DOMAIN), 'parent_item' => __('Parent Category', DR_TEXT_DOMAIN), 'edit_item' => __('Edit Listing Category', DR_TEXT_DOMAIN), 'update_item' => __('Update Listing Category', DR_TEXT_DOMAIN), 'add_new_item' => __('Add New Listing Category', DR_TEXT_DOMAIN), 'new_item_name' => __('New Listing Category', DR_TEXT_DOMAIN), 'parent_item_colon' => __('Parent Category:', DR_TEXT_DOMAIN), 'add_or_remove_items' => __('Add or remove listing categories', DR_TEXT_DOMAIN))); if (is_network_admin()) { $ct_custom_taxonomies = get_site_option('ct_custom_taxonomies'); $ct_custom_taxonomies['listing_category'] = $listing_category_default; update_site_option('ct_custom_taxonomies', $ct_custom_taxonomies); } else { $ct_custom_taxonomies = get_option('ct_custom_taxonomies'); $ct_custom_taxonomies['listing_category'] = $listing_category_default; update_option('ct_custom_taxonomies', $ct_custom_taxonomies); } flush_network_rewrite_rules(); } //Custompress specfic if (is_multisite()) { update_site_option('allow_per_site_content_types', true); update_site_option('display_network_content_types', true); } flush_network_rewrite_rules(); }
/** * Check whether new users are registered, since we need to flush the rewrite * rules for them. * * @return void */ function set_user_registration_rewrite_rules() { flush_network_rewrite_rules(); }
/** * Intercepts $_POST request and processes the custom taxonomy requests * * @return void */ function handle_taxonomy_requests() { //$params is the $_POST variable with slashes stripped $params = array_map('stripslashes_deep', $_POST); $defaults = array('labels' => array('name' => '', 'singular_name' => '', 'add_new_item' => '', 'new_item_name' => '', 'edit_item' => '', 'update_item' => '', 'search_items' => '', 'popular_items' => '', 'all_items' => '', 'parent_item' => '', 'parent_item_colon' => '', 'add_or_remove_items' => '', 'separate_items_with_commas' => '', 'choose_from_most_used' => ''), 'public' => null, 'show_ui' => null, 'show_tagcloud' => null, 'show_admin_column' => null, 'show_in_nav_menus' => false, 'hierarchical' => false, 'rewrite' => false, 'query_var' => false); $params = apply_filters('handle_taxonomy_requests_params', wp_parse_args($params, $defaults)); // If valid add/edit taxonomy request is made if (isset($params['submit']) && isset($params['_wpnonce']) && wp_verify_nonce($params['_wpnonce'], 'submit_taxonomy')) { // Validate input fields $valid_taxonomy = $this->validate_field('taxonomy', isset($params['taxonomy']) ? strtolower($params['taxonomy']) : null); $valid_object_type = $this->validate_field('object_type', isset($params['object_type']) ? $params['object_type'] : null); if ($valid_taxonomy && $valid_object_type) { // Construct args $labels = array('name' => $params['labels']['name'], 'singular_name' => $params['labels']['singular_name'], 'add_new_item' => $params['labels']['add_new_item'], 'new_item_name' => $params['labels']['new_item_name'], 'edit_item' => $params['labels']['edit_item'], 'update_item' => $params['labels']['update_item'], 'search_items' => $params['labels']['search_items'], 'popular_items' => $params['labels']['popular_items'], 'all_items' => $params['labels']['all_items'], 'parent_item' => $params['labels']['parent_item'], 'parent_item_colon' => $params['labels']['parent_item_colon'], 'add_or_remove_items' => $params['labels']['add_or_remove_items'], 'separate_items_with_commas' => $params['labels']['separate_items_with_commas'], 'choose_from_most_used' => $params['labels']['all_items']); $args = array('labels' => $labels, 'public' => (bool) $params['public'], 'show_ui' => isset($params['show_ui']) ? (bool) $params['show_ui'] : null, 'show_tagcloud' => isset($params['show_tagcloud']) ? (bool) $params['show_tagcloud'] : null, 'show_admin_column' => isset($params['show_admin_column']) ? (bool) $params['show_admin_column'] : null, 'show_in_nav_menus' => isset($params['show_in_nav_menus']) ? (bool) $params['show_in_nav_menus'] : null, 'hierarchical' => (bool) $params['hierarchical'], 'rewrite' => (bool) $params['rewrite'], 'query_var' => (bool) $params['query_var'], 'capabilities' => array('manage_terms' => 'manage_categories', 'edit_terms' => 'manage_categories', 'delete_terms' => 'manage_categories', 'assign_terms' => 'edit_posts')); // Remove empty values from labels so we can use the defaults foreach ($args['labels'] as $key => $value) { if (empty($value)) { unset($args['labels'][$key]); } } // If no advanced is set, unset values so we can use the defaults if ($params['public'] == 'advanced') { unset($args['public']); } else { unset($args['show_ui']); unset($args['show_tagcloud']); unset($args['show_in_nav_menus']); } // Set key for taxonomy query var if (!empty($params['query_var_key']) && $args['query_var'] !== false) { $args['query_var'] = sanitize_key($params['query_var_key']); } // Customize taxonomy rewrite if (!empty($params['rewrite'])) { if (!empty($params['rewrite_slug'])) { $args['rewrite'] = (array) $args['rewrite'] + array('slug' => $params['rewrite_slug']); } $args['rewrite'] = (array) $args['rewrite'] + array('with_front' => !empty($params['rewrite_with_front']) ? true : false); $args['rewrite'] = (array) $args['rewrite'] + array('hierarchical' => !empty($params['rewrite_hierarchical']) ? true : false); $args['rewrite']['ep_mask'] = array_sum($params['ep_mask']); // Remove boolean remaining from the type casting if (is_array($args['rewrite'])) { unset($args['rewrite'][0]); } $this->flush_rewrite_rules = true; } // Set the associated object types ( post types ) if (is_network_admin()) { $post_types = get_site_option('ct_custom_post_types'); } else { $post_types = get_option('ct_custom_post_types'); } $object_type = $params['object_type']; //Set assign_terms for this associated post_type if not already includes 'post' $cap_type = 'post'; global $wp_post_types; foreach ($object_type as $post_type) { //Check the customs first $cap = $post_types[$post_type]['capability_type']; if (!empty($cap) && $cap != 'post') { $cap_type = $cap; break; } //No then check the builtins if (!empty($wp_post_types[$post_type])) { $cap = $wp_post_types[$post_type]->capability_type; if (!empty($cap) && $cap != 'post') { $cap_type = $cap; break; } } } $args['capabilities']['assign_terms'] = "edit_{$cap_type}s"; // Set the taxonomy which we are adding/updating $taxonomy = isset($params['taxonomy']) ? strtolower($params['taxonomy']) : $_GET['ct_edit_taxonomy']; // Set new taxonomies $taxonomies = $this->taxonomies ? array_merge($this->taxonomies, array($taxonomy => array('object_type' => $object_type, 'args' => $args))) : array($taxonomy => array('object_type' => $object_type, 'args' => $args)); // Check whether we have a new post type and set flush rewrite rules if (!is_array($this->all_taxonomies) || !array_key_exists($taxonomy, $this->all_taxonomies)) { $this->flush_rewrite_rules = true; } // Update wp_options with the taxonomies options if ($this->enable_subsite_content_types == 1 && !is_network_admin()) { $taxonomies = $this->taxonomies ? array_merge($this->taxonomies, array($taxonomy => array('object_type' => $object_type, 'args' => $args))) : array($taxonomy => array('object_type' => $object_type, 'args' => $args)); update_option('ct_custom_taxonomies', $taxonomies); } else { $taxonomies = $this->network_taxonomies ? array_merge($this->network_taxonomies, array($taxonomy => array('object_type' => $object_type, 'args' => $args))) : array($taxonomy => array('object_type' => $object_type, 'args' => $args)); update_site_option('ct_custom_taxonomies', $taxonomies); // Set flag for flush rewrite rules network-wide flush_network_rewrite_rules(); } // Redirect back to the taxonomies page wp_redirect(self_admin_url('admin.php?page=ct_content_types&ct_content_type=taxonomy&updated&frr' . $this->flush_rewrite_rules)); } } elseif (isset($params['submit']) && isset($params['_wpnonce']) && wp_verify_nonce($params['_wpnonce'], 'delete_taxonomy')) { // Set available taxonomies $taxonomies = is_network_admin() ? $this->network_taxonomies : $this->taxonomies; // Remove the deleted taxonomy unset($taxonomies[$params['taxonomy_name']]); // Update the available taxonomies if ($this->enable_subsite_content_types == 1 && !is_network_admin()) { update_option('ct_custom_taxonomies', $taxonomies); } else { update_site_option('ct_custom_taxonomies', $taxonomies); flush_network_rewrite_rules(); } // Redirect back to the taxonomies page wp_redirect(self_admin_url('admin.php?page=ct_content_types&ct_content_type=taxonomy&updated')); } elseif (isset($params['redirect_add_taxonomy'])) { wp_redirect(self_admin_url('admin.php?page=ct_content_types&ct_content_type=taxonomy&ct_add_taxonomy=true')); } }