base ) {
return;
}
if ( wp_doing_ajax() ) {
return;
}
wp_enqueue_style( 'cptui-css' );
}
add_action( 'admin_enqueue_scripts', 'cptui_tools_assets' );
/**
* Register our tabs for the Tools screen.
*
* @since 1.3.0
* @since 1.5.0 Renamed to "Tools"
*
* @internal
*
* @param array $tabs Array of tabs to display. Optional.
* @param string $current_page Current page being shown. Optional. Default empty string.
* @return array Amended array of tabs to show.
*/
function cptui_tools_tabs( $tabs = [], $current_page = '' ) {
if ( 'tools' === $current_page ) {
$classes = [ 'nav-tab' ];
$tabs['page_title'] = get_admin_page_title();
$tabs['tabs'] = [];
$tabs['tabs']['post_types'] = [
'text' => __( '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' => __( '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' => __( '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' => __( '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 = '';
if ( ! empty( $_GET ) ) {
if ( ! empty( $_GET['action'] ) && 'taxonomies' === $_GET['action'] ) {
$tab = 'taxonomies';
} elseif ( ! empty( $_GET['action'] ) && 'get_code' === $_GET['action'] ) {
$tab = 'get_code';
} elseif ( ! empty( $_GET['action'] ) && 'debuginfo' === $_GET['action'] ) {
$tab = 'debuginfo';
} else {
$tab = 'post_types';
}
}
echo '
';
/**
* 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 '
';
}
/**
* Display our copy-able code for registered taxonomies.
*
* @since 1.0.0
* @since 1.2.0 Added $cptui_taxonomies parameter.
* @since 1.2.0 Added $single parameter.
*
* @param array $cptui_taxonomies Array of taxonomies to render. Optional.
* @param bool $single Whether or not we are rendering a single taxonomy. Optional. Default false.
*/
function cptui_get_taxonomy_code( $cptui_taxonomies = [], $single = false ) {
if ( ! empty( $cptui_taxonomies ) ) {
$callback = 'cptui_register_my_taxes';
if ( $single ) {
$key = key( $cptui_taxonomies );
$callback = 'cptui_register_my_taxes_' . str_replace( '-', '_', esc_html( $cptui_taxonomies[ $key ]['name'] ) );
}
?>
function () {
}
add_action( 'init', '' );
\'' . $taxonomy['name'] . '\',';
if ( ! empty( $taxonomy['rewrite_slug'] ) ) {
$rewrite_slug = ' \'slug\' => \'' . $taxonomy['rewrite_slug'] . '\',';
}
$rewrite_withfront = '';
$withfront = disp_boolean( $taxonomy['rewrite_withfront'] );
if ( ! empty( $withfront ) ) {
$rewrite_withfront = ' \'with_front\' => ' . $withfront . ', ';
}
$hierarchical = ! empty( $taxonomy['rewrite_hierarchical'] ) ? disp_boolean( $taxonomy['rewrite_hierarchical'] ) : '';
$rewrite_hierarchcial = '';
if ( ! empty( $hierarchical ) ) {
$rewrite_hierarchcial = ' \'hierarchical\' => ' . $hierarchical . ', ';
}
if ( ! empty( $taxonomy['rewrite_slug'] ) || false !== disp_boolean( $taxonomy['rewrite_withfront'] ) ) {
$rewrite_start = '[';
$rewrite_end = ']';
$rewrite = $rewrite_start . $rewrite_slug . $rewrite_withfront . $rewrite_hierarchcial . $rewrite_end;
}
} else {
$rewrite = disp_boolean( $taxonomy['rewrite'] );
}
$public = isset( $taxonomy['public'] ) ? disp_boolean( $taxonomy['public'] ) : 'true';
$publicly_queryable = isset( $taxonomy['publicly_queryable'] ) ? disp_boolean( $taxonomy['publicly_queryable'] ) : disp_boolean( $taxonomy['public'] );
$show_in_quick_edit = isset( $taxonomy['show_in_quick_edit'] ) ? disp_boolean( $taxonomy['show_in_quick_edit'] ) : disp_boolean( $taxonomy['show_ui'] );
$show_in_menu = ( ! empty( $taxonomy['show_in_menu'] ) && false !== get_disp_boolean( $taxonomy['show_in_menu'] ) ) ? 'true' : 'false';
if ( empty( $taxonomy['show_in_menu'] ) ) {
$show_in_menu = disp_boolean( $taxonomy['show_ui'] );
}
$show_in_nav_menus = ( ! empty( $taxonomy['show_in_nav_menus'] ) && false !== get_disp_boolean( $taxonomy['show_in_nav_menus'] ) ) ? 'true' : 'false';
if ( empty( $taxonomy['show_in_nav_menus'] ) ) {
$show_in_nav_menus = $public;
}
$show_in_rest = ( ! empty( $taxonomy['show_in_rest'] ) && false !== get_disp_boolean( $taxonomy['show_in_rest'] ) ) ? 'true' : 'false';
$rest_base = ! empty( $taxonomy['rest_base'] ) ? $taxonomy['rest_base'] : $taxonomy['name'];
$rest_controller_class = ! empty( $taxonomy['rest_controller_class'] ) ? $taxonomy['rest_controller_class'] : 'WP_REST_Terms_Controller';
if ( ! empty( $taxonomy['meta_box_cb'] ) ) {
$meta_box_cb = ( false !== get_disp_boolean( $taxonomy['meta_box_cb'] ) ) ? '"' . $taxonomy['meta_box_cb'] . '"' : 'false';
}
$default_term = '';
if ( ! empty( $taxonomy['default_term'] ) ) {
$term_parts = explode( ',', $taxonomy['default_term'] );
$default_term_start = '[';
$default_term_end = ']';
if ( ! empty( $term_parts[0] ) ) {
$default_term .= "'name' => '" . trim( $term_parts[0] ) . "'";
}
if ( ! empty( $term_parts[1] ) ) {
$default_term .= ", 'slug' => '" . trim( $term_parts[1] ) . "'";
}
if ( ! empty( $term_parts[2] ) ) {
$default_term .= ", 'description' => '" . trim( $term_parts[2] ) . "'";
}
$default_term = $default_term_start . $default_term . $default_term_end;
}
$my_theme = wp_get_theme();
$textdomain = $my_theme->get( 'TextDomain' );
if ( empty( $textdomain ) ) {
$textdomain = 'custom-post-type-ui';
}
?>
/**
* Taxonomy: .
*/
$labels = [
"name" => __( "", "" ),
"singular_name" => __( "", "" ),
$label ) {
if ( ! empty( $label ) ) {
echo "\t\t" . '"' . esc_html( $key ) . '" => __( "' . esc_html( $label ) . '", "' . esc_html( $textdomain ) . '" ),' . "\n";
}
}
?>
];
$args = [
"label" => __( "", "" ),
"labels" => $labels,
"public" => ,
"publicly_queryable" => ,
"hierarchical" => ,
"show_ui" => ,
"show_in_menu" => ,
"show_in_nav_menus" => ,
"query_var" => ,
"rewrite" => ,
"show_admin_column" => ,
"show_in_rest" => ,
"rest_base" => "",
"rest_controller_class" => "",
"show_in_quick_edit" => ,
"show_in_graphql" => ,
"graphql_single_name" => "",
"graphql_plural_name" => "",
"show_in_graphql" => ,
"meta_box_cb" => ,
"default_term" => ,
];
register_taxonomy( "", , $args );
function () {
}
add_action( 'init', '' );
"' . $post_type['name'] . '",';
if ( ! empty( $post_type['rewrite_slug'] ) ) {
$rewrite_slug = ' "slug" => "' . $post_type['rewrite_slug'] . '",';
}
$withfront = disp_boolean( $post_type['rewrite_withfront'] );
if ( ! empty( $withfront ) ) {
$rewrite_withfront = ' "with_front" => ' . $withfront . ' ';
}
if ( ! empty( $post_type['rewrite_slug'] ) || ! empty( $post_type['rewrite_withfront'] ) ) {
$rewrite_start = '[';
$rewrite_end = ']';
$rewrite = $rewrite_start . $rewrite_slug . $rewrite_withfront . $rewrite_end;
}
} else {
$rewrite = disp_boolean( $post_type['rewrite'] );
}
$has_archive = get_disp_boolean( $post_type['has_archive'] );
if ( false !== $has_archive ) {
$has_archive = disp_boolean( $post_type['has_archive'] );
if ( ! empty( $post_type['has_archive_string'] ) ) {
$has_archive = '"' . $post_type['has_archive_string'] . '"';
}
} else {
$has_archive = disp_boolean( $post_type['has_archive'] );
}
$supports = '';
// Do a little bit of php work to get these into strings.
if ( ! empty( $post_type['supports'] ) && is_array( $post_type['supports'] ) ) {
$supports = '[ "' . implode( '", "', $post_type['supports'] ) . '" ]';
}
if ( in_array( 'none', $post_type['supports'], true ) ) {
$supports = 'false';
}
$taxonomies = '';
if ( ! empty( $post_type['taxonomies'] ) && is_array( $post_type['taxonomies'] ) ) {
$taxonomies = '[ "' . implode( '", "', $post_type['taxonomies'] ) . '" ]';
}
if ( in_array( $post_type['query_var'], [ 'true', 'false', '0', '1' ], true ) ) {
$post_type['query_var'] = disp_boolean( $post_type['query_var'] );
}
if ( ! empty( $post_type['query_var_slug'] ) ) {
$post_type['query_var'] = '"' . $post_type['query_var_slug'] . '"';
}
if ( empty( $post_type['show_in_rest'] ) ) {
$post_type['show_in_rest'] = 'false';
}
$rest_controller_class = ! empty( $post_type['rest_controller_class'] ) ? $post_type['rest_controller_class'] : 'WP_REST_Posts_Controller';
$show_in_menu = get_disp_boolean( $post_type['show_in_menu'] );
if ( false !== $show_in_menu ) {
$show_in_menu = disp_boolean( $post_type['show_in_menu'] );
if ( ! empty( $post_type['show_in_menu_string'] ) ) {
$show_in_menu = '"' . $post_type['show_in_menu_string'] . '"';
}
} else {
$show_in_menu = disp_boolean( $post_type['show_in_menu'] );
}
$delete_with_user = 'false';
if ( isset( $post_type['delete_with_user'] ) ) {
$delete_with_user = disp_boolean( $post_type['delete_with_user'] );
}
$public = isset( $post_type['public'] ) ? disp_boolean( $post_type['public'] ) : 'true';
$show_in_nav_menus = ( ! empty( $post_type['show_in_nav_menus'] ) && false !== get_disp_boolean( $post_type['show_in_nav_menus'] ) ) ? 'true' : 'false';
if ( empty( $post_type['show_in_nav_menus'] ) ) {
$show_in_nav_menus = $public;
}
$capability_type = '"post"';
if ( ! empty( $post_type['capability_type'] ) ) {
$capability_type = '"' . $post_type['capability_type'] . '"';
if ( false !== strpos( $post_type['capability_type'], ',' ) ) {
$caps = array_map( 'trim', explode( ',', $post_type['capability_type'] ) );
if ( count( $caps ) > 2 ) {
$caps = array_slice( $caps, 0, 2 );
}
$capability_type = '[ "' . $caps[0] . '", "' . $caps[1] . '" ]';
}
}
$post_type['description'] = addslashes( $post_type['description'] );
$my_theme = wp_get_theme();
$textdomain = $my_theme->get( 'TextDomain' );
if ( empty( $textdomain ) ) {
$textdomain = 'custom-post-type-ui';
}
?>
/**
* Post Type: .
*/
$labels = [
"name" => __( "", "" ),
"singular_name" => __( "", "" ),
$label ) {
if ( ! empty( $label ) ) {
if ( 'parent' === $key && ! array_key_exists( 'parent_item_colon', $post_type['labels'] ) ) {
// Fix for incorrect label key. See #439.
echo "\t\t" . '"' . 'parent_item_colon' . '" => __( "' . $label . '", "' . $textdomain . '" ),' . "\n";
} else {
echo "\t\t" . '"' . $key . '" => __( "' . $label . '", "' . $textdomain . '" ),' . "\n";
}
}
}
?>
];
$args = [
"label" => __( "", "" ),
"labels" => $labels,
"description" => "",
"public" => ,
"publicly_queryable" => ,
"show_ui" => ,
"show_in_rest" => ,
"rest_base" => "",
"rest_controller_class" => "",
"has_archive" => ,
"show_in_menu" => ,
"show_in_nav_menus" => ,
"delete_with_user" => ,
"exclude_from_search" => ,
"capability_type" => ,
"map_meta_cap" => ,
"hierarchical" => ,
"rewrite" => ,
"query_var" => ,
"menu_position" => ,
"menu_icon" => "",
"supports" => ,
"taxonomies" => ,
"yarpp_support" => ,
"show_in_graphql" => ,
"graphql_single_name" => "",
"graphql_plural_name" => "",
"show_in_graphql" => ,
];
register_post_type( "", $args );
%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' )
);
?>
';
$debuginfo->tab_site_info();
wp_nonce_field( 'cptui_debuginfo_nonce_action', 'cptui_debuginfo_nonce_field' );
if ( ! empty( $_POST ) && isset( $_POST['cptui_debug_info_email'] ) && isset( $_POST['cptui_debuginfo_nonce_field'] ) ) {
wp_verify_nonce( 'cptui_debuginfo_nonce_field', 'cptui_debuginfo_nonce_action' );
$email_args = [];
$email_args['email'] = sanitize_text_field( $_POST['cptui_debug_info_email'] );
$debuginfo->send_email( $email_args );
}
echo '' . esc_html__( 'Please provide an email address to send debug information to: ', 'custom-post-type-ui' ) . '
';
/**
* Filters the text value to use on the button when sending debug information.
*
* @since 1.2.0
*
* @param string $value Text to use for the button.
*/
echo '
';
echo '';
/**
* Fires after the display of the site information.
*
* @since 1.3.0
*/
do_action( 'cptui_after_site_info' );
}
/**
* Renders various tab sections for the Tools page, based on current tab.
*
* @since 1.2.0
*
* @internal
*
* @param string $tab Current tab to display.
*/
function cptui_render_tools( $tab ) {
if ( isset( $tab ) ) {
if ( 'post_types' === $tab || 'taxonomies' === $tab ) {
cptui_render_posttypes_taxonomies_section();
}
if ( 'get_code' === $tab ) {
cptui_render_getcode_section();
}
if ( 'debuginfo' === $tab ) {
cptui_render_debuginfo_section();
}
}
}
add_action( 'cptui_tools_sections', 'cptui_render_tools' );
/**
* Handle the import of transferred post types and taxonomies.
*
* @since 1.5.0
*/
function cptui_do_import_types_taxes() {
if ( ! empty( $_POST ) &&
( ! empty( $_POST['cptui_post_import'] ) && isset( $_POST['cptui_post_import'] ) ) ||
( ! empty( $_POST['cptui_tax_import'] ) && isset( $_POST['cptui_tax_import'] ) )
) {
$success = cptui_import_types_taxes_settings( $_POST );
add_action( 'admin_notices', "cptui_{$success}_admin_notice" );
}
}
add_action( 'init', 'cptui_do_import_types_taxes', 8 );