$taxonomy_settings ) {
$rowclass = ( 0 === $counter % 2 ) ? '' : 'alternate';
@@ -355,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
@@ -370,7 +385,12 @@ function cptui_listings() {
esc_attr( admin_url( 'admin.php?page=cptui_tools&action=get_code#' . $taxonomy ) ),
esc_html__( 'Get code', 'custom-post-type-ui' )
);
- ?>
+ ?>
+
+
+
+
+
|
';
}
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" );
+ }
+
+ 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 );
+
+/**
+ * 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;
+ $result = 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;
+ $result = 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" );
+ }
+
+ 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 );
diff --git a/inc/local-json.php b/inc/local-json.php
new file mode 100644
index 00000000..764d0bbf
--- /dev/null
+++ b/inc/local-json.php
@@ -0,0 +1,460 @@
+base &&
+ empty( $_GET['action'] )
+ ) ||
+ (
+ 'cpt-ui_page_cptui_manage_post_types' === $current_screen->base
+ )
+ ) {
+ return $cpts;
+ }
+ }
+
+ $data_new = local_combine_post_types();
+
+ if ( empty( $data_new ) ) {
+ return $cpts;
+ }
+
+ return $data_new;
+}
+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;
+ }
+
+ 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'
+ ) ||
+ (
+ 'cpt-ui_page_cptui_manage_taxonomies' === $current_screen->base
+ )
+
+ ) {
+ return $taxes;
+ }
+ }
+
+ $data_new = local_combine_taxonomies();
+
+ if ( empty( $data_new ) ) {
+ return $taxes;
+ }
+
+ return $data_new;
+}
+add_filter( 'cptui_get_taxonomy_data', __NAMESPACE__ . '\local_get_taxonomy_data', 10, 2 );
+
+/**
+ * Check if `cptui-json` is a directory and writable, thus enabled.
+ *
+ * @since 1.14.0
+ *
+ * @return bool
+ */
+function local_json_is_enabled() {
+ $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 );
+}
+
+/**
+ * Return our intended local JSON folder server path.
+ *
+ * @since 1.14.0
+ *
+ * @return string
+ */
+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-json' );
+}
+
+/**
+ * Potentially add an admin notice about `cptui-json` not being writeable.
+ *
+ * @since 1.14.0
+ */
+function local_json_is_writable_admin_notice() {
+ $dirpath = local_json_get_dirpath();
+ if ( ! is_dir( $dirpath ) ) {
+ return;
+ }
+ 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' );
+
+/**
+ * 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';
+
+ 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 );
+}
+
+/**
+ * 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;
+ }
+
+ $maybe_post_types = local_combine_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;
+ }
+
+ $maybe_taxonomies = local_combine_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 ) {
+ if ( $fileInfo->isDot() ) {
+ continue;
+ }
+ if ( false === strpos( $fileInfo->getFilename(), 'post_type' ) ) {
+ 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;
+ }
+ 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 ) {
+ if ( $fileInfo->isDot() ) {
+ continue;
+ }
+ if ( false === strpos( $fileInfo->getFilename(), 'taxonomy' ) ) {
+ 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;
+ }
+
+ 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() ) {
+ return $orig_text;
+ }
+
+ $db_types = get_option( 'cptui_post_types', [] );
+ $loaded = local_has_post_types();
+
+ 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' );
+
+/**
+ * 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() ) {
+ return $orig_text;
+ }
+
+ $db_taxes = get_option( 'cptui_taxonomies', [] );
+ $loaded = local_has_taxonomies();
+
+ 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' );
+
+/**
+ * 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/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/tools.php b/inc/tools.php
index 52695e72..ce58d167 100644
--- a/inc/tools.php
+++ b/inc/tools.php
@@ -381,6 +381,15 @@ function cptui_render_posttypes_taxonomies_section() {
+
+
+
+
+
@@ -395,7 +404,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' )
+ );
}
?>
@@ -423,6 +435,15 @@ function cptui_render_posttypes_taxonomies_section() {
+
+
+
+
+
@@ -437,7 +458,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' )
+ );
}
?>
@@ -527,3 +551,49 @@ 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 );
diff --git a/inc/utility.php b/inc/utility.php
index 018e888b..38ba1526 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' )
+ );
}
/**
@@ -618,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()
)
);
@@ -633,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
@@ -649,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()
)
);
@@ -664,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
@@ -680,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()
)
);
@@ -695,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
@@ -720,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
);
}
@@ -732,7 +742,18 @@ 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
+ );
+}
+
+/**
+ * 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
);
}
@@ -815,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()
);
}
@@ -1002,3 +1023,48 @@ 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 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.
+ */
+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' )
+ );
+}
+
+/**
+ * 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' )
+ );
+}
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);
|