esc_html__( 'Post types', 'custom-post-type-ui' ), 'classes' => $classes, 'url' => cptui_admin_url( 'admin.php?page=cptui_' . $current_page ), 'aria-selected' => 'false', ]; $tabs['tabs']['taxonomies'] = [ 'text' => esc_html__( 'Taxonomies', 'custom-post-type-ui' ), 'classes' => $classes, 'url' => esc_url( add_query_arg( [ 'action' => 'taxonomies' ], cptui_admin_url( 'admin.php?page=cptui_' . $current_page ) ) ), 'aria-selected' => 'false', ]; $tabs['tabs']['get_code'] = [ 'text' => esc_html__( 'Get code', 'custom-post-type-ui' ), 'classes' => $classes, 'url' => esc_url( add_query_arg( [ 'action' => 'get_code' ], cptui_admin_url( 'admin.php?page=cptui_' . $current_page ) ) ), 'aria-selected' => 'false', ]; $tabs['tabs']['debuginfo'] = [ 'text' => esc_html__( 'Debug info', 'custom-post-type-ui' ), 'classes' => $classes, 'url' => esc_url( add_query_arg( [ 'action' => 'debuginfo' ], cptui_admin_url( 'admin.php?page=cptui_' . $current_page ) ) ), 'aria-selected' => 'false', ]; $active_class = 'nav-tab-active'; $action = cptui_get_current_action(); if ( ! empty( $action ) ) { if ( 'taxonomies' === $action ) { $tabs['tabs']['taxonomies']['classes'][] = $active_class; $tabs['tabs']['taxonomies']['aria-selected'] = 'true'; } elseif ( 'get_code' === $action ) { $tabs['tabs']['get_code']['classes'][] = $active_class; $tabs['tabs']['get_code']['aria-selected'] = 'true'; } elseif ( 'debuginfo' === $action ) { $tabs['tabs']['debuginfo']['classes'][] = $active_class; $tabs['tabs']['debuginfo']['aria-selected'] = 'true'; } } else { $tabs['tabs']['post_types']['classes'][] = $active_class; $tabs['tabs']['post_types']['aria-selected'] = 'true'; } /** * Filters the tabs being added for the tools area. * * @since 1.5.0 * * @param array $tabs Array of tabs to show. * @param string $action Current tab being shown. * @param string $active_class Class to use to mark the tab active. */ $tabs = apply_filters( 'cptui_tools_tabs', $tabs, $action, $active_class ); } return $tabs; } add_filter( 'cptui_get_tabs', 'cptui_tools_tabs', 10, 2 ); /** * Create our settings page output. * * @since 1.0.0 * * @internal */ function cptui_tools() { $tab = 'post_types'; if ( ! empty( $_GET ) ) { // phpcs:ignore WordPress.Security.NonceVerification if ( ! empty( $_GET['action'] ) && 'taxonomies' === $_GET['action'] ) { // phpcs:ignore WordPress.Security.NonceVerification $tab = 'taxonomies'; } elseif ( ! empty( $_GET['action'] ) && 'get_code' === $_GET['action'] ) { // phpcs:ignore WordPress.Security.NonceVerification $tab = 'get_code'; } elseif ( ! empty( $_GET['action'] ) && 'debuginfo' === $_GET['action'] ) { // phpcs:ignore WordPress.Security.NonceVerification $tab = 'debuginfo'; } } echo '
'; /** * Fires immediately after wrap div started on all of the cptui admin pages. * * @since 1.14.0 */ do_action( 'cptui_inside_wrap' ); /** * Fires right inside the wrap div for the import/export pages. * * @since 1.3.0 * * @deprecated 1.5.0 */ do_action_deprecated( 'cptui_inside_importexport_wrap', [], '1.5.0', 'cptui_inside_tools_wrap' ); /** * Fires right inside the wrap div for the tools pages. * * @since 1.5.0 */ do_action( 'cptui_inside_tools_wrap' ); // Create our tabs. cptui_settings_tab_menu( 'tools' ); /** * Fires inside the markup for the import/export section. * * Allows for more modular control and adding more sections more easily. * * @since 1.2.0 * * @deprecated 1.5.0 * * @param string $tab Current tab being displayed. */ do_action_deprecated( 'cptui_import_export_sections', [ $tab ], '1.5.0', 'cptui_tools_sections' ); /** * Fires inside the markup for the tools section. * * Allows for more modular control and adding more sections more easily. * * @since 1.5.0 * * @param string $tab Current tab being displayed. */ do_action( 'cptui_tools_sections', $tab ); echo '
'; } /** * Import the posted JSON data from a separate export. * * @since 1.0.0 * * @internal * * @param array $postdata $_POST data as json. Optional. * @return mixed false on nothing to do, otherwise void. */ function cptui_import_types_taxes_settings( $postdata = [] ) { if ( ! isset( $postdata['cptui_post_import'] ) && ! isset( $postdata['cptui_tax_import'] ) && ! array_key_exists( 'delete', $postdata ) ) { return false; } $doing_wp_cli = ( defined( 'WP_CLI' ) && WP_CLI ); if ( ! $doing_wp_cli && ! check_admin_referer( 'cptui_typetaximport_nonce_action', 'cptui_typetaximport_nonce_field' ) ) { return 'nonce_fail'; } $status = 'import_fail'; $success = false; /** * Filters the post type data to import. * * Allows third parties to provide their own data dump and import instead of going through our UI. * * @since 1.2.0 * * @param bool $value Default to no data. */ $third_party_post_type_data = apply_filters( 'cptui_third_party_post_type_import', false ); /** * Filters the taxonomy data to import. * * Allows third parties to provide their own data dump and import instead of going through our UI. * * @since 1.2.0 * * @param bool $value Default to no data. */ $third_party_taxonomy_data = apply_filters( 'cptui_third_party_taxonomy_import', false ); if ( false !== $third_party_post_type_data ) { $postdata['cptui_post_import'] = $third_party_post_type_data; } if ( false !== $third_party_taxonomy_data ) { $postdata['cptui_tax_import'] = $third_party_taxonomy_data; } if ( ! empty( $postdata['cptui_post_import'] ) || ( isset( $postdata['delete'] ) && 'type_true' === $postdata['delete'] ) ) { $settings = null; if ( ! empty( $postdata['cptui_post_import'] ) ) { $settings = $postdata['cptui_post_import']; } // Add support to delete settings outright, without accessing database. // Doing double check to protect. if ( null === $settings && ( isset( $postdata['delete'] ) && 'type_true' === $postdata['delete'] ) ) { /** * Filters whether or not 3rd party options were deleted successfully within post type import. * * @since 1.3.0 * * @param bool $value Whether or not someone else deleted successfully. Default false. * @param array $postdata Post type data. */ if ( false === ( $success = apply_filters( 'cptui_post_type_import_delete_save', false, $postdata ) ) ) { // phpcs:ignore. $success = delete_option( 'cptui_post_types' ); } } if ( $settings ) { if ( false !== cptui_get_post_type_data() ) { /** This filter is documented in /inc/import-export.php */ if ( false === ( $success = apply_filters( 'cptui_post_type_import_delete_save', false, $postdata ) ) ) { // phpcs:ignore. delete_option( 'cptui_post_types' ); } } /** * Filters whether or not 3rd party options were updated successfully within the post type import. * * @since 1.3.0 * * @param bool $value Whether or not someone else updated successfully. Default false. * @param array $postdata Post type data. */ if ( false === ( $success = apply_filters( 'cptui_post_type_import_update_save', false, $postdata ) ) ) { // phpcs:ignore. $success = update_option( 'cptui_post_types', $settings ); } } // Used to help flush rewrite rules on init. set_transient( 'cptui_flush_rewrite_rules', 'true', 5 * 60 ); if ( $success ) { $status = 'import_success'; } } elseif ( ! empty( $postdata['cptui_tax_import'] ) || ( isset( $postdata['delete'] ) && 'tax_true' === $postdata['delete'] ) ) { $settings = null; if ( ! empty( $postdata['cptui_tax_import'] ) ) { $settings = $postdata['cptui_tax_import']; } // Add support to delete settings outright, without accessing database. // Doing double check to protect. if ( null === $settings && ( isset( $postdata['delete'] ) && 'tax_true' === $postdata['delete'] ) ) { /** * Filters whether or not 3rd party options were deleted successfully within taxonomy import. * * @since 1.3.0 * * @param bool $value Whether or not someone else deleted successfully. Default false. * @param array $postdata Taxonomy data */ if ( false === ( $success = apply_filters( 'cptui_taxonomy_import_delete_save', false, $postdata ) ) ) { // phpcs:ignore. $success = delete_option( 'cptui_taxonomies' ); } } if ( $settings ) { if ( false !== cptui_get_taxonomy_data() ) { /** This filter is documented in /inc/import-export.php */ if ( false === ( $success = apply_filters( 'cptui_taxonomy_import_delete_save', false, $postdata ) ) ) { // phpcs:ignore. delete_option( 'cptui_taxonomies' ); } } /** * Filters whether or not 3rd party options were updated successfully within the taxonomy import. * * @since 1.3.0 * * @param bool $value Whether or not someone else updated successfully. Default false. * @param array $postdata Taxonomy data. */ if ( false === ( $success = apply_filters( 'cptui_taxonomy_import_update_save', false, $postdata ) ) ) { // phpcs:ignore. $success = update_option( 'cptui_taxonomies', $settings ); } } // Used to help flush rewrite rules on init. set_transient( 'cptui_flush_rewrite_rules', 'true', 5 * 60 ); if ( $success ) { $status = 'import_success'; } } return $status; } /** * Content for the Post Types/Taxonomies Tools tab. * * @since 1.2.0 * * @internal */ function cptui_render_posttypes_taxonomies_section() { ?>

%s: %s', esc_html__( 'NOTE', 'custom-post-type-ui' ), esc_html__( 'This will not export the associated posts or taxonomy terms, just the settings.', 'custom-post-type-ui' ) ); ?>

$values ) { if ( ! empty( $values['description'] ) ) { $cptui_post_types[ $type ]['description'] = wp_slash( html_entity_decode( $values['description'] ) ); } } $content = wp_json_encode( $cptui_post_types ); } else { $content = esc_html__( 'No post types registered yet.', 'custom-post-type-ui' ); } ?>

$values ) { if ( ! empty( $values['description'] ) ) { $cptui_taxonomies[ $tax ]['description'] = wp_slash( html_entity_decode( $values['description'] ) ); } } $content = wp_json_encode( $cptui_taxonomies ); } else { $content = esc_html__( 'No taxonomies registered yet.', 'custom-post-type-ui' ); } ?>