_x( 'Imports', 'Post Type General Name', 'admin-help-docs' ), 'singular_name' => _x( 'Import', 'Post Type Singular Name', 'admin-help-docs' ), 'menu_name' => __( 'Imports', 'admin-help-docs' ), 'name_admin_bar' => __( 'Imports', 'admin-help-docs' ), 'archives' => __( 'Import Archives', 'admin-help-docs' ), 'attributes' => __( 'Import Attributes', 'admin-help-docs' ), 'parent_item_colon' => __( 'Parent Import:', 'admin-help-docs' ), 'all_items' => __( 'All Imports', 'admin-help-docs' ), 'add_new_item' => __( 'Add New Import', 'admin-help-docs' ), 'add_new' => __( 'Add New', 'admin-help-docs' ), 'new_item' => __( 'New Import', 'admin-help-docs' ), 'edit_item' => __( 'Edit Import', 'admin-help-docs' ), 'update_item' => __( 'Update Import', 'admin-help-docs' ), 'view_item' => __( 'View Import', 'admin-help-docs' ), 'view_items' => __( 'View Imports', 'admin-help-docs' ), 'search_items' => __( 'Search Imports', 'admin-help-docs' ), 'not_found' => __( 'Not found', 'admin-help-docs' ), 'not_found_in_trash' => __( 'Not found in Trash', 'admin-help-docs' ), 'insert_into_item' => __( 'Insert into import', 'admin-help-docs' ), 'uploaded_to_this_item' => __( 'Uploaded to this import', 'admin-help-docs' ), 'items_list' => __( 'Import list', 'admin-help-docs' ), 'items_list_navigation' => __( 'Import list navigation', 'admin-help-docs' ), 'filter_items_list' => __( 'Filter import list', 'admin-help-docs' ), ]; // Allow filter for supports and taxonomies $supports = apply_filters( 'helpdocs_imports_supports', [ 'title', 'excerpt' ] ); $taxonomies = apply_filters( 'helpdocs_imports_taxonomies', [] ); // Set the CPT args $args = [ 'label' => __( 'Imports', 'admin-help-docs' ), 'description' => __( 'Imports', 'admin-help-docs' ), 'labels' => $labels, 'supports' => $supports, 'taxonomies' => $taxonomies, 'public' => true, 'show_ui' => true, 'show_in_menu' => false, 'show_in_admin_bar' => false, 'show_in_nav_menus' => false, 'can_export' => true, 'has_archive' => false, 'exclude_from_search' => true, 'publicly_queryable' => false, 'query_var' => self::$post_type, 'capability_type' => 'post', 'show_in_rest' => false, ]; // Register the CPT register_post_type( self::$post_type, $args ); } // End register_post_type() /** * Add the header to the top of the admin list page * * @return void */ public function add_header() { $screen = get_current_screen(); if ( 'edit-' . self::$post_type === $screen->id ) { add_action( 'in_admin_header', function() { include Bootstrap::path( 'inc/header.php' ); } ); } } // End add_header() /** * Add a search box to the subheader on the folders page * * @param string $current_tab The current admin tab * @return void */ public function render_search_box( string $current_tab ) { if ( $current_tab !== 'imports' ) { return; } $search_value = sanitize_text_field( wp_unslash( $_GET[ 's' ] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>
post_type === self::$post_type ) { return add_query_arg( [ 'id' => $post_id ], Bootstrap::tab_url( 'import' ) ); } return $link; } // End redirect_import_edit_link() /** * If a user manually tries to go to post-new.php for our CPT, * or clicks the "Add New" on the list table, bounce them to our tab. */ public function redirect_new_post_screen() { global $pagenow; if ( 'post-new.php' === $pagenow && isset( $_GET[ 'post_type' ] ) && sanitize_text_field( wp_unslash( $_GET[ 'post_type' ] ) ) === self::$post_type ) { // phpcs:ignore wp_safe_redirect( Bootstrap::tab_url( 'editor' ) ); exit; } if ( 'post.php' === $pagenow && isset( $_GET[ 'post' ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $action = isset( $_GET[ 'action' ] ) ? sanitize_text_field( wp_unslash( $_GET[ 'action' ] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( ! empty( $action ) && 'edit' !== $action ) { return; } $post_id = isset( $_GET[ 'post' ] ) ? absint( wp_unslash( $_GET[ 'post' ] ) ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Recommended $post = get_post( $post_id ); if ( $post && $post->post_type === self::$post_type ) { wp_safe_redirect( add_query_arg( [ 'id' => $post_id ], Bootstrap::tab_url( 'import' ) ) ); exit; } } } // End redirect_new_post_screen() /** * Admin columns * * @param array $columns * @return array */ public function admin_columns( $columns ) { $new_columns = [ 'cb' => $columns[ 'cb' ], 'helpdocs_status' => __( 'Status', 'admin-help-docs' ), ]; unset( $columns[ 'cb' ], $columns[ 'featured_image' ] ); $columns[ 'helpdocs_url' ] = __( 'URL', 'admin-help-docs' ); $columns[ 'helpdocs_all' ] = __( 'Import All?', 'admin-help-docs' ); return array_merge( $new_columns, $columns ); } // End admin_columns() /** * Admin column content * * @param string $column * @param int $post_id * @return void */ public function admin_column_content( $column, $post_id ) { // Status Toggle if ( 'helpdocs_status' === $column ) { $status = get_post_status( $post_id ); $is_published = ( 'publish' === $status ); $class = $is_published ? ' is-active' : ' is-inactive'; $label = $is_published ? __( 'Active', 'admin-help-docs' ) : __( 'Inactive', 'admin-help-docs' ); echo ''; } // URL if ( 'helpdocs_url' === $column ) { $website_url = get_post_meta( $post_id, 'helpdocs_url', true ); echo $website_url ? esc_url( $website_url ) : ''; $api_key = get_post_meta( $post_id, 'helpdocs_api_key', true ); if ( $api_key ) { echo '