Making WordPress.org


Ignore:
Timestamp:
01/15/2024 05:23:52 AM (2 years ago)
Author:
dd32
Message:

Plugin Directory: Allow plugins to upload additional versions for review.

This is currently limited to new plugins, which is prior to the first human review.

Iterations upon this will open it to plugins in the pending state as well, which is during the human review.

See #7384.

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  
    2323            'methods'             => WP_REST_Server::EDITABLE,
    2424            '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' ),
    4038            'args' => [
    4139                'post_name' => [
    4240                    'type'     => 'string',
    4341                    'required' => true,
    44                 ]
     42                ],
    4543            ]
    4644        ) );
    4745    }
    4846
     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
    4963    public function upload( $request ) {
    5064        $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'] );
    5179        $slug   = trim( $request['post_name'] ?? '' );
    52 
    5380        $result = $this->perform_slug_change( $plugin, $slug );
    5481        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.
    5683            Tools::audit_log(
    5784                sprintf(
Note: See TracChangeset for help on using the changeset viewer.