\d+)', array( 'methods' => 'GET', 'permission_callback' => $can, 'callback' => static function ( \WP_REST_Request $r ) { return rest_ensure_response( Smartcodes::catalog( (int) $r['id'] ) ); }, ) ); register_rest_route( 'fwren/v1', '/forms/(?P\d+)/schema', array( 'methods' => 'GET', 'permission_callback' => $can, 'callback' => static function ( \WP_REST_Request $r ) { return rest_ensure_response( Schema::get( (int) $r['id'] ) ); }, ) ); register_rest_route( 'fwren/v1', '/entries/(?P\d+)', array( 'methods' => 'GET', 'permission_callback' => static function () { return current_user_can( 'fwren_view_entries' ); }, 'callback' => static function ( \WP_REST_Request $r ) { $e = Entries::get( (int) $r['id'] ); return $e ? rest_ensure_response( $e ) : new \WP_Error( 'fwren_not_found', 'Not found', array( 'status' => 404 ) ); }, ) ); register_rest_route( 'fwren/v1', '/entries', array( 'methods' => 'GET', 'permission_callback' => static function () { return current_user_can( 'fwren_view_entries' ); }, 'callback' => static function ( \WP_REST_Request $r ) { list( $rows, $total ) = Entries::query( array( 'form_id' => (int) $r->get_param( 'form_id' ), 'status' => sanitize_key( (string) $r->get_param( 'status' ) ), 'search' => sanitize_text_field( (string) $r->get_param( 'search' ) ), 'per_page' => min( 100, max( 1, (int) ( $r->get_param( 'per_page' ) ? $r->get_param( 'per_page' ) : 20 ) ) ), 'page' => max( 1, (int) $r->get_param( 'page' ) ), ) ); $resp = rest_ensure_response( $rows ); $resp->header( 'X-WP-Total', (string) $total ); return $resp; }, ) ); } /** Viewing a form post itself (preview / landing page without the module): print the form. */ public static function single_placeholder( $content ) { if ( is_singular( Plugin::POST_TYPE ) && in_the_loop() && is_main_query() ) { return ''; } return $content; } /** Replace the placeholder after every other filter (wpautop would break the markup). */ public static function single_render( $content ) { if ( false !== strpos( (string) $content, '' ) ) { return str_replace( '', Renderer::render( get_the_ID() ), $content ); } return $content; } }