From 6023243eb63ea69de1e86636325e1b364142d7df Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Fri, 16 Sep 2022 13:13:34 -0500 Subject: [PATCH 01/42] starter info for local JSON including enabled checks, and saving to file with MS ID when appropriate --- inc/local-json.php | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 inc/local-json.php diff --git a/inc/local-json.php b/inc/local-json.php new file mode 100644 index 00000000..849064ef --- /dev/null +++ b/inc/local-json.php @@ -0,0 +1,67 @@ + Date: Fri, 16 Sep 2022 13:13:53 -0500 Subject: [PATCH 02/42] load our new local json management file --- custom-post-type-ui.php | 1 + 1 file changed, 1 insertion(+) diff --git a/custom-post-type-ui.php b/custom-post-type-ui.php index 3ce66bf1..f21ed499 100644 --- a/custom-post-type-ui.php +++ b/custom-post-type-ui.php @@ -204,6 +204,7 @@ function cptui_create_submenus() { require_once plugin_dir_path( __FILE__ ) . 'inc/taxonomies.php'; require_once plugin_dir_path( __FILE__ ) . 'inc/listings.php'; require_once plugin_dir_path( __FILE__ ) . 'inc/tools.php'; + require_once plugin_dir_path( __FILE__ ) . 'inc/local-json.php'; require_once plugin_dir_path( __FILE__ ) . 'inc/tools-sections/tools-post-types.php'; require_once plugin_dir_path( __FILE__ ) . 'inc/tools-sections/tools-taxonomies.php'; require_once plugin_dir_path( __FILE__ ) . 'inc/tools-sections/tools-get-code.php'; From 84c28364ec7f846db05b6129771a4a59634ea1bf Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Fri, 16 Sep 2022 13:35:33 -0500 Subject: [PATCH 03/42] code ordering and PHPDocs --- inc/local-json.php | 62 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/inc/local-json.php b/inc/local-json.php index 849064ef..92f3a6e5 100644 --- a/inc/local-json.php +++ b/inc/local-json.php @@ -17,15 +17,14 @@ exit; } -function local_json_is_enabled() { - $dirname = local_json_get_dirname(); - return ( is_dir( $dirname ) && is_writable( $dirname ) ); -} - -function local_json_get_dirname() { - return get_stylesheet_directory() . '/cptui_data'; -} - +/** + * Save post type data to local JSON file if enabled and able. + * + * Saves to suffixed site IDs if in multisite. + * + * @since 1.14.0 + * @param $data + */ function save_local_post_type_data( $data = [] ) { if ( ! local_json_is_enabled() ) { @@ -46,6 +45,14 @@ function save_local_post_type_data( $data = [] ) { } add_action( 'cptui_after_update_post_type', __NAMESPACE__ . '\save_local_post_type_data' ); +/** + * Save taxonomy data to local JSON file if enabled and able. + * + * Saves to suffixed site IDs if in multisite. + * + * @since 1.14.0 + * @param $data + */ function save_local_taxonomy_data( $data = [] ) { if ( ! local_json_is_enabled() ) { return; @@ -65,3 +72,40 @@ function save_local_taxonomy_data( $data = [] ) { } } add_action( 'cptui_after_update_taxonomy', __NAMESPACE__ . '\save_local_taxonomy_data' ); + +/** + * Check if `cptui_data` is a directory and writable, thus enabled. + * + * @since 1.14.0 + * @return bool + */ +function local_json_is_enabled() { + $dirname = local_json_get_dirname(); + + return ( is_dir( $dirname ) && is_writable( $dirname ) ); +} + +/** + * Return our intended local JSON folder server path. + * + * @since 1.14.0 + * @return string + */ +function local_json_get_dirname() { + return get_stylesheet_directory() . '/cptui_data'; +} + +/** + * Potentially add an admin notice about `cptui_data` not being writeable. + * @since 1.14.0 + */ +function local_json_is_writable_admin_notice() { + $dirname = local_json_get_dirname(); + if ( ! is_dir( $dirname ) ) { + return; + } + if ( ! is_writable( $dirname ) ) { + add_action( 'admin_notices', "cptui_local_json_not_writable_admin_notice" ); + } +} +add_action( 'admin_init', __NAMESPACE__ . '\local_json_is_writable_admin_notice' ); From ce2e916c31cd7fd0264d2c670011e99e73a69c32 Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Fri, 16 Sep 2022 13:36:15 -0500 Subject: [PATCH 04/42] add new admin notice callback for non-writable folders --- inc/utility.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/inc/utility.php b/inc/utility.php index 018e888b..35ddc6b9 100644 --- a/inc/utility.php +++ b/inc/utility.php @@ -737,6 +737,17 @@ function cptui_nonce_fail_admin_notice() { ); } +/** + * Local JSON folder not writable callback + * @since 1.14.0 + */ +function cptui_local_json_not_writable_admin_notice() { + echo cptui_admin_notices_helper( // phpcs:ignore WordPress.Security.EscapeOutput + esc_html__( 'A "cptui_data" folder exists in your active theme but the server cannot write to it. Please check folder permissions.', 'custom-post-type-ui' ), + false + ); +} + /** * Returns error message for if trying to register existing post type. * From bbf70a7fd10777db66c63295e03bc758ba464ca3 Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Fri, 16 Sep 2022 14:03:09 -0500 Subject: [PATCH 05/42] add support for when deleting post types and taxonomies, to still update local JSON --- inc/local-json.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/inc/local-json.php b/inc/local-json.php index 92f3a6e5..445af097 100644 --- a/inc/local-json.php +++ b/inc/local-json.php @@ -37,13 +37,12 @@ function save_local_post_type_data( $data = [] ) { $blog_id = '_' . get_current_blog_id(); } - if ( array_key_exists( 'cpt_custom_post_type', $data ) ) { - $cptui_post_types = get_option( 'cptui_post_types', [] ); - $content = json_encode( $cptui_post_types ); - file_put_contents( $theme_dir . "/cptui_post_type_data{$blog_id}.json", $content ); - } + $cptui_post_types = get_option( 'cptui_post_types', [] ); + $content = json_encode( $cptui_post_types ); + file_put_contents( $theme_dir . "/cptui_post_type_data{$blog_id}.json", $content ); } add_action( 'cptui_after_update_post_type', __NAMESPACE__ . '\save_local_post_type_data' ); +add_action( 'cptui_after_delete_post_type', __NAMESPACE__ . '\save_local_post_type_data' ); /** * Save taxonomy data to local JSON file if enabled and able. @@ -65,13 +64,12 @@ function save_local_taxonomy_data( $data = [] ) { $blog_id = '_' . get_current_blog_id(); } - if ( array_key_exists( 'cpt_custom_tax', $data ) ) { - $cptui_taxonomies = get_option( 'cptui_taxonomies', [] ); - $content = json_encode( $cptui_taxonomies ); - file_put_contents( $theme_dir . "/cptui_taxonomy_data{$blog_id}.json", $content ); - } + $cptui_taxonomies = get_option( 'cptui_taxonomies', [] ); + $content = json_encode( $cptui_taxonomies ); + file_put_contents( $theme_dir . "/cptui_taxonomy_data{$blog_id}.json", $content ); } add_action( 'cptui_after_update_taxonomy', __NAMESPACE__ . '\save_local_taxonomy_data' ); +add_action( 'cptui_after_delete_taxonomy', __NAMESPACE__ . '\save_local_taxonomy_data' ); /** * Check if `cptui_data` is a directory and writable, thus enabled. From 3e97c82f6e290f330565ce5991be9b58b677bbe8 Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Fri, 16 Sep 2022 17:36:00 -0500 Subject: [PATCH 06/42] add existing post type and taxonomy data to override filters --- custom-post-type-ui.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/custom-post-type-ui.php b/custom-post-type-ui.php index f21ed499..146613a9 100644 --- a/custom-post-type-ui.php +++ b/custom-post-type-ui.php @@ -266,10 +266,12 @@ function cptui_create_custom_post_types() { * Filters an override array of post type data to be registered instead of our saved option. * * @since 1.10.0 + * @since 1.14.0 Added $cpts as secondary argument. * * @param array $value Default override value. + * @param array $cpts Existing CPTUI data. */ - $cpts_override = apply_filters( 'cptui_post_types_override', [] ); + $cpts_override = apply_filters( 'cptui_post_types_override', [], $cpts ); if ( empty( $cpts ) && empty( $cpts_override ) ) { return; @@ -570,10 +572,12 @@ function cptui_create_custom_taxonomies() { * Filters an override array of taxonomy data to be registered instead of our saved option. * * @since 1.10.0 + * @since 1.14.0 Added $taxes as secondary argument * * @param array $value Default override value. + * @param array $taxes Existing CPTUI data. */ - $taxes_override = apply_filters( 'cptui_taxonomies_override', [] ); + $taxes_override = apply_filters( 'cptui_taxonomies_override', [], $taxes ); if ( empty( $taxes ) && empty( $taxes_override ) ) { return; From b9ed132c41447933e03434c57274016a43c0d38e Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Fri, 16 Sep 2022 17:36:38 -0500 Subject: [PATCH 07/42] revise file name construction and create some helper functions --- inc/local-json.php | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/inc/local-json.php b/inc/local-json.php index 445af097..49f49eac 100644 --- a/inc/local-json.php +++ b/inc/local-json.php @@ -30,16 +30,12 @@ function save_local_post_type_data( $data = [] ) { if ( ! local_json_is_enabled() ) { return; } - $theme_dir = local_json_get_dirname(); - $blog_id = ''; - if ( is_multisite() ) { - $blog_id = '_' . get_current_blog_id(); - } + $json_path = get_current_site_type_tax_json_file_name( 'post_type' ); $cptui_post_types = get_option( 'cptui_post_types', [] ); $content = json_encode( $cptui_post_types ); - file_put_contents( $theme_dir . "/cptui_post_type_data{$blog_id}.json", $content ); + file_put_contents( $json_path, $content ); } add_action( 'cptui_after_update_post_type', __NAMESPACE__ . '\save_local_post_type_data' ); add_action( 'cptui_after_delete_post_type', __NAMESPACE__ . '\save_local_post_type_data' ); @@ -107,3 +103,21 @@ function local_json_is_writable_admin_notice() { } } add_action( 'admin_init', __NAMESPACE__ . '\local_json_is_writable_admin_notice' ); + +function get_current_site_type_tax_json_file_name( $content_type ) { + $theme_dir = local_json_get_dirname(); + $blog_id = ''; + + if ( is_multisite() ) { + $blog_id = '_' . get_current_blog_id(); + } + return $theme_dir . "/cptui_{$content_type}_data{$blog_id}.json"; +} + +function load_local_cptui_data( $file_name = '' ) { + if ( empty( $file_name ) ) { + return false; + } + + return file_get_contents( $file_name ); +} From ca15a8f4954bd5d319791bb71b6ef59da80d13d8 Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Fri, 16 Sep 2022 17:37:12 -0500 Subject: [PATCH 08/42] potentially override our content types if we have none in database, and do have locally --- inc/local-json.php | 55 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/inc/local-json.php b/inc/local-json.php index 49f49eac..2ab3cc5a 100644 --- a/inc/local-json.php +++ b/inc/local-json.php @@ -53,20 +53,61 @@ function save_local_taxonomy_data( $data = [] ) { return; } - $theme_dir = local_json_get_dirname(); - $blog_id = ''; - - if ( is_multisite() ) { - $blog_id = '_' . get_current_blog_id(); - } + $json_path = get_current_site_type_tax_json_file_name( 'taxonomy' ); $cptui_taxonomies = get_option( 'cptui_taxonomies', [] ); $content = json_encode( $cptui_taxonomies ); - file_put_contents( $theme_dir . "/cptui_taxonomy_data{$blog_id}.json", $content ); + file_put_contents( $json_path, $content ); } add_action( 'cptui_after_update_taxonomy', __NAMESPACE__ . '\save_local_taxonomy_data' ); add_action( 'cptui_after_delete_taxonomy', __NAMESPACE__ . '\save_local_taxonomy_data' ); +function load_local_post_type_data( $data = [], $existing_cpts = [] ) { + + // We want to prefer database copy first, in case of editing content. + if ( ! empty( $existing_cpts ) ) { + return $existing_cpts; + } + + $loaded = load_local_cptui_data( get_current_site_type_tax_json_file_name( 'post_type' ) ); + + if ( false === $loaded ) { + return $data; + } + + $data_new = json_decode( $loaded, true ); + + if ( $data_new ) { + return $data_new; + } + + return $data; +} +add_filter( 'cptui_post_types_override', __NAMESPACE__ . '\load_local_post_type_data', 10, 2 ); + +function load_local_taxonomies_data( $data = [], $existing_taxes = [] ) { + + // We want to prefer database copy first, in case of editing content. + if ( ! empty( $existing_taxes ) ) { + return $existing_taxes; + } + + $loaded = load_local_cptui_data( get_current_site_type_tax_json_file_name( 'taxonomy' ) ); + + if ( false === $loaded ) { + return $data; + } + + $data_new = json_decode( $loaded, true ); + + if ( $data_new ) { + return $data_new; + } + + return $data; +} +add_filter( 'cptui_taxonomies_override', __NAMESPACE__ . '\load_local_taxonomies_data', 10, 2 ); + /** * Check if `cptui_data` is a directory and writable, thus enabled. * From 32f14fdd282d3f161acb22dd9e09f0c5fc57db62 Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Fri, 16 Sep 2022 18:55:57 -0500 Subject: [PATCH 09/42] return original empty data if local JSON not enabled --- inc/local-json.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/inc/local-json.php b/inc/local-json.php index 2ab3cc5a..8e0997a5 100644 --- a/inc/local-json.php +++ b/inc/local-json.php @@ -49,6 +49,7 @@ function save_local_post_type_data( $data = [] ) { * @param $data */ function save_local_taxonomy_data( $data = [] ) { + if ( ! local_json_is_enabled() ) { return; } @@ -64,6 +65,10 @@ function save_local_taxonomy_data( $data = [] ) { function load_local_post_type_data( $data = [], $existing_cpts = [] ) { + if ( ! local_json_is_enabled() ) { + return $data; + } + // We want to prefer database copy first, in case of editing content. if ( ! empty( $existing_cpts ) ) { return $existing_cpts; @@ -87,6 +92,10 @@ function load_local_post_type_data( $data = [], $existing_cpts = [] ) { function load_local_taxonomies_data( $data = [], $existing_taxes = [] ) { + if ( ! local_json_is_enabled() ) { + return $data; + } + // We want to prefer database copy first, in case of editing content. if ( ! empty( $existing_taxes ) ) { return $existing_taxes; From 0ca16a59ea720e703a81a549a176f663fbf9ac7f Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Fri, 16 Sep 2022 19:14:38 -0500 Subject: [PATCH 10/42] starter function for this for the moment --- inc/local-json.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/inc/local-json.php b/inc/local-json.php index 8e0997a5..1a4b8b40 100644 --- a/inc/local-json.php +++ b/inc/local-json.php @@ -117,6 +117,26 @@ function load_local_taxonomies_data( $data = [], $existing_taxes = [] ) { } add_filter( 'cptui_taxonomies_override', __NAMESPACE__ . '\load_local_taxonomies_data', 10, 2 ); +function local_get_post_type_data( $cpts = [], $current_site_id = 0 ) { + + if ( ! local_json_is_enabled() ) { + return $cpts; + } + + return $cpts; +} +add_filter( 'cptui_get_post_type_data', __NAMESPACE__ . '\local_get_post_type_data', 10, 2 ); + +function local_get_taxonomy_data( $taxes = [], $current_site_id = 0 ) { + + if ( ! local_json_is_enabled() ) { + return $taxes; + } + + return $taxes; +} +add_filter( 'cptui_get_taxonomy_data', __NAMESPACE__ . '\local_get_taxonomy_data', 10, 2 ); + /** * Check if `cptui_data` is a directory and writable, thus enabled. * From c3a2102001b122ff28b723e8d1125a15a65d32a4 Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Fri, 16 Sep 2022 19:16:09 -0500 Subject: [PATCH 11/42] rename function, add filter --- inc/local-json.php | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/inc/local-json.php b/inc/local-json.php index 1a4b8b40..bef4f2f5 100644 --- a/inc/local-json.php +++ b/inc/local-json.php @@ -144,9 +144,18 @@ function local_get_taxonomy_data( $taxes = [], $current_site_id = 0 ) { * @return bool */ function local_json_is_enabled() { - $dirname = local_json_get_dirname(); - - return ( is_dir( $dirname ) && is_writable( $dirname ) ); + $dirpath = local_json_get_dirpath(); + + $is_enabled = ( is_dir( $dirpath ) && is_writable( $dirpath ) ); + + /** + * Filters the `$is_enabled value for local JSON status. + * + * @since 1.14.0 + * + * @oaram bool $is_enabled Whether or not the folder exists and is writeable. + */ + return apply_filters( 'cptui_local_json_is_enabled', $is_enabled ); } /** @@ -155,8 +164,16 @@ function local_json_is_enabled() { * @since 1.14.0 * @return string */ -function local_json_get_dirname() { - return get_stylesheet_directory() . '/cptui_data'; +function local_json_get_dirpath() { + + /** + * Filters the server directory path to the intended folder in active theme. + * + * @since 1.14.0 + * + * @param string $value Path to the folder in the active theme. + */ + return apply_filters( 'cptui_local_json_dirpath', get_stylesheet_directory() . '/cptui_data' ); } /** @@ -164,18 +181,18 @@ function local_json_get_dirname() { * @since 1.14.0 */ function local_json_is_writable_admin_notice() { - $dirname = local_json_get_dirname(); - if ( ! is_dir( $dirname ) ) { + $dirpath = local_json_get_dirpath(); + if ( ! is_dir( $dirpath ) ) { return; } - if ( ! is_writable( $dirname ) ) { + if ( ! is_writable( $dirpath ) ) { add_action( 'admin_notices', "cptui_local_json_not_writable_admin_notice" ); } } add_action( 'admin_init', __NAMESPACE__ . '\local_json_is_writable_admin_notice' ); function get_current_site_type_tax_json_file_name( $content_type ) { - $theme_dir = local_json_get_dirname(); + $theme_dir = local_json_get_dirpath(); $blog_id = ''; if ( is_multisite() ) { From f1a77c8cb1375ac2247b9f479b931333a329c9c7 Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Fri, 16 Sep 2022 19:20:34 -0500 Subject: [PATCH 12/42] filter the entire server path, including json file name --- inc/local-json.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/inc/local-json.php b/inc/local-json.php index bef4f2f5..120b0d89 100644 --- a/inc/local-json.php +++ b/inc/local-json.php @@ -198,7 +198,18 @@ function get_current_site_type_tax_json_file_name( $content_type ) { if ( is_multisite() ) { $blog_id = '_' . get_current_blog_id(); } - return $theme_dir . "/cptui_{$content_type}_data{$blog_id}.json"; + $full_path = $theme_dir . "/cptui_{$content_type}_data{$blog_id}.json"; + + /** + * Filters the full path including file for chosen content type for current site. + * + * @since 1.14.0 + * + * @param string $full_path Full server path including file name. + * @param string $content_type Whether or not we are fetching post type or taxonomy + * @param string $blog_id Current site ID, with underscore prefix. + */ + return apply_filters( 'cptui_current_site_type_tax_json_file_name', $full_path, $content_type, $blog_id ); } function load_local_cptui_data( $file_name = '' ) { From 3cbaebec896fb6617b42fc36f0d626badb484f65 Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Wed, 21 Sep 2022 15:32:17 -0500 Subject: [PATCH 13/42] new filters for our textarea messaging so we can amend if using local JSON --- inc/tools.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/inc/tools.php b/inc/tools.php index 52695e72..225ea0bd 100644 --- a/inc/tools.php +++ b/inc/tools.php @@ -395,7 +395,10 @@ function cptui_render_posttypes_taxonomies_section() { } $content = wp_json_encode( $cptui_post_types ); } else { - $content = esc_html__( 'No post types registered yet.', 'custom-post-type-ui' ); + $content = apply_filters( + 'cptui_no_post_types_registered_message', + esc_html__( 'No post types registered yet.', 'custom-post-type-ui' ) + ); } ?> @@ -437,7 +440,10 @@ function cptui_render_posttypes_taxonomies_section() { } $content = wp_json_encode( $cptui_taxonomies ); } else { - $content = esc_html__( 'No taxonomies registered yet.', 'custom-post-type-ui' ); + $content = apply_filters( + 'cptui_no_taxonomies_registered_message', + esc_html__( 'No taxonomies registered yet.', 'custom-post-type-ui' ) + ); } ?> From e6a8f603a4b8d76d9d1cd5ec202a7b45ce714650 Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Wed, 21 Sep 2022 15:33:31 -0500 Subject: [PATCH 14/42] all sorts of new messaging and filtering --- inc/local-json.php | 117 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 115 insertions(+), 2 deletions(-) diff --git a/inc/local-json.php b/inc/local-json.php index 120b0d89..37993f5d 100644 --- a/inc/local-json.php +++ b/inc/local-json.php @@ -123,6 +123,23 @@ function local_get_post_type_data( $cpts = [], $current_site_id = 0 ) { return $cpts; } + $current_screen = get_current_screen(); + if ( ! is_object( $current_screen ) || 'cpt-ui_page_cptui_tools' === $current_screen->base ) { + return $cpts; + } + + $loaded = load_local_cptui_data( get_current_site_type_tax_json_file_name( 'post_type' ) ); + + if ( false === $loaded ) { + return $cpts; + } + + $cpts_new = json_decode( $loaded, true ); + + if ( $cpts_new ) { + return $cpts_new; + } + return $cpts; } add_filter( 'cptui_get_post_type_data', __NAMESPACE__ . '\local_get_post_type_data', 10, 2 ); @@ -133,6 +150,23 @@ function local_get_taxonomy_data( $taxes = [], $current_site_id = 0 ) { return $taxes; } + $current_screen = get_current_screen(); + if ( ! is_object( $current_screen ) || 'cpt-ui_page_cptui_tools' === $current_screen->base ) { + return $taxes; + } + + $loaded = load_local_cptui_data( get_current_site_type_tax_json_file_name( 'taxonomy' ) ); + + if ( false === $loaded ) { + return $taxes; + } + + $data_new = json_decode( $loaded, true ); + + if ( $data_new ) { + return $data_new; + } + return $taxes; } add_filter( 'cptui_get_taxonomy_data', __NAMESPACE__ . '\local_get_taxonomy_data', 10, 2 ); @@ -213,9 +247,88 @@ function get_current_site_type_tax_json_file_name( $content_type ) { } function load_local_cptui_data( $file_name = '' ) { - if ( empty( $file_name ) ) { + if ( empty( $file_name ) || ! file_exists( $file_name ) ) { return false; } - return file_get_contents( $file_name ); + $data = file_get_contents( $file_name ); + if ( false === $data ) { + return false; + } + + return $data; +} + +function local_post_type_listings_note() { + + if ( ! local_json_is_enabled() ) { + return; + } + + $db_types = get_option( 'cptui_post_types', [] ); + $loaded = load_local_cptui_data( get_current_site_type_tax_json_file_name( 'post_type' ) ); + + if ( ! empty( $db_types ) || false === $loaded ) { + return; + } + + printf( + '

%s

', + esc_html__( 'These post types were loaded via local JSON in your active theme.', 'custom-post-type-ui' ) + ); +} +add_action( 'cptui_before_post_type_listing', __NAMESPACE__ . '\local_post_type_listings_note' ); + +function local_taxonomy_listings_note() { + + if ( ! local_json_is_enabled() ) { + return; + } + + $db_taxes = get_option( 'cptui_taxonomies', [] ); + $loaded = load_local_cptui_data( get_current_site_type_tax_json_file_name( 'taxonomy' ) ); + + if ( ! empty( $db_taxes ) || false === $loaded ) { + return; + } + + printf( + '

%s

', + esc_html__( 'These taxonomies were loaded via local JSON in your active theme.', 'custom-post-type-ui' ) + ); +} +add_action( 'cptui_before_taxonomy_listing', __NAMESPACE__ . '\local_taxonomy_listings_note' ); + +function local_post_type_tools_export_message( $orig_text ) { + + if ( ! local_json_is_enabled() ) { + return $orig_text; + } + + $db_types = get_option( 'cptui_post_types', [] ); + $loaded = load_local_cptui_data( get_current_site_type_tax_json_file_name( 'post_type' ) ); + + if ( ! empty( $db_types ) || false === $loaded ) { + return $orig_text; + } + + return esc_html__( 'Post types are registered with local JSON.', 'custom-post-type-ui' ); +} +add_filter( 'cptui_no_post_types_registered_message', __NAMESPACE__ . '\local_post_type_tools_export_message' ); + +function local_taxonomy_tools_export_message( $orig_text ) { + + if ( ! local_json_is_enabled() ) { + return $orig_text; + } + + $db_taxes = get_option( 'cptui_taxonomies', [] ); + $loaded = load_local_cptui_data( get_current_site_type_tax_json_file_name( 'taxonomy' ) ); + + if ( ! empty( $db_taxes ) || false === $loaded ) { + return $orig_text; + } + + return esc_html__( 'Taxonomies are registered with local JSON.', 'custom-post-type-ui' ); } +add_filter( 'cptui_no_taxonomies_registered_message', __NAMESPACE__ . '\local_taxonomy_tools_export_message' ); From 75362725af93910f9eadab986988c95a2e2162d4 Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Wed, 21 Sep 2022 16:26:19 -0500 Subject: [PATCH 15/42] make sure we have get_current_screen before using --- inc/local-json.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/inc/local-json.php b/inc/local-json.php index 37993f5d..2928476c 100644 --- a/inc/local-json.php +++ b/inc/local-json.php @@ -123,9 +123,12 @@ function local_get_post_type_data( $cpts = [], $current_site_id = 0 ) { return $cpts; } - $current_screen = get_current_screen(); - if ( ! is_object( $current_screen ) || 'cpt-ui_page_cptui_tools' === $current_screen->base ) { - return $cpts; + if ( function_exists( 'get_current_screen' ) ) { + $current_screen = \get_current_screen(); + + if ( ! is_object( $current_screen ) || 'cpt-ui_page_cptui_tools' === $current_screen->base ) { + return $cpts; + } } $loaded = load_local_cptui_data( get_current_site_type_tax_json_file_name( 'post_type' ) ); @@ -150,9 +153,12 @@ function local_get_taxonomy_data( $taxes = [], $current_site_id = 0 ) { return $taxes; } - $current_screen = get_current_screen(); - if ( ! is_object( $current_screen ) || 'cpt-ui_page_cptui_tools' === $current_screen->base ) { - return $taxes; + if ( function_exists( 'get_current_screen' ) ) { + $current_screen = \get_current_screen(); + + if ( ! is_object( $current_screen ) || 'cpt-ui_page_cptui_tools' === $current_screen->base ) { + return $taxes; + } } $loaded = load_local_cptui_data( get_current_site_type_tax_json_file_name( 'taxonomy' ) ); From 6a462a406f1febc3f8fa1c0c80f949531d897a7c Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Mon, 17 Oct 2022 15:14:50 -0500 Subject: [PATCH 16/42] lets get even closer to familiar naming convention here, rename to cptui-json --- inc/local-json.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/inc/local-json.php b/inc/local-json.php index 2928476c..736d7d0b 100644 --- a/inc/local-json.php +++ b/inc/local-json.php @@ -178,7 +178,7 @@ function local_get_taxonomy_data( $taxes = [], $current_site_id = 0 ) { add_filter( 'cptui_get_taxonomy_data', __NAMESPACE__ . '\local_get_taxonomy_data', 10, 2 ); /** - * Check if `cptui_data` is a directory and writable, thus enabled. + * Check if `cptui-json` is a directory and writable, thus enabled. * * @since 1.14.0 * @return bool @@ -213,11 +213,11 @@ function local_json_get_dirpath() { * * @param string $value Path to the folder in the active theme. */ - return apply_filters( 'cptui_local_json_dirpath', get_stylesheet_directory() . '/cptui_data' ); + return apply_filters( 'cptui_local_json_dirpath', get_stylesheet_directory() . '/cptui-json' ); } /** - * Potentially add an admin notice about `cptui_data` not being writeable. + * Potentially add an admin notice about `cptui-json` not being writeable. * @since 1.14.0 */ function local_json_is_writable_admin_notice() { From 476a59a279ce5bc91f797a7049bbabf19cae099b Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Mon, 17 Oct 2022 19:14:55 -0500 Subject: [PATCH 17/42] way too much new changes from todays work --- inc/local-json.php | 168 +++++++++++++++++++++++++++++---------------- 1 file changed, 108 insertions(+), 60 deletions(-) diff --git a/inc/local-json.php b/inc/local-json.php index 736d7d0b..cf447dfa 100644 --- a/inc/local-json.php +++ b/inc/local-json.php @@ -31,10 +31,10 @@ function save_local_post_type_data( $data = [] ) { return; } - $json_path = get_current_site_type_tax_json_file_name( 'post_type' ); - - $cptui_post_types = get_option( 'cptui_post_types', [] ); - $content = json_encode( $cptui_post_types ); + $json_path = get_specific_type_tax_file_name( 'post_type', $data['cpt_custom_post_type']['name'] ); + $cptui_post_types = get_option( 'cptui_post_types', [] ); + $individual_post_type = $cptui_post_types[ $data['cpt_custom_post_type']['name'] ]; + $content = json_encode( $individual_post_type ); file_put_contents( $json_path, $content ); } add_action( 'cptui_after_update_post_type', __NAMESPACE__ . '\save_local_post_type_data' ); @@ -54,10 +54,10 @@ function save_local_taxonomy_data( $data = [] ) { return; } - $json_path = get_current_site_type_tax_json_file_name( 'taxonomy' ); - - $cptui_taxonomies = get_option( 'cptui_taxonomies', [] ); - $content = json_encode( $cptui_taxonomies ); + $json_path = get_specific_type_tax_file_name( 'taxonomy', $data['cpt_custom_tax']['name'] ); + $cptui_taxonomies = get_option( 'cptui_taxonomies', [] ); + $individual_taxonomy = $cptui_taxonomies[ $data['cpt_custom_tax']['name'] ]; + $content = json_encode( $individual_taxonomy ); file_put_contents( $json_path, $content ); } add_action( 'cptui_after_update_taxonomy', __NAMESPACE__ . '\save_local_taxonomy_data' ); @@ -74,19 +74,13 @@ function load_local_post_type_data( $data = [], $existing_cpts = [] ) { return $existing_cpts; } - $loaded = load_local_cptui_data( get_current_site_type_tax_json_file_name( 'post_type' ) ); + $data_new = local_combine_post_types(); - if ( false === $loaded ) { + if ( empty( $data_new ) ) { return $data; } - $data_new = json_decode( $loaded, true ); - - if ( $data_new ) { - return $data_new; - } - - return $data; + return $data_new; } add_filter( 'cptui_post_types_override', __NAMESPACE__ . '\load_local_post_type_data', 10, 2 ); @@ -101,19 +95,13 @@ function load_local_taxonomies_data( $data = [], $existing_taxes = [] ) { return $existing_taxes; } - $loaded = load_local_cptui_data( get_current_site_type_tax_json_file_name( 'taxonomy' ) ); + $data_new = local_combine_taxonomies(); - if ( false === $loaded ) { + if ( empty( $data_new ) ) { return $data; } - $data_new = json_decode( $loaded, true ); - - if ( $data_new ) { - return $data_new; - } - - return $data; + return $data_new; } add_filter( 'cptui_taxonomies_override', __NAMESPACE__ . '\load_local_taxonomies_data', 10, 2 ); @@ -126,24 +114,24 @@ function local_get_post_type_data( $cpts = [], $current_site_id = 0 ) { if ( function_exists( 'get_current_screen' ) ) { $current_screen = \get_current_screen(); - if ( ! is_object( $current_screen ) || 'cpt-ui_page_cptui_tools' === $current_screen->base ) { + if ( + ! is_object( $current_screen ) || + ( + 'cpt-ui_page_cptui_tools' === $current_screen->base && + empty( $_GET['action'] ) + ) + ) { return $cpts; } } - $loaded = load_local_cptui_data( get_current_site_type_tax_json_file_name( 'post_type' ) ); + $data_new = local_combine_post_types(); - if ( false === $loaded ) { + if ( empty( $data_new ) ) { return $cpts; } - $cpts_new = json_decode( $loaded, true ); - - if ( $cpts_new ) { - return $cpts_new; - } - - return $cpts; + return $data_new; } add_filter( 'cptui_get_post_type_data', __NAMESPACE__ . '\local_get_post_type_data', 10, 2 ); @@ -156,24 +144,21 @@ function local_get_taxonomy_data( $taxes = [], $current_site_id = 0 ) { if ( function_exists( 'get_current_screen' ) ) { $current_screen = \get_current_screen(); - if ( ! is_object( $current_screen ) || 'cpt-ui_page_cptui_tools' === $current_screen->base ) { + if ( ! is_object( $current_screen ) || + 'cpt-ui_page_cptui_tools' === $current_screen->base && + $_GET['action'] === 'taxonomies' + ) { return $taxes; } } - $loaded = load_local_cptui_data( get_current_site_type_tax_json_file_name( 'taxonomy' ) ); + $data_new = local_combine_taxonomies(); - if ( false === $loaded ) { + if ( empty( $data_new ) ) { return $taxes; } - $data_new = json_decode( $loaded, true ); - - if ( $data_new ) { - return $data_new; - } - - return $taxes; + return $data_new; } add_filter( 'cptui_get_taxonomy_data', __NAMESPACE__ . '\local_get_taxonomy_data', 10, 2 ); @@ -231,14 +216,14 @@ function local_json_is_writable_admin_notice() { } add_action( 'admin_init', __NAMESPACE__ . '\local_json_is_writable_admin_notice' ); -function get_current_site_type_tax_json_file_name( $content_type ) { +function get_current_site_type_tax_json_file_name( $content_type = '', $content_slug = '' ) { $theme_dir = local_json_get_dirpath(); $blog_id = ''; if ( is_multisite() ) { $blog_id = '_' . get_current_blog_id(); } - $full_path = $theme_dir . "/cptui_{$content_type}_data{$blog_id}.json"; + $full_path = $theme_dir . "/cptui_{$content_type}_{$content_slug}_data{$blog_id}.json"; /** * Filters the full path including file for chosen content type for current site. @@ -247,22 +232,85 @@ function get_current_site_type_tax_json_file_name( $content_type ) { * * @param string $full_path Full server path including file name. * @param string $content_type Whether or not we are fetching post type or taxonomy + * @param string $content_slug The slug of the content type being managed. * @param string $blog_id Current site ID, with underscore prefix. */ - return apply_filters( 'cptui_current_site_type_tax_json_file_name', $full_path, $content_type, $blog_id ); + return apply_filters( 'cptui_current_site_type_tax_json_file_name', $full_path, $content_type, $content_slug, $blog_id ); } -function load_local_cptui_data( $file_name = '' ) { - if ( empty( $file_name ) || ! file_exists( $file_name ) ) { - return false; +function get_specific_type_tax_file_name( $content_type = '', $content_slug = '' ) { + $theme_dir = local_json_get_dirpath(); + $blog_id = ''; + + if ( is_multisite() ) { + $blog_id = '_' . get_current_blog_id(); } + $full_path = $theme_dir . "/cptui_{$content_type}_{$content_slug}_data{$blog_id}.json"; + + /** + * Filters the full path including file for chosen content type for current site. + * + * @param string $full_path Full server path including file name. + * @param string $content_type Whether or not we are fetching post type or taxonomy + * @param string $content_slug The slug of the content type being managed. + * @param string $blog_id Current site ID, with underscore prefix. + * + * @since 1.14.0 + */ + return apply_filters( 'cptui_specific_type_tax_file_name', $full_path, $content_type, $content_slug, $blog_id ); +} + +function local_has_post_types() { + if ( ! local_json_is_enabled() ) { + return; + } + + $maybe_post_types = local_combine_post_types(); + return ! empty( $maybe_post_types ); +} + +function local_has_taxonomies() { + if ( ! local_json_is_enabled() ) { + return; + } + + $maybe_taxonomies = local_combine_taxonomies(); + return ! empty( $maybe_taxonomies ); +} + +function local_combine_post_types() { + $post_types = []; + foreach ( new \DirectoryIterator( local_json_get_dirpath() ) as $fileInfo ) { + if ( $fileInfo->isDot() ) { + continue; + } + if ( false === strpos( $fileInfo->getFilename(), 'post_type' ) ) { + continue; + } + + $content = file_get_contents( $fileInfo->getPathname() ); + $content_decoded = json_decode( $content, true ); + $post_types[ $content_decoded['name'] ] = $content_decoded; + } + return $post_types; +} + +function local_combine_taxonomies() { + $taxonomies = []; + foreach ( new \DirectoryIterator( local_json_get_dirpath() ) as $fileInfo ) { + if ( $fileInfo->isDot() ) { + continue; + } + if ( false === strpos( $fileInfo->getFilename(), 'taxonomy' ) ) { + continue; + } - $data = file_get_contents( $file_name ); - if ( false === $data ) { - return false; + $content = file_get_contents( $fileInfo->getPathname() ); + $content_decoded = json_decode( $content, true ); + $taxonomies[ $content_decoded['name'] ] = $content_decoded; } - return $data; + return $taxonomies; } function local_post_type_listings_note() { @@ -272,7 +320,7 @@ function local_post_type_listings_note() { } $db_types = get_option( 'cptui_post_types', [] ); - $loaded = load_local_cptui_data( get_current_site_type_tax_json_file_name( 'post_type' ) ); + $loaded = local_has_post_types(); if ( ! empty( $db_types ) || false === $loaded ) { return; @@ -292,7 +340,7 @@ function local_taxonomy_listings_note() { } $db_taxes = get_option( 'cptui_taxonomies', [] ); - $loaded = load_local_cptui_data( get_current_site_type_tax_json_file_name( 'taxonomy' ) ); + $loaded = local_has_taxonomies(); if ( ! empty( $db_taxes ) || false === $loaded ) { return; @@ -312,7 +360,7 @@ function local_post_type_tools_export_message( $orig_text ) { } $db_types = get_option( 'cptui_post_types', [] ); - $loaded = load_local_cptui_data( get_current_site_type_tax_json_file_name( 'post_type' ) ); + $loaded = local_has_post_types(); if ( ! empty( $db_types ) || false === $loaded ) { return $orig_text; @@ -329,7 +377,7 @@ function local_taxonomy_tools_export_message( $orig_text ) { } $db_taxes = get_option( 'cptui_taxonomies', [] ); - $loaded = load_local_cptui_data( get_current_site_type_tax_json_file_name( 'taxonomy' ) ); + $loaded = local_has_taxonomies(); if ( ! empty( $db_taxes ) || false === $loaded ) { return $orig_text; From 15b1b553aebc2a53096ef065c73b6c8c2c9ee8fb Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Tue, 18 Oct 2022 10:19:09 -0500 Subject: [PATCH 18/42] start the import process with some new buttons. --- inc/tools.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/inc/tools.php b/inc/tools.php index 225ea0bd..4b7e623d 100644 --- a/inc/tools.php +++ b/inc/tools.php @@ -381,6 +381,7 @@ function cptui_render_posttypes_taxonomies_section() {

+

@@ -426,6 +427,7 @@ function cptui_render_posttypes_taxonomies_section() {

+

From 735339c70bfb6ebbbc884c80aa7cb6f8974e03f5 Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Tue, 18 Oct 2022 10:22:05 -0500 Subject: [PATCH 19/42] lets only output if we are enabled --- inc/tools.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/inc/tools.php b/inc/tools.php index 4b7e623d..fdc366d6 100644 --- a/inc/tools.php +++ b/inc/tools.php @@ -381,7 +381,14 @@ function cptui_render_posttypes_taxonomies_section() {

- + + + +

@@ -427,7 +434,14 @@ function cptui_render_posttypes_taxonomies_section() {

- + + + +

From e52e339c3c4994baa970af82f6837d29a5e8cc68 Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Wed, 19 Oct 2022 14:23:20 -0500 Subject: [PATCH 20/42] add "import local json" button to tools menu, handle import --- inc/tools.php | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/inc/tools.php b/inc/tools.php index fdc366d6..4e074d2a 100644 --- a/inc/tools.php +++ b/inc/tools.php @@ -386,6 +386,7 @@ function cptui_render_posttypes_taxonomies_section() { if ( CPTUI\local_json_is_enabled() && CPTUI\local_has_taxonomies() ) { ?> + @@ -439,6 +440,7 @@ function cptui_render_posttypes_taxonomies_section() { if ( CPTUI\local_json_is_enabled() && CPTUI\local_has_taxonomies() ) { ?> + @@ -549,3 +551,48 @@ function cptui_do_import_types_taxes() { } } add_action( 'init', 'cptui_do_import_types_taxes', 8 ); + +/** + * Handle the import of transferred post types and taxonomies. + * @since 1.5.0 + */ +function cptui_do_import_types_taxes_json() { + if ( empty( $_POST ) ) { + return; + } + + if ( + empty( $_POST['cptui_import_post_types_json'] ) && + empty( $_POST['cptui_import_taxonomies_json'] ) + ) { + return; + } + + if ( + ( ! empty( $_POST['cptui_import_post_types_json_hidden'] ) && 'do-import-json' === $_POST['cptui_import_post_types_json_hidden'] ) || // phpcs:ignore WordPress.Security.NonceVerification + ( ! empty( $_POST['cptui_import_taxonomies_json_hidden'] ) && 'do-import-json' === $_POST['cptui_import_taxonomies_json_hidden'] ) + ) { + $data = []; + $decoded_post_data = null; + $decoded_tax_data = null; + + if ( ! empty( $_POST['cptui_import_post_types_json'] ) ) { // phpcs:ignore. + $decoded_post_data = CPTUI\local_combine_post_types(); + } + + if ( ! empty( $_POST['cptui_import_taxonomies_json'] ) ) { // phpcs:ignore. + $decoded_tax_data = CPTUI\local_combine_taxonomies(); // phpcs:ignore. + } + + if ( null !== $decoded_post_data ) { + $data['cptui_post_import'] = $decoded_post_data; + } + if ( null !== $decoded_tax_data ) { + $data['cptui_tax_import'] = $decoded_tax_data; + } + + $success = cptui_import_types_taxes_settings( $data ); + add_action( 'admin_notices', "cptui_{$success}_admin_notice" ); + } +} +add_action( 'init', 'cptui_do_import_types_taxes_json', 8 ); From 7b61ed911efed3d34eb5e8cb137dfa715a21e28c Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Wed, 19 Oct 2022 14:24:14 -0500 Subject: [PATCH 21/42] handle loading per-network site to prevent loading all for each --- inc/local-json.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/inc/local-json.php b/inc/local-json.php index cf447dfa..2ee30c55 100644 --- a/inc/local-json.php +++ b/inc/local-json.php @@ -288,6 +288,12 @@ function local_combine_post_types() { continue; } + $file_site_id = local_get_site_id_from_json_file( $fileInfo->getFilename() ); + $site_id = get_current_blog_id(); + if ( $file_site_id !== $site_id ) { + continue; + } + $content = file_get_contents( $fileInfo->getPathname() ); $content_decoded = json_decode( $content, true ); $post_types[ $content_decoded['name'] ] = $content_decoded; @@ -305,6 +311,12 @@ function local_combine_taxonomies() { continue; } + $file_site_id = local_get_site_id_from_json_file( $fileInfo->getFilename() ); + $site_id = get_current_blog_id(); + if ( $file_site_id !== $site_id ) { + continue; + } + $content = file_get_contents( $fileInfo->getPathname() ); $content_decoded = json_decode( $content, true ); $taxonomies[ $content_decoded['name'] ] = $content_decoded; @@ -386,3 +398,7 @@ function local_taxonomy_tools_export_message( $orig_text ) { return esc_html__( 'Taxonomies are registered with local JSON.', 'custom-post-type-ui' ); } add_filter( 'cptui_no_taxonomies_registered_message', __NAMESPACE__ . '\local_taxonomy_tools_export_message' ); + +function local_get_site_id_from_json_file( $filename = '' ) { + return (int) substr( basename( $filename, '.json' ), - 1 ); +} From bc6c004b75166d54a93586e04b7efeb5157c350f Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Wed, 19 Oct 2022 15:38:26 -0500 Subject: [PATCH 22/42] merge in #687 for individual content type removal --- build/cptui-scripts.js | 21 +++++++++++ build/cptui-scripts.min.js | 2 +- build/cptui-scripts.min.js.map | 2 +- inc/listings.php | 68 +++++++++++++++++++++++++++++++++- inc/post-types.php | 24 +++++++----- inc/taxonomies.php | 26 ++++++++----- inc/utility.php | 34 ++++++++++++++++- src/js/cptui-scripts.js | 22 +++++++++++ 8 files changed, 174 insertions(+), 25 deletions(-) diff --git a/build/cptui-scripts.js b/build/cptui-scripts.js index 200eee5b..92732d66 100644 --- a/build/cptui-scripts.js +++ b/build/cptui-scripts.js @@ -288,4 +288,25 @@ postboxes.add_postbox_toggles(pagenow); $(el).val(""); }); }); + $(".cptui-delete-post-type, .cptui-delete-taxonomy").on("click tap", function(e) { + e.preventDefault(); + let msg = ""; + let href = $(this).attr("href"); + if (typeof cptui_listings_data !== "undefined") { + msg = cptui_listings_data.confirm; + } + let submit_delete_warning = $('
' + msg + "
").appendTo(".cptui-listings").dialog({ + dialogClass: "wp-dialog", + modal: true, + autoOpen: true, + buttons: { + OK: function() { + window.location.href = href; + }, + Cancel: function() { + $(this).dialog("close"); + } + } + }); + }); })(jQuery); \ No newline at end of file diff --git a/build/cptui-scripts.min.js b/build/cptui-scripts.min.js index e6cf2465..5631772d 100644 --- a/build/cptui-scripts.min.js +++ b/build/cptui-scripts.min.js @@ -1 +1 @@ -postboxes.add_postbox_toggles(pagenow),function(c){var i;function t(e){var t=/(http|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/.test(e);return e?0===e.indexOf("dashicons-")?c('

').addClass(String(e).replace(/[^-\w. ]/gi,function(e){return"&#"+e.charCodeAt(0)+";"})):t?(t=encodeURI(e),(e=document.createElement("IMG")).src=t,e):void 0:""}c("#cptui_select_post_type_submit").hide(),c("#cptui_select_taxonomy_submit").hide(),"edit"===function(e,t){t=t||window.location.href;e=e.replace(/[\[\]]/g,"\\$&");e=new RegExp("[?&]"+e+"(=([^&#]*)|&|#|$)").exec(t);return e?e[2]?decodeURIComponent(e[2].replace(/\+/g," ")):"":null}("action")&&(i=c("#name").val()),c("#hierarchical").on("change",function(){"1"===c(this).val()?c("#page-attributes").prop("checked",!0):c("#page-attributes").prop("checked",!1)}),c("#post_type").on("change",function(){c("#cptui_select_post_type").submit()}),c("#taxonomy").on("change",function(){c("#cptui_select_taxonomy").submit()}),c(".cptui-delete-top, .cptui-delete-bottom").on("click",function(e){e.preventDefault();var t="";"undefined"!=typeof cptui_type_data?t=cptui_type_data.confirm:"undefined"!=typeof cptui_tax_data&&(t=cptui_tax_data.confirm),c('
'+t+"
").appendTo("#poststuff").dialog({dialogClass:"wp-dialog",modal:!0,autoOpen:!0,buttons:{OK:function(){c(e.target).closest("form");c(e.target).off("click").click()},Cancel:function(){c(this).dialog("close")}}})}),c("#support .question").each(function(){var t=c(this),a=!1,i=t.next("div").slideUp();t.on("click keydown",function(e){"keydown"===e.type&&32!==e.keyCode&&13!==e.keyCode||(e.preventDefault(),a=!a,i.slideToggle(a),t.toggleClass("active",a),t.attr("aria-expanded",a.toString()),t.focus())})}),c("#name").on("keyup",function(e){var t=a=c(this).val(),a=(9!==e.keyCode&&37!==e.keyCode&&38!==e.keyCode&&39!==e.keyCode&&40!==e.keyCode&&(t=function(e){e="cpt-ui_page_cptui_manage_post_types"===window.pagenow?e.replace(/[^a-z0-9\s-]/gi,"_"):e.replace(/[^a-z0-9\s]/gi,"_");return e}(t=(t=function(e){for(var t=[/[\300-\306]/g,/[\340-\346]/g,/[\310-\313]/g,/[\350-\353]/g,/[\314-\317]/g,/[\354-\357]/g,/[\322-\330]/g,/[\362-\370]/g,/[\331-\334]/g,/[\371-\374]/g,/[\321]/g,/[\361]/g,/[\307]/g,/[\347]/g],a=["A","a","E","e","I","i","O","o","U","u","N","n","C","c"],i=0;i'+cptui_tax_data.no_associated_type+"").appendTo("#poststuff").dialog({dialogClass:"wp-dialog",modal:!0,autoOpen:!0,buttons:{OK:function(){c(this).dialog("close")}}}))}),c("#auto-populate").on("click tap",function(e){e.preventDefault();var e=c("#name").val(),n=c("#label").val(),o=c("#singular_label").val(),t=c('.cptui-labels input[type="text"]');""!==e&&(""===n&&(n=e),""===o&&(o=e),c(t).each(function(e,t){var a=c(t).data("label"),i=c(t).data("plurality");"undefined"!==a&&(a="plural"===i?a.replace(/item/gi,n):a.replace(/item/gi,o),""===c(t).val()&&c(t).val(a))}))}),c("#auto-clear").on("click tap",function(e){e.preventDefault();e=c('.cptui-labels input[type="text"]');c(e).each(function(e,t){c(t).val("")})})}(jQuery); \ No newline at end of file +postboxes.add_postbox_toggles(pagenow),function(c){var i;function t(e){var t=/(http|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/.test(e);return e?0===e.indexOf("dashicons-")?c('

').addClass(String(e).replace(/[^-\w. ]/gi,function(e){return"&#"+e.charCodeAt(0)+";"})):t?(t=encodeURI(e),(e=document.createElement("IMG")).src=t,e):void 0:""}c("#cptui_select_post_type_submit").hide(),c("#cptui_select_taxonomy_submit").hide(),"edit"===function(e,t){t=t||window.location.href;e=e.replace(/[\[\]]/g,"\\$&");e=new RegExp("[?&]"+e+"(=([^&#]*)|&|#|$)").exec(t);return e?e[2]?decodeURIComponent(e[2].replace(/\+/g," ")):"":null}("action")&&(i=c("#name").val()),c("#hierarchical").on("change",function(){"1"===c(this).val()?c("#page-attributes").prop("checked",!0):c("#page-attributes").prop("checked",!1)}),c("#post_type").on("change",function(){c("#cptui_select_post_type").submit()}),c("#taxonomy").on("change",function(){c("#cptui_select_taxonomy").submit()}),c(".cptui-delete-top, .cptui-delete-bottom").on("click",function(e){e.preventDefault();var t="";"undefined"!=typeof cptui_type_data?t=cptui_type_data.confirm:"undefined"!=typeof cptui_tax_data&&(t=cptui_tax_data.confirm),c('
'+t+"
").appendTo("#poststuff").dialog({dialogClass:"wp-dialog",modal:!0,autoOpen:!0,buttons:{OK:function(){c(e.target).closest("form");c(e.target).off("click").click()},Cancel:function(){c(this).dialog("close")}}})}),c("#support .question").each(function(){var t=c(this),a=!1,i=t.next("div").slideUp();t.on("click keydown",function(e){"keydown"===e.type&&32!==e.keyCode&&13!==e.keyCode||(e.preventDefault(),a=!a,i.slideToggle(a),t.toggleClass("active",a),t.attr("aria-expanded",a.toString()),t.focus())})}),c("#name").on("keyup",function(e){var t=a=c(this).val(),a=(9!==e.keyCode&&37!==e.keyCode&&38!==e.keyCode&&39!==e.keyCode&&40!==e.keyCode&&(t=function(e){e="cpt-ui_page_cptui_manage_post_types"===window.pagenow?e.replace(/[^a-z0-9\s-]/gi,"_"):e.replace(/[^a-z0-9\s]/gi,"_");return e}(t=(t=function(e){for(var t=[/[\300-\306]/g,/[\340-\346]/g,/[\310-\313]/g,/[\350-\353]/g,/[\314-\317]/g,/[\354-\357]/g,/[\322-\330]/g,/[\362-\370]/g,/[\331-\334]/g,/[\371-\374]/g,/[\321]/g,/[\361]/g,/[\307]/g,/[\347]/g],a=["A","a","E","e","I","i","O","o","U","u","N","n","C","c"],i=0;i'+cptui_tax_data.no_associated_type+"").appendTo("#poststuff").dialog({dialogClass:"wp-dialog",modal:!0,autoOpen:!0,buttons:{OK:function(){c(this).dialog("close")}}}))}),c("#auto-populate").on("click tap",function(e){e.preventDefault();var e=c("#name").val(),n=c("#label").val(),o=c("#singular_label").val(),t=c('.cptui-labels input[type="text"]');""!==e&&(""===n&&(n=e),""===o&&(o=e),c(t).each(function(e,t){var a=c(t).data("label"),i=c(t).data("plurality");"undefined"!==a&&(a="plural"===i?a.replace(/item/gi,n):a.replace(/item/gi,o),""===c(t).val()&&c(t).val(a))}))}),c("#auto-clear").on("click tap",function(e){e.preventDefault();e=c('.cptui-labels input[type="text"]');c(e).each(function(e,t){c(t).val("")})}),c(".cptui-delete-post-type, .cptui-delete-taxonomy").on("click tap",function(e){e.preventDefault();let t="",a=c(this).attr("href");"undefined"!=typeof cptui_listings_data&&(t=cptui_listings_data.confirm);c('
'+t+"
").appendTo(".cptui-listings").dialog({dialogClass:"wp-dialog",modal:!0,autoOpen:!0,buttons:{OK:function(){window.location.href=a},Cancel:function(){c(this).dialog("close")}}})})}(jQuery); \ No newline at end of file diff --git a/build/cptui-scripts.min.js.map b/build/cptui-scripts.min.js.map index 82f6d221..debcf8a8 100644 --- a/build/cptui-scripts.min.js.map +++ b/build/cptui-scripts.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["src/js/cptui-scripts.js"],"names":["postboxes","add_postbox_toggles","pagenow","$","original_slug","composePreviewContent","value","is_url","test","indexOf","addClass","String","replace","c","charCodeAt","imgsrc","encodeURI","theimg","document","createElement","src","hide","name","url","window","location","href","results","RegExp","exec","decodeURIComponent","getParameterByName","val","on","this","prop","submit","e","preventDefault","msg","cptui_type_data","confirm","cptui_tax_data","appendTo","dialog","dialogClass","modal","autoOpen","buttons","OK","target","closest","off","click","Cancel","each","tis","state","answer","next","slideUp","type","keyCode","slideToggle","toggleClass","attr","toString","focus","original_value","$slugexists","s","replaceSpecialCharacters","diacritics","chars","i","length","replaceDiacritics","toLowerCase","split","map","char","cyrillic","join","$slugchanged","removeClass","existing_post_types","hasOwnProperty","existing_taxonomies","_custom_media","_orig_send_attachment","Ё","Й","Ц","У","К","Е","Н","Г","Ш","Щ","З","Х","Ъ","ё","й","ц","у","к","е","н","г","ш","щ","з","х","ъ","Ф","Ы","В","А","П","Р","О","Л","Д","Ж","Э","ф","ы","в","а","п","р","о","л","д","ж","э","Я","Ч","С","М","И","Т","Ь","Б","Ю","я","ч","с","м","и","т","ь","б","ю","undefined","wp","media","editor","send","attachment","button","id","jQuery","props","apply","change","open","trim","html","no_associated_type","slug","plural","singular","fields","el","newval","data","plurality"],"mappings":"AAGAA,UAAUC,oBAAoBC,SAK9B,SAAUC,GAKT,IAEKC,EA0IL,SAASC,EAAsBC,GAE9B,IACIC,EADK,4EACOC,KAAKF,GAErB,OAAKA,EAEM,IAAMA,EAAMG,QAAQ,cACvBN,EAAE,4CAA4CO,SAU/CC,OAVmEL,GAUvDM,QAAQ,aAAc,SAAUC,GAClD,MAAO,KAAOA,EAAEC,WAAW,GAAK,OAVrBP,GACPQ,EAASC,UAAUV,IACnBW,EAASC,SAASC,cAAc,QAC7BC,IAAML,EACNE,QAJD,EAHC,GArJTd,EAAE,kCAAkCkB,OACpClB,EAAE,iCAAiCkB,OAE/B,SAkLJ,SAA4BC,EAAMC,GACvBA,EAALA,GAAWC,OAAOC,SAASC,KAChCJ,EAAOA,EAAKV,QAAQ,UAAW,QAE9Be,EADW,IAAIC,OAAO,OAASN,EAAO,qBACtBO,KAAKN,GACtB,OAAKI,EACAA,EAAQ,GACNG,mBAAmBH,EAAQ,GAAGf,QAAQ,MAAO,MAD5B,GADH,KAvLPmB,CAAmB,YAE7B3B,EAAgBD,EAAE,SAAS6B,OAKhC7B,EAAE,iBAAiB8B,GAAG,SAAU,WAE3B,MADe9B,EAAE+B,MAAMF,MAE1B7B,EAAE,oBAAoBgC,KAAK,WAAW,GAEtChC,EAAE,oBAAoBgC,KAAK,WAAW,KAKxChC,EAAE,cAAc8B,GAAG,SAAS,WAC3B9B,EAAE,2BAA2BiC,WAG9BjC,EAAE,aAAa8B,GAAG,SAAS,WAC1B9B,EAAG,0BAA2BiC,WAI/BjC,EAAE,2CAA2C8B,GAAG,QAAQ,SAASI,GAChEA,EAAEC,iBACF,IAAIC,EAAM,GACqB,oBAApBC,gBACVD,EAAMC,gBAAgBC,QACc,oBAAnBC,iBACjBH,EAAMG,eAAeD,SAEMtC,EAAE,2CAA6CoC,EAAM,UAAUI,SAAS,cAAcC,OAAO,CAC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6I,EAAW1K,EAAE,UAAU6B,MACvB8I,EAAW3K,EAAE,mBAAmB6B,MAChC+I,EAAW5K,EAAE,oCAEZ,KAAOyK,IAGP,KAAOC,IACXA,EAASD,GAEL,KAAOE,IACXA,EAAWF,GAGZzK,EAAE4K,GAAQxH,KAAM,SAAUmB,EAAGsG,GAC5B,IAAIC,EAAS9K,EAAG6K,GAAKE,KAAM,SACvBC,EAAYhL,EAAG6K,GAAKE,KAAM,aACzB,cAAgBD,IAGnBA,EADI,WAAaE,EACRF,EAAOrK,QAAQ,SAAUiK,GAEzBI,EAAOrK,QAAQ,SAAUkK,GAEZ,KAAlB3K,EAAG6K,GAAKhJ,OACZ7B,EAAE6K,GAAIhJ,IAAIiJ,SAMd9K,EAAE,eAAe8B,GAAI,YAAa,SAASI,GAC1CA,EAAEC,iBAEEyI,EAAS5K,EAAE,oCAEfA,EAAE4K,GAAQxH,KAAM,SAAUmB,EAAGsG,GAC5B7K,EAAE6K,GAAIhJ,IAAI,QAtRb,CA0RGoI"} \ No newline at end of file +{"version":3,"sources":["src/js/cptui-scripts.js"],"names":["postboxes","add_postbox_toggles","pagenow","$","original_slug","composePreviewContent","value","is_url","test","indexOf","addClass","String","replace","c","charCodeAt","imgsrc","encodeURI","theimg","document","createElement","src","hide","name","url","window","location","href","results","RegExp","exec","decodeURIComponent","getParameterByName","val","on","this","prop","submit","e","preventDefault","msg","cptui_type_data","confirm","cptui_tax_data","appendTo","dialog","dialogClass","modal","autoOpen","buttons","OK","target","closest","off","click","Cancel","each","tis","state","answer","next","slideUp","type","keyCode","slideToggle","toggleClass","attr","toString","focus","original_value","$slugexists","s","replaceSpecialCharacters","diacritics","chars","i","length","replaceDiacritics","toLowerCase","split","map","char","cyrillic","join","$slugchanged","removeClass","existing_post_types","hasOwnProperty","existing_taxonomies","_custom_media","_orig_send_attachment","Ё","Й","Ц","У","К","Е","Н","Г","Ш","Щ","З","Х","Ъ","ё","й","ц","у","к","е","н","г","ш","щ","з","х","ъ","Ф","Ы","В","А","П","Р","О","Л","Д","Ж","Э","ф","ы","в","а","п","р","о","л","д","ж","э","Я","Ч","С","М","И","Т","Ь","Б","Ю","я","ч","с","м","и","т","ь","б","ю","undefined","wp","media","editor","send","attachment","button","id","jQuery","props","apply","change","open","trim","html","no_associated_type","slug","plural","singular","fields","el","newval","data","plurality","let","cptui_listings_data"],"mappings":"AAGAA,UAAUC,oBAAoBC,SAK9B,SAAUC,GAKT,IAEKC,EA0IL,SAASC,EAAsBC,GAE9B,IACIC,EADK,4EACOC,KAAKF,GAErB,OAAKA,EAEM,IAAMA,EAAMG,QAAQ,cACvBN,EAAE,4CAA4CO,SAU/CC,OAVmEL,GAUvDM,QAAQ,aAAc,SAAUC,GAClD,MAAO,KAAOA,EAAEC,WAAW,GAAK,OAVrBP,GACPQ,EAASC,UAAUV,IACnBW,EAASC,SAASC,cAAc,QAC7BC,IAAML,EACNE,QAJD,EAHC,GArJTd,EAAE,kCAAkCkB,OACpClB,EAAE,iCAAiCkB,OAE/B,SAkLJ,SAA4BC,EAAMC,GACvBA,EAALA,GAAWC,OAAOC,SAASC,KAChCJ,EAAOA,EAAKV,QAAQ,UAAW,QAE9Be,EADW,IAAIC,OAAO,OAASN,EAAO,qBACtBO,KAAKN,GACtB,OAAKI,EACAA,EAAQ,GACNG,mBAAmBH,EAAQ,GAAGf,QAAQ,MAAO,MAD5B,GADH,KAvLPmB,CAAmB,YAE7B3B,EAAgBD,EAAE,SAAS6B,OAKhC7B,EAAE,iBAAiB8B,GAAG,SAAU,WAE3B,MADe9B,EAAE+B,MAAMF,MAE1B7B,EAAE,oBAAoBgC,KAAK,WAAW,GAEtChC,EAAE,oBAAoBgC,KAAK,WAAW,KAKxChC,EAAE,cAAc8B,GAAG,SAAS,WAC3B9B,EAAE,2BAA2BiC,WAG9BjC,EAAE,aAAa8B,GAAG,SAAS,WAC1B9B,EAAG,0BAA2BiC,WAI/BjC,EAAE,2CAA2C8B,GAAG,QAAQ,SAASI,GAChEA,EAAEC,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,QAAkB,CACjBC,GAAM,WACL9C,EAAE+B,MAAMU,OAAO,gBAOpBzC,EAAE,kBAAkB8B,GAAI,YAAa,SAASI,GAC7CA,EAAEC,iBAEF,IAAIsI,EAAWzK,EAAE,SAAS6B,MACtB6I,EAAW1K,EAAE,UAAU6B,MACvB8I,EAAW3K,EAAE,mBAAmB6B,MAChC+I,EAAW5K,EAAE,oCAEZ,KAAOyK,IAGP,KAAOC,IACXA,EAASD,GAEL,KAAOE,IACXA,EAAWF,GAGZzK,EAAE4K,GAAQxH,KAAM,SAAUmB,EAAGsG,GAC5B,IAAIC,EAAS9K,EAAG6K,GAAKE,KAAM,SACvBC,EAAYhL,EAAG6K,GAAKE,KAAM,aACzB,cAAgBD,IAGnBA,EADI,WAAaE,EACRF,EAAOrK,QAAQ,SAAUiK,GAEzBI,EAAOrK,QAAQ,SAAUkK,GAEZ,KAAlB3K,EAAG6K,GAAKhJ,OACZ7B,EAAE6K,GAAIhJ,IAAIiJ,SAMd9K,EAAE,eAAe8B,GAAI,YAAa,SAASI,GAC1CA,EAAEC,iBAEEyI,EAAS5K,EAAE,oCAEfA,EAAE4K,GAAQxH,KAAM,SAAUmB,EAAGsG,GAC5B7K,EAAE6K,GAAIhJ,IAAI,QAKZ7B,EAAE,mDAAmD8B,GAAG,YAAa,SAASI,GAC7EA,EAAEC,iBACF8I,IAAI7I,EAAM,GACNb,EAAOvB,EAAE+B,MAAM+B,KAAK,QACW,oBAAxBoH,sBACV9I,EAAM8I,oBAAoB5I,SAECtC,EAAE,2CAA6CoC,EAAM,UAAUI,SAAS,mBAAmBC,OAAO,CAC7HC,YAAe,YACfC,OAAe,EACfC,UAAe,EACfC,QAAe,CACdC,GAAU,WACTzB,OAAOC,SAASC,KAAOA,GAExB4B,OAAU,WACTnD,EAAE+B,MAAMU,OAAO,eA3SpB,CAgTGwH"} \ No newline at end of file diff --git a/inc/listings.php b/inc/listings.php index b9826de9..65950cc4 100644 --- a/inc/listings.php +++ b/inc/listings.php @@ -33,6 +33,13 @@ function cptui_listings_assets() { } wp_enqueue_style( 'cptui-css' ); + wp_enqueue_script( 'cptui' ); + + wp_localize_script( 'cptui', 'cptui_listings_data', + [ + '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_listings_assets' ); @@ -159,8 +166,9 @@ function cptui_listings() { if ( $archive ) { ?> - +
+ + ?>
+ '; } add_action( 'cptui_no_taxonomies_listing', 'cptui_no_taxonomies_to_list' ); + +/** + * Handle the deletion of registered content types from within the CPTUI Listings page. + * + * @since 1.14.0 + */ +function cptui_listings_delete_post_type_or_taxonomy() { + + if ( wp_doing_ajax() ) { + return; + } + + if ( empty( $_GET['page'] ) || 'cptui_listings' !== $_GET['page'] ) { + return; + } + + $result = false; + $values = []; + if ( ! empty( $_GET['delete_post_type'] ) ) { + $post_type = filter_input( INPUT_GET, 'delete_post_type', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); + if ( ! wp_verify_nonce( $_GET[ 'delete_' . $post_type ], 'do_delete_' . $post_type ) ) { + return; + } + $values['post_type'] = $post_type; + $result = cptui_delete_post_type( $post_type, true ); + } + + if ( ! empty( $_GET['delete_taxonomy'] ) ) { + $taxonomy = filter_input( INPUT_GET, 'delete_taxonomy', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); + if ( ! wp_verify_nonce( $_GET[ 'delete_' . $taxonomy ], 'do_delete_' . $taxonomy ) ) { + return; + } + $values['taxonomy'] = $taxonomy; + $result = cptui_delete_taxonomy( $taxonomy, true ); + } + + if ( $result ) { + add_filter( + 'cptui_get_object_from_post_global', + function( $orig_value ) use ( $values ) { + if ( ! empty( $values['post_type'] ) ) { + return $values['post_type']; + } + if ( ! empty( $values['taxonomy'] ) ) { + return $values['taxonomy']; + } + return $orig_value; + } + ); + if ( is_callable( "cptui_{$result}_admin_notice" ) ) { + add_action( 'admin_notices', "cptui_{$result}_admin_notice" ); + } + } +} +add_action( 'admin_init', 'cptui_listings_delete_post_type_or_taxonomy', 8 ); diff --git a/inc/post-types.php b/inc/post-types.php index ef623ae7..a55d0986 100644 --- a/inc/post-types.php +++ b/inc/post-types.php @@ -1884,10 +1884,11 @@ function cptui_get_current_post_type( $post_type_deleted = false ) { * * @internal * - * @param array $data $_POST values. Optional. + * @param array $data $_POST values. Optional. + * @param bool $bypass_after_delete_hook Whether or not to run after delete hook. Optional. * @return bool|string False on failure, string on success. */ -function cptui_delete_post_type( $data = [] ) { +function cptui_delete_post_type( $data = [], $bypass_after_delete_hook = false ) { // Pass double data into last function despite matching values. if ( is_string( $data ) && cptui_get_post_type_exists( $data, $data ) ) { @@ -1929,14 +1930,17 @@ function cptui_delete_post_type( $data = [] ) { } } - /** - * Fires after a post type is deleted from our saved options. - * - * @since 1.0.0 - * - * @param array $data Array of post type data that was deleted. - */ - do_action( 'cptui_after_delete_post_type', $data ); + if ( false === $bypass_after_delete_hook ) { + + /** + * Fires after a post type is deleted from our saved options. + * + * @param array $data Array of post type data that was deleted. + * + * @since 1.0.0 + */ + do_action( 'cptui_after_delete_post_type', $data ); + } // Used to help flush rewrite rules on init. set_transient( 'cptui_flush_rewrite_rules', 'true', 5 * 60 ); diff --git a/inc/taxonomies.php b/inc/taxonomies.php index 46d6fbac..92a2cd7b 100644 --- a/inc/taxonomies.php +++ b/inc/taxonomies.php @@ -1479,13 +1479,16 @@ function cptui_get_current_taxonomy( $taxonomy_deleted = false ) { * Delete our custom taxonomy from the array of taxonomies. * * @since 1.0.0 + * @since 1.14.0 Added `$bypass_after_delete_hook` parameter * * @internal * - * @param array $data The $_POST values. Optional. + * @param array $data The $_POST values. Optional. + * @param bool $bypass_after_delete_hook Whether or not to run after delete hook. Optional. + * * @return bool|string False on failure, string on success. */ -function cptui_delete_taxonomy( $data = [] ) { +function cptui_delete_taxonomy( $data = [], $bypass_after_delete_hook = false ) { if ( is_string( $data ) && taxonomy_exists( $data ) ) { $slug = $data; @@ -1528,14 +1531,17 @@ function cptui_delete_taxonomy( $data = [] ) { } delete_option( "default_term_{$data['name']}" ); - /** - * Fires after a taxonomy is deleted from our saved options. - * - * @since 1.0.0 - * - * @param array $data Array of taxonomy data that was deleted. - */ - do_action( 'cptui_after_delete_taxonomy', $data ); + if ( false === $bypass_after_delete_hook ) { + + /** + * Fires after a taxonomy is deleted from our saved options. + * + * @param array $data Array of taxonomy data that was deleted. + * + * @since 1.0.0 + */ + do_action( 'cptui_after_delete_taxonomy', $data ); + } // Used to help flush rewrite rules on init. set_transient( 'cptui_flush_rewrite_rules', 'true', 5 * 60 ); diff --git a/inc/utility.php b/inc/utility.php index 35ddc6b9..253aa622 100644 --- a/inc/utility.php +++ b/inc/utility.php @@ -606,7 +606,17 @@ function cptui_get_object_from_post_global() { } } - return esc_html__( 'Object', 'custom-post-type-ui' ); + /** + * Filter the value used for `cptui_get_object_from_post_global` text + * + * @since 1.14.0 + * + * @oaram string $value Default object text if post type or taxonomy not available. + */ + return apply_filters( + 'cptui_get_object_from_post_global', + esc_html__( 'Object', 'custom-post-type-ui' ) + ); } /** @@ -1013,3 +1023,25 @@ function cptui_get_add_new_link( $content_type = '' ) { return cptui_admin_url( 'admin.php?page=cptui_manage_' . $content_type ); } + +/** + * Construct a URL to use to delete a post type or taxonomy. + * + * @since 1.14.0 + * + * @param $content_type The content type being deleted. `post_type` or `taxonomy` + * @param $content_type_slug The slug of the specific content type being deleted. + * + * @return string $value. The constructed URL. + */ +function cptui_get_delete_listing_link( $content_type, $content_type_slug ) { + return add_query_arg( + [ + 'delete_' . $content_type_slug => wp_create_nonce( + 'do_delete_' . $content_type_slug + ), + 'delete_' . $content_type => esc_attr( $content_type_slug ) + ], + admin_url( 'admin.php?page=cptui_listings' ) + ); +} diff --git a/src/js/cptui-scripts.js b/src/js/cptui-scripts.js index 1313ce63..5242e802 100644 --- a/src/js/cptui-scripts.js +++ b/src/js/cptui-scripts.js @@ -288,4 +288,26 @@ postboxes.add_postbox_toggles(pagenow); }); }); + // Confirm our deletions from CPTUI Listings + $('.cptui-delete-post-type, .cptui-delete-taxonomy').on('click tap', function(e) { + e.preventDefault(); + let msg = ''; + let href = $(this).attr('href'); + if (typeof cptui_listings_data !== 'undefined') { + msg = cptui_listings_data.confirm; + } + let submit_delete_warning = $('
' + msg + '
').appendTo('.cptui-listings').dialog({ + 'dialogClass': 'wp-dialog', + 'modal' : true, + 'autoOpen' : true, + 'buttons' : { + "OK" : function () { + window.location.href = href; + }, + "Cancel": function () { + $(this).dialog('close'); + } + } + }); + }); })(jQuery); From a2186b6c309ef97e46e06fadb35524590a7a8612 Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Wed, 19 Oct 2022 16:26:31 -0500 Subject: [PATCH 23/42] change out new delete link with messagine about local JSON if applicable --- inc/listings.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/inc/listings.php b/inc/listings.php index 65950cc4..06d72b32 100644 --- a/inc/listings.php +++ b/inc/listings.php @@ -111,6 +111,7 @@ function cptui_listings() { $post_type_settings ) { $rowclass = ( 0 === $counter % 2 ) ? '' : 'alternate'; @@ -168,7 +169,12 @@ function cptui_listings() { ?>
- + + + + +

+ $taxonomy_settings ) { $rowclass = ( 0 === $counter % 2 ) ? '' : 'alternate'; @@ -379,7 +386,11 @@ function cptui_listings() { esc_html__( 'Get code', 'custom-post-type-ui' ) ); ?>
- + + + +

+ Date: Wed, 19 Oct 2022 16:27:05 -0500 Subject: [PATCH 24/42] remove these callbacks since we went more inline for messaging --- inc/local-json.php | 40 ---------------------------------------- 1 file changed, 40 deletions(-) diff --git a/inc/local-json.php b/inc/local-json.php index 2ee30c55..61710934 100644 --- a/inc/local-json.php +++ b/inc/local-json.php @@ -325,46 +325,6 @@ function local_combine_taxonomies() { return $taxonomies; } -function local_post_type_listings_note() { - - if ( ! local_json_is_enabled() ) { - return; - } - - $db_types = get_option( 'cptui_post_types', [] ); - $loaded = local_has_post_types(); - - if ( ! empty( $db_types ) || false === $loaded ) { - return; - } - - printf( - '

%s

', - esc_html__( 'These post types were loaded via local JSON in your active theme.', 'custom-post-type-ui' ) - ); -} -add_action( 'cptui_before_post_type_listing', __NAMESPACE__ . '\local_post_type_listings_note' ); - -function local_taxonomy_listings_note() { - - if ( ! local_json_is_enabled() ) { - return; - } - - $db_taxes = get_option( 'cptui_taxonomies', [] ); - $loaded = local_has_taxonomies(); - - if ( ! empty( $db_taxes ) || false === $loaded ) { - return; - } - - printf( - '

%s

', - esc_html__( 'These taxonomies were loaded via local JSON in your active theme.', 'custom-post-type-ui' ) - ); -} -add_action( 'cptui_before_taxonomy_listing', __NAMESPACE__ . '\local_taxonomy_listings_note' ); - function local_post_type_tools_export_message( $orig_text ) { if ( ! local_json_is_enabled() ) { From d1f0cd180054a02f567cef575f5c27ec81e565e3 Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Mon, 24 Oct 2022 11:35:33 -0500 Subject: [PATCH 25/42] latest changes, weak commit message --- inc/local-json.php | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/inc/local-json.php b/inc/local-json.php index 61710934..4c7dbdc7 100644 --- a/inc/local-json.php +++ b/inc/local-json.php @@ -38,7 +38,6 @@ function save_local_post_type_data( $data = [] ) { file_put_contents( $json_path, $content ); } add_action( 'cptui_after_update_post_type', __NAMESPACE__ . '\save_local_post_type_data' ); -add_action( 'cptui_after_delete_post_type', __NAMESPACE__ . '\save_local_post_type_data' ); /** * Save taxonomy data to local JSON file if enabled and able. @@ -61,7 +60,28 @@ function save_local_taxonomy_data( $data = [] ) { file_put_contents( $json_path, $content ); } add_action( 'cptui_after_update_taxonomy', __NAMESPACE__ . '\save_local_taxonomy_data' ); -add_action( 'cptui_after_delete_taxonomy', __NAMESPACE__ . '\save_local_taxonomy_data' ); + +function delete_local_post_type_data( $data = [] ) { + + if ( ! local_json_is_enabled() ) { + return; + } + + $json_path = get_specific_type_tax_file_name( 'post_type', $data['name'] ); + unlink( $json_path ); +} +#add_action( 'cptui_after_delete_post_type', __NAMESPACE__ . '\delete_local_post_type_data' ); + +function delete_local_taxonomy_data( $data = [] ) { + + if ( ! local_json_is_enabled() ) { + return; + } + + $json_path = get_specific_type_tax_file_name( 'post_type', $data['name'] ); + unlink( $json_path ); +} +#add_action( 'cptui_after_delete_taxonomy', __NAMESPACE__ . '\delete_local_taxonomy_data' ); function load_local_post_type_data( $data = [], $existing_cpts = [] ) { @@ -70,9 +90,9 @@ function load_local_post_type_data( $data = [], $existing_cpts = [] ) { } // We want to prefer database copy first, in case of editing content. - if ( ! empty( $existing_cpts ) ) { - return $existing_cpts; - } + //if ( ! empty( $existing_cpts ) ) { + // return $existing_cpts; + //} $data_new = local_combine_post_types(); @@ -80,7 +100,7 @@ function load_local_post_type_data( $data = [], $existing_cpts = [] ) { return $data; } - return $data_new; + return array_merge( $data_new, $existing_cpts ); } add_filter( 'cptui_post_types_override', __NAMESPACE__ . '\load_local_post_type_data', 10, 2 ); From 9af657650d12c38b2c9a5da9e309e60738b2287c Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Mon, 31 Oct 2022 11:27:39 -0500 Subject: [PATCH 26/42] admin notice punctuation --- custom-post-type-ui.php | 16 ++++++++-------- inc/utility.php | 18 +++++++++--------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/custom-post-type-ui.php b/custom-post-type-ui.php index 146613a9..42b15e49 100644 --- a/custom-post-type-ui.php +++ b/custom-post-type-ui.php @@ -932,27 +932,27 @@ function cptui_admin_notices( $action = '', $object_type = '', $success = true, if ( 'add' === $action ) { if ( $success ) { - $message .= sprintf( __( '%s has been successfully added', 'custom-post-type-ui' ), $object_type ); + $message .= sprintf( __( '%s has been successfully added.', 'custom-post-type-ui' ), $object_type ); } else { - $message .= sprintf( __( '%s has failed to be added', 'custom-post-type-ui' ), $object_type ); + $message .= sprintf( __( '%s has failed to be added.', 'custom-post-type-ui' ), $object_type ); } } elseif ( 'update' === $action ) { if ( $success ) { - $message .= sprintf( __( '%s has been successfully updated', 'custom-post-type-ui' ), $object_type ); + $message .= sprintf( __( '%s has been successfully updated.', 'custom-post-type-ui' ), $object_type ); } else { - $message .= sprintf( __( '%s has failed to be updated', 'custom-post-type-ui' ), $object_type ); + $message .= sprintf( __( '%s has failed to be updated.', 'custom-post-type-ui' ), $object_type ); } } elseif ( 'delete' === $action ) { if ( $success ) { - $message .= sprintf( __( '%s has been successfully deleted', 'custom-post-type-ui' ), $object_type ); + $message .= sprintf( __( '%s has been successfully deleted.', 'custom-post-type-ui' ), $object_type ); } else { - $message .= sprintf( __( '%s has failed to be deleted', 'custom-post-type-ui' ), $object_type ); + $message .= sprintf( __( '%s has failed to be deleted.', 'custom-post-type-ui' ), $object_type ); } } elseif ( 'import' === $action ) { if ( $success ) { - $message .= sprintf( __( '%s has been successfully imported', 'custom-post-type-ui' ), $object_type ); + $message .= sprintf( __( '%s has been successfully imported.', 'custom-post-type-ui' ), $object_type ); } else { - $message .= sprintf( __( '%s has failed to be imported', 'custom-post-type-ui' ), $object_type ); + $message .= sprintf( __( '%s has failed to be imported.', 'custom-post-type-ui' ), $object_type ); } } elseif ( 'error' === $action ) { if ( ! empty( $custom ) ) { diff --git a/inc/utility.php b/inc/utility.php index 253aa622..02b1d087 100644 --- a/inc/utility.php +++ b/inc/utility.php @@ -628,7 +628,7 @@ function cptui_add_success_admin_notice() { echo cptui_admin_notices_helper( // phpcs:ignore WordPress.Security.EscapeOutput sprintf( /* translators: Placeholders are just for HTML markup that doesn't need translated */ - esc_html__( '%s has been successfully added', 'custom-post-type-ui' ), + esc_html__( '%s has been successfully added.', 'custom-post-type-ui' ), cptui_get_object_from_post_global() ) ); @@ -643,7 +643,7 @@ function cptui_add_fail_admin_notice() { echo cptui_admin_notices_helper( // phpcs:ignore WordPress.Security.EscapeOutput sprintf( /* translators: Placeholders are just for HTML markup that doesn't need translated */ - esc_html__( '%s has failed to be added', 'custom-post-type-ui' ), + esc_html__( '%s has failed to be added.', 'custom-post-type-ui' ), cptui_get_object_from_post_global() ), false @@ -659,7 +659,7 @@ function cptui_update_success_admin_notice() { echo cptui_admin_notices_helper( // phpcs:ignore WordPress.Security.EscapeOutput sprintf( /* translators: Placeholders are just for HTML markup that doesn't need translated */ - esc_html__( '%s has been successfully updated', 'custom-post-type-ui' ), + esc_html__( '%s has been successfully updated.', 'custom-post-type-ui' ), cptui_get_object_from_post_global() ) ); @@ -674,7 +674,7 @@ function cptui_update_fail_admin_notice() { echo cptui_admin_notices_helper( // phpcs:ignore WordPress.Security.EscapeOutput sprintf( /* translators: Placeholders are just for HTML markup that doesn't need translated */ - esc_html__( '%s has failed to be updated', 'custom-post-type-ui' ), + esc_html__( '%s has failed to be updated.', 'custom-post-type-ui' ), cptui_get_object_from_post_global() ), false @@ -690,7 +690,7 @@ function cptui_delete_success_admin_notice() { echo cptui_admin_notices_helper( // phpcs:ignore WordPress.Security.EscapeOutput sprintf( /* translators: Placeholders are just for HTML markup that doesn't need translated */ - esc_html__( '%s has been successfully deleted', 'custom-post-type-ui' ), + esc_html__( '%s has been successfully deleted.', 'custom-post-type-ui' ), cptui_get_object_from_post_global() ) ); @@ -705,7 +705,7 @@ function cptui_delete_fail_admin_notice() { echo cptui_admin_notices_helper( // phpcs:ignore WordPress.Security.EscapeOutput sprintf( /* translators: Placeholders are just for HTML markup that doesn't need translated */ - esc_html__( '%s has failed to be deleted', 'custom-post-type-ui' ), + esc_html__( '%s has failed to be deleted.', 'custom-post-type-ui' ), cptui_get_object_from_post_global() ), false @@ -730,7 +730,7 @@ function cptui_import_success_admin_notice() { */ function cptui_import_fail_admin_notice() { echo cptui_admin_notices_helper( // phpcs:ignore WordPress.Security.EscapeOutput - esc_html__( 'Invalid data provided', 'custom-post-type-ui' ), + esc_html__( 'Invalid data provided.', 'custom-post-type-ui' ), false ); } @@ -742,7 +742,7 @@ function cptui_import_fail_admin_notice() { */ function cptui_nonce_fail_admin_notice() { echo cptui_admin_notices_helper( // phpcs:ignore WordPress.Security.EscapeOutput - esc_html__( 'Nonce failed verification', 'custom-post-type-ui' ), + esc_html__( 'Nonce failed verification.', 'custom-post-type-ui' ), false ); } @@ -836,7 +836,7 @@ function cptui_slug_matches_page() { */ function cptui_slug_has_quotes() { return sprintf( - esc_html__( 'Please do not use quotes in post type/taxonomy names or rewrite slugs', 'custom-post-type-ui' ), + esc_html__( 'Please do not use quotes in post type/taxonomy names or rewrite slugs.', 'custom-post-type-ui' ), cptui_get_object_from_post_global() ); } From 044615b8d3f445bd94b38b82b8e4f07763ecb136 Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Mon, 31 Oct 2022 11:28:01 -0500 Subject: [PATCH 27/42] borrow from WP core for some red liink styling --- inc/listings.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/inc/listings.php b/inc/listings.php index 06d72b32..516e2bde 100644 --- a/inc/listings.php +++ b/inc/listings.php @@ -149,7 +149,7 @@ function cptui_listings() { $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 ); ?> - + %s
@@ -171,7 +171,7 @@ function cptui_listings() { - +

@@ -370,7 +370,7 @@ function cptui_listings() { $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 ); ?> - + %s
@@ -387,7 +387,7 @@ function cptui_listings() { ); ?>
- +

From edee76b9b2cfe6d616b50bf44b3b9ab700382b78 Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Mon, 31 Oct 2022 12:28:59 -0500 Subject: [PATCH 28/42] create import links for items listed as local JSON only. Handle import --- inc/listings.php | 68 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/inc/listings.php b/inc/listings.php index 516e2bde..e8f23610 100644 --- a/inc/listings.php +++ b/inc/listings.php @@ -173,7 +173,7 @@ function cptui_listings() { -

+ @@ -389,7 +389,7 @@ function cptui_listings() { -

+ @@ -592,3 +592,67 @@ function( $orig_value ) use ( $values ) { } } add_action( 'admin_init', 'cptui_listings_delete_post_type_or_taxonomy', 8 ); + +/** + * Handle the import of individual content types from within the CPTUI Listings page. + * + * @since 1.14.0 + */ +function cptui_listings_import_post_type_or_taxonomy() { + + if ( wp_doing_ajax() ) { + return; + } + + if ( empty( $_GET['page'] ) || 'cptui_listings' !== $_GET['page'] ) { + return; + } + + $result = false; + $values = []; + if ( ! empty( $_GET['import_post_type'] ) ) { + $post_type = filter_input( INPUT_GET, 'import_post_type', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); + if ( ! wp_verify_nonce( $_GET[ 'import_' . $post_type ], 'do_import_' . $post_type ) ) { + return; + } + $values['post_type'] = $post_type; + $content = file_get_contents( CPTUI\get_specific_type_tax_file_name( 'post_type', $post_type ) ); + $content_decoded = json_decode( $content, true ); + $database_content = cptui_get_post_type_data(); + $database_content[ $post_type ] = $content_decoded; + update_option( 'cptui_post_types', $database_content ); + } + + if ( ! empty( $_GET['import_taxonomy'] ) ) { + $taxonomy = filter_input( INPUT_GET, 'import_taxonomy', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); + if ( ! wp_verify_nonce( $_GET[ 'import_' . $taxonomy ], 'do_import_' . $taxonomy ) ) { + return; + } + $values['taxonomy'] = $taxonomy; + $content = file_get_contents( CPTUI\get_specific_type_tax_file_name( 'taxonomy', $taxonomy ) ); + $content_decoded = json_decode( $content, true ); + $database_content = cptui_get_taxonomy_data(); + $database_content[ $taxonomy ] = $content_decoded; + update_option( 'cptui_taxonomies', $database_content ); + } + + if ( $result ) { + add_filter( + 'cptui_get_object_from_post_global', + function ( $orig_value ) use ( $values ) { + if ( ! empty( $values['post_type'] ) ) { + return $values['post_type']; + } + if ( ! empty( $values['taxonomy'] ) ) { + return $values['taxonomy']; + } + + return $orig_value; + } + ); + if ( is_callable( "cptui_{$result}_admin_notice" ) ) { + add_action( 'admin_notices', "cptui_{$result}_admin_notice" ); + } + } +} +add_action( 'admin_init', 'cptui_listings_import_post_type_or_taxonomy', 8 ); From c5354b3b184dbf79f7b38ac482472b71a39f840f Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Mon, 31 Oct 2022 12:29:18 -0500 Subject: [PATCH 29/42] remove no longer needed function --- inc/local-json.php | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/inc/local-json.php b/inc/local-json.php index 4c7dbdc7..9c4d682d 100644 --- a/inc/local-json.php +++ b/inc/local-json.php @@ -236,28 +236,6 @@ function local_json_is_writable_admin_notice() { } add_action( 'admin_init', __NAMESPACE__ . '\local_json_is_writable_admin_notice' ); -function get_current_site_type_tax_json_file_name( $content_type = '', $content_slug = '' ) { - $theme_dir = local_json_get_dirpath(); - $blog_id = ''; - - if ( is_multisite() ) { - $blog_id = '_' . get_current_blog_id(); - } - $full_path = $theme_dir . "/cptui_{$content_type}_{$content_slug}_data{$blog_id}.json"; - - /** - * Filters the full path including file for chosen content type for current site. - * - * @since 1.14.0 - * - * @param string $full_path Full server path including file name. - * @param string $content_type Whether or not we are fetching post type or taxonomy - * @param string $content_slug The slug of the content type being managed. - * @param string $blog_id Current site ID, with underscore prefix. - */ - return apply_filters( 'cptui_current_site_type_tax_json_file_name', $full_path, $content_type, $content_slug, $blog_id ); -} - function get_specific_type_tax_file_name( $content_type = '', $content_slug = '' ) { $theme_dir = local_json_get_dirpath(); $blog_id = ''; From 2931f835f59f02a15c68191ac3f2db0609b24201 Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Mon, 31 Oct 2022 12:29:38 -0500 Subject: [PATCH 30/42] blog ID defaults to 1 anyway --- inc/local-json.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/local-json.php b/inc/local-json.php index 9c4d682d..a89677e5 100644 --- a/inc/local-json.php +++ b/inc/local-json.php @@ -238,7 +238,7 @@ function local_json_is_writable_admin_notice() { function get_specific_type_tax_file_name( $content_type = '', $content_slug = '' ) { $theme_dir = local_json_get_dirpath(); - $blog_id = ''; + $blog_id = '1'; if ( is_multisite() ) { $blog_id = '_' . get_current_blog_id(); From f05dee7fee60fef86ef1ca0c2584bae45b06ecc6 Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Mon, 31 Oct 2022 12:30:03 -0500 Subject: [PATCH 31/42] fix misused function for post type section --- inc/tools.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/tools.php b/inc/tools.php index 4e074d2a..cd8d5dcc 100644 --- a/inc/tools.php +++ b/inc/tools.php @@ -383,7 +383,7 @@ function cptui_render_posttypes_taxonomies_section() { From 59ef19eeee9f19051e109ba479125c92f63ef536 Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Mon, 31 Oct 2022 12:30:25 -0500 Subject: [PATCH 32/42] fix type declaratins --- inc/utility.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/utility.php b/inc/utility.php index 02b1d087..2e17c8b9 100644 --- a/inc/utility.php +++ b/inc/utility.php @@ -1029,8 +1029,8 @@ function cptui_get_add_new_link( $content_type = '' ) { * * @since 1.14.0 * - * @param $content_type The content type being deleted. `post_type` or `taxonomy` - * @param $content_type_slug The slug of the specific content type being deleted. + * @param string $content_type The content type being deleted. `post_type` or `taxonomy` + * @param string $content_type_slug The slug of the specific content type being deleted. * * @return string $value. The constructed URL. */ From 31e3eb6fa7a31f34eccb3b4f823a09d082ef28de Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Mon, 31 Oct 2022 12:30:45 -0500 Subject: [PATCH 33/42] add an import link helper --- inc/utility.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/inc/utility.php b/inc/utility.php index 2e17c8b9..38ba1526 100644 --- a/inc/utility.php +++ b/inc/utility.php @@ -1045,3 +1045,26 @@ function cptui_get_delete_listing_link( $content_type, $content_type_slug ) { admin_url( 'admin.php?page=cptui_listings' ) ); } + +/** + * Construct a URL to use to import a post type or taxonomy. + * + * @since 1.14.0 + * + * @param string $content_type The content type being imported. `post_type` or `taxonomy` + * @param string $content_type_slug The slug of the specific content type being imported. + * + * @return string $value. The constructed URL. + * + */ +function cptui_get_impoort_listing_link( $content_type, $content_type_slug ) { + return add_query_arg( + [ + 'import_' . $content_type_slug => wp_create_nonce( + 'do_import_' . $content_type_slug + ), + 'import_' . $content_type => esc_attr( $content_type_slug ) + ], + admin_url( 'admin.php?page=cptui_listings' ) + ); +} From 7d7e8ece70e9d555ab13ef3cca36a3a6edd63c4b Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Mon, 31 Oct 2022 13:31:40 -0500 Subject: [PATCH 34/42] redirect after handling. --- inc/listings.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/inc/listings.php b/inc/listings.php index e8f23610..3719e2f3 100644 --- a/inc/listings.php +++ b/inc/listings.php @@ -589,6 +589,13 @@ function( $orig_value ) use ( $values ) { if ( is_callable( "cptui_{$result}_admin_notice" ) ) { add_action( 'admin_notices', "cptui_{$result}_admin_notice" ); } + + wp_safe_redirect( + add_query_arg( + [ 'page' => 'cptui_listings' ], + cptui_admin_url( 'admin.php?page=cptui_listings' ) + ) + ); } } add_action( 'admin_init', 'cptui_listings_delete_post_type_or_taxonomy', 8 ); @@ -620,7 +627,7 @@ function cptui_listings_import_post_type_or_taxonomy() { $content_decoded = json_decode( $content, true ); $database_content = cptui_get_post_type_data(); $database_content[ $post_type ] = $content_decoded; - update_option( 'cptui_post_types', $database_content ); + $result = update_option( 'cptui_post_types', $database_content ); } if ( ! empty( $_GET['import_taxonomy'] ) ) { @@ -633,7 +640,7 @@ function cptui_listings_import_post_type_or_taxonomy() { $content_decoded = json_decode( $content, true ); $database_content = cptui_get_taxonomy_data(); $database_content[ $taxonomy ] = $content_decoded; - update_option( 'cptui_taxonomies', $database_content ); + $result = update_option( 'cptui_taxonomies', $database_content ); } if ( $result ) { @@ -653,6 +660,13 @@ function ( $orig_value ) use ( $values ) { if ( is_callable( "cptui_{$result}_admin_notice" ) ) { add_action( 'admin_notices', "cptui_{$result}_admin_notice" ); } + + wp_safe_redirect( + add_query_arg( + [ 'page' => 'cptui_listings' ], + cptui_admin_url( 'admin.php?page=cptui_listings' ) + ) + ); } } add_action( 'admin_init', 'cptui_listings_import_post_type_or_taxonomy', 8 ); From 2114260ac84758b80a218ebc684cdec35930bc29 Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Mon, 31 Oct 2022 13:48:33 -0500 Subject: [PATCH 35/42] touch up our phpdocs --- inc/local-json.php | 64 ++++++++++++++++++++++++++++++++++++++++++++++ inc/tools.php | 1 + 2 files changed, 65 insertions(+) diff --git a/inc/local-json.php b/inc/local-json.php index a89677e5..b7829c39 100644 --- a/inc/local-json.php +++ b/inc/local-json.php @@ -186,6 +186,7 @@ function local_get_taxonomy_data( $taxes = [], $current_site_id = 0 ) { * Check if `cptui-json` is a directory and writable, thus enabled. * * @since 1.14.0 + * * @return bool */ function local_json_is_enabled() { @@ -207,6 +208,7 @@ function local_json_is_enabled() { * Return our intended local JSON folder server path. * * @since 1.14.0 + * * @return string */ function local_json_get_dirpath() { @@ -223,6 +225,7 @@ function local_json_get_dirpath() { /** * Potentially add an admin notice about `cptui-json` not being writeable. + * * @since 1.14.0 */ function local_json_is_writable_admin_notice() { @@ -236,6 +239,15 @@ function local_json_is_writable_admin_notice() { } add_action( 'admin_init', __NAMESPACE__ . '\local_json_is_writable_admin_notice' ); +/** + * Retrieve full JSON file path for a specified content type. + * + * @since 1.14.0 + * + * @param string $content_type Content type, Either "post_type" or "taxonomy". + * @param string $content_slug Slug for the desired content type. + * @return mixed|null + */ function get_specific_type_tax_file_name( $content_type = '', $content_slug = '' ) { $theme_dir = local_json_get_dirpath(); $blog_id = '1'; @@ -258,6 +270,13 @@ function get_specific_type_tax_file_name( $content_type = '', $content_slug = '' return apply_filters( 'cptui_specific_type_tax_file_name', $full_path, $content_type, $content_slug, $blog_id ); } +/** + * Whether or not there's some post types in local JSON. + * + * @since 1.14.0 + * + * @return bool|void + */ function local_has_post_types() { if ( ! local_json_is_enabled() ) { return; @@ -267,6 +286,13 @@ function local_has_post_types() { return ! empty( $maybe_post_types ); } +/** + * Whether or not there's some taxonomies in local JSON. + * + * @since 1.14.0 + * + * @return bool|void + */ function local_has_taxonomies() { if ( ! local_json_is_enabled() ) { return; @@ -276,6 +302,13 @@ function local_has_taxonomies() { return ! empty( $maybe_taxonomies ); } +/** + * Iterates and combines all local post type JSON files into one array. + * + * @since 1.14.0 + * + * @return array + */ function local_combine_post_types() { $post_types = []; foreach ( new \DirectoryIterator( local_json_get_dirpath() ) as $fileInfo ) { @@ -299,6 +332,13 @@ function local_combine_post_types() { return $post_types; } +/** + * Iteratesand combines all local taxonomy JSON files into one array. + * + * @since 1.14.0 + * + * @return array + */ function local_combine_taxonomies() { $taxonomies = []; foreach ( new \DirectoryIterator( local_json_get_dirpath() ) as $fileInfo ) { @@ -323,6 +363,14 @@ function local_combine_taxonomies() { return $taxonomies; } +/** + * Filters the text used when there are no post types registered in database. + * + * @since 1.14.0 + * + * @param string $orig_text Original text for the messaging. + * @return mixed|string + */ function local_post_type_tools_export_message( $orig_text ) { if ( ! local_json_is_enabled() ) { @@ -340,6 +388,14 @@ function local_post_type_tools_export_message( $orig_text ) { } add_filter( 'cptui_no_post_types_registered_message', __NAMESPACE__ . '\local_post_type_tools_export_message' ); +/** + * Filters the text used when there are no taxonomies registered in database. + * + * @since 1.14.0 + * + * @param string $orig_text Original text for the messaging. + * @return mixed|string + */ function local_taxonomy_tools_export_message( $orig_text ) { if ( ! local_json_is_enabled() ) { @@ -357,6 +413,14 @@ function local_taxonomy_tools_export_message( $orig_text ) { } add_filter( 'cptui_no_taxonomies_registered_message', __NAMESPACE__ . '\local_taxonomy_tools_export_message' ); +/** + * Extracts the site ID from a local JSON file name. + * + * @since 1.14.0 + * + * @param string $filename File name used for extraction. + * @return int + */ function local_get_site_id_from_json_file( $filename = '' ) { return (int) substr( basename( $filename, '.json' ), - 1 ); } diff --git a/inc/tools.php b/inc/tools.php index cd8d5dcc..ce58d167 100644 --- a/inc/tools.php +++ b/inc/tools.php @@ -554,6 +554,7 @@ function cptui_do_import_types_taxes() { /** * Handle the import of transferred post types and taxonomies. + * * @since 1.5.0 */ function cptui_do_import_types_taxes_json() { From 6db86c6aec6800e05fd6599e075128c94fc7bfe1 Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Mon, 28 Nov 2022 14:38:32 -0600 Subject: [PATCH 36/42] touch up some phpdocs --- inc/local-json.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/inc/local-json.php b/inc/local-json.php index b7829c39..c963bc4f 100644 --- a/inc/local-json.php +++ b/inc/local-json.php @@ -61,6 +61,13 @@ function save_local_taxonomy_data( $data = [] ) { } add_action( 'cptui_after_update_taxonomy', __NAMESPACE__ . '\save_local_taxonomy_data' ); +/** + * Delete a local JSON copy of a post type. + * + * @since 1.14.0 + * + * @param $data + */ function delete_local_post_type_data( $data = [] ) { if ( ! local_json_is_enabled() ) { @@ -72,6 +79,13 @@ function delete_local_post_type_data( $data = [] ) { } #add_action( 'cptui_after_delete_post_type', __NAMESPACE__ . '\delete_local_post_type_data' ); +/** + * Delete a loca JSON copy of a taxonomy. + * + * @since 1.14.0 + * + * @param $data + */ function delete_local_taxonomy_data( $data = [] ) { if ( ! local_json_is_enabled() ) { @@ -83,6 +97,16 @@ function delete_local_taxonomy_data( $data = [] ) { } #add_action( 'cptui_after_delete_taxonomy', __NAMESPACE__ . '\delete_local_taxonomy_data' ); +/** + * Combine local and existing database copies of post type data. + * + * @since 1.14.0 + * + * @param array $data The version of the post types to ultimately register. + * @param array $existing_cpts Existing post types from the database. + * + * @return array|mixed + */ function load_local_post_type_data( $data = [], $existing_cpts = [] ) { if ( ! local_json_is_enabled() ) { @@ -104,6 +128,16 @@ function load_local_post_type_data( $data = [], $existing_cpts = [] ) { } add_filter( 'cptui_post_types_override', __NAMESPACE__ . '\load_local_post_type_data', 10, 2 ); +/** + * Combine local and existing database copies of taxonomy data. + * + * @since 1.14.0 + * + * @param array $data The version of the taxonomies to ultimately register. + * @param array $existing_taxes Existing taxonomy data from the database. + * + * @return array|mixed + */ function load_local_taxonomies_data( $data = [], $existing_taxes = [] ) { if ( ! local_json_is_enabled() ) { From b10072f7afda7369bfbe2739417d666d8cc78c7f Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Mon, 28 Nov 2022 14:39:00 -0600 Subject: [PATCH 37/42] fix copy paste error --- inc/local-json.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/local-json.php b/inc/local-json.php index c963bc4f..7ea249f2 100644 --- a/inc/local-json.php +++ b/inc/local-json.php @@ -92,7 +92,7 @@ function delete_local_taxonomy_data( $data = [] ) { return; } - $json_path = get_specific_type_tax_file_name( 'post_type', $data['name'] ); + $json_path = get_specific_type_tax_file_name( 'taxonomy', $data['name'] ); unlink( $json_path ); } #add_action( 'cptui_after_delete_taxonomy', __NAMESPACE__ . '\delete_local_taxonomy_data' ); From 2c5b406d4538ac12906a874e2bb9c83372e98561 Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Mon, 28 Nov 2022 14:39:20 -0600 Subject: [PATCH 38/42] re-add our callbacks --- inc/local-json.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/local-json.php b/inc/local-json.php index 7ea249f2..e4079f91 100644 --- a/inc/local-json.php +++ b/inc/local-json.php @@ -77,7 +77,7 @@ function delete_local_post_type_data( $data = [] ) { $json_path = get_specific_type_tax_file_name( 'post_type', $data['name'] ); unlink( $json_path ); } -#add_action( 'cptui_after_delete_post_type', __NAMESPACE__ . '\delete_local_post_type_data' ); +add_action( 'cptui_after_delete_post_type', __NAMESPACE__ . '\delete_local_post_type_data' ); /** * Delete a loca JSON copy of a taxonomy. @@ -95,7 +95,7 @@ function delete_local_taxonomy_data( $data = [] ) { $json_path = get_specific_type_tax_file_name( 'taxonomy', $data['name'] ); unlink( $json_path ); } -#add_action( 'cptui_after_delete_taxonomy', __NAMESPACE__ . '\delete_local_taxonomy_data' ); +add_action( 'cptui_after_delete_taxonomy', __NAMESPACE__ . '\delete_local_taxonomy_data' ); /** * Combine local and existing database copies of post type data. From 8ffd31ebeebd8651f6a5ee1f8e529719e2c7edd4 Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Mon, 28 Nov 2022 14:39:49 -0600 Subject: [PATCH 39/42] remove early returns for when we had db versions --- inc/local-json.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/inc/local-json.php b/inc/local-json.php index e4079f91..5b8a2cc4 100644 --- a/inc/local-json.php +++ b/inc/local-json.php @@ -113,11 +113,6 @@ function load_local_post_type_data( $data = [], $existing_cpts = [] ) { return $data; } - // We want to prefer database copy first, in case of editing content. - //if ( ! empty( $existing_cpts ) ) { - // return $existing_cpts; - //} - $data_new = local_combine_post_types(); if ( empty( $data_new ) ) { @@ -144,11 +139,6 @@ function load_local_taxonomies_data( $data = [], $existing_taxes = [] ) { return $data; } - // We want to prefer database copy first, in case of editing content. - if ( ! empty( $existing_taxes ) ) { - return $existing_taxes; - } - $data_new = local_combine_taxonomies(); if ( empty( $data_new ) ) { From 94a3c0969a39e01cf17016b4e0aab29be2fb463e Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Mon, 28 Nov 2022 14:40:38 -0600 Subject: [PATCH 40/42] returned merged arrays for taxonomies --- inc/local-json.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/local-json.php b/inc/local-json.php index 5b8a2cc4..27ab8946 100644 --- a/inc/local-json.php +++ b/inc/local-json.php @@ -145,7 +145,7 @@ function load_local_taxonomies_data( $data = [], $existing_taxes = [] ) { return $data; } - return $data_new; + return array_merge( $data_new, $existing_taxes ); } add_filter( 'cptui_taxonomies_override', __NAMESPACE__ . '\load_local_taxonomies_data', 10, 2 ); From 81e698ffe21f422f873287a88749ae303ad2612d Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Mon, 28 Nov 2022 14:41:12 -0600 Subject: [PATCH 41/42] more return early conditions --- inc/local-json.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/inc/local-json.php b/inc/local-json.php index 27ab8946..2e2d50b9 100644 --- a/inc/local-json.php +++ b/inc/local-json.php @@ -163,6 +163,9 @@ function local_get_post_type_data( $cpts = [], $current_site_id = 0 ) { ( 'cpt-ui_page_cptui_tools' === $current_screen->base && empty( $_GET['action'] ) + ) || + ( + 'cpt-ui_page_cptui_manage_post_types' === $current_screen->base ) ) { return $cpts; From 059e0fb0c5ce6984fef498b398fa230411d3a7fc Mon Sep 17 00:00:00 2001 From: Michael Beckwith Date: Tue, 29 Nov 2022 11:12:14 -0600 Subject: [PATCH 42/42] guarding on taxonomies screen --- inc/local-json.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/inc/local-json.php b/inc/local-json.php index 2e2d50b9..764d0bbf 100644 --- a/inc/local-json.php +++ b/inc/local-json.php @@ -191,9 +191,16 @@ function local_get_taxonomy_data( $taxes = [], $current_site_id = 0 ) { if ( function_exists( 'get_current_screen' ) ) { $current_screen = \get_current_screen(); - if ( ! is_object( $current_screen ) || - 'cpt-ui_page_cptui_tools' === $current_screen->base && - $_GET['action'] === 'taxonomies' + if ( + ! is_object( $current_screen ) || + ( + 'cpt-ui_page_cptui_tools' === $current_screen->base && + $_GET['action'] === 'taxonomies' + ) || + ( + 'cpt-ui_page_cptui_manage_taxonomies' === $current_screen->base + ) + ) { return $taxes; }