Changeset 9666
- Timestamp:
- 04/01/2020 02:23:09 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-favorites.php
r6287 r9666 34 34 'permission_callback' => 'is_user_logged_in', 35 35 ) ); 36 37 add_filter( 'rest_pre_echo_response', [ $this, 'override_cookie_expired_message' ], 10, 3 ); 38 } 39 40 /** 41 * Redirect back to the plugins page when this endpoint is accessed with an invalid nonce. 42 */ 43 function override_cookie_expired_message( $result, $obj, $request ) { 44 if ( 45 is_array( $result ) && isset( $result['code'] ) && 46 'rest_cookie_invalid_nonce' == $result['code'] && 47 preg_match( '!^/plugins/v1/plugin/([^/]+)/favorite$!', $request->get_route(), $m ) 48 ) { 49 $location = get_permalink( Plugin_Directory::get_plugin_post( $m[1] ) ) ?: home_url( '/' ); 50 header( "Location: $location" ); 51 // Still allow the REST API response to be rendered, browsers will follow the location header though. 52 } 53 54 return $result; 36 55 } 37 56
Note: See TracChangeset
for help on using the changeset viewer.