';
- # Create our tabs.
+ /**
+ * Fires right inside the wrap div for the import/export pages.
+ *
+ * @since 1.3.0
+ */
+ do_action( 'cptui_inside_importexport_wrap' );
+
+ // Create our tabs.
cptui_settings_tab_menu( $page = 'importexport' );
+ /**
+ * Fires inside the markup for the import/export section.
+ *
+ * Allows for more modular control and adding more sections more easily.
+ *
+ * @since 1.2.0
+ *
+ * @param string $tab Current tab being displayed.
+ */
do_action( 'cptui_import_export_sections', $tab );
echo '
';
@@ -53,8 +148,6 @@ function cptui_importexport() {
*
* @param array $cptui_taxonomies Array of taxonomies to render.
* @param bool $single Whether or not we are rendering a single taxonomy.
- *
- * @return string Taxonomy registration text for use elsewhere.
*/
function cptui_get_taxonomy_code( $cptui_taxonomies = array(), $single = false ) {
if ( !empty( $cptui_taxonomies ) ) {
@@ -84,8 +177,6 @@ function () {
* @since 1.0.0
*
* @param array $taxonomy Taxonomy data to output.
- *
- * @return string Copy/paste ready "php" code.
*/
function cptui_get_single_taxonomy_registery( $taxonomy = array() ) {
@@ -94,7 +185,6 @@ function cptui_get_single_taxonomy_registery( $taxonomy = array() ) {
$post_types = 'array( "' . implode( '", "', $taxonomy['object_types'] ) . '" )';
}
- $rewrite = get_disp_boolean( $taxonomy['rewrite'] );
if ( false !== get_disp_boolean( $taxonomy['rewrite'] ) ) {
$rewrite = disp_boolean( $taxonomy['rewrite'] );
@@ -124,28 +214,35 @@ function cptui_get_single_taxonomy_registery( $taxonomy = array() ) {
} else {
$rewrite = disp_boolean( $taxonomy['rewrite'] );
}
+ $public = ( isset( $taxonomy['public'] ) ) ? disp_boolean( $taxonomy['public'] ) : 'true';
+ $my_theme = wp_get_theme();
+ $textdomain = $my_theme->get( 'TextDomain' );
?>
-
$labels = array(
- "name" => "",
- "label" => "",
+ "name" => __( '', '' ),
+ "singular_name" => __( '', '' ),
$label ) {
if ( !empty( $label ) ) {
- echo '"' . $key . '" => "' . $label . '",' . "\n\t\t";
+ echo '"' . $key . '" => __( \'' . $label . '\', \'' . $textdomain . '\' ),' . "\n\t\t";
}
} ?>);
$args = array(
+ "label" => __( '', '' ),
"labels" => $labels,
+ "public" => ,
"hierarchical" => ,
"label" => "",
"show_ui" => ,
"query_var" => ,
"rewrite" => ,
"show_admin_column" => ,
+ "show_in_rest" => ,
+ "rest_base" => "",
+ "show_in_quick_edit" => ,
);
-
+
register_taxonomy( "", , $args );
add_action( 'init', '' );
function () {
-
@@ -191,7 +287,6 @@ function () {
* @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() ) {
@@ -205,11 +300,11 @@ function cptui_get_single_post_type_registery( $post_type = array() ) {
$post_type['supports'] = array_merge( $post_type['supports'], $user_supports_params );
}
- $yarpp = false; # Prevent notices.
+ $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.
+ // We'll handle YARPP separately.
if ( in_array( $part, array( 'YARPP', 'yarpp' ) ) ) {
$yarpp = true;
continue;
@@ -245,7 +340,7 @@ function cptui_get_single_post_type_registery( $post_type = array() ) {
}
$supports = '';
- # Do a little bit of php work to get these into strings.
+ // 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'] ) . '" )';
}
@@ -271,22 +366,27 @@ function cptui_get_single_post_type_registery( $post_type = array() ) {
}
$post_type['description'] = addslashes( $post_type['description'] );
+
+ $my_theme = wp_get_theme();
+ $textdomain = $my_theme->get( 'TextDomain' );
?>
$labels = array(
- "name" => "",
- "singular_name" => "",
+ "name" => __( '', '' ),
+ "singular_name" => __( '', '' ),
$label ) {
if ( !empty( $label ) ) {
- echo '"' . $key . '" => "' . $label . '",' . "\n\t\t";
+ echo '"' . $key . '" => __( \'' . $label . '\', \'' . $textdomain . '\' ),' . "\n\t\t";
}
} ?>);
$args = array(
+ "label" => __( '', '' ),
"labels" => $labels,
"description" => "",
"public" => ,
"show_ui" => ,
"show_in_rest" => ,
+ "rest_base" => "",
"has_archive" => ,
"show_in_menu" => ,
"exclude_from_search" => ,
@@ -309,8 +409,9 @@ function cptui_get_single_post_type_registery( $post_type = array() ) {
*
* @since 1.0.0
*
- * @param array $postdata $_POST data as json.
+ * @internal
*
+ * @param array $postdata $_POST data as json.
* @return mixed false on nothing to do, otherwise void.
*/
function cptui_import_types_taxes_settings( $postdata = array() ) {
@@ -354,50 +455,106 @@ function cptui_import_types_taxes_settings( $postdata = array() ) {
$cpt_data = stripslashes_deep( trim( $postdata['cptui_post_import'] ) );
$settings = json_decode( $cpt_data, true );
- # Add support to delete settings outright, without accessing database.
- # Doing double check to protect.
+ // Add support to delete settings outright, without accessing database.
+ // Doing double check to protect.
if ( is_null( $settings ) && '{""}' === $cpt_data ) {
- delete_option( 'cptui_post_types' );
- # We're technically successful in a sense. Importing nothing.
+
+ /**
+ * Filters whether or not 3rd party options were deleted successfully within post type import.
+ *
+ * @since 1.3.0
+ *
+ * @param bool $value Whether or not someone else deleted successfully. Default false.
+ * @param array $postdata Post type data.
+ */
+ if ( false === ( $success = apply_filters( 'cptui_post_type_import_delete_save', false, $postdata ) ) ) {
+ delete_option( 'cptui_post_types' );
+ }
+ // We're technically successful in a sense. Importing nothing.
$success = true;
}
if ( $settings ) {
- if ( false !== get_option( 'cptui_post_types' ) ) {
- delete_option( 'cptui_post_types' );
+ if ( false !== cptui_get_post_type_data() ) {
+ /** This filter is documented in /inc/import-export.php */
+ if ( false === ( $success = apply_filters( 'cptui_post_type_import_delete_save', false, $postdata ) ) ) {
+ delete_option( 'cptui_post_types' );
+ }
}
- $success = update_option( 'cptui_post_types', $settings );
+ /**
+ * Filters whether or not 3rd party options were updated successfully within the post type import.
+ *
+ * @since 1.3.0
+ *
+ * @param bool $value Whether or not someone else updated successfully. Default false.
+ * @param array $postdata Post type data.
+ */
+ if ( false === ( $success = apply_filters( 'cptui_post_type_import_update_save', false, $postdata ) ) ) {
+ $success = update_option( 'cptui_post_types', $settings );
+ }
}
+ // Used to help flush rewrite rules on init.
+ set_transient( 'cptui_flush_rewrite_rules', 'true', 5 * 60 );
return cptui_admin_notices( 'import', __( 'Post types', 'custom-post-type-ui' ), $success );
} elseif ( !empty( $postdata['cptui_tax_import'] ) ) {
$tax_data = stripslashes_deep( trim( $postdata['cptui_tax_import'] ) );
$settings = json_decode( $tax_data, true );
- # Add support to delete settings outright, without accessing database.
- # Doing double check to protect.
+ // Add support to delete settings outright, without accessing database.
+ // Doing double check to protect.
if ( is_null( $settings ) && '{""}' === $tax_data ) {
- delete_option( 'cptui_taxonomies' );
- # We're technically successful in a sense. Importing nothing.
+
+ /**
+ * Filters whether or not 3rd party options were deleted successfully within taxonomy import.
+ *
+ * @since 1.3.0
+ *
+ * @param bool $value Whether or not someone else deleted successfully. Default false.
+ * @param array $postdata Taxonomy data
+ */
+ if ( false === ( $success = apply_filters( 'cptui_taxonomy_import_delete_save', false, $postdata ) ) ) {
+ delete_option( 'cptui_taxonomies' );
+ }
+ // We're technically successful in a sense. Importing nothing.
$success = true;
}
if ( $settings ) {
- if ( false !== get_option( 'cptui_taxonomies' ) ) {
- delete_option( 'cptui_taxonomies' );
+ if ( false !== cptui_get_taxonomy_data() ) {
+ /** This filter is documented in /inc/import-export.php */
+ if ( false === ( $success = apply_filters( 'cptui_taxonomy_import_delete_save', false, $postdata ) ) ) {
+ delete_option( 'cptui_taxonomies' );
+ }
+ }
+ /**
+ * Filters whether or not 3rd party options were updated successfully within the taxonomy import.
+ *
+ * @since 1.3.0
+ *
+ * @param bool $value Whether or not someone else updated successfully. Default false.
+ * @param array $postdata Taxonomy data.
+ */
+ if ( false === ( $success = apply_filters( 'cptui_taxonomy_import_update_save', false, $postdata ) ) ) {
+ $success = update_option( 'cptui_taxonomies', $settings );
}
-
- $success = update_option( 'cptui_taxonomies', $settings );
}
+ // Used to help flush rewrite rules on init.
+ set_transient( 'cptui_flush_rewrite_rules', 'true', 5 * 60 );
return cptui_admin_notices( 'import', __( 'Taxonomies', 'custom-post-type-ui' ), $success );
}
- flush_rewrite_rules();
-
return $success;
}
+/**
+ * Content for the Post Types/Taxonomies Import/Export tab.
+ *
+ * @since 1.2.0
+ *
+ * @internal
+ */
function cptui_render_posttypes_taxonomies_section() {
?>
@@ -412,8 +569,7 @@ function cptui_render_posttypes_taxonomies_section() {
-
+
|
-
+
-
+
@@ -494,15 +647,22 @@ function cptui_render_posttypes_taxonomies_section() {
-
+
-
+
-
+
-
+
-
+
-
+
';
- echo '';
+ /**
+ * Filters the text value to use on the button when sending debug information.
+ *
+ * @since 1.2.0
+ *
+ * @param string $value Text to use for the button.
+ */
+ echo '';
echo '';
+
+ /**
+ * Fires after the display of the site information.
+ *
+ * @since 1.3.0
+ */
+ do_action( 'cptui_after_site_info' );
}
+/**
+ * Renders various tab sections for the Import/Export page, based on current tab.
+ *
+ * @since 1.2.0
+ *
+ * @internal
+ *
+ * @param string $tab Current tab to display.
+ */
function cptui_render_importexportsections( $tab ) {
if ( isset( $tab ) ) {
if ( 'post_types' == $tab || 'taxonomies' == $tab ) {
diff --git a/www/wp-content/plugins/custom-post-type-ui/inc/listings.php b/www/wp-content/plugins/custom-post-type-ui/inc/listings.php
index 31a4e6f..7ce4aef 100644
--- a/www/wp-content/plugins/custom-post-type-ui/inc/listings.php
+++ b/www/wp-content/plugins/custom-post-type-ui/inc/listings.php
@@ -1,19 +1,44 @@
+
-
+
' . __( 'Post Types', 'custom-post-type-ui' ) . '';
- if ( !empty( $post_types ) ) {
+ $post_types = cptui_get_post_type_data();
+ echo ' ' . esc_html__( 'Post Types', 'custom-post-type-ui' ) . '';
+ if ( ! empty( $post_types ) ) {
?>
-
+
- ' . $head . '';
+ ' . esc_html( $head ) . '';
} ?>
$post_type_settings ) {
- $rowclass = ( $counter % 2 == 0 ) ? '' : 'alternate';
+ $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 ) {
+ foreach ( $post_type_settings as $settings_key => $settings_value ) {
+ if ( 'labels' === $settings_key ) {
continue;
}
@@ -64,7 +90,7 @@ function cptui_listings() {
if ( 'taxonomies' === $settings_key ) {
$taxonomies[ $settings_key ] = $settings_value;
- # In case they are not associated from the post type settings
+ // In case they are not associated from the post type settings.
if ( empty( $taxonomies['taxonomies'] ) ) {
$taxonomies['taxonomies'] = get_object_taxonomies( $post_type );
}
@@ -73,95 +99,110 @@ function cptui_listings() {
$archive = get_post_type_archive_link( $post_type );
}
?>
-
+
-
+ |
|
-
+
|
- $value ) {
- printf( '%s: ', $key );
+ $value ) {
+ printf( '%s: ', esc_html( $key ) );
if ( in_array( $value, array( '1', '0' ) ) ) {
- echo disp_boolean( $value );
+ echo esc_html( disp_boolean( $value ) );
} else {
- echo $value;
+ echo esc_html( $value );
}
echo ' ';
} ?>
|
- ';
+ ';
} ?>
|
';
+ echo esc_html( $taxonomy ) . ' ';
} ?>
|
$value ) {
- echo $key . ': ' . $value . ' ';
+ printf(
+ '%s: %s ',
+ esc_html( $key ),
+ esc_html( $value )
+ );
}
} else {
- _e( 'No custom labels to display', 'custom-post-type-ui' );
+ esc_html_e( 'No custom labels to display', 'custom-post-type-ui' );
}
?>
|
-
- archive-.php
+
+ archive-.php
archive.php
index.php
-
- single-.php
+
+ single-.php
single.php
singular.php(WP 4.3+)
index.php
- %s',
- __( 'Template hierarchy Theme Handbook', 'custom-post-type-ui' )
+ esc_html__( 'Template hierarchy Theme Handbook', 'custom-post-type-ui' )
); ?>
|
- ' . $head . '';
+ ' . esc_html( $head ) . '';
} ?>
' . sprintf( __( 'No post types registered for display. Visit %s to get started.', 'custom-post-type-ui' ),
- sprintf( ' %s',
- admin_url( 'admin.php?page=cptui_manage_post_types' ),
- __( 'Add/Edit Post Types', 'custom-post-type-ui' )
- )
- ) . '';
+
+ /**
+ * Fires when there are no registered post types to list.
+ *
+ * @since 1.3.0
+ */
+ do_action( 'cptui_no_post_types_listing' );
}
- $taxonomies = get_option( 'cptui_taxonomies' );
- echo ' ' . __( 'Taxonomies', 'custom-post-type-ui' ) . '';
- if ( !empty( $taxonomies ) ) {
+ $taxonomies = cptui_get_taxonomy_data( 'cptui_taxonomies' );
+ echo ' ' . esc_html__( 'Taxonomies', 'custom-post-type-ui' ) . '';
+ if ( ! empty( $taxonomies ) ) {
?>
-
+
- ' . $head . '';
+ ' . esc_html( $head ) . '';
} ?>
$taxonomy_settings ) {
- $rowclass = ( $counter % 2 == 0 ) ? '' : 'alternate';
+ $rowclass = ( 0 === $counter % 2 ) ? '' : 'alternate';
$strings = array();
$object_types = array();
- foreach( $taxonomy_settings as $settings_key => $settings_value ) {
- if ( 'labels' == $settings_key ) {
+ foreach ( $taxonomy_settings as $settings_key => $settings_value ) {
+ if ( 'labels' === $settings_key ) {
continue;
}
@@ -205,7 +247,7 @@ function cptui_listings() {
if ( 'object_types' === $settings_key ) {
$object_types[ $settings_key ] = $settings_value;
- # In case they are not associated from the post type settings
+ // 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;
@@ -214,82 +256,135 @@ function cptui_listings() {
}
}
?>
-
+
-
-
+ |
+
|
- $value ) {
- printf( '%s: ', $key );
+ $value ) {
+ printf( '%s: ', esc_html( $key ) );
if ( in_array( $value, array( '1', '0' ) ) ) {
- echo disp_boolean( $value );
+ echo esc_html( disp_boolean( $value ) );
} else {
- echo $value;
+ echo esc_html( $value );
}
echo ' ';
} ?>
|
';
+ echo esc_html( $type ) . ' ';
}
} ?>
|
$value ) {
- echo $key . ': ' . $value . ' ';
+ printf(
+ '%s: %s ',
+ esc_html( $key ),
+ esc_html( $value )
+ );
}
} else {
- _e( 'No custom labels to display', 'custom-post-type-ui' );
+ esc_html_e( 'No custom labels to display', 'custom-post-type-ui' );
}
?>
|
-
- taxonomy--term_slug.php *
- taxonomy-.php
+
+ taxonomy--term_slug.php *
+ taxonomy-.php
taxonomy.php
archive.php
index.php
-
+
- %s',
- __( 'Template hierarchy Theme Handbook', 'custom-post-type-ui' )
+ esc_html__( 'Template hierarchy Theme Handbook', 'custom-post-type-ui' )
); ?>
|
- ' . $head . '';
+ ' . esc_html( $head ) . '';
} ?>
' . sprintf( __( 'No taxonomies registered for display. Visit %s to get started.', 'custom-post-type-ui' ),
- sprintf( ' %s',
- admin_url( 'admin.php?page=cptui_manage_taxonomies' ),
- __( 'Add/Edit Taxonomies', 'custom-post-type-ui' )
- )
- ) . '';
- }
+ /**
+ * 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' );
+ }
?>
' . sprintf( esc_html__( 'No post types registered for display. Visit %s to get started.', 'custom-post-type-ui' ),
+ sprintf( '%s',
+ esc_attr( admin_url( 'admin.php?page=cptui_manage_post_types' ) ),
+ esc_html__( 'Add/Edit Post Types', 'custom-post-type-ui' )
+ )
+ ) . '';
+}
+add_action( 'cptui_no_post_types_listing', 'cptui_no_post_types_to_list' );
+
+/**
+ * Displays a message for when no taxonomies are registered.
+ *
+ * Uses the `cptui_no_taxonomies_listing` hook.
+ *
+ * @since 1.3.0
+ *
+ * @internal
+ */
+function cptui_no_taxonomies_to_list() {
+ echo '' . sprintf( esc_html__( 'No taxonomies registered for display. Visit %s to get started.', 'custom-post-type-ui' ),
+ sprintf( '%s',
+ esc_attr( admin_url( 'admin.php?page=cptui_manage_taxonomies' ) ),
+ esc_html__( 'Add/Edit Taxonomies', 'custom-post-type-ui' )
+ )
+ ) . ' ';
+}
+add_action( 'cptui_no_taxonomies_listing', 'cptui_no_taxonomies_to_list' );
diff --git a/www/wp-content/plugins/custom-post-type-ui/inc/post-types.php b/www/wp-content/plugins/custom-post-type-ui/inc/post-types.php
index f8c2280..c7608a2 100644
--- a/www/wp-content/plugins/custom-post-type-ui/inc/post-types.php
+++ b/www/wp-content/plugins/custom-post-type-ui/inc/post-types.php
@@ -1,21 +1,30 @@
base == "post" ) {
+ if ( ! is_object( $current_screen ) || 'post' === $current_screen->base ) {
return;
}
@@ -23,34 +32,86 @@ function cptui_post_type_enqueue_scripts() {
return;
}
- /*$post_types = get_option( 'cptui_post_types' );
- foreach( $post_types as $type ) {
- $types[] = $type['name'];
- }*/
-
- wp_enqueue_script( 'cptui', plugins_url( 'js/cptui.js', dirname(__FILE__) ), array( 'jquery', 'jquery-ui-core', 'jquery-ui-accordion' ), CPTUI_VERSION, true );
- wp_localize_script( 'cptui', 'cptui_type_data',
+ wp_enqueue_media();
+ wp_enqueue_script( 'cptui' );
+ wp_localize_script( 'cptui', 'cptui_type_data',
array(
- 'confirm' => __( 'Are you sure you want to delete this?', 'custom-post-type-ui' ),
- # 'post_types' => $types,
- #'post_change_name' => '' . __( 'Changing this will rename the post type.', 'custom-post-type-ui' ) . ' '
+ 'confirm' => esc_html__( 'Are you sure you want to delete this? Deleting will NOT remove created content.', 'custom-post-type-ui' ),
)
);
}
add_action( 'admin_enqueue_scripts', 'cptui_post_type_enqueue_scripts' );
+/**
+ * Register our tabs for the Post Type screen.
+ *
+ * @since 1.3.0
+ *
+ * @internal
+ *
+ * @param array $tabs Array of tabs to display.
+ * @param string $current_page Current page being shown.
+ * @return array Amended array of tabs to show.
+ */
+function cptui_post_type_tabs( $tabs = array(), $current_page = '' ) {
+
+ if ( 'post_types' == $current_page ) {
+ $post_types = cptui_get_post_type_data();
+ $classes = array( 'nav-tab' );
+
+ $tabs['page_title'] = __( 'Manage Post Types', 'custom-post-type-ui' );
+ $tabs['tabs'] = array();
+ // Start out with our basic "Add new" tab.
+ $tabs['tabs']['add'] = array(
+ 'text' => __( 'Add New Post Type', 'custom-post-type-ui' ),
+ 'classes' => $classes,
+ 'url' => cptui_admin_url( 'admin.php?page=cptui_manage_' . $current_page ),
+ 'aria-selected' => 'false'
+ );
+
+ $action = cptui_get_current_action();
+ if ( empty( $action ) ) {
+ $tabs['tabs']['add']['classes'][] = 'nav-tab-active';
+ $tabs['tabs']['add']['aria-selected'] = 'true';
+ }
+
+ if ( ! empty( $post_types ) ) {
+
+ if ( ! empty( $action ) ) {
+ $classes[] = 'nav-tab-active';
+ }
+ $tabs['tabs']['edit'] = array(
+ 'text' => __( 'Edit Post Types', 'custom-post-type-ui' ),
+ 'classes' => $classes,
+ 'url' => esc_url( add_query_arg( array( 'action' => 'edit' ), cptui_admin_url( 'admin.php?page=cptui_manage_' . $current_page ) ) ),
+ 'aria-selected' => ( ! empty( $action ) ) ? 'true' : 'false'
+ );
+
+ $tabs['tabs']['view'] = array(
+ 'text' => __( 'View Post Types', 'custom-post-type-ui' ),
+ 'classes' => array( 'nav-tab' ), // Prevent notices.
+ 'url' => esc_url( cptui_admin_url( 'admin.php?page=cptui_listings#post-types' ) ),
+ 'aria-selected' => 'false',
+ );
+ }
+ }
+
+ return $tabs;
+}
+add_filter( 'cptui_get_tabs', 'cptui_post_type_tabs', 10, 2 );
+
/**
* Create our settings page output.
*
* @since 1.0.0
*
- * @return string HTML output for the page.
+ * @internal
*/
function cptui_manage_post_types() {
$post_type_deleted = false;
- if ( !empty( $_POST ) ) {
+ if ( ! empty( $_POST ) ) {
if ( isset( $_POST['cpt_submit'] ) ) {
check_admin_referer( 'cptui_addedit_post_type_nonce_action', 'cptui_addedit_post_type_nonce_field' );
$notice = cptui_update_post_type( $_POST );
@@ -61,20 +122,35 @@ function cptui_manage_post_types() {
}
}
- $tab = ( !empty( $_GET ) && !empty( $_GET['action'] ) && 'edit' == $_GET['action'] ) ? 'edit' : 'new'; ?>
+ $tab = ( ! empty( $_GET ) && ! empty( $_GET['action'] ) && 'edit' === $_GET['action'] ) ? 'edit' : 'new';
+ $tab_class = 'cptui-' . $tab; ?>
-
+
-
array(
'name' => $data
@@ -1081,8 +1213,8 @@ function cptui_delete_post_type( $data = array() ) {
);
}
- if ( empty( $data['cpt_custom_post_type']['name'] ) || ! post_type_exists( $data['cpt_custom_post_type']['name'] ) ) {
- return cptui_admin_notices( 'error', '', false, __( 'Please provide a post type to delete', 'custom-post-type-ui' ) );
+ if ( empty( $data['cpt_custom_post_type']['name'] ) || ! cptui_get_post_type_exists( $data['cpt_custom_post_type']['name'], $data ) ) {
+ return cptui_admin_notices( 'error', '', false, __( 'Please provide a post type to delete', 'custom-post-type-ui' ) );
}
/**
@@ -1094,13 +1226,24 @@ function cptui_delete_post_type( $data = array() ) {
*/
do_action( 'cptui_before_delete_post_type', $data );
- $post_types = get_option( 'cptui_post_types' );
+ $post_types = cptui_get_post_type_data();
if ( array_key_exists( strtolower( $data['cpt_custom_post_type']['name'] ), $post_types ) ) {
unset( $post_types[ $data['cpt_custom_post_type']['name'] ] );
- $success = update_option( 'cptui_post_types', $post_types );
+ /**
+ * Filters whether or not 3rd party options were saved successfully within post type deletion.
+ *
+ * @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_delete_type', false, $post_types, $data ) ) ) {
+ $success = update_option( 'cptui_post_types', $post_types );
+ }
}
/**
@@ -1112,7 +1255,8 @@ function cptui_delete_post_type( $data = array() ) {
*/
do_action( 'cptui_after_delete_post_type', $data );
- flush_rewrite_rules();
+ // Used to help flush rewrite rules on init.
+ set_transient( 'cptui_flush_rewrite_rules', 'true', 5 * 60 );
if ( isset( $success ) ) {
return cptui_admin_notices( 'delete', $data['cpt_custom_post_type']['name'], $success );
@@ -1125,6 +1269,8 @@ function cptui_delete_post_type( $data = array() ) {
*
* @since 1.0.0
*
+ * @internal
+ *
* @param array $data Array of post type data to update.
*
* @return bool|string False on failure, string on success.
@@ -1140,7 +1286,7 @@ function cptui_update_post_type( $data = array() ) {
*/
do_action( 'cptui_before_update_post_type', $data );
- # They need to provide a name
+ // 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' ) );
}
@@ -1151,7 +1297,7 @@ function cptui_update_post_type( $data = array() ) {
}
}
- # clean up $_POST data
+ // clean up $_POST data.
foreach( $data as $key => $value ) {
if ( is_string( $value ) ) {
$data[ $key ] = sanitize_text_field( $value );
@@ -1160,7 +1306,7 @@ function cptui_update_post_type( $data = array() ) {
}
}
- # Check if they didn't put quotes in the name or rewrite slug.
+ // 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'], '\'' ) ||
@@ -1169,11 +1315,26 @@ function cptui_update_post_type( $data = array() ) {
return cptui_admin_notices( 'error', '', false, __( 'Please do not use quotes in post type names or rewrite slugs', 'custom-post-type-ui' ) );
}
- $post_types = get_option( 'cptui_post_types', array() );
+ $post_types = cptui_get_post_type_data();
- # 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.', 'custom-post-type-ui' ), $data['cpt_custom_post_type']['name'] ) );
+ /**
+ * 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'] ) ) {
@@ -1199,11 +1360,17 @@ function cptui_update_post_type( $data = array() ) {
$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 );
+ $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 = str_replace( '"', '', htmlspecialchars_decode( $data['cpt_custom_post_type']['singular_label'] ) );
- $singular_label = htmlspecialchars( stripslashes( $singular_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'] );
@@ -1247,7 +1414,18 @@ function cptui_update_post_type( $data = array() ) {
'custom_supports' => $custom_supports
);
- $success = update_option( 'cptui_post_types', $post_types );
+ /**
+ * 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.
@@ -1258,7 +1436,8 @@ function cptui_update_post_type( $data = array() ) {
*/
do_action( 'cptui_after_update_post_type', $data );
- flush_rewrite_rules();
+ // 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'] ) {
@@ -1315,6 +1494,8 @@ function cptui_reserved_post_types() {
*
* @since 1.1.0
*
+ * @internal
+ *
* @param string $original_slug Original post type slug.
* @param string $new_slug New post type slug.
*/
@@ -1331,3 +1512,64 @@ function cptui_convert_post_type_posts( $original_slug = '', $new_slug = '' ) {
cptui_delete_post_type( $original_slug );
}
+
+/**
+ * Checks if we are trying to register an already registered post type slug.
+ *
+ * @since 1.3.0
+ *
+ * @param bool $slug_exists Whether or not the post type slug exists.
+ * @param string $post_type_slug The post type slug being saved.
+ * @param array $post_types Array of CPTUI-registered post types.
+ *
+ * @return bool
+ */
+function cptui_check_existing_post_type_slugs( $slug_exists = false, $post_type_slug = '', $post_types = array() ) {
+
+ // If true, then we'll already have a conflict, let's not re-process.
+ if ( true === $slug_exists ) {
+ return $slug_exists;
+ }
+
+ // Check if CPTUI has already registered this slug.
+ if ( array_key_exists( strtolower( $post_type_slug ), $post_types ) ) {
+ return true;
+ }
+
+ // Check if we're registering a reserved post type slug.
+ if ( in_array( $post_type_slug, cptui_reserved_post_types() ) ) {
+ return true;
+ }
+
+ // Check if other plugins have registered this same slug.
+ $registered_post_types = get_post_types( array( '_builtin' => false, 'public' => false ) );
+ if ( in_array( $post_type_slug, $registered_post_types ) ) {
+ return true;
+ }
+
+ // If we're this far, it's false.
+ return $slug_exists;
+}
+add_filter( 'cptui_post_type_slug_exists', 'cptui_check_existing_post_type_slugs', 10, 3 );
+
+/**
+ * Checks if the slug matches any existing page slug.
+ *
+ * @since 1.3.0
+ *
+ * @param string $post_type_slug The post type slug being saved.
+ * @return bool Whether or not the slug exists.
+ */
+function cptui_check_page_slugs( $post_type_slug = '' ) {
+ $page = get_page_by_path( $post_type_slug );
+
+ if ( is_null( $page ) ) {
+ return false;
+ }
+
+ if ( is_object( $page ) && ( true === $page instanceof WP_Post ) ) {
+ return true;
+ }
+
+ return false;
+}
diff --git a/www/wp-content/plugins/custom-post-type-ui/inc/support.php b/www/wp-content/plugins/custom-post-type-ui/inc/support.php
index 3080170..905d1c1 100644
--- a/www/wp-content/plugins/custom-post-type-ui/inc/support.php
+++ b/www/wp-content/plugins/custom-post-type-ui/inc/support.php
@@ -1,19 +1,30 @@
base == "post" ) {
+ if ( ! is_object( $current_screen ) || 'post' === $current_screen->base ) {
return;
}
@@ -21,7 +32,7 @@ function cptui_support_enqueue_scripts() {
return;
}
- wp_enqueue_script( 'cptui', plugins_url( 'js/cptui.js' , dirname(__FILE__) ) . '', array( 'jquery' ), '0.9', true );
+ wp_enqueue_script( 'cptui' );
}
add_action( 'admin_enqueue_scripts', 'cptui_support_enqueue_scripts' );
@@ -30,7 +41,7 @@ function cptui_support_enqueue_scripts() {
*
* @since 1.0.0
*
- * @return string HTML output for the page.
+ * @internal
*/
function cptui_support() {
echo ' ';
@@ -44,9 +55,10 @@ function cptui_support() {
- ' . __( 'Support Forums', 'custom-post-type-ui' ) . ''
- ); ?>
+ ' . __( 'Support Forums', 'custom-post-type-ui' ) . ''
+ ); ?>
|