Created
February 23, 2022 04:53
-
-
Save victormattosvm/5ad95b733bd16108b772f070f77baad5 to your computer and use it in GitHub Desktop.
How to bypass X-WP-Nonce in WP Rest API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_filter( | |
| 'determine_current_user', | |
| function( $user_id ) { | |
| $expression = '/wordpress_logged_in/'; | |
| $matches = preg_grep( $expression, array_keys( $_COOKIE ) ); | |
| foreach ( $_COOKIE as $cookie_key => $cookie_value ) { | |
| if ( in_array( $cookie_key, $matches, true ) ) { | |
| $logged_in_cookie = $cookie_key; | |
| } | |
| } | |
| if( ! $logged_in_cookie || ! $_COOKIE[ $logged_in_cookie ] ){ | |
| return $user_id; | |
| } | |
| remove_action( 'auth_cookie_valid', 'rest_cookie_collect_status' ); | |
| $user_id = wp_validate_auth_cookie( $_COOKIE[ $logged_in_cookie ], 'logged_in' ); | |
| return $user_id; | |
| } | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment