should_adjust_meta_caps_return_early( $caps, $cap, $user_id, $args ) ) { return $caps; } // $args[0] could be a post ID or a post_type string. if ( is_int( $args[0] ) ) { $_post = get_post( $args[0] ); if ( ! empty( $_post ) ) { $post_type = get_post_type_object( $_post->post_type ); } } elseif ( is_string( $args[0] ) ) { $post_type = get_post_type_object( $args[0] ); } // no post type found, bail. if ( empty( $post_type ) ) { return $caps; } // reset the needed caps. $caps = array(); // Add 'do_not_allow' cap if user is spam or deleted. if ( bbp_is_user_inactive( $user_id ) ) { $caps[] = 'do_not_allow'; // Moderators can always edit meta. } elseif ( user_can( $user_id, 'moderate' ) ) { $caps[] = 'moderate'; // Unknown so map to edit_posts. } else { $caps[] = $post_type->cap->edit_posts; } return $caps; } /** * Should adjust_meta_caps return early? * * @param array $caps Capabilities for meta capability. * @param string $cap Capability name. * @param int $user_id User id. * @param array $args Arguments. * * @return bool */ private function should_adjust_meta_caps_return_early( $caps, $cap, $user_id, $args ) { // only run for REST API requests. if ( ! defined( 'REST_API_REQUEST' ) || ! REST_API_REQUEST ) { return true; } // only modify caps for meta caps and for bbPress meta keys. if ( ! in_array( $cap, array( 'edit_post_meta', 'delete_post_meta', 'add_post_meta' ), true ) || empty( $args[1] ) || false === strpos( $args[1], '_bbp_' ) ) { return true; } return false; } }