예제 #1
1
/**
 * Output the content for the "Registered Types/Taxes" page.
 *
 * @since 1.1.0
 *
 * @internal
 */
function cptui_listings()
{
    ?>
		<div class="wrap cptui-listings">
			<?php 
    /**
     * Fires right inside the wrap div for the listings screen.
     *
     * @since 1.3.0
     */
    do_action('cptui_inside_listings_wrap');
    ?>

			<h1><?php 
    esc_html_e('Post Types and Taxonomies registered by Custom Post Type UI.', 'custom-post-type-ui');
    ?>
</h1>
			<?php 
    $post_types = cptui_get_post_type_data();
    echo '<h2 id="post-types">' . esc_html__('Post Types', 'custom-post-type-ui') . '</h2>';
    if (!empty($post_types)) {
        ?>
			<p><?php 
        printf(esc_html__('CPTUI registered post types count total: %d', 'custom-post-type-ui'), count($post_types));
        ?>
</p>

			<?php 
        $post_type_table_heads = array(__('Post Type', 'custom-post-type-ui'), __('Settings', 'custom-post-type-ui'), __('Supports', 'custom-post-type-ui'), __('Taxonomies', 'custom-post-type-ui'), __('Labels', 'custom-post-type-ui'), __('Template Hierarchy', 'custom-post-type-ui'));
        /**
         * Fires before the listing of registered post type data.
         *
         * @since 1.1.0
         */
        do_action('cptui_before_post_type_listing');
        ?>
			<table class="wp-list-table widefat post-type-listing">
				<tr>
					<?php 
        foreach ($post_type_table_heads as $head) {
            echo '<th>' . esc_html($head) . '</th>';
        }
        ?>
				</tr>
				<?php 
        $counter = 1;
        foreach ($post_types as $post_type => $post_type_settings) {
            $rowclass = 0 === $counter % 2 ? '' : 'alternate';
            $strings = array();
            $supports = array();
            $taxonomies = array();
            $archive = '';
            foreach ($post_type_settings as $settings_key => $settings_value) {
                if ('labels' === $settings_key) {
                    continue;
                }
                if (is_string($settings_value)) {
                    $strings[$settings_key] = $settings_value;
                } else {
                    if ('supports' === $settings_key) {
                        $supports[$settings_key] = $settings_value;
                    }
                    if ('taxonomies' === $settings_key) {
                        $taxonomies[$settings_key] = $settings_value;
                        // In case they are not associated from the post type settings.
                        if (empty($taxonomies['taxonomies'])) {
                            $taxonomies['taxonomies'] = get_object_taxonomies($post_type);
                        }
                    }
                }
                $archive = get_post_type_archive_link($post_type);
            }
            ?>
						<tr class="<?php 
            echo esc_attr($rowclass);
            ?>
">
							<?php 
            $edit_path = 'admin.php?page=cptui_manage_post_types&action=edit&cptui_post_type=' . $post_type;
            $post_type_link_url = is_network_admin() ? network_admin_url($edit_path) : admin_url($edit_path);
            ?>
							<td>
								<?php 
            printf('<a href="%s">%s</a> | <a href="%s">%s</a><br/>', esc_attr($post_type_link_url), sprintf(esc_html__('Edit %s', 'custom-post-type-ui'), esc_html($post_type)), esc_attr(admin_url('admin.php?page=cptui_importexport&action=get_code#' . $post_type)), esc_html__('Get code', 'custom-post-type-ui'));
            if ($archive) {
                ?>
								<a href="<?php 
                echo esc_attr(get_post_type_archive_link($post_type));
                ?>
"><?php 
                esc_html_e('View frontend archive', 'custom-post-type-ui');
                ?>
</a>
								<?php 
            }
            ?>
							</td>
							<td>
								<?php 
            foreach ($strings as $key => $value) {
                printf('<strong>%s:</strong> ', esc_html($key));
                if (in_array($value, array('1', '0'))) {
                    echo esc_html(disp_boolean($value));
                } else {
                    echo esc_html($value);
                }
                echo '<br/>';
            }
            ?>
							</td>
							<td>
								<?php 
            foreach ($supports['supports'] as $support) {
                echo esc_html($support) . '<br/>';
            }
            ?>
							</td>
							<td>
								<?php 
            foreach ($taxonomies['taxonomies'] as $taxonomy) {
                echo esc_html($taxonomy) . '<br/>';
            }
            ?>
							</td>
							<td>
								<?php 
            $maybe_empty = array_filter($post_type_settings['labels']);
            if (!empty($maybe_empty)) {
                foreach ($post_type_settings['labels'] as $key => $value) {
                    if ('parent' === $key && array_key_exists('parent_item_colon', $post_type_settings['labels'])) {
                        continue;
                    }
                    printf('%s: %s<br/>', esc_html($key), esc_html($value));
                }
            } else {
                esc_html_e('No custom labels to display', 'custom-post-type-ui');
            }
            ?>
							</td>
							<td>
								<p><strong><?php 
            esc_html_e('Archives file name examples.', 'custom-post-type-ui');
            ?>
</strong><br/>
								archive-<?php 
            echo esc_html($post_type);
            ?>
.php<br/>
								archive.php<br/>
								index.php
								</p>

								<p><strong><?php 
            esc_html_e('Single Posts file name examples.', 'custom-post-type-ui');
            ?>
</strong><br/>
								single-<?php 
            echo esc_html($post_type);
            ?>
-post_slug.php (WP 4.4+) *<br/>
								single-<?php 
            echo esc_html($post_type);
            ?>
.php<br/>
								single.php<br/>
								singular.php (WP 4.3+)<br/>
								index.php
								</p>

								<p>
									<?php 
            esc_html_e('*Replace "post_slug" with the slug of the actual post slug.', 'custom-post-type-ui');
            ?>
								</p>

								<p><?php 
            printf('<a href="https://developer.wordpress.org/themes/basics/template-hierarchy/">%s</a>', esc_html__('Template hierarchy Theme Handbook', 'custom-post-type-ui'));
            ?>
								</p>
							</td>
						</tr>

					<?php 
            $counter++;
        }
        ?>
				<tr>
					<?php 
        foreach ($post_type_table_heads as $head) {
            echo '<th>' . esc_html($head) . '</th>';
        }
        ?>
				</tr>
			</table>
			<?php 
        /**
         * Fires after the listing of registered post type data.
         *
         * @since 1.3.0
         */
        do_action('cptui_after_post_type_listing');
    } else {
        /**
         * Fires when there are no registered post types to list.
         *
         * @since 1.3.0
         */
        do_action('cptui_no_post_types_listing');
    }
    $taxonomies = cptui_get_taxonomy_data();
    echo '<h2 id="taxonomies">' . esc_html__('Taxonomies', 'custom-post-type-ui') . '</h2>';
    if (!empty($taxonomies)) {
        ?>
				<p><?php 
        printf(esc_html__('CPTUI registered taxonomies count total: %d', 'custom-post-type-ui'), count($taxonomies));
        ?>
</p>

				<?php 
        $taxonomy_table_heads = array(__('Taxonomy', 'custom-post-type-ui'), __('Settings', 'custom-post-type-ui'), __('Post Types', 'custom-post-type-ui'), __('Labels', 'custom-post-type-ui'), __('Template Hierarchy', 'custom-post-type-ui'));
        /**
         * Fires before the listing of registered taxonomy data.
         *
         * @since 1.1.0
         */
        do_action('cptui_before_taxonomy_listing');
        ?>
				<table class="wp-list-table widefat taxonomy-listing">
					<tr>
						<?php 
        foreach ($taxonomy_table_heads as $head) {
            echo '<th>' . esc_html($head) . '</th>';
        }
        ?>
					</tr>
					<?php 
        $counter = 1;
        foreach ($taxonomies as $taxonomy => $taxonomy_settings) {
            $rowclass = 0 === $counter % 2 ? '' : 'alternate';
            $strings = array();
            $object_types = array();
            foreach ($taxonomy_settings as $settings_key => $settings_value) {
                if ('labels' === $settings_key) {
                    continue;
                }
                if (is_string($settings_value)) {
                    $strings[$settings_key] = $settings_value;
                } else {
                    if ('object_types' === $settings_key) {
                        $object_types[$settings_key] = $settings_value;
                        // In case they are not associated from the post type settings.
                        if (empty($object_types['object_types'])) {
                            $types = get_taxonomy($taxonomy);
                            $object_types['object_types'] = $types->object_type;
                        }
                    }
                }
            }
            ?>
							<tr class="<?php 
            echo esc_attr($rowclass);
            ?>
">
								<?php 
            $edit_path = 'admin.php?page=cptui_manage_taxonomies&action=edit&cptui_taxonomy=' . $taxonomy;
            $taxonomy_link_url = is_network_admin() ? network_admin_url($edit_path) : admin_url($edit_path);
            ?>
								<td>
									<?php 
            printf('<a href="%s">%s</a> | <a href="%s">%s</a>', esc_attr($taxonomy_link_url), sprintf(esc_html__('Edit %s', 'custom-post-type-ui'), esc_html($taxonomy)), esc_attr(admin_url('admin.php?page=cptui_importexport&action=get_code#' . $taxonomy)), esc_html__('Get code', 'custom-post-type-ui'));
            ?>
								</td>
								<td>
									<?php 
            foreach ($strings as $key => $value) {
                printf('<strong>%s:</strong> ', esc_html($key));
                if (in_array($value, array('1', '0'))) {
                    echo esc_html(disp_boolean($value));
                } else {
                    echo esc_html($value);
                }
                echo '<br/>';
            }
            ?>
								</td>
								<td>
									<?php 
            if (!empty($object_types['object_types'])) {
                foreach ($object_types['object_types'] as $type) {
                    echo esc_html($type) . '<br/>';
                }
            }
            ?>
								</td>
								<td>
									<?php 
            $maybe_empty = array_filter($taxonomy_settings['labels']);
            if (!empty($maybe_empty)) {
                foreach ($taxonomy_settings['labels'] as $key => $value) {
                    printf('%s: %s<br/>', esc_html($key), esc_html($value));
                }
            } else {
                esc_html_e('No custom labels to display', 'custom-post-type-ui');
            }
            ?>
								</td>
								<td>
									<p><strong><?php 
            esc_html_e('Archives', 'custom-post-type-ui');
            ?>
</strong><br />
										taxonomy-<?php 
            echo esc_html($taxonomy);
            ?>
-term_slug.php *<br />
										taxonomy-<?php 
            echo esc_html($taxonomy);
            ?>
.php<br />
										taxonomy.php<br />
										archive.php<br />
										index.php
									</p>

									<p>
										<?php 
            esc_html_e('*Replace "term_slug" with the slug of the actual taxonomy term.', 'custom-post-type-ui');
            ?>
									</p>
									<p><?php 
            printf('<a href="https://developer.wordpress.org/themes/basics/template-hierarchy/">%s</a>', esc_html__('Template hierarchy Theme Handbook', 'custom-post-type-ui'));
            ?>
</p>
								</td>
							</tr>

						<?php 
            $counter++;
        }
        ?>
					<tr>
						<?php 
        foreach ($taxonomy_table_heads as $head) {
            echo '<th>' . esc_html($head) . '</th>';
        }
        ?>
					</tr>
				</table>
			<?php 
        /**
         * Fires after the listing of registered taxonomy data.
         *
         * @since 1.3.0
         */
        do_action('cptui_after_taxonomy_listing');
    } else {
        /**
         * Fires when there are no registered taxonomies to list.
         *
         * @since 1.3.0
         */
        do_action('cptui_no_taxonomies_listing');
    }
    ?>

		</div>
	<?php 
}
예제 #2
0
/**
 * Add to or update our CPTUI option with new data.
 *
 * @since 1.0.0
 *
 * @param array $data Array of taxonomy data to update.
 *
 * @return bool|string False on failure, string on success.
 */
function cptui_update_taxonomy($data = array())
{
    /**
     * Fires before a taxonomy is updated to our saved options.
     *
     * @since 1.0.0
     *
     * @param array $data Array of taxonomy data we are updating.
     */
    do_action('cptui_before_update_taxonomy', $data);
    # They need to provide a name
    if (empty($data['cpt_custom_tax']['name'])) {
        return cptui_admin_notices('error', '', false, __('Please provide a taxonomy name', 'cpt-plugin'));
    }
    foreach ($data as $key => $value) {
        if (is_string($value)) {
            $data[$key] = sanitize_text_field($value);
        } else {
            array_map('sanitize_text_field', $data[$key]);
        }
    }
    if (false !== strpos($data['cpt_custom_tax']['name'], '\'') || false !== strpos($data['cpt_custom_tax']['name'], '\\"') || false !== strpos($data['cpt_custom_tax']['rewrite_slug'], '\'') || false !== strpos($data['cpt_custom_tax']['rewrite_slug'], '\\"')) {
        return cptui_admin_notices('error', '', false, __('Please do not use quotes in taxonomy names or rewrite slugs', 'cpt-plugin'));
    }
    $taxonomies = get_option('cptui_taxonomies', array());
    if ('new' == $data['cpt_tax_status'] && array_key_exists(strtolower($data['cpt_custom_tax']['name']), $taxonomies)) {
        return cptui_admin_notices('error', '', false, sprintf(__('Please choose a different taxonomy name. %s is already used.', 'cpt-plugin'), $data['cpt_custom_tax']['name']));
    }
    if (empty($data['cpt_post_types']) || !is_array($data['cpt_post_types'])) {
        $data['cpt_post_types'] = '';
    }
    foreach ($data['cpt_tax_labels'] as $key => $label) {
        if (empty($label)) {
            unset($data['cpt_tax_labels'][$key]);
        }
        $label = str_replace('"', '', htmlspecialchars_decode($label));
        $label = htmlspecialchars($label, ENT_QUOTES);
        $data['cpt_tax_labels'][$key] = stripslashes_deep($label);
    }
    $label = str_replace('"', '', htmlspecialchars_decode($data['cpt_custom_tax']['label']));
    $label = htmlspecialchars(stripslashes($label), ENT_QUOTES);
    $singular_label = str_replace('"', '', htmlspecialchars_decode($data['cpt_custom_tax']['singular_label']));
    $singular_label = htmlspecialchars(stripslashes($singular_label));
    $taxonomies[$data['cpt_custom_tax']['name']] = array('name' => $data['cpt_custom_tax']['name'], 'label' => $label, 'singular_label' => $singular_label, 'hierarchical' => disp_boolean($data['cpt_custom_tax']['hierarchical']), 'show_ui' => disp_boolean($data['cpt_custom_tax']['show_ui']), 'query_var' => disp_boolean($data['cpt_custom_tax']['query_var']), 'query_var_slug' => $data['cpt_custom_tax']['query_var_slug'], 'rewrite' => disp_boolean($data['cpt_custom_tax']['rewrite']), 'rewrite_slug' => $data['cpt_custom_tax']['rewrite_slug'], 'rewrite_withfront' => $data['cpt_custom_tax']['rewrite_withfront'], 'rewrite_hierarchical' => $data['cpt_custom_tax']['rewrite_hierarchical'], 'show_admin_column' => disp_boolean($data['cpt_custom_tax']['show_admin_column']), 'labels' => $data['cpt_tax_labels']);
    $taxonomies[$data['cpt_custom_tax']['name']]['object_types'] = $data['cpt_post_types'];
    $success = update_option('cptui_taxonomies', $taxonomies);
    /**
     * Fires after a taxonomy is updated to our saved options.
     *
     * @since 1.0.0
     *
     * @param array $data Array of taxonomy data that was updated.
     */
    do_action('cptui_after_update_taxonomy', $data);
    flush_rewrite_rules();
    if (isset($success)) {
        if ('new' == $data['cpt_tax_status']) {
            return cptui_admin_notices('add', $data['cpt_custom_tax']['name'], $success);
        }
    }
    return cptui_admin_notices('update', $data['cpt_custom_tax']['name'], true);
}
예제 #3
0
/**
 * Helper function to register the actual taxonomy.
 *
 * @param array $taxonomy Taxonomy array to register.
 *
 * @return null Result of register_taxonomy.
 */
function cptui_register_single_taxonomy($taxonomy = array())
{
    $labels = array('name' => $taxonomy['label'], 'singular_name' => $taxonomy['singular_label']);
    $preserved = cptui_get_preserved_keys('taxonomies');
    foreach ($taxonomy['labels'] as $key => $label) {
        if (!empty($label)) {
            $labels[$key] = $label;
        } elseif (empty($label) && in_array($key, $preserved)) {
            $labels[$key] = cptui_get_preserved_label('taxonomies', $key, $taxonomy['label'], $taxonomy['singular_label']);
        }
    }
    $rewrite = get_disp_boolean($taxonomy['rewrite']);
    if (false !== get_disp_boolean($taxonomy['rewrite'])) {
        $rewrite = array();
        $rewrite['slug'] = !empty($taxonomy['rewrite_slug']) ? $taxonomy['rewrite_slug'] : $taxonomy['name'];
        $rewrite['with_front'] = 'false' === disp_boolean($taxonomy['rewrite_withfront']) ? false : true;
        $rewrite['hierarchical'] = 'true' === disp_boolean($taxonomy['rewrite_hierarchical']) ? true : false;
    }
    if (in_array($taxonomy['query_var'], array('true', 'false', '0', '1'))) {
        $taxonomy['query_var'] = get_disp_boolean($taxonomy['query_var']);
    }
    if (true === $taxonomy['query_var'] && !empty($taxonomy['query_var_slug'])) {
        $taxonomy['query_var'] = $taxonomy['query_var_slug'];
    }
    $show_admin_column = !empty($taxonomy['show_admin_column']) && false !== get_disp_boolean($taxonomy['show_admin_column']) ? true : false;
    $args = array('labels' => $labels, 'label' => $taxonomy['label'], 'hierarchical' => get_disp_boolean($taxonomy['hierarchical']), 'show_ui' => get_disp_boolean($taxonomy['show_ui']), 'query_var' => $taxonomy['query_var'], 'rewrite' => $rewrite, 'show_admin_column' => $show_admin_column);
    $object_type = !empty($taxonomy['object_types']) ? $taxonomy['object_types'] : '';
    /**
     * Filters the arguments used for a taxonomy right before registering.
     *
     * @since 1.0.0
     *
     * @param array  $args Array of arguments to use for registering taxonomy.
     * @param string $value Taxonomy slug to be registered.
     */
    $args = apply_filters('cptui_pre_register_taxonomy', $args, $taxonomy['name']);
    return register_taxonomy($taxonomy['name'], $object_type, $args);
}
function cpt_manage_taxonomies()
{
    global $CPT_URL;
    $MANAGE_URL = cpt_check_return('add');
    ?>
<div class="wrap">
<?php 
    //check for success/error messages
    if (isset($_GET['cpt_msg']) && $_GET['cpt_msg'] == 'del') {
        ?>
	<div id="message" class="updated">
		<?php 
        _e('Custom taxonomy deleted successfully', 'cpt-plugin');
        ?>
	</div>
	<?php 
    }
    screen_icon('plugins');
    ?>
<h2><?php 
    _e('Manage Custom Taxonomies', 'cpt-plugin');
    ?>
</h2>
<p><?php 
    _e('Deleting custom taxonomies does <strong>NOT</strong> delete any content added to those taxonomies.  You can easily recreate your taxonomies and the content will still exist.', 'cpt-plugin');
    ?>
</p>
	<?php 
    $cpt_tax_types = get_option('cpt_custom_tax_types', array());
    if (is_array($cpt_tax_types)) {
        ?>
		<table width="100%" class="widefat">
			<thead>
				<tr>
				<th><?php 
        _e('Action', 'cpt-plugin');
        ?>
</th>
				<th><?php 
        _e('Name', 'cpt-plugin');
        ?>
</th>
				<th><?php 
        _e('Label', 'cpt-plugin');
        ?>
</th>
				<th><?php 
        _e('Singular Label', 'cpt-plugin');
        ?>
</th>
				<th><?php 
        _e('Attached Post Types', 'cpt-plugin');
        ?>
</th>
				<th><?php 
        _e('Hierarchical', 'cpt-plugin');
        ?>
</th>
				<th><?php 
        _e('Show UI', 'cpt-plugin');
        ?>
</th>
				<th><?php 
        _e('Rewrite', 'cpt-plugin');
        ?>
</th>
				<th><?php 
        _e('Rewrite Slug', 'cpt-plugin');
        ?>
</th>
				</tr>
			</thead>
			<tfoot>
				<tr>
				<th><?php 
        _e('Action', 'cpt-plugin');
        ?>
</th>
				<th><?php 
        _e('Name', 'cpt-plugin');
        ?>
</th>
				<th><?php 
        _e('Label', 'cpt-plugin');
        ?>
</th>
				<th><?php 
        _e('Singular Label', 'cpt-plugin');
        ?>
</th>
				<th><?php 
        _e('Attached Post Types', 'cpt-plugin');
        ?>
</th>
				<th><?php 
        _e('Hierarchical', 'cpt-plugin');
        ?>
</th>
				<th><?php 
        _e('Show UI', 'cpt-plugin');
        ?>
</th>
				<th><?php 
        _e('Rewrite', 'cpt-plugin');
        ?>
</th>
				<th><?php 
        _e('Rewrite Slug', 'cpt-plugin');
        ?>
</th>
				</tr>
			</tfoot>
		<?php 
        $thecounter = 0;
        foreach ($cpt_tax_types as $cpt_tax_type) {
            $del_url = cpt_check_return('cpt') . '&deltax=' . $thecounter . '&return=tax';
            $del_url = function_exists('wp_nonce_url') ? wp_nonce_url($del_url, 'cpt_delete_tax') : $del_url;
            $edit_url = $MANAGE_URL . '&edittax=' . $thecounter . '&return=tax';
            $edit_url = function_exists('wp_nonce_url') ? wp_nonce_url($edit_url, 'cpt_edit_tax') : $edit_url;
            $rewrite_slug = $cpt_tax_type["rewrite_slug"] ? $cpt_tax_type["rewrite_slug"] : $cpt_tax_type["name"];
            ?>
			<tr>
				<td valign="top"><a href="<?php 
            echo $del_url;
            ?>
"><?php 
            _e('Delete', 'cpt-plugin');
            ?>
</a> / <a href="<?php 
            echo $edit_url;
            ?>
"><?php 
            _e('Edit', 'cpt-plugin');
            ?>
</a> / <a href="#" class="comment_button" id="<?php 
            echo $thecounter;
            ?>
"><?php 
            _e('Get Code', 'cpt-plugin');
            ?>
</a></td>
				<td valign="top"><?php 
            echo stripslashes($cpt_tax_type["name"]);
            ?>
</td>
				<td valign="top"><?php 
            echo stripslashes($cpt_tax_type["label"]);
            ?>
</td>
				<td valign="top"><?php 
            echo stripslashes($cpt_tax_type["singular_label"]);
            ?>
</td>
				<td valign="top">
				<?php 
            if (isset($cpt_tax_type["cpt_name"])) {
                echo stripslashes($cpt_tax_type["cpt_name"]);
            } elseif (is_array($cpt_tax_type[1])) {
                foreach ($cpt_tax_type[1] as $cpt_post_types) {
                    echo $cpt_post_types . '<br />';
                }
            }
            ?>
				</td>
				<td valign="top"><?php 
            echo disp_boolean($cpt_tax_type["hierarchical"]);
            ?>
</td>
				<td valign="top"><?php 
            echo disp_boolean($cpt_tax_type["show_ui"]);
            ?>
</td>
				<td valign="top"><?php 
            echo disp_boolean($cpt_tax_type["rewrite"]);
            ?>
</td>
				<td valign="top"><?php 
            echo $rewrite_slug;
            ?>
</td>
			</tr>
			<tr>
				<td colspan="10">
					<div style="display:none;" id="slidepanel<?php 
            echo $thecounter;
            ?>
">
						<?php 
            $cpt_tax_sanitized_name = str_replace('-', '_', $cpt_tax_type['name']);
            //display register_taxonomy code
            $custom_tax = '';
            $custom_tax = "add_action('init', 'cptui_register_my_taxes_" . $cpt_tax_sanitized_name . "');\n";
            $custom_tax .= "function cptui_register_my_taxes_" . $cpt_tax_sanitized_name . "() {\n";
            if (!$cpt_tax_type["label"]) {
                $cpt_label = esc_html($cpt_tax_type["name"]);
            } else {
                $cpt_label = esc_html($cpt_tax_type["label"]);
            }
            //check if singular label was filled out
            if (!$cpt_tax_type["singular_label"]) {
                $cpt_singular_label = esc_html($cpt_tax_type["name"]);
            } else {
                $cpt_singular_label = esc_html($cpt_tax_type["singular_label"]);
            }
            $labels = var_export(array('search_items' => !empty($cpt_tax_type["singular_label"]) ? esc_html($cpt_tax_type["singular_label"]) : '', 'popular_items' => !empty($cpt_tax_type[0]["popular_items"]) ? esc_html($cpt_tax_type[0]["popular_items"]) : '', 'all_items' => !empty($cpt_tax_type[0]["all_items"]) ? esc_html($cpt_tax_type[0]["all_items"]) : '', 'parent_item' => !empty($cpt_tax_type[0]["parent_item"]) ? esc_html($cpt_tax_type[0]["parent_item"]) : '', 'parent_item_colon' => !empty($cpt_tax_type[0]["parent_item_colon"]) ? esc_html($cpt_tax_type[0]["parent_item_colon"]) : '', 'edit_item' => !empty($cpt_tax_type[0]["edit_item"]) ? esc_html($cpt_tax_type[0]["edit_item"]) : '', 'update_item' => !empty($cpt_tax_type[0]["update_item"]) ? esc_html($cpt_tax_type[0]["update_item"]) : '', 'add_new_item' => !empty($cpt_tax_type[0]["add_new_item"]) ? esc_html($cpt_tax_type[0]["add_new_item"]) : '', 'new_item_name' => !empty($cpt_tax_type[0]["new_item_name"]) ? esc_html($cpt_tax_type[0]["new_item_name"]) : '', 'separate_items_with_commas' => !empty($cpt_tax_type[0]["separate_items_with_commas"]) ? esc_html($cpt_tax_type[0]["separate_items_with_commas"]) : '', 'add_or_remove_items' => !empty($cpt_tax_type[0]["add_or_remove_items"]) ? esc_html($cpt_tax_type[0]["add_or_remove_items"]) : '', 'choose_from_most_used' => !empty($cpt_tax_type[0]["choose_from_most_used"]) ? esc_html($cpt_tax_type[0]["choose_from_most_used"]) : ''), true);
            $cpt_post_types = !$cpt_tax_type[1] ? $cpt_tax_type["cpt_name"] : var_export($cpt_tax_type[1], true);
            //register our custom taxonomies
            $custom_tax .= "register_taxonomy( '" . $cpt_tax_type["name"] . "',";
            $custom_tax .= $cpt_post_types . ",\n";
            $custom_tax .= "array( 'hierarchical' => " . disp_boolean($cpt_tax_type["hierarchical"]) . ",\n";
            $custom_tax .= "\t'label' => '" . $cpt_label . "',\n";
            $custom_tax .= "\t'show_ui' => " . disp_boolean($cpt_tax_type["show_ui"]) . ",\n";
            $custom_tax .= "\t'query_var' => " . disp_boolean($cpt_tax_type["query_var"]) . ",\n";
            if (!empty($cpt_tax_type["rewrite_slug"])) {
                $custom_tax .= "\t'rewrite' => array( 'slug' => '" . $cpt_tax_type["rewrite_slug"] . "' ),\n";
            }
            if (version_compare(CPTUI_WP_VERSION, '3.5', '>')) {
                $custom_tax .= "\t'show_admin_column' => " . disp_boolean($cpt_tax_type["show_admin_column"]) . ",\n";
            }
            if (!empty($labels)) {
                $custom_tax .= "\t'labels' => " . $labels . "\n";
            }
            $custom_tax .= ") ); \n}";
            echo '<br>';
            echo _e('Place the below code in your themes functions.php file to manually create this custom taxonomy', 'cpt-plugin') . '<br>';
            echo _e('This is a <strong>BETA</strong> feature. Please <a href="http://webdevstudios.com/support/forum/custom-post-type-ui/">report bugs</a>.', 'cpt-plugin') . '<br>';
            echo '<textarea rows="10" cols="100">' . $custom_tax . '</textarea>';
            ?>
					</div>
				</td>
			</tr>
		<?php 
            $thecounter++;
        }
        ?>
</table>
		</div>
		<?php 
        //load footer
        cpt_footer();
    }
}
예제 #5
0
/**
 * Helper function to register the actual taxonomy.
 *
 * @since 1.0.0
 *
 * @internal
 *
 * @param array $taxonomy Taxonomy array to register.
 * @return null Result of register_taxonomy.
 */
function cptui_register_single_taxonomy($taxonomy = array())
{
    $labels = array('name' => $taxonomy['label'], 'singular_name' => $taxonomy['singular_label']);
    $description = '';
    if (!empty($taxonomy['description'])) {
        $description = $taxonomy['description'];
    }
    $preserved = cptui_get_preserved_keys('taxonomies');
    foreach ($taxonomy['labels'] as $key => $label) {
        if (!empty($label)) {
            $labels[$key] = $label;
        } elseif (empty($label) && in_array($key, $preserved)) {
            $labels[$key] = cptui_get_preserved_label('taxonomies', $key, $taxonomy['label'], $taxonomy['singular_label']);
        }
    }
    $rewrite = get_disp_boolean($taxonomy['rewrite']);
    if (false !== get_disp_boolean($taxonomy['rewrite'])) {
        $rewrite = array();
        $rewrite['slug'] = !empty($taxonomy['rewrite_slug']) ? $taxonomy['rewrite_slug'] : $taxonomy['name'];
        $rewrite['with_front'] = 'false' === disp_boolean($taxonomy['rewrite_withfront']) ? false : true;
        $rewrite['hierarchical'] = 'true' === disp_boolean($taxonomy['rewrite_hierarchical']) ? true : false;
    }
    if (in_array($taxonomy['query_var'], array('true', 'false', '0', '1'))) {
        $taxonomy['query_var'] = get_disp_boolean($taxonomy['query_var']);
    }
    if (true === $taxonomy['query_var'] && !empty($taxonomy['query_var_slug'])) {
        $taxonomy['query_var'] = $taxonomy['query_var_slug'];
    }
    $public = !empty($taxonomy['public']) && false === get_disp_boolean($taxonomy['public']) ? false : true;
    $show_admin_column = !empty($taxonomy['show_admin_column']) && false !== get_disp_boolean($taxonomy['show_admin_column']) ? true : false;
    $show_in_menu = !empty($taxonomy['show_in_menu']) && false !== get_disp_boolean($taxonomy['show_in_menu']) ? true : false;
    if (empty($taxonomy['show_in_menu'])) {
        $show_in_menu = get_disp_boolean($taxonomy['show_ui']);
    }
    $show_in_nav_menus = !empty($taxonomy['show_in_nav_menus']) && false !== get_disp_boolean($taxonomy['show_in_nav_menus']) ? true : false;
    if (empty($taxonomy['show_in_nav_menus'])) {
        $show_in_nav_menus = $public;
    }
    $show_in_rest = !empty($taxonomy['show_in_rest']) && false !== get_disp_boolean($taxonomy['show_in_rest']) ? true : false;
    $show_in_quick_edit = !empty($taxonomy['show_in_quick_edit']) && false !== get_disp_boolean($taxonomy['show_in_quick_edit']) ? true : false;
    $rest_base = null;
    if (!empty($taxonomy['rest_base'])) {
        $rest_base = $taxonomy['rest_base'];
    }
    $args = array('labels' => $labels, 'label' => $taxonomy['label'], 'description' => $description, 'public' => $public, 'hierarchical' => get_disp_boolean($taxonomy['hierarchical']), 'show_ui' => get_disp_boolean($taxonomy['show_ui']), 'show_in_menu' => $show_in_menu, 'show_in_nav_menus' => $show_in_nav_menus, 'query_var' => $taxonomy['query_var'], 'rewrite' => $rewrite, 'show_admin_column' => $show_admin_column, 'show_in_rest' => $show_in_rest, 'rest_base' => $rest_base, 'show_in_quick_edit' => $show_in_quick_edit);
    $object_type = !empty($taxonomy['object_types']) ? $taxonomy['object_types'] : '';
    /**
     * Filters the arguments used for a taxonomy right before registering.
     *
     * @since 1.0.0
     * @since 1.3.0 Added original passed in values array
     *
     * @param array  $args     Array of arguments to use for registering taxonomy.
     * @param string $value    Taxonomy slug to be registered.
     * @param array  $taxonomy Original passed in values for taxonomy.
     */
    $args = apply_filters('cptui_pre_register_taxonomy', $args, $taxonomy['name'], $taxonomy);
    return register_taxonomy($taxonomy['name'], $object_type, $args);
}
예제 #6
0
/**
 * Add to or update our CPTUI option with new data.
 *
 * @since 1.0.0
 *
 * @param array $data Array of post type data to update.
 *
 * @return bool|string False on failure, string on success.
 */
function cptui_update_post_type($data = array())
{
    /**
     * Fires before a post_type is updated to our saved options.
     *
     * @since 1.0.0
     *
     * @param array $data Array of post_type data we are updating.
     */
    do_action('cptui_before_update_post_type', $data);
    # They need to provide a name
    if (empty($data['cpt_custom_post_type']['name'])) {
        return cptui_admin_notices('error', '', false, __('Please provide a post type name', 'cpt-plugin'));
    }
    # clean up $_POST data
    foreach ($data as $key => $value) {
        if (is_string($value)) {
            $data[$key] = sanitize_text_field($value);
        } else {
            array_map('sanitize_text_field', $data[$key]);
        }
    }
    # Check if they didn't put quotes in the name or rewrite slug.
    if (false !== strpos($data['cpt_custom_post_type']['name'], '\'') || false !== strpos($data['cpt_custom_post_type']['name'], '\\"') || false !== strpos($data['cpt_custom_post_type']['rewrite_slug'], '\'') || false !== strpos($data['cpt_custom_post_type']['rewrite_slug'], '\\"')) {
        return cptui_admin_notices('error', '', false, __('Please do not use quotes in post type names or rewrite slugs', 'cpt-plugin'));
    }
    $post_types = get_option('cptui_post_types', array());
    # Check if we already have a post type of that name.
    if ('new' == $data['cpt_type_status'] && (array_key_exists(strtolower($data['cpt_custom_post_type']['name']), $post_types) || in_array($data['cpt_custom_post_type']['name'], cptui_reserved_post_types()))) {
        return cptui_admin_notices('error', '', false, sprintf(__('Please choose a different post type name. %s is already registered.', 'cpt-plugin'), $data['cpt_custom_post_type']['name']));
    }
    if (empty($data['cpt_addon_taxes']) || !is_array($data['cpt_addon_taxes'])) {
        $data['cpt_addon_taxes'] = array();
    }
    if (empty($data['cpt_supports']) || !is_array($data['cpt_supports'])) {
        $data['cpt_supports'] = array();
    }
    foreach ($data['cpt_labels'] as $key => $label) {
        if (empty($label)) {
            unset($data['cpt_labels'][$key]);
        }
        $label = str_replace('"', '', htmlspecialchars_decode($label));
        $label = htmlspecialchars($label, ENT_QUOTES);
        $data['cpt_labels'][$key] = stripslashes_deep($label);
    }
    if (empty($data['cpt_custom_post_type']['menu_icon'])) {
        $data['cpt_custom_post_type']['menu_icon'] = null;
    }
    $label = str_replace('"', '', htmlspecialchars_decode($data['cpt_custom_post_type']['label']));
    $label = htmlspecialchars(stripslashes($label), ENT_QUOTES);
    $singular_label = str_replace('"', '', htmlspecialchars_decode($data['cpt_custom_post_type']['singular_label']));
    $singular_label = htmlspecialchars(stripslashes($singular_label), ENT_QUOTES);
    $description = stripslashes_deep($data['cpt_custom_post_type']['description']);
    $post_types[$data['cpt_custom_post_type']['name']] = array('name' => $data['cpt_custom_post_type']['name'], 'label' => $label, 'singular_label' => $singular_label, 'description' => $description, 'public' => disp_boolean($data['cpt_custom_post_type']['public']), 'show_ui' => disp_boolean($data['cpt_custom_post_type']['show_ui']), 'has_archive' => disp_boolean($data['cpt_custom_post_type']['has_archive']), 'has_archive_string' => $data['cpt_custom_post_type']['has_archive_string'], 'exclude_from_search' => disp_boolean($data['cpt_custom_post_type']['exclude_from_search']), 'capability_type' => $data['cpt_custom_post_type']['capability_type'], 'hierarchical' => disp_boolean($data['cpt_custom_post_type']['hierarchical']), 'rewrite' => disp_boolean($data['cpt_custom_post_type']['rewrite']), 'rewrite_slug' => $data['cpt_custom_post_type']['rewrite_slug'], 'rewrite_withfront' => disp_boolean($data['cpt_custom_post_type']['rewrite_withfront']), 'query_var' => disp_boolean($data['cpt_custom_post_type']['query_var']), 'menu_position' => $data['cpt_custom_post_type']['menu_position'], 'show_in_menu' => disp_boolean($data['cpt_custom_post_type']['show_in_menu']), 'show_in_menu_string' => $data['cpt_custom_post_type']['show_in_menu_string'], 'menu_icon' => $data['cpt_custom_post_type']['menu_icon'], 'supports' => $data['cpt_supports'], 'taxonomies' => $data['cpt_addon_taxes'], 'labels' => $data['cpt_labels']);
    $success = update_option('cptui_post_types', $post_types);
    /**
     * Fires after a post type is updated to our saved options.
     *
     * @since 1.0.0
     *
     * @param array $data Array of post type data that was updated.
     */
    do_action('cptui_after_update_post_type', $data);
    flush_rewrite_rules();
    if (isset($success)) {
        if ('new' == $data['cpt_type_status']) {
            return cptui_admin_notices('add', $data['cpt_custom_post_type']['name'], $success);
        }
    }
    return cptui_admin_notices('update', $data['cpt_custom_post_type']['name'], true);
}
예제 #7
0
function cpt_manage_taxonomies() {
	global $CPT_URL;

	$MANAGE_URL = cpt_check_return( 'add' );

	//flush rewrite rules
	flush_rewrite_rules();
?>
<div class="wrap">
<?php
//check for success/error messages
If (isset($_GET['cpt_msg']) && $_GET['cpt_msg']=='del') { ?>
    <div id="message" class="updated">
    	<?php _e('Custom taxonomy deleted successfully', 'cpt-plugin'); ?>
    </div>
    <?php
}
?>
<h2><?php _e('Manage Custom Taxonomies', 'cpt-plugin') ?></h2>
<p><?php _e('Deleting custom taxonomies does <strong>NOT</strong> delete any content added to those taxonomies.  You can easily recreate your taxonomies and the content will still exist.', 'cpt-plugin') ?></p>
<?php
	$cpt_tax_types = get_option('cpt_custom_tax_types');

	If (is_array($cpt_tax_types)) {
		?>
        <table width="100%">
        	<tr>
            	<td><strong><?php _e('Action', 'cpt-plugin');?></strong></td>
            	<td><strong><?php _e('Name', 'cpt-plugin');?></strong></td>
                <td><strong><?php _e('Label', 'cpt-plugin');?></strong></td>
                <td><strong><?php _e('Singular Label', 'cpt-plugin');?></strong></td>
                <td><strong><?php _e('Attached Post Types', 'cpt-plugin');?></strong></td>
                <td><strong><?php _e('Hierarchical', 'cpt-plugin');?></strong></td>
                <td><strong><?php _e('Show UI', 'cpt-plugin');?></strong></td>
                <td><strong><?php _e('Rewrite', 'cpt-plugin');?></strong></td>
                <td><strong><?php _e('Rewrite Slug', 'cpt-plugin');?></strong></td>
            </tr>
        <?php
		$thecounter=0;
		foreach ($cpt_tax_types as $cpt_tax_type) {

			$del_url = cpt_check_return( 'cpt' ) .'&deltax=' .$thecounter .'&return=tax';
			$del_url = ( function_exists('wp_nonce_url') ) ? wp_nonce_url($del_url, 'cpt_delete_tax') : $del_url;

			$edit_url = $MANAGE_URL .'&edittax=' .$thecounter .'&return=tax';
			$edit_url = ( function_exists('wp_nonce_url') ) ? wp_nonce_url($edit_url, 'cpt_edit_tax') : $edit_url;
			
			$rewrite_slug = ( $cpt_tax_type["rewrite_slug"] ) ? $cpt_tax_type["rewrite_slug"] : $cpt_tax_type["name"];
		?>
        	<tr>
            	<td valign="top"><a href="<?php echo $del_url; ?>">Delete</a> / <a href="<?php echo $edit_url; ?>">Edit</a><!-- / <a href="#" class="comment_button" id="<?php echo $thecounter; ?>">Get Code</a>--></td>
            	<td valign="top"><?php echo stripslashes($cpt_tax_type["name"]); ?></td>
                <td valign="top"><?php echo stripslashes($cpt_tax_type["label"]); ?></td>
                <td valign="top"><?php echo stripslashes($cpt_tax_type["singular_label"]); ?></td>
                <td valign="top">
				<?php 
				if ( isset( $cpt_tax_type["cpt_name"] ) ) {
					echo stripslashes($cpt_tax_type["cpt_name"]); 
				}elseif ( is_array( $cpt_tax_type[1] ) ) {
					foreach ($cpt_tax_type[1] as $cpt_post_types) {
						echo $cpt_post_types .'<br />';
					}
				}
				?>
                </td>
                <td valign="top"><?php echo disp_boolean($cpt_tax_type["hierarchical"]); ?></td>
                <td valign="top"><?php echo disp_boolean($cpt_tax_type["show_ui"]); ?></td>
                <td valign="top"><?php echo disp_boolean($cpt_tax_type["rewrite"]); ?></td>
                <td valign="top"><?php echo $rewrite_slug; ?></td>
            </tr>
        	<tr>
            	<td colspan="10">
                    <div style="display:none;" id="slidepanel<?php echo $thecounter; ?>">
                        <?php
                        //display register_taxonomy code
                        $cpt_tax_types = get_option('cpt_custom_tax_types');
                        $custom_tax = '';

                        //check if option value is an Array before proceeding
                        If (is_array($cpt_tax_types)) {
                            //foreach ($cpt_tax_types as $cpt_tax_type) {

                                If (!$cpt_tax_type["label"]) {
                                    $cpt_label = esc_html($cpt_tax_type["name"]);
                                }Else{
                                    $cpt_label = esc_html($cpt_tax_type["label"]);
                                }

                                //check if singular label was filled out
                                If (!$cpt_tax_type["singular_label"]) {
                                    $cpt_singular_label = esc_html($cpt_tax_type["name"]);
                                }Else{
                                    $cpt_singular_label = esc_html($cpt_tax_type["singular_label"]);
                                }

                                //register our custom taxonomies
                                $custom_tax = 'register_taxonomy(\'' .$cpt_tax_type["name"]. '\',';
                                $custom_tax .= '\''.$cpt_tax_type["cpt_name"] .'\',';
                                $custom_tax .= 'array( \'hierarchical\' => '.disp_boolean($cpt_tax_type["hierarchical"]).', ';
                                $custom_tax .= 	'\'label\' => \''.$cpt_label.'\',';
                                $custom_tax .= 	'\'show_ui\' => '.disp_boolean($cpt_tax_type["show_ui"]).',';
                                $custom_tax .= 	'\'query_var\' => '. disp_boolean($cpt_tax_type["query_var"]).',';
								$custom_tax .= 	'\'rewrite\' => array(\'slug\' => \'' .$cpt_tax_type["rewrite_slug"]. '\'),';
                                $custom_tax .= 	'\'singular_label\' => \''.$cpt_singular_label.'\'';
                                $custom_tax .= ') );';

								echo '<br>';
								echo _e('Place the below code in your themes functions.php file to manually create this custom taxonomy','cpt-plugin').'<br>';
                                echo '<textarea rows="5" cols="100">' .$custom_tax .'</textarea>';

                            //}
                        }
                        ?>
                    </div>
				</td>
            </tr>
            <tr>
            	<td colspan="10"><hr /></td>
            </tr>

		<?php
		$thecounter++;
		}
		?></table>
		</div>
		<?php
		//load footer
		cpt_footer();
	}
}
예제 #8
0
/**
 * Create output for single post type to be ready for copy/paste from Get Code.
 *
 * @since 1.0.0
 *
 * @param array $post_type Post type data to output.
 *
 * @return string Copy/paste ready "php" code.
 */
function cptui_get_single_post_type_registery($post_type = array())
{
    /** This filter is documented in custom-post-type-ui/custom-post-type-ui.php */
    $post_type['map_meta_cap'] = apply_filters('cptui_map_meta_cap', 'true', $post_type['name'], $post_type);
    $user_supports_params = apply_filters('cptui_user_supports_params', array(), $post_type['name'], $post_type);
    if (is_array($user_supports_params)) {
        $post_type['supports'] = array_merge($post_type['supports'], $user_supports_params);
    }
    $rewrite = get_disp_boolean($post_type['rewrite']);
    if (false !== $rewrite) {
        $rewrite = disp_boolean($post_type['rewrite']);
        $rewrite_slug = ' "slug" => "' . $post_type['name'] . '",';
        if (!empty($post_type['rewrite_slug'])) {
            $rewrite_slug = ' "slug" => "' . $post_type['rewrite_slug'] . '",';
        }
        $withfront = disp_boolean($post_type['rewrite_withfront']);
        if (!empty($withfront)) {
            $rewrite_withfront = ' "with_front" => ' . $withfront . ' ';
        }
        if (!empty($post_type['rewrite_slug']) || !empty($post_type['rewrite_withfront'])) {
            $rewrite_start = 'array(';
            $rewrite_end = ')';
            $rewrite = $rewrite_start . $rewrite_slug . $rewrite_withfront . $rewrite_end;
        }
    } else {
        $rewrite = disp_boolean($post_type['rewrite']);
    }
    $supports = '';
    # Do a little bit of php work to get these into strings.
    if (!empty($post_type['supports']) && is_array($post_type['supports'])) {
        $supports = 'array( "' . implode('", "', $post_type['supports']) . '" )';
    }
    if (in_array('none', $post_type['supports'])) {
        $supports = 'false';
    }
    $taxonomies = '';
    if (!empty($post_type['taxonomies']) && is_array($post_type['taxonomies'])) {
        $taxonomies = 'array( "' . implode('", "', $post_type['taxonomies']) . '" )';
    }
    if (in_array($post_type['query_var'], array('true', 'false', '0', '1'))) {
        $post_type['query_var'] = get_disp_boolean($post_type['query_var']);
    }
    $post_type['description'] = addslashes($post_type['description']);
    ?>
	$labels = array(
		"name" => "<?php 
    echo $post_type['label'];
    ?>
",
		"singular_name" => "<?php 
    echo $post_type['singular_label'];
    ?>
",
		<?php 
    foreach ($post_type['labels'] as $key => $label) {
        if (!empty($label)) {
            echo '"' . $key . '" => "' . $label . '",' . "\n\t\t";
        }
    }
    ?>
);

	$args = array(
		"labels" => $labels,
		"description" => "<?php 
    echo $post_type['description'];
    ?>
",
		"public" => <?php 
    echo disp_boolean($post_type['public']);
    ?>
,
		"show_ui" => <?php 
    echo disp_boolean($post_type['show_ui']);
    ?>
,
		"has_archive" => <?php 
    echo disp_boolean($post_type['has_archive']);
    ?>
,
		"show_in_menu" => <?php 
    echo disp_boolean($post_type['show_in_menu']);
    ?>
,
		"exclude_from_search" => <?php 
    echo disp_boolean($post_type['exclude_from_search']);
    ?>
,
		"capability_type" => "<?php 
    echo $post_type['capability_type'];
    ?>
",
		"map_meta_cap" => <?php 
    echo disp_boolean($post_type['map_meta_cap']);
    ?>
,
		"hierarchical" => <?php 
    echo disp_boolean($post_type['hierarchical']);
    ?>
,
		"rewrite" => <?php 
    echo $rewrite;
    ?>
,
		"query_var" => <?php 
    echo disp_boolean($post_type['query_var']);
    ?>
,
		<?php 
    if (!empty($post_type['menu_position'])) {
        ?>
"menu_position" => <?php 
        echo $post_type['menu_position'];
        ?>
,<?php 
    }
    ?>
		<?php 
    if (!empty($post_type['menu_icon'])) {
        ?>
"menu_icon" => "<?php 
        echo $post_type['menu_icon'];
        ?>
",<?php 
    }
    ?>
		<?php 
    if (!empty($supports)) {
        ?>
"supports" => <?php 
        echo $supports;
        ?>
,<?php 
    }
    ?>
		<?php 
    if (!empty($taxonomies)) {
        ?>
"taxonomies" => <?php 
        echo $taxonomies;
    }
    ?>
	);
	register_post_type( "<?php 
    echo $post_type['name'];
    ?>
", $args );
<?php 
}
예제 #9
0
/**
 * Add to or update our CPTUI option with new data.
 *
 * @since 1.0.0
 *
 * @internal
 *
 * @param array $data Array of post type data to update.
 *
 * @return bool|string False on failure, string on success.
 */
function cptui_update_post_type($data = array())
{
    /**
     * Fires before a post_type is updated to our saved options.
     *
     * @since 1.0.0
     *
     * @param array $data Array of post_type data we are updating.
     */
    do_action('cptui_before_update_post_type', $data);
    // They need to provide a name.
    if (empty($data['cpt_custom_post_type']['name'])) {
        return cptui_admin_notices('error', '', false, __('Please provide a post type name', 'custom-post-type-ui'));
    }
    if (!empty($data['cpt_original']) && $data['cpt_original'] != $data['cpt_custom_post_type']['name']) {
        if (!empty($data['update_post_types'])) {
            cptui_convert_post_type_posts($data['cpt_original'], $data['cpt_custom_post_type']['name']);
        }
    }
    // clean up $_POST data.
    foreach ($data as $key => $value) {
        if (is_string($value)) {
            $data[$key] = sanitize_text_field($value);
        } else {
            array_map('sanitize_text_field', $data[$key]);
        }
    }
    // Check if they didn't put quotes in the name or rewrite slug.
    if (false !== strpos($data['cpt_custom_post_type']['name'], '\'') || false !== strpos($data['cpt_custom_post_type']['name'], '\\"') || false !== strpos($data['cpt_custom_post_type']['rewrite_slug'], '\'') || false !== strpos($data['cpt_custom_post_type']['rewrite_slug'], '\\"')) {
        return cptui_admin_notices('error', '', false, __('Please do not use quotes in post type names or rewrite slugs', 'custom-post-type-ui'));
    }
    $post_types = cptui_get_post_type_data();
    /**
     * Check if we already have a post type of that name.
     *
     * @since 1.3.0
     *
     * @param bool   $value Assume we have no conflict by default.
     * @param string $value Post type slug being saved.
     * @param array  $post_types Array of existing post types from CPTUI.
     */
    $slug_exists = apply_filters('cptui_post_type_slug_exists', false, $data['cpt_custom_post_type']['name'], $post_types);
    $slug_as_page = cptui_check_page_slugs($data['cpt_custom_post_type']['name']);
    if ('new' == $data['cpt_type_status']) {
        if (true === $slug_exists) {
            return cptui_admin_notices('error', '', false, sprintf(__('Please choose a different post type name. %s is already registered.', 'custom-post-type-ui'), $data['cpt_custom_post_type']['name']));
        }
        if (true === $slug_as_page) {
            return cptui_admin_notices('error', '', false, sprintf(__('Please choose a different post type name. %s matches an existing page slug, which can cause conflicts.', 'custom-post-type-ui'), $data['cpt_custom_post_type']['name']));
        }
    }
    if (empty($data['cpt_addon_taxes']) || !is_array($data['cpt_addon_taxes'])) {
        $data['cpt_addon_taxes'] = array();
    }
    if (empty($data['cpt_supports']) || !is_array($data['cpt_supports'])) {
        $data['cpt_supports'] = array();
    }
    foreach ($data['cpt_labels'] as $key => $label) {
        if (empty($label)) {
            unset($data['cpt_labels'][$key]);
        }
        $label = str_replace('"', '', htmlspecialchars_decode($label));
        $label = htmlspecialchars($label, ENT_QUOTES);
        $label = trim($label);
        $data['cpt_labels'][$key] = stripslashes_deep($label);
    }
    if (empty($data['cpt_custom_post_type']['menu_icon'])) {
        $data['cpt_custom_post_type']['menu_icon'] = null;
    }
    $label = ucwords(str_replace('_', ' ', $data['cpt_custom_post_type']['name']));
    if (!empty($data['cpt_custom_post_type']['label'])) {
        $label = str_replace('"', '', htmlspecialchars_decode($data['cpt_custom_post_type']['label']));
        $label = htmlspecialchars(stripslashes($label), ENT_QUOTES);
    }
    $singular_label = ucwords(str_replace('_', ' ', $data['cpt_custom_post_type']['name']));
    if (!empty($data['cpt_custom_post_type']['singular_label'])) {
        $singular_label = str_replace('"', '', htmlspecialchars_decode($data['cpt_custom_post_type']['singular_label']));
        $singular_label = htmlspecialchars(stripslashes($singular_label), ENT_QUOTES);
    }
    $name = trim($data['cpt_custom_post_type']['name']);
    $description = stripslashes_deep($data['cpt_custom_post_type']['description']);
    $rest_base = trim($data['cpt_custom_post_type']['rest_base']);
    $has_archive_string = trim($data['cpt_custom_post_type']['has_archive_string']);
    $capability_type = trim($data['cpt_custom_post_type']['capability_type']);
    $rewrite_slug = trim($data['cpt_custom_post_type']['rewrite_slug']);
    $query_var_slug = trim($data['cpt_custom_post_type']['query_var_slug']);
    $menu_position = trim($data['cpt_custom_post_type']['menu_position']);
    $show_in_menu_string = trim($data['cpt_custom_post_type']['show_in_menu_string']);
    $menu_icon = trim($data['cpt_custom_post_type']['menu_icon']);
    $custom_supports = trim($data['cpt_custom_post_type']['custom_supports']);
    $post_types[$data['cpt_custom_post_type']['name']] = array('name' => $name, 'label' => $label, 'singular_label' => $singular_label, 'description' => $description, 'public' => disp_boolean($data['cpt_custom_post_type']['public']), 'show_ui' => disp_boolean($data['cpt_custom_post_type']['show_ui']), 'show_in_nav_menus' => disp_boolean($data['cpt_custom_post_type']['show_in_nav_menus']), 'show_in_rest' => disp_boolean($data['cpt_custom_post_type']['show_in_rest']), 'rest_base' => $rest_base, 'has_archive' => disp_boolean($data['cpt_custom_post_type']['has_archive']), 'has_archive_string' => $has_archive_string, 'exclude_from_search' => disp_boolean($data['cpt_custom_post_type']['exclude_from_search']), 'capability_type' => $capability_type, 'hierarchical' => disp_boolean($data['cpt_custom_post_type']['hierarchical']), 'rewrite' => disp_boolean($data['cpt_custom_post_type']['rewrite']), 'rewrite_slug' => $rewrite_slug, 'rewrite_withfront' => disp_boolean($data['cpt_custom_post_type']['rewrite_withfront']), 'query_var' => disp_boolean($data['cpt_custom_post_type']['query_var']), 'query_var_slug' => $query_var_slug, 'menu_position' => $menu_position, 'show_in_menu' => disp_boolean($data['cpt_custom_post_type']['show_in_menu']), 'show_in_menu_string' => $show_in_menu_string, 'menu_icon' => $menu_icon, 'supports' => $data['cpt_supports'], 'taxonomies' => $data['cpt_addon_taxes'], 'labels' => $data['cpt_labels'], 'custom_supports' => $custom_supports);
    /**
     * Filters whether or not 3rd party options were saved successfully within post type add/update.
     *
     * @since 1.3.0
     *
     * @param bool  $value      Whether or not someone else saved successfully. Default false.
     * @param array $post_types Array of our updated post types data.
     * @param array $data       Array of submitted post type to update.
     */
    if (false === ($success = apply_filters('cptui_post_type_update_save', false, $post_types, $data))) {
        $success = update_option('cptui_post_types', $post_types);
    }
    /**
     * Fires after a post type is updated to our saved options.
     *
     * @since 1.0.0
     *
     * @param array $data Array of post type data that was updated.
     */
    do_action('cptui_after_update_post_type', $data);
    // Used to help flush rewrite rules on init.
    set_transient('cptui_flush_rewrite_rules', 'true', 5 * 60);
    if (isset($success)) {
        if ('new' == $data['cpt_type_status']) {
            return cptui_admin_notices('add', $data['cpt_custom_post_type']['name'], $success);
        }
    }
    return cptui_admin_notices('update', $data['cpt_custom_post_type']['name'], true);
}
예제 #10
0
파일: listings.php 프로젝트: Aqro/NewDWM
function cptui_listings()
{
    ?>
		<div class="wrap">

			<h1><?php 
    _e('Post Types and Taxonomies registered by Custom Post Type UI.', 'custom-post-type-ui');
    ?>
</h1>
			<?php 
    $post_types = get_option('cptui_post_types');
    echo '<h2>' . __('Post Types', 'custom-post-type-ui') . '</h2>';
    if (!empty($post_types)) {
        ?>
			<p><?php 
        printf(__('Total count: %d', 'custom-post-type-ui'), count($post_types));
        ?>
</p>

			<?php 
        $post_type_table_heads = array(__('Post Type', 'custom-post-type-ui'), __('Settings', 'custom-post-type-ui'), __('Supports', 'custom-post-type-ui'), __('Taxonomies', 'custom-post-type-ui'), __('Labels', 'custom-post-type-ui'), __('Template Hierarchy', 'custom-post-type-ui'));
        /**
         * Fires before the listing of registered post type data.
         *
         * @since 1.1.0
         */
        do_action('cptui_before_post_type_listing');
        ?>
			<table class="wp-list-table widefat">
				<tr>
					<?php 
        foreach ($post_type_table_heads as $head) {
            echo '<th>' . $head . '</th>';
        }
        ?>
				</tr>
				<?php 
        $counter = 1;
        foreach ($post_types as $post_type => $post_type_settings) {
            $rowclass = $counter % 2 == 0 ? '' : 'alternate';
            $strings = array();
            $supports = array();
            $taxonomies = array();
            $archive = '';
            foreach ($post_type_settings as $settings_key => $settings_value) {
                if ('labels' == $settings_key) {
                    continue;
                }
                if (is_string($settings_value)) {
                    $strings[$settings_key] = $settings_value;
                } else {
                    if ('supports' === $settings_key) {
                        $supports[$settings_key] = $settings_value;
                    }
                    if ('taxonomies' === $settings_key) {
                        $taxonomies[$settings_key] = $settings_value;
                        # In case they are not associated from the post type settings
                        if (empty($taxonomies['taxonomies'])) {
                            $taxonomies['taxonomies'] = get_object_taxonomies($post_type);
                        }
                    }
                }
                $archive = get_post_type_archive_link($post_type);
            }
            ?>
						<tr class="<?php 
            echo $rowclass;
            ?>
">
							<?php 
            $post_type_link_url = admin_url('admin.php?page=cptui_manage_post_types&action=edit&cptui_post_type=' . $post_type);
            ?>
							<td><a href="<?php 
            echo $post_type_link_url;
            ?>
"><?php 
            printf(__('Edit %s', 'custom-post-type-ui'), $post_type);
            ?>
</a>
								<?php 
            if ($archive) {
                ?>
								|
								<a href="<?php 
                echo get_post_type_archive_link($post_type);
                ?>
"><?php 
                _e('View frontend archive', 'custom-post-type-ui');
                ?>
</a>
								<?php 
            }
            ?>
							</td>
							<td>
								<?php 
            foreach ($strings as $key => $value) {
                printf('<strong>%s:</strong> ', $key);
                if (in_array($value, array('1', '0'))) {
                    echo disp_boolean($value);
                } else {
                    echo $value;
                }
                echo '<br/>';
            }
            ?>
							</td>
							<td>
								<?php 
            foreach ($supports['supports'] as $support) {
                echo $support . '<br/>';
            }
            ?>
							</td>
							<td>
								<?php 
            foreach ($taxonomies['taxonomies'] as $taxonomy) {
                echo $taxonomy . '<br/>';
            }
            ?>
							</td>
							<td>
								<?php 
            $maybe_empty = array_filter($post_type_settings['labels']);
            if (!empty($maybe_empty)) {
                foreach ($post_type_settings['labels'] as $key => $value) {
                    echo $key . ': ' . $value . '<br/>';
                }
            } else {
                _e('No custom labels to display', 'custom-post-type-ui');
            }
            ?>
							</td>
							<td>
								<p><strong><?php 
            _e('Archives file name examples.', 'custom-post-type-ui');
            ?>
</strong><br/>
								archive-<?php 
            echo $post_type;
            ?>
.php<br/>
								archive.php<br/>
								index.php
								</p>

								<p><strong><?php 
            _e('Single Posts file name examples.', 'custom-post-type-ui');
            ?>
</strong><br/>
								single-<?php 
            echo $post_type;
            ?>
.php<br/>
								single.php<br/>
								singular.php(WP 4.3+)<br/>
								index.php
								</p>

								<p><?php 
            printf('<a href="https://developer.wordpress.org/themes/basics/template-hierarchy/">%s</a>', __('Template hierarchy Theme Handbook', 'custom-post-type-ui'));
            ?>
								</p>
							</td>
						</tr>

					<?php 
            $counter++;
        }
        ?>
				<tr>
					<?php 
        foreach ($post_type_table_heads as $head) {
            echo '<th>' . $head . '</th>';
        }
        ?>
				</tr>
			</table>
			<?php 
    } else {
        echo '<p>' . sprintf(__('No post types registered for display. Visit %s to get started.', 'custom-post-type-ui'), sprintf('<a href="%s">%s</a>', admin_url('admin.php?page=cptui_manage_post_types'), __('Add/Edit Post Types', 'custom-post-type-ui'))) . '</p>';
    }
    $taxonomies = get_option('cptui_taxonomies');
    echo '<h2>' . __('Taxonomies', 'custom-post-type-ui') . '</h2>';
    if (!empty($taxonomies)) {
        ?>
				<p><?php 
        printf(__('Total count: %d', 'custom-post-type-ui'), count($taxonomies));
        ?>
</p>

				<?php 
        $taxonomy_table_heads = array(__('Taxonomy', 'custom-post-type-ui'), __('Settings', 'custom-post-type-ui'), __('Post Types', 'custom-post-type-ui'), __('Labels', 'custom-post-type-ui'), __('Template Hierarchy', 'custom-post-type-ui'));
        /**
         * Fires before the listing of registered taxonomy data.
         *
         * @since 1.1.0
         */
        do_action('cptui_before_taxonomy_listing');
        ?>
				<table class="wp-list-table widefat">
					<tr>
						<?php 
        foreach ($taxonomy_table_heads as $head) {
            echo '<th>' . $head . '</th>';
        }
        ?>
					</tr>
					<?php 
        $counter = 1;
        foreach ($taxonomies as $taxonomy => $taxonomy_settings) {
            $rowclass = $counter % 2 == 0 ? '' : 'alternate';
            $strings = array();
            $object_types = array();
            foreach ($taxonomy_settings as $settings_key => $settings_value) {
                if ('labels' == $settings_key) {
                    continue;
                }
                if (is_string($settings_value)) {
                    $strings[$settings_key] = $settings_value;
                } else {
                    if ('object_types' === $settings_key) {
                        $object_types[$settings_key] = $settings_value;
                        # In case they are not associated from the post type settings
                        if (empty($object_types['object_types'])) {
                            $types = get_taxonomy($taxonomy);
                            $object_types['object_types'] = $types->object_type;
                        }
                    }
                }
            }
            ?>
							<tr class="<?php 
            echo $rowclass;
            ?>
">
								<?php 
            $taxonomy_link_url = admin_url('admin.php?page=cptui_manage_taxonomies&action=edit&cptui_taxonomy=' . $taxonomy);
            ?>
								<td><a href="<?php 
            echo $taxonomy_link_url;
            ?>
"><?php 
            echo $taxonomy;
            ?>
</a><br/><hr/>
									<a href="<?php 
            echo $taxonomy_link_url;
            ?>
"><?php 
            printf(__('Edit %s', 'custom-post-type-ui'), $taxonomy);
            ?>
</a>
								</td>
								<td>
									<?php 
            foreach ($strings as $key => $value) {
                printf('<strong>%s:</strong> ', $key);
                if (in_array($value, array('1', '0'))) {
                    echo disp_boolean($value);
                } else {
                    echo $value;
                }
                echo '<br/>';
            }
            ?>
								</td>
								<td>
									<?php 
            if (!empty($object_types['object_types'])) {
                foreach ($object_types['object_types'] as $type) {
                    echo $type . '<br/>';
                }
            }
            ?>
								</td>
								<td>
									<?php 
            $maybe_empty = array_filter($taxonomy_settings['labels']);
            if (!empty($maybe_empty)) {
                foreach ($taxonomy_settings['labels'] as $key => $value) {
                    echo $key . ': ' . $value . '<br/>';
                }
            } else {
                _e('No custom labels to display', 'custom-post-type-ui');
            }
            ?>
								</td>
								<td>
									<p><strong><?php 
            _e('Archives', 'custom-post-type-ui');
            ?>
</strong><br />
										taxonomy-<?php 
            echo $taxonomy;
            ?>
-term_slug.php *<br />
										taxonomy-<?php 
            echo $taxonomy;
            ?>
.php<br />
										taxonomy.php<br />
										archive.php<br />
										index.php
									</p>

									<p>
										<?php 
            _e('*Replace "term_slug" with the slug of the actual taxonomy term.', 'custom-post-type-ui');
            ?>
									</p>
									<p><?php 
            printf('<a href="https://developer.wordpress.org/themes/basics/template-hierarchy/">%s</a>', __('Template hierarchy Theme Handbook', 'custom-post-type-ui'));
            ?>
</p>
								</td>
							</tr>

						<?php 
            $counter++;
        }
        ?>
					<tr>
						<?php 
        foreach ($taxonomy_table_heads as $head) {
            echo '<th>' . $head . '</th>';
        }
        ?>
					</tr>
				</table>
			<?php 
    } else {
        echo '<p>' . sprintf(__('No taxonomies registered for display. Visit %s to get started.', 'custom-post-type-ui'), sprintf('<a href="%s">%s</a>', admin_url('admin.php?page=cptui_manage_taxonomies'), __('Add/Edit Taxonomies', 'custom-post-type-ui'))) . '</p>';
    }
    ?>

		</div>
	<?php 
}
예제 #11
0
 public function test_disp_boolean()
 {
     $this->assertEquals('false', disp_boolean(0));
     $this->assertEquals('false', disp_boolean('0'));
     $this->assertEquals('false', disp_boolean(false));
     $this->assertEquals('false', disp_boolean('false'));
     $this->assertEquals('false', disp_boolean(''));
     $this->assertEquals('false', disp_boolean(null));
     $this->assertEquals('true', disp_boolean(1));
     $this->assertEquals('true', disp_boolean('1'));
     $this->assertEquals('true', disp_boolean(true));
     $this->assertEquals('true', disp_boolean('true'));
     $this->assertEquals('true', disp_boolean('abcd'));
     $this->assertEquals('true', disp_boolean(1235));
 }
예제 #12
0
 /**
  * Return a populated `<select>` input.
  *
  * @since 1.0.0
  *
  * @param array $args Arguments to use with the `<select>` input.
  * @return string $value Complete <select> input with options and selected attribute.
  */
 public function get_select_input($args = array())
 {
     $defaults = $this->get_default_input_parameters(array('selections' => array()));
     $args = wp_parse_args($args, $defaults);
     $value = '';
     if ($args['wrap']) {
         $value = $this->get_tr_start();
         $value .= $this->get_th_start();
         $value .= $this->get_label($args['name'], $args['labeltext']);
         if ($args['required']) {
             $value .= $this->get_required_span();
         }
         if (!empty($args['helptext'])) {
             $value .= $this->get_help($args['helptext']);
         }
         $value .= $this->get_th_end();
         $value .= $this->get_td_start();
     }
     $value .= '<select id="' . $args['name'] . '" name="' . $args['namearray'] . '[' . $args['name'] . ']">';
     if (!empty($args['selections']['options']) && is_array($args['selections']['options'])) {
         foreach ($args['selections']['options'] as $val) {
             $result = '';
             $bool = disp_boolean($val['attr']);
             if (is_numeric($args['selections']['selected'])) {
                 $selected = disp_boolean($args['selections']['selected']);
             } elseif (in_array($args['selections']['selected'], array('true', 'false'))) {
                 $selected = $args['selections']['selected'];
             }
             if (!empty($selected) && $selected === $bool) {
                 $result = ' selected="selected"';
             } else {
                 if (array_key_exists('default', $val) && !empty($val['default'])) {
                     if (empty($selected)) {
                         $result = ' selected="selected"';
                     }
                 }
             }
             if (!is_numeric($args['selections']['selected']) && (!empty($args['selections']['selected']) && $args['selections']['selected'] === $val['attr'])) {
                 $result = ' selected="selected"';
             }
             $value .= '<option value="' . $val['attr'] . '"' . $result . '>' . $val['text'] . '</option>';
         }
     }
     $value .= '</select>';
     if (!empty($args['aftertext'])) {
         $value .= ' ' . $this->get_description($args['aftertext']);
     }
     if ($args['wrap']) {
         $value .= $this->get_td_end();
         $value .= $this->get_tr_end();
     }
     return $value;
 }
예제 #13
0
/**
 * Add to or update our CPTUI option with new data.
 *
 * @since 1.0.0
 *
 * @internal
 *
 * @param array $data Array of taxonomy data to update.
 * @return bool|string False on failure, string on success.
 */
function cptui_update_taxonomy($data = array())
{
    /**
     * Fires before a taxonomy is updated to our saved options.
     *
     * @since 1.0.0
     *
     * @param array $data Array of taxonomy data we are updating.
     */
    do_action('cptui_before_update_taxonomy', $data);
    // They need to provide a name.
    if (empty($data['cpt_custom_tax']['name'])) {
        return cptui_admin_notices('error', '', false, __('Please provide a taxonomy name', 'custom-post-type-ui'));
    }
    if (empty($data['cpt_post_types'])) {
        return cptui_admin_notices('error', '', false, __('Please provide a post type to attach to.', 'custom-post-type-ui'));
    }
    if (!empty($data['tax_original']) && $data['tax_original'] != $data['cpt_custom_tax']['name']) {
        if (!empty($data['update_taxonomy'])) {
            cptui_convert_taxonomy_terms($data['tax_original'], $data['cpt_custom_tax']['name']);
        }
    }
    foreach ($data as $key => $value) {
        if (is_string($value)) {
            $data[$key] = sanitize_text_field($value);
        } else {
            array_map('sanitize_text_field', $data[$key]);
        }
    }
    if (false !== strpos($data['cpt_custom_tax']['name'], '\'') || false !== strpos($data['cpt_custom_tax']['name'], '\\"') || false !== strpos($data['cpt_custom_tax']['rewrite_slug'], '\'') || false !== strpos($data['cpt_custom_tax']['rewrite_slug'], '\\"')) {
        return cptui_admin_notices('error', '', false, __('Please do not use quotes in taxonomy names or rewrite slugs', 'custom-post-type-ui'));
    }
    $taxonomies = cptui_get_taxonomy_data();
    /**
     * Check if we already have a post type of that name.
     *
     * @since 1.3.0
     *
     * @param bool   $value      Assume we have no conflict by default.
     * @param string $value      Post type slug being saved.
     * @param array  $post_types Array of existing post types from CPTUI.
     */
    $slug_exists = apply_filters('cptui_taxonomy_slug_exists', false, $data['cpt_custom_tax']['name'], $taxonomies);
    if ('new' == $data['cpt_tax_status']) {
        if (true === $slug_exists) {
            return cptui_admin_notices('error', '', false, sprintf(__('Please choose a different taxonomy name. %s is already registered.', 'custom-post-type-ui'), $data['cpt_custom_tax']['name']));
        }
    }
    foreach ($data['cpt_tax_labels'] as $key => $label) {
        if (empty($label)) {
            unset($data['cpt_tax_labels'][$key]);
        }
        $label = str_replace('"', '', htmlspecialchars_decode($label));
        $label = htmlspecialchars($label, ENT_QUOTES);
        $label = trim($label);
        $data['cpt_tax_labels'][$key] = stripslashes_deep($label);
    }
    $label = ucwords(str_replace('_', ' ', $data['cpt_custom_tax']['name']));
    if (!empty($data['cpt_custom_tax']['label'])) {
        $label = str_replace('"', '', htmlspecialchars_decode($data['cpt_custom_tax']['label']));
        $label = htmlspecialchars(stripslashes($label), ENT_QUOTES);
    }
    $name = trim($data['cpt_custom_tax']['name']);
    $singular_label = ucwords(str_replace('_', ' ', $data['cpt_custom_tax']['name']));
    if (!empty($data['cpt_custom_tax']['singular_label'])) {
        $singular_label = str_replace('"', '', htmlspecialchars_decode($data['cpt_custom_tax']['singular_label']));
        $singular_label = htmlspecialchars(stripslashes($singular_label));
    }
    $description = stripslashes_deep($data['cpt_custom_tax']['description']);
    $query_var_slug = trim($data['cpt_custom_tax']['query_var_slug']);
    $rewrite_slug = trim($data['cpt_custom_tax']['rewrite_slug']);
    $rest_base = trim($data['cpt_custom_tax']['rest_base']);
    $show_quickpanel_bulk = !empty($data['cpt_custom_tax']['show_in_quick_edit']) ? disp_boolean($data['cpt_custom_tax']['show_in_quick_edit']) : '';
    $taxonomies[$data['cpt_custom_tax']['name']] = array('name' => $name, 'label' => $label, 'singular_label' => $singular_label, 'description' => $description, 'public' => disp_boolean($data['cpt_custom_tax']['public']), 'hierarchical' => disp_boolean($data['cpt_custom_tax']['hierarchical']), 'show_ui' => disp_boolean($data['cpt_custom_tax']['show_ui']), 'query_var' => disp_boolean($data['cpt_custom_tax']['query_var']), 'query_var_slug' => $query_var_slug, 'rewrite' => disp_boolean($data['cpt_custom_tax']['rewrite']), 'rewrite_slug' => $rewrite_slug, 'rewrite_withfront' => $data['cpt_custom_tax']['rewrite_withfront'], 'rewrite_hierarchical' => $data['cpt_custom_tax']['rewrite_hierarchical'], 'show_admin_column' => disp_boolean($data['cpt_custom_tax']['show_admin_column']), 'show_in_rest' => disp_boolean($data['cpt_custom_tax']['show_in_rest']), 'show_in_quick_edit' => $show_quickpanel_bulk, 'rest_base' => $rest_base, 'labels' => $data['cpt_tax_labels']);
    $taxonomies[$data['cpt_custom_tax']['name']]['object_types'] = $data['cpt_post_types'];
    /**
     * Filters whether or not 3rd party options were saved successfully within taxonomy add/update.
     *
     * @since 1.3.0
     *
     * @param bool  $value      Whether or not someone else saved successfully. Default false.
     * @param array $taxonomies Array of our updated taxonomies data.
     * @param array $data       Array of submitted taxonomy to update.
     */
    if (false === ($success = apply_filters('cptui_taxonomy_update_save', false, $taxonomies, $data))) {
        $success = update_option('cptui_taxonomies', $taxonomies);
    }
    /**
     * Fires after a taxonomy is updated to our saved options.
     *
     * @since 1.0.0
     *
     * @param array $data Array of taxonomy data that was updated.
     */
    do_action('cptui_after_update_taxonomy', $data);
    // Used to help flush rewrite rules on init.
    set_transient('cptui_flush_rewrite_rules', 'true', 5 * 60);
    if (isset($success)) {
        if ('new' == $data['cpt_tax_status']) {
            return cptui_admin_notices('add', $data['cpt_custom_tax']['name'], $success);
        }
    }
    return cptui_admin_notices('update', $data['cpt_custom_tax']['name'], true);
}
예제 #14
0
function cptui_listings()
{
    ?>
		<div class="wrap">

			<h1><?php 
    _e('Post Types and Taxonomies registered by Custom Post Type UI.', 'cpt-plugin');
    ?>
</h1>
			<?php 
    $post_types = get_option('cptui_post_types');
    if (!empty($post_types)) {
        echo '<h2>' . __('Post Types', 'cpt-plugin') . '</h2>';
        ?>
			<p><?php 
        printf(__('Total count: %d', 'cpt-plugin'), count($post_types));
        ?>
</p>

			<?php 
        /**
         * Fires before the listing of registered post type data.
         *
         * @since 1.1.0
         */
        do_action('cptui_before_post_type_listing');
        ?>
			<table class="wp-list-table widefat">
				<tr>
					<th><?php 
        _e('Post Type', 'cpt-plugin');
        ?>
</th>
					<th><?php 
        _e('Settings', 'cpt-plugin');
        ?>
</th>
					<th><?php 
        _e('Supports', 'cpt-plugin');
        ?>
</th>
					<th><?php 
        _e('Taxonomies', 'cpt-plugin');
        ?>
</th>
					<th><?php 
        _e('Labels', 'cpt-plugin');
        ?>
</th>
				</tr>
				<?php 
        $counter = 1;
        foreach ($post_types as $post_type => $post_type_settings) {
            $rowclass = $counter % 2 == 0 ? '' : 'alternate';
            $strings = array();
            $supports = array();
            $taxonomies = array();
            foreach ($post_type_settings as $settings_key => $settings_value) {
                if ('labels' == $settings_key) {
                    continue;
                }
                if (is_string($settings_value)) {
                    $strings[$settings_key] = $settings_value;
                } else {
                    if ('supports' === $settings_key) {
                        $supports[$settings_key] = $settings_value;
                    }
                    if ('taxonomies' === $settings_key) {
                        $taxonomies[$settings_key] = $settings_value;
                        # In case they are not associated from the post type settings
                        if (empty($taxonomies['taxonomies'])) {
                            $taxonomies['taxonomies'] = get_object_taxonomies($post_type);
                        }
                    }
                }
                $archive = get_post_type_archive_link($post_type);
            }
            ?>
						<tr class="<?php 
            echo $rowclass;
            ?>
">
							<td><a href="<?php 
            echo admin_url('admin.php?page=cptui_manage_post_types&action=edit&cptui_post_type=' . $post_type);
            ?>
"><?php 
            echo $post_type;
            ?>
</a><br/><hr/>
								<a href="<?php 
            echo admin_url('admin.php?page=cptui_manage_post_types&action=edit&cptui_post_type=' . $post_type);
            ?>
"><?php 
            _e('Edit', 'cpt-plugin');
            ?>
</a>
								<?php 
            if ($archive) {
                ?>
								|
								<a href="<?php 
                echo get_post_type_archive_link($post_type);
                ?>
"><?php 
                _e('View frontend archive', 'cpt-plugin');
                ?>
</a>
								<?php 
            }
            ?>
							</td>
							<td>
								<?php 
            foreach ($strings as $key => $value) {
                printf('<strong>%s:</strong> ', $key);
                if (in_array($value, array('1', '0'))) {
                    echo disp_boolean($value);
                } else {
                    echo $value;
                }
                echo '<br/>';
            }
            ?>
							</td>
							<td>
								<?php 
            foreach ($supports['supports'] as $support) {
                echo $support . '<br/>';
            }
            ?>
							</td>
							<td>
								<?php 
            foreach ($taxonomies['taxonomies'] as $taxonomy) {
                echo $taxonomy . '<br/>';
            }
            ?>
							</td>
							<td>
								<?php 
            $maybe_empty = array_filter($post_type_settings['labels']);
            if (!empty($maybe_empty)) {
                foreach ($post_type_settings['labels'] as $key => $value) {
                    echo $key . ': ' . $value . '<br/>';
                }
            } else {
                _e('No custom labels to display', 'cpt-plugin');
            }
            ?>
							</td>
						</tr>

					<?php 
            $counter++;
        }
        ?>
				<tr>
					<th><?php 
        _e('Post Type', 'cpt-plugin');
        ?>
</th>
					<th><?php 
        _e('Settings', 'cpt-plugin');
        ?>
</th>
					<th><?php 
        _e('Supports', 'cpt-plugin');
        ?>
</th>
					<th><?php 
        _e('Taxonomies', 'cpt-plugin');
        ?>
</th>
					<th><?php 
        _e('Labels', 'cpt-plugin');
        ?>
</th>
				</tr>
			</table>
		<?php 
    }
    $taxonomies = get_option('cptui_taxonomies');
    if (!empty($taxonomies)) {
        echo '<h2>' . __('Taxonomies', 'cpt-plugin') . '</h2>';
        ?>
			<p><?php 
        printf(__('Total count: %d', 'cpt-plugin'), count($taxonomies));
        ?>
</p>

			<?php 
        /**
         * Fires before the listing of registered taxonomy data.
         *
         * @since 1.1.0
         */
        do_action('cptui_before_taxonomy_listing');
        ?>
			<table class="wp-list-table widefat">
				<tr>
					<th><?php 
        _e('Taxonomy', 'cpt-plugin');
        ?>
</th>
					<th><?php 
        _e('Settings', 'cpt-plugin');
        ?>
</th>
					<th><?php 
        _e('Post Types', 'cpt-plugin');
        ?>
</th>
					<th><?php 
        _e('Labels', 'cpt-plugin');
        ?>
</th>
				</tr>
				<?php 
        $counter = 1;
        foreach ($taxonomies as $taxonomy => $taxonomy_settings) {
            $rowclass = $counter % 2 == 0 ? '' : 'alternate';
            $strings = array();
            $object_types = array();
            foreach ($taxonomy_settings as $settings_key => $settings_value) {
                if ('labels' == $settings_key) {
                    continue;
                }
                if (is_string($settings_value)) {
                    $strings[$settings_key] = $settings_value;
                } else {
                    if ('object_types' === $settings_key) {
                        $object_types[$settings_key] = $settings_value;
                        # In case they are not associated from the post type settings
                        if (empty($object_types['taxonomies'])) {
                            $types = get_taxonomy($taxonomy);
                            $object_types['types'] = $types->object_type;
                        }
                    }
                }
            }
            ?>
						<tr class="<?php 
            echo $rowclass;
            ?>
">
							<td><a href="<?php 
            echo admin_url('admin.php?page=cptui_manage_taxonomies&action=edit&cptui_taxonomy=' . $taxonomy);
            ?>
"><?php 
            echo $taxonomy;
            ?>
</a><br/><hr/>
								<a href="<?php 
            echo admin_url('admin.php?page=cptui_manage_taxonomies&action=edit&cptui_taxonomy=' . $taxonomy);
            ?>
"><?php 
            _e('Edit', 'cpt-plugin');
            ?>
</a>
							</td>
							<td>
								<?php 
            foreach ($strings as $key => $value) {
                printf('<strong>%s:</strong> ', $key);
                if (in_array($value, array('1', '0'))) {
                    echo disp_boolean($value);
                } else {
                    echo $value;
                }
                echo '<br/>';
            }
            ?>
							</td>
							<td>
								<?php 
            if (!empty($object_types['types'])) {
                foreach ($object_types['types'] as $type) {
                    echo $type . '<br/>';
                }
            }
            ?>
							</td>
							<td>
								<?php 
            $maybe_empty = array_filter($taxonomy_settings['labels']);
            if (!empty($maybe_empty)) {
                foreach ($taxonomy_settings['labels'] as $key => $value) {
                    echo $key . ': ' . $value . '<br/>';
                }
            } else {
                _e('No custom labels to display', 'cpt-plugin');
            }
            ?>
							</td>
						</tr>

					<?php 
            $counter++;
        }
        ?>
				<tr>
					<th><?php 
        _e('Taxonomy', 'cpt-plugin');
        ?>
</th>
					<th><?php 
        _e('Settings', 'cpt-plugin');
        ?>
</th>
					<th><?php 
        _e('Post Types', 'cpt-plugin');
        ?>
</th>
					<th><?php 
        _e('Labels', 'cpt-plugin');
        ?>
</th>
				</tr>
			</table>
		<?php 
    }
    ?>

		</div>
	<?php 
}
/**
 * Create output for single post type to be ready for copy/paste from Get Code.
 *
 * @since 1.0.0
 *
 * @param array $post_type Post type data to output.
 * @return string Copy/paste ready "php" code.
 */
function cptui_get_single_post_type_registery($post_type = array())
{
    /** This filter is documented in custom-post-type-ui/custom-post-type-ui.php */
    $post_type['map_meta_cap'] = apply_filters('cptui_map_meta_cap', 'true', $post_type['name'], $post_type);
    /** This filter is documented in custom-post-type-ui/custom-post-type-ui.php */
    $user_supports_params = apply_filters('cptui_user_supports_params', array(), $post_type['name'], $post_type);
    if (is_array($user_supports_params)) {
        $post_type['supports'] = array_merge($post_type['supports'], $user_supports_params);
    }
    $yarpp = false;
    // Prevent notices.
    if (!empty($post_type['custom_supports'])) {
        $custom = explode(',', $post_type['custom_supports']);
        foreach ($custom as $part) {
            // We'll handle YARPP separately.
            if (in_array($part, array('YARPP', 'yarpp'))) {
                $yarpp = true;
                continue;
            }
            $post_type['supports'][] = $part;
        }
    }
    $rewrite_withfront = '';
    $rewrite = get_disp_boolean($post_type['rewrite']);
    if (false !== $rewrite) {
        $rewrite = disp_boolean($post_type['rewrite']);
        $rewrite_slug = ' "slug" => "' . $post_type['name'] . '",';
        if (!empty($post_type['rewrite_slug'])) {
            $rewrite_slug = ' "slug" => "' . $post_type['rewrite_slug'] . '",';
        }
        $withfront = disp_boolean($post_type['rewrite_withfront']);
        if (!empty($withfront)) {
            $rewrite_withfront = ' "with_front" => ' . $withfront . ' ';
        }
        if (!empty($post_type['rewrite_slug']) || !empty($post_type['rewrite_withfront'])) {
            $rewrite_start = 'array(';
            $rewrite_end = ')';
            $rewrite = $rewrite_start . $rewrite_slug . $rewrite_withfront . $rewrite_end;
        }
    } else {
        $rewrite = disp_boolean($post_type['rewrite']);
    }
    $supports = '';
    // Do a little bit of php work to get these into strings.
    if (!empty($post_type['supports']) && is_array($post_type['supports'])) {
        $supports = 'array( "' . implode('", "', $post_type['supports']) . '" )';
    }
    if (in_array('none', $post_type['supports'])) {
        $supports = 'false';
    }
    $taxonomies = '';
    if (!empty($post_type['taxonomies']) && is_array($post_type['taxonomies'])) {
        $taxonomies = 'array( "' . implode('", "', $post_type['taxonomies']) . '" )';
    }
    if (in_array($post_type['query_var'], array('true', 'false', '0', '1'))) {
        $post_type['query_var'] = disp_boolean($post_type['query_var']);
    }
    if (!empty($post_type['query_var_slug'])) {
        $post_type['query_var'] = '"' . $post_type['query_var_slug'] . '"';
    }
    if (empty($post_type['show_in_rest'])) {
        $post_type['show_in_rest'] = 'false';
    }
    $post_type['description'] = addslashes($post_type['description']);
    $my_theme = wp_get_theme();
    $textdomain = $my_theme->get('TextDomain');
    ?>
	$labels = array(
		"name" => __( '<?php 
    echo $post_type['label'];
    ?>
', '<?php 
    echo $textdomain;
    ?>
' ),
		"singular_name" => __( '<?php 
    echo $post_type['singular_label'];
    ?>
', '<?php 
    echo $textdomain;
    ?>
' ),
		<?php 
    foreach ($post_type['labels'] as $key => $label) {
        if (!empty($label)) {
            echo '"' . $key . '" => __( \'' . $label . '\', \'' . $textdomain . '\' ),' . "\n\t\t";
        }
    }
    ?>
);

	$args = array(
		"label" => __( '<?php 
    echo $post_type['label'];
    ?>
', '<?php 
    echo $textdomain;
    ?>
' ),
		"labels" => $labels,
		"description" => "<?php 
    echo $post_type['description'];
    ?>
",
		"public" => <?php 
    echo disp_boolean($post_type['public']);
    ?>
,
		"show_ui" => <?php 
    echo disp_boolean($post_type['show_ui']);
    ?>
,
		"show_in_rest" => <?php 
    echo disp_boolean($post_type['show_in_rest']);
    ?>
,
		"rest_base" => "<?php 
    echo $post_type['rest_base'];
    ?>
",
		"has_archive" => <?php 
    echo disp_boolean($post_type['has_archive']);
    ?>
,
		"show_in_menu" => <?php 
    echo disp_boolean($post_type['show_in_menu']);
    ?>
,
		"exclude_from_search" => <?php 
    echo disp_boolean($post_type['exclude_from_search']);
    ?>
,
		"capability_type" => "<?php 
    echo $post_type['capability_type'];
    ?>
",
		"map_meta_cap" => <?php 
    echo disp_boolean($post_type['map_meta_cap']);
    ?>
,
		"hierarchical" => <?php 
    echo disp_boolean($post_type['hierarchical']);
    ?>
,
		"rewrite" => <?php 
    echo $rewrite;
    ?>
,
		"query_var" => <?php 
    echo $post_type['query_var'];
    ?>
,
		<?php 
    if (!empty($post_type['menu_position'])) {
        ?>
"menu_position" => <?php 
        echo $post_type['menu_position'];
        ?>
,<?php 
    }
    if (!empty($post_type['menu_icon'])) {
        ?>
"menu_icon" => "<?php 
        echo $post_type['menu_icon'];
        ?>
",<?php 
    }
    ?>
		<?php 
    if (!empty($supports)) {
        echo "\n\t\t";
        ?>
"supports" => <?php 
        echo $supports;
        ?>
,<?php 
    }
    ?>
		<?php 
    if (!empty($taxonomies)) {
        echo "\n\t\t";
        ?>
"taxonomies" => <?php 
        echo $taxonomies;
        ?>
,<?php 
    }
    ?>
		<?php 
    if (true === $yarpp) {
        echo "\n\t\t";
        ?>
"yarpp_support" => <?php 
        echo disp_boolean($yarpp);
    }
    echo "\n";
    ?>
	);
	register_post_type( "<?php 
    echo $post_type['name'];
    ?>
", $args );
<?php 
}
예제 #16
0
/**
 * Create output for single post type to be ready for copy/paste from Get Code.
 *
 * @since 1.0.0
 *
 * @param array $post_type Post type data to output.
 *
 * @return string Copy/paste ready "php" code.
 */
function cptui_get_single_post_type_registery($post_type = array())
{
    /** This filter is documented in custom-post-type-ui/custom-post-type-ui.php */
    $post_type['map_meta_cap'] = apply_filters('cptui_map_meta_cap', 'true', $post_type['name'], $post_type);
    $user_supports_params = apply_filters('cptui_user_supports_params', array(), $post_type['name'], $post_type);
    if (is_array($user_supports_params)) {
        $post_type['supports'] = array_merge($post_type['supports'], $user_supports_params);
    }
    $rewrite = get_disp_boolean($post_type['rewrite']);
    if (false !== $rewrite) {
        $rewrite = disp_boolean($post_type['rewrite']);
        $rewrite_slug = ' \'slug\' => \'' . $post_type['name'] . '\',';
        if (!empty($post_type['rewrite_slug'])) {
            $rewrite_slug = ' \'slug\' => \'' . $post_type['rewrite_slug'] . '\',';
        }
        $withfront = disp_boolean($post_type['rewrite_withfront']);
        if (!empty($withfront)) {
            $rewrite_withfront = ' \'with_front\' => ' . $withfront . ' ';
        }
        if (!empty($post_type['rewrite_slug']) || !empty($post_type['rewrite_withfront'])) {
            $rewrite_start = 'array(';
            $rewrite_end = ')';
            $rewrite = $rewrite_start . $rewrite_slug . $rewrite_withfront . $rewrite_end;
        }
    } else {
        $rewrite = disp_boolean($post_type['rewrite']);
    }
    $supports = '';
    # Do a little bit of php work to get these into strings.
    if (!empty($post_type['supports']) && is_array($post_type['supports'])) {
        $supports = 'array( \'' . implode('\', \'', $post_type['supports']) . '\' )';
    }
    $taxonomies = '';
    if (!empty($post_type['taxonomies']) && is_array($post_type['taxonomies'])) {
        $taxonomies = 'array( \'' . implode('\', \'', $post_type['taxonomies']) . '\' )';
    }
    $post_type['description'] = addslashes($post_type['description']);
    ?>
	$labels = array(
		'name' => '<?php 
    echo $post_type['label'];
    ?>
',
		'singular_name' => '<?php 
    echo $post_type['singular_label'];
    ?>
',
		<?php 
    foreach ($post_type['labels'] as $key => $label) {
        if (!empty($label)) {
            echo "'{$key}' => '{$label}',\n\t\t";
        }
    }
    ?>
);

	$args = array(
		'labels' => $labels,
		'description' => '<?php 
    echo $post_type['description'];
    ?>
',
		'public' => <?php 
    echo $post_type['public'];
    ?>
,
		'show_ui' => <?php 
    echo $post_type['show_ui'];
    ?>
,
		'has_archive' => <?php 
    echo $post_type['has_archive'];
    ?>
,
		'show_in_menu' => <?php 
    echo $post_type['show_in_menu'];
    ?>
,
		'exclude_from_search' => <?php 
    echo $post_type['exclude_from_search'];
    ?>
,
		'capability_type' => '<?php 
    echo $post_type['capability_type'];
    ?>
',
		'map_meta_cap' => <?php 
    echo $post_type['map_meta_cap'];
    ?>
,
		'hierarchical' => <?php 
    echo $post_type['hierarchical'];
    ?>
,
		'rewrite' => <?php 
    echo $rewrite;
    ?>
,
		'query_var' => <?php 
    echo $post_type['query_var'];
    ?>
,
		<?php 
    if (!empty($post_type['menu_position'])) {
        ?>
'menu_position' => <?php 
        echo $post_type['menu_position'];
        ?>
,<?php 
    }
    ?>
		<?php 
    if (!empty($post_type['menu_icon'])) {
        ?>
'menu_icon' => '<?php 
        echo $post_type['menu_icon'];
        ?>
',<?php 
    }
    ?>
		<?php 
    if (!empty($supports)) {
        ?>
'supports' => <?php 
        echo $supports;
        ?>
,<?php 
    }
    ?>
		<?php 
    if (!empty($taxonomies)) {
        ?>
'taxonomies' => <?php 
        echo $taxonomies;
    }
    ?>
	);
	register_post_type( '<?php 
    echo $post_type['name'];
    ?>
', $args );
<?php 
}