get_param( 'post_type' ); // 1. Basic auth check. if ( ! is_user_logged_in() ) { return false; } // 2. Administrators can always view everything. if ( current_user_can( 'manage_options' ) ) { return true; } $post_type_object = get_post_type_object( $post_type ); // 3. Fallback for Addifect specific design types. $addifect_types = array( 'addifect_design' ); if ( in_array( $post_type, $addifect_types, true ) ) { return current_user_can( 'addifect_edit_design_files' ); } // 4. Handle standard post types (posts, pages, etc.). if ( $post_type_object ) { return current_user_can( $post_type_object->cap->edit_posts ); } return false; } /** * Check if the user is allowed to access the editor's post type list. * * @return bool True if they can edit posts, pages, or designs. */ function addifect_can_access_editor_api() { return is_user_logged_in() && ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) || current_user_can( 'addifect_edit_design_files' ) || current_user_can( 'manage_options' ) ); } /** * Permission callback for loading post data. * * @param WP_REST_Request $request Full details about the request. * @return bool|WP_Error */ function addifect_load_post_permission_check( $request ) { $post_id = (int) $request->get_param( 'id' ); $post = get_post( $post_id ); if ( ! $post ) { return new WP_Error( 'rest_post_invalid_id', __( 'Invalid post ID.', 'addifect' ), array( 'status' => 404 ) ); } /** * 1. Check for Addifect Design Post Type. * Requires the specific 'addifect_edit_design_files' capability. */ if ( 'addifect_design' === $post->post_type ) { return current_user_can( 'addifect_edit_design_files' ); } /** * 2. For other post types. * Check if the user has permission to edit the specific post ID. */ return current_user_can( 'edit_post', $post_id ); }