'GET', 'callback' => 'addifect_get_post_types', 'permission_callback' => 'addifect_can_access_editor_api', ) ); } ); /** * Get available post types for Addifect editor with granular permission filtering. * * @return WP_REST_Response */ function addifect_get_post_types() { $site_options = get_option( 'addifect_site_options', array() ); $post_types = array(); // 1. LOCK: Add Addifect design files ONLY for high-level users. // phpcs:ignore WordPress.WP.Capabilities.Unknown if ( current_user_can( 'addifect_edit_design_files' ) || current_user_can( 'manage_options' ) ) { $post_types[] = array( 'id' => 'addifect_design', 'label' => __( 'Designs', 'addifect' ), 'type' => 'design', ); } // 2. Add Standard Posts (Filtered by user capability). if ( current_user_can( 'edit_posts' ) ) { $post_types[] = array( 'id' => 'post', 'label' => __( 'Posts', 'addifect' ), 'type' => 'post', ); } // 3. Add Standard Pages (Filtered by user capability). if ( current_user_can( 'edit_pages' ) ) { $post_types[] = array( 'id' => 'page', 'label' => __( 'Pages', 'addifect' ), 'type' => 'page', ); } // 4. Custom post types from site options. if ( ! empty( $site_options['custom_posts'] ) && is_array( $site_options['custom_posts'] ) ) { foreach ( $site_options['custom_posts'] as $post_type ) { if ( empty( $post_type['id'] ) || empty( $post_type['type'] ) ) { continue; } // Determine the actual WP capability for this custom type if possible. // If it's a virtual type, we default to 'edit_posts'. $capability = 'edit_posts'; if ( current_user_can( $capability ) ) { $label = ! empty( $post_type['labelPlural'] ) ? $post_type['labelPlural'] : $post_type['labelSingle']; $post_types[] = array( 'id' => 'addifect_cp_' . sanitize_key( $post_type['id'] ), 'label' => sanitize_text_field( $label ), 'type' => sanitize_key( $post_type['type'] ), ); } } } return new WP_REST_Response( $post_types, 200 ); }