/** * 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 }
/** * Generate the debug information content. * * @since 1.2.0 * * @return string */ private function system_status() { if (!current_user_can('manage_options')) { return ''; } global $wpdb; $theme_data = wp_get_theme(); $theme = $theme_data->Name . ' ' . $theme_data->Version; ob_start(); ?> ### Begin Custom Post Type UI Debug Info ### Multisite: <?php echo is_multisite() ? 'Yes' . "\n" : 'No' . "\n"; ?> SITE_URL: <?php echo site_url() . "\n"; ?> HOME_URL: <?php echo home_url() . "\n"; ?> WordPress Version: <?php echo get_bloginfo('version') . "\n"; ?> Permalink Structure: <?php echo get_option('permalink_structure') . "\n"; ?> Active Theme: <?php echo $theme . "\n"; ?> Registered Post Types: <?php echo implode(', ', get_post_types('', 'names')) . "\n"; ?> PHP Version: <?php echo PHP_VERSION . "\n"; ?> MySQL Version: <?php echo $wpdb->db_version() . "\n"; ?> Web Server Info: <?php echo $_SERVER['SERVER_SOFTWARE'] . "\n"; ?> Show On Front: <?php echo get_option('show_on_front') . "\n"; ?> Page On Front: <?php $id = get_option('page_on_front'); echo get_the_title($id) . ' (#' . $id . ')' . "\n"; ?> Page For Posts: <?php $id = get_option('page_for_posts'); echo get_the_title($id) . ' (#' . $id . ')' . "\n"; ?> WordPress Memory Limit: <?php echo $this->num_convt(WP_MEMORY_LIMIT) / 1024 . 'MB'; echo "\n"; ?> <?php $plugins = get_plugins(); $pg_count = count($plugins); echo 'TOTAL PLUGINS: ' . $pg_count . "\n\n"; // MU plugins. $mu_plugins = get_mu_plugins(); if ($mu_plugins) { echo "\t\t" . 'MU PLUGINS: (' . count($mu_plugins) . ')' . "\n\n"; foreach ($mu_plugins as $mu_path => $mu_plugin) { echo "\t\t" . $mu_plugin['Name'] . ': ' . $mu_plugin['Version'] . "\n"; } } // Standard plugins - active. echo "\n"; $active = get_option('active_plugins', array()); $ac_count = count($active); $ic_count = $pg_count - $ac_count; echo "\t\t" . 'ACTIVE PLUGINS: (' . $ac_count . ')' . "\n\n"; foreach ($plugins as $plugin_path => $plugin) { // If the plugin isn't active, don't show it. if (!in_array($plugin_path, $active)) { continue; } echo "\t\t" . $plugin['Name'] . ': ' . $plugin['Version'] . "\n"; } // Standard plugins - inactive. echo "\n"; echo "\t\t", 'INACTIVE PLUGINS: (' . $ic_count . ')' . "\n\n"; foreach ($plugins as $plugin_path => $plugin) { // If the plugin isn't active, show it here. if (in_array($plugin_path, $active)) { continue; } echo "\t\t" . $plugin['Name'] . ': ' . $plugin['Version'] . "\n"; } // If multisite, grab network as well. if (is_multisite()) { $net_plugins = wp_get_active_network_plugins(); $net_active = get_site_option('active_sitewide_plugins', array()); echo "\n"; echo 'NETWORK ACTIVE PLUGINS: (' . count($net_plugins) . ')' . "\n\n"; foreach ($net_plugins as $plugin_path) { $plugin_base = plugin_basename($plugin_path); // If the plugin isn't active, don't show it. if (!array_key_exists($plugin_base, $net_active)) { continue; } $plugin = get_plugin_data($plugin_path); echo $plugin['Name'] . ' :' . $plugin['Version'] . "\n"; } } echo "\n"; $cptui_post_types = cptui_get_post_type_data(); echo "\t\t" . 'Post Types: ' . "\n"; echo "\t\t" . esc_html(json_encode($cptui_post_types)) . "\n"; echo "\n\n"; $cptui_taxonomies = cptui_get_taxonomy_data(); echo "\t\t" . 'Taxonomies: ' . "\n"; echo "\t\t" . esc_html(json_encode($cptui_taxonomies)) . "\n"; echo "\n"; if (has_action('cptui_custom_debug_info')) { echo "\t\t" . 'EXTRA DEBUG INFO'; } /** * Fires at the end of the debug info output. * * @since 1.3.0 */ do_action('cptui_custom_debug_info'); echo "\n"; ?> ### End Debug Info ### <?php return ob_get_clean(); }
/** * 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); }
/** * Content for the Get Code tab. * * @since 1.2.0 * * @internal */ function cptui_render_getcode_section() { ?> <h1><?php _e('Get Post Type and Taxonomy Code', 'custom-post-type-ui'); ?> </h1> <h2><?php _e('All CPT UI Post Types', 'custom-post-type-ui'); ?> </h2> <?php $cptui_post_types = cptui_get_post_type_data(); ?> <label for="cptui_post_type_get_code"><?php _e('Copy/paste the code below into your functions.php file.', 'custom-post-type-ui'); ?> </label> <textarea name="cptui_post_type_get_code" id="cptui_post_type_get_code" class="cptui_post_type_get_code" onclick="this.focus();this.select()" onfocus="this.focus();this.select();" readonly="readonly" aria-readonly="true"><?php cptui_get_post_type_code($cptui_post_types); ?> </textarea> <?php if (!empty($cptui_post_types)) { foreach ($cptui_post_types as $post_type) { ?> <h2><?php $type = !empty($post_type['label']) ? $post_type['label'] : $post_type['name']; printf(__('%s Post Type', 'custom-post-type-ui'), $type); ?> </h2> <label for="cptui_post_type_get_code_<?php echo $post_type['name']; ?> "><?php _e('Copy/paste the code below into your functions.php file.', 'custom-post-type-ui'); ?> </label> <textarea name="cptui_post_type_get_code_<?php echo $post_type['name']; ?> " id="cptui_post_type_get_code_<?php echo $post_type['name']; ?> " class="cptui_post_type_get_code" onclick="this.focus();this.select()" onfocus="this.focus();this.select();" readonly="readonly" aria-readonly="true"><?php cptui_get_post_type_code(array($post_type), true); ?> </textarea> <?php } } ?> <h2><?php _e('All CPT UI Taxonomies', 'custom-post-type-ui'); ?> </h2> <?php $cptui_taxonomies = cptui_get_taxonomy_data(); ?> <label for="cptui_tax_get_code"><?php _e('Copy/paste the code below into your functions.php file.', 'custom-post-type-ui'); ?> </label> <textarea name="cptui_tax_get_code" id="cptui_tax_get_code" class="cptui_tax_get_code" onclick="this.focus();this.select()" onfocus="this.focus();this.select();" readonly="readonly" aria-readonly="true"><?php cptui_get_taxonomy_code($cptui_taxonomies); ?> </textarea> <?php if (!empty($cptui_taxonomies)) { foreach ($cptui_taxonomies as $taxonomy) { ?> <h2><?php $tax = !empty($taxonomy['label']) ? $taxonomy['label'] : $taxonomy['name']; printf(__('%s Taxonomy', 'custom-post-type-ui'), $tax); ?> </h2> <label for="cptui_tax_get_code_<?php echo $taxonomy['name']; ?> "><?php _e('Copy/paste the code below into your functions.php file.', 'custom-post-type-ui'); ?> </label> <textarea name="cptui_tax_get_code_<?php echo $taxonomy['name']; ?> " id="cptui_tax_get_code_<?php echo $taxonomy['name']; ?> " class="cptui_tax_get_code" onclick="this.focus();this.select()" onfocus="this.focus();this.select();" readonly="readonly" aria-readonly="true"><?php cptui_get_taxonomy_code(array($taxonomy), true); ?> </textarea> <?php } } ?> <?php }