Changeset 13109 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-upload.php
- Timestamp:
- 01/15/2024 05:23:52 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-upload.php
r12617 r13109 23 23 'methods' => WP_REST_Server::EDITABLE, 24 24 'callback' => array( $this, 'upload' ), 25 'permission_callback' => function( $request ) { 26 if ( 27 ! current_user_can( 'plugin_approve' ) && 28 get_current_user_id() != get_post_field( 'post_author', $request['ID'] ) 29 ) { 30 return false; 31 } 32 33 $post = get_post( $request['ID'] ); 34 if ( $post->ID != $request['ID'] || 'plugin' !== $post->post_type ) { 35 return false; 36 } 37 38 return true; 39 }, 25 'permission_callback' => array( $this, 'permission_check' ), 26 'args' => [ 27 'post_name' => [ 28 'type' => 'string', 29 'required' => false, 30 ], 31 ] 32 ) ); 33 34 register_rest_route( 'plugins/v1', '/upload/(?P<ID>[0-9]+)/slug', array( 35 'methods' => WP_REST_Server::EDITABLE, 36 'callback' => array( $this, 'slug' ), 37 'permission_callback' => array( $this, 'permission_check' ), 40 38 'args' => [ 41 39 'post_name' => [ 42 40 'type' => 'string', 43 41 'required' => true, 44 ] 42 ], 45 43 ] 46 44 ) ); 47 45 } 48 46 47 public function permission_check( $request ) { 48 if ( 49 ! current_user_can( 'plugin_approve' ) && 50 get_current_user_id() != get_post_field( 'post_author', $request['ID'] ) 51 ) { 52 return false; 53 } 54 55 $post = get_post( $request['ID'] ); 56 if ( $post->ID != $request['ID'] || 'plugin' !== $post->post_type ) { 57 return false; 58 } 59 60 return true; 61 } 62 49 63 public function upload( $request ) { 50 64 $plugin = get_post( $request['ID'] ); 65 66 if ( ! empty( $request['post_name'] ) ) { 67 return $this->slug( $request ); 68 69 } elseif ( ! empty( $_FILES['zip_file'] ) && current_user_can( 'plugin_approve' ) ) { 70 return ( new Upload_Handler() )->process_upload( $plugin->ID ); 71 } 72 } 73 74 /** 75 * Change the slug of a plugin. 76 */ 77 public function slug( $request ) { 78 $plugin = get_post( $request['ID'] ); 51 79 $slug = trim( $request['post_name'] ?? '' ); 52 53 80 $result = $this->perform_slug_change( $plugin, $slug ); 54 81 if ( is_wp_error( $result ) ) { 55 // Warn the reviewer when a plugin author has attempted to use an unavailable slug. 82 // Warn the reviewer when a plugin author has attempted to use an unavailable slug. 56 83 Tools::audit_log( 57 84 sprintf(
Note: See TracChangeset
for help on using the changeset viewer.