Changeset 14262 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-release-confirmation.php
- Timestamp:
- 12/11/2024 05:36:31 AM (18 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-release-confirmation.php
r14218 r14262 7 7 use WordPressdotorg\Plugin_Directory\Tools; 8 8 use WordPressdotorg\Plugin_Directory\Jobs\Plugin_Import; 9 use WordPressdotorg\Plugin_Directory\Shortcodes\Release_Confirmation as Release_Confirmation_Shortcode;10 9 use WordPressdotorg\Plugin_Directory\Email\Release_Confirmation_Enabled as Release_Confirmation_Enabled_Email; 11 use WordPressdotorg\Plugin_Directory\Email\Release_Confirmation_Access as Release_Confirmation_Access_Email; 10 use Two_Factor_Core; 11 use function WordPressdotorg\Two_Factor\Revalidation\{ 12 get_status as get_revalidation_status, 13 get_url as get_revalidation_url, 14 }; 12 15 13 16 /** … … 80 83 return false; 81 84 }, 82 ] );83 84 register_rest_route( 'plugins/v1', '/release-confirmation-access', [85 'methods' => \WP_REST_Server::READABLE,86 'callback' => [ $this, 'send_access_email' ],87 'args' => [88 ],89 'permission_callback' => 'is_user_logged_in',90 85 ] ); 91 86 … … 119 114 $plugin = Plugin_Directory::get_plugin_post( $request['plugin_slug'] ); 120 115 121 return ( 122 Release_Confirmation_Shortcode::can_access() && 123 current_user_can( 'plugin_manage_releases', $plugin ) 124 ); 116 if ( ! $plugin || ! current_user_can( 'plugin_manage_releases', $plugin ) ) { 117 return false; 118 } 119 120 // Check to see if they've confirmed their 2FA status recently.. 121 $status = get_revalidation_status(); 122 if ( $status && $status['can_save'] ) { 123 return true; 124 } 125 126 // Before we say no, check if the user just needs to validate their 2FA. 127 if ( $status && $status['needs_revalidate'] && 'GET' === $request->get_method() ) { 128 $current_rest_url = add_query_arg( 129 array( 130 '_wpnonce' => wp_create_nonce( 'wp_rest' ), 131 '_wp_http_referer' => wp_get_referer(), 132 ), 133 get_rest_url( null, $request->get_route() ) 134 ); 135 136 wp_safe_redirect( get_revalidation_url( $current_rest_url ) ); 137 exit; 138 } 139 140 return false; 125 141 } 126 142 … … 300 316 } 301 317 302 /**303 * Send a Access email304 */305 public function send_access_email( $request ) {306 $result = [307 'location' => wp_get_referer() ?: home_url( '/developers/releases/' ),308 ];309 $result['location'] = add_query_arg( 'send_access_email', '1', $result['location'] );310 header( 'Location: ' . $result['location'] );311 312 $email = new Release_Confirmation_Access_Email(313 wp_get_current_user()314 );315 $result['sent'] = $email->send();316 317 return $result;318 }319 320 318 public function validate_plugin_tag_callback( $tag, $request ) { 321 319 $plugin = Plugin_Directory::get_plugin_post( $request['plugin_slug'] );
Note: See TracChangeset
for help on using the changeset viewer.