__( 'Admin Guidance', 'ait-ai-admin-assistance' ), 'singular_name' => __( 'Guidance Item', 'ait-ai-admin-assistance' ), 'add_new' => __( 'Add New', 'ait-ai-admin-assistance' ), 'add_new_item' => __( 'Add New Guidance Item', 'ait-ai-admin-assistance' ), 'edit_item' => __( 'Edit Guidance Item', 'ait-ai-admin-assistance' ), 'new_item' => __( 'New Guidance Item', 'ait-ai-admin-assistance' ), 'view_item' => __( 'View Guidance Item', 'ait-ai-admin-assistance' ), 'search_items' => __( 'Search Guidance Items', 'ait-ai-admin-assistance' ), 'not_found' => __( 'No guidance items found', 'ait-ai-admin-assistance' ), 'not_found_in_trash' => __( 'No guidance items found in Trash', 'ait-ai-admin-assistance' ), 'menu_name' => __( 'Admin Guidance', 'ait-ai-admin-assistance' ), ); register_post_type( self::CPT, array( 'labels' => $labels, 'public' => false, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 59, // above Appearance (60) 'menu_icon' => 'dashicons-editor-help', 'supports' => array( 'title', 'editor' ), 'capability_type' => 'post', 'map_meta_cap' => true, 'has_archive' => false, ) ); } public function register_table_columns( $columns ) { // Keep checkbox + title at the front. $new = array(); if ( isset( $columns['cb'] ) ) { $new['cb'] = $columns['cb']; } if ( isset( $columns['title'] ) ) { $new['title'] = $columns['title']; } $new['ait_aiaa_priority'] = __( 'Priority', 'ait-ai-admin-assistance' ); $new['ait_aiaa_target_type'] = __( 'Target Type', 'ait-ai-admin-assistance' ); $new['ait_aiaa_field_level'] = __( 'Field-level', 'ait-ai-admin-assistance' ); $new['ait_aiaa_hide_roles'] = __( 'Hide for Roles', 'ait-ai-admin-assistance' ); // Append any remaining columns (e.g. date). foreach ( $columns as $k => $v ) { if ( isset( $new[ $k ] ) ) { continue; } $new[ $k ] = $v; } return $new; } public function render_table_column( $column, $post_id ) { if ( 'ait_aiaa_priority' === $column ) { $priority = get_post_meta( $post_id, '_ait_ag_priority', true ); if ( '' === $priority ) { $priority = '1'; } echo esc_html( $priority ); return; } if ( 'ait_aiaa_target_type' === $column ) { $target_type = get_post_meta( $post_id, '_ait_ag_target_type', true ); if ( '' === $target_type ) { $target_type = 'global'; } $map = array( 'global' => __( 'Global', 'ait-ai-admin-assistance' ), 'screen' => __( 'Screen', 'ait-ai-admin-assistance' ), 'post_type' => __( 'Post Type', 'ait-ai-admin-assistance' ), 'taxonomy' => __( 'Taxonomy', 'ait-ai-admin-assistance' ), ); $label = isset( $map[ $target_type ] ) ? $map[ $target_type ] : $target_type; // Add a small hint value where helpful. if ( 'screen' === $target_type ) { $sid = get_post_meta( $post_id, '_ait_ag_screen_id', true ); if ( $sid ) { $label .= ' — ' . $sid; } } elseif ( 'post_type' === $target_type ) { $pts = get_post_meta( $post_id, '_ait_ag_post_types', true ); if ( is_array( $pts ) && ! empty( $pts ) ) { $label .= ' — ' . implode( ', ', $pts ); } } elseif ( 'taxonomy' === $target_type ) { $tax = get_post_meta( $post_id, '_ait_ag_taxonomies', true ); if ( is_array( $tax ) && ! empty( $tax ) ) { $label .= ' — ' . implode( ', ', $tax ); } } echo esc_html( $label ); return; } if ( 'ait_aiaa_field_level' === $column ) { $selectors = get_post_meta( $post_id, '_ait_ag_field_selectors', true ); $has = ( is_string( $selectors ) && trim( $selectors ) !== '' ); echo $has ? esc_html__( 'Yes', 'ait-ai-admin-assistance' ) : '—'; return; } if ( 'ait_aiaa_hide_roles' === $column ) { $hide_roles = get_post_meta( $post_id, '_ait_ag_hide_roles', true ); if ( ! is_array( $hide_roles ) ) { $hide_roles = array(); } if ( empty( $hide_roles ) ) { echo '—'; return; } $wp_roles = function_exists( 'wp_roles' ) ? wp_roles() : null; $all_roles = ( $wp_roles && isset( $wp_roles->roles ) && is_array( $wp_roles->roles ) ) ? $wp_roles->roles : array(); $names = array(); foreach ( $hide_roles as $rk ) { if ( isset( $all_roles[ $rk ]['name'] ) ) { $names[] = $all_roles[ $rk ]['name']; } else { $names[] = $rk; } } echo esc_html( implode( ', ', $names ) ); return; } } public function add_meta_boxes() { add_meta_box( 'ait-aiaa-guidance-meta', __( 'Guidance Targeting', 'ait-ai-admin-assistance' ), array( $this, 'render_meta_box' ), self::CPT, 'side', 'default' ); } public function render_meta_box( $post ) { wp_nonce_field( 'ait_aiaa_guidance_meta', 'ait_aiaa_guidance_meta_nonce' ); $enabled = get_post_meta( $post->ID, '_ait_ag_enabled', true ); $priority = get_post_meta( $post->ID, '_ait_ag_priority', true ); $target_type = get_post_meta( $post->ID, '_ait_ag_target_type', true ); $screen_id = get_post_meta( $post->ID, '_ait_ag_screen_id', true ); // New multi-select fields. $post_types = get_post_meta( $post->ID, '_ait_ag_post_types', true ); $taxonomies = get_post_meta( $post->ID, '_ait_ag_taxonomies', true ); $field_selectors = get_post_meta( $post->ID, '_ait_ag_field_selectors', true ); $field_selectors = is_string( $field_selectors ) ? $field_selectors : ''; // Back-compat with old single post_type field. if ( ( empty( $post_types ) || ! is_array( $post_types ) ) ) { $old_post_type = get_post_meta( $post->ID, '_ait_ag_post_type', true ); if ( ! empty( $old_post_type ) && is_string( $old_post_type ) ) { $post_types = array( $old_post_type ); } } if ( ! is_array( $post_types ) ) { $post_types = array(); } if ( ! is_array( $taxonomies ) ) { $taxonomies = array(); } // Hide for roles. $hide_roles = get_post_meta( $post->ID, '_ait_ag_hide_roles', true ); if ( ! is_array( $hide_roles ) ) { $hide_roles = array(); } $wp_roles = function_exists( 'wp_roles' ) ? wp_roles() : null; $all_roles = ( $wp_roles && isset( $wp_roles->roles ) && is_array( $wp_roles->roles ) ) ? $wp_roles->roles : array(); if ( '' === $target_type ) { $target_type = 'global'; } if ( '' === $enabled ) { $enabled = '1'; } if ( '' === $priority ) { $priority = '10'; } $all_post_types = get_post_types( array( 'show_ui' => true ), 'objects' ); $all_taxonomies = get_taxonomies( array( 'show_ui' => true ), 'objects' ); ?>
$pt_obj ) : ?>
$tx_obj ) : ?>