| @@ -82,12 +82,20 @@ | ||
| 82 | 82 | 'methods' => \WP_REST_Server::READABLE, |
| 83 | 83 | 'callback' => array( $this, 'get_item' ), |
| 84 | 84 | 'permission_callback' => array( $this, 'permissions_check' ), |
| 85 | 85 | 'args' => array( |
| 86 | - 'id' => array( | |
| 86 | + 'id' => array( | |
| 87 | 87 | 'description' => __( 'Post ID.', 'top-10' ), |
| 88 | 88 | 'type' => 'integer', |
| 89 | 89 | ), |
| 90 | + 'lang' => array( | |
| 91 | + 'description' => __( 'TranslatePress language code to render the response in.', 'top-10' ), | |
| 92 | + 'type' => 'string', | |
| 93 | + 'sanitize_callback' => 'sanitize_text_field', | |
| 94 | + 'validate_callback' => static function ( $value ) { | |
| 95 | + return is_string( $value ) && strlen( $value ) <= 20; | |
| 96 | + }, | |
| 97 | + ), | |
| 90 | 98 | ), |
| 91 | 99 | ) |
| 92 | 100 | ); |
| 93 | 101 | register_rest_route( |
| @@ -153,8 +161,11 @@ | ||
| 153 | 161 | $popular_posts = array(); |
| 154 | 162 | |
| 155 | 163 | $args = $request->get_params(); |
| 156 | 164 | |
| 165 | + // Transport-only: the language must not reach the query or its cache key. | |
| 166 | + unset( $args['lang'] ); | |
| 167 | + | |
| 157 | 168 | /** |
| 158 | 169 | * Filter the REST API arguments before they passed to get_tptn_posts(). |
| 159 | 170 | * |
| 160 | 171 | * @since 3.0.0 |
| @@ -330,8 +341,16 @@ | ||
| 330 | 341 | 'description' => esc_html__( 'Scope under which the request is made; determines fields present in response.', 'top-10' ), |
| 331 | 342 | 'type' => 'string', |
| 332 | 343 | 'enum' => array( 'view', 'embed', 'edit' ), |
| 333 | 344 | 'default' => 'view', |
| 345 | + ), | |
| 346 | + 'lang' => array( | |
| 347 | + 'description' => esc_html__( 'TranslatePress language code to render the response in.', 'top-10' ), | |
| 348 | + 'type' => 'string', | |
| 349 | + 'sanitize_callback' => 'sanitize_text_field', | |
| 350 | + 'validate_callback' => static function ( $value ) { | |
| 351 | + return is_string( $value ) && strlen( $value ) <= 20; | |
| 352 | + }, | |
| 334 | 353 | ), |
| 335 | 354 | ); |
| 336 | 355 | |
| 337 | 356 | /** |