芝麻web文件管理V1.00
编辑当前文件:/home/ephorei/www/wp-content/plugins/sureforms/inc/forms-data.php
'GET', 'callback' => [ $this, 'load_forms' ], 'permission_callback' => [ $this, 'get_form_permissions_check' ], ] ); } /** * Checks whether a given request has permission to read the form. * * @return true|WP_Error True if the request has read access, WP_Error object otherwise. * @since 0.0.1 */ public function get_form_permissions_check() { if ( current_user_can( 'edit_posts' ) ) { return true; } return new \WP_Error( 'rest_cannot_view', __( 'Sorry, you are not allowed to view the form.', 'sureforms' ), [ 'status' => \rest_authorization_required_code() ] ); } /** * Handle Form status * * @param \WP_REST_Request $request Full details about the request. * * @return WP_REST_Response * @since 0.0.1 */ public function load_forms( $request ) { $nonce = Helper::get_string_value( $request->get_header( 'X-WP-Nonce' ) ); if ( ! wp_verify_nonce( sanitize_text_field( $nonce ), 'wp_rest' ) ) { wp_send_json_error( [ 'data' => __( 'Nonce verification failed.', 'sureforms' ), 'status' => false, ] ); } $args = [ 'post_type' => 'sureforms_form', 'post_status' => 'publish', 'posts_per_page' => -1, // Retrieve all posts. ]; $form_posts = get_posts( $args ); $data = []; foreach ( $form_posts as $post ) { $data[] = [ 'id' => $post->ID, 'title' => $post->post_title, 'content' => $post->post_content, ]; } return new WP_REST_Response( $data ); } }