Making WordPress.org

Changeset 13620


Ignore:
Timestamp:
04/30/2024 05:26:07 AM (2 years ago)
Author:
dd32
Message:

Plugin Directory: Expose the plugin closed status through the plugin_information API endpoint.

This only applies to v1.2+ clients, as v1.0/1.1 expect a null response for any error case.

See #7057.

Location:
sites/trunk/wordpress.org/public_html/wp-content
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin.php

    r13610 r13620  
    77use WordPressdotorg\Plugin_Directory\Tools;
    88use WordPressdotorg\Plugin_Directory\API\Base;
     9use function WordPressdotorg\Plugin_Directory\Theme\get_plugin_status_notice;
    910use WP_REST_Server;
    1011
    … …  
    3940         */
    4041        function plugin_info( $request ) {
     42                global $post;
    4143                $post = Plugin_Directory::get_plugin_post( $request['plugin_slug'] );
    4244
    43                 if ( ! $post || 'publish' != $post->post_status ) {
     45                // Support returning API data in different locales, even on wordpress.org (for api.wordpress.org usage)
     46                if ( ! empty( $request['locale'] ) && ! in_array( strtolower( $request['locale'] ), array( 'en_us', 'en' ) ) ) {
     47                        switch_to_locale( $request['locale'] );
     48                }
     49
     50                if ( $post && in_array( $post->post_status, [ 'closed', 'disabled' ] ) ) {
     51                        $close_data = Template::get_close_data( $post );
     52
     53                        $close_text = '';
     54                        if ( is_callable( '\WordPressdotorg\Plugin_Directory\Theme\get_plugin_status_notice' ) ) {
     55                                $close_text = strip_tags( get_plugin_status_notice( $post ) );
     56                        }
     57
     58                        return [
     59                                'error'       => 'closed',
     60                                'name'        => get_the_title(),
     61                                'slug'        => $post->post_name,
     62                                'description' => $close_text,
     63                                'closed'      => true,
     64                                'closed_date' => $close_data['date'] ?: false,
     65                                'reason'      => $close_data['public'] ? $close_data['reason'] : false,
     66                                'reason_text' => $close_data['public'] ? $close_data['label'] : false,
     67                        ];
     68
     69                } elseif ( ! $post || 'publish' != $post->post_status ) {
    4470                        // Copy what the REST API does if the param is incorrect
    4571                        return new \WP_Error(
    … …  
    6995         */
    7096        public function plugin_info_data( $request, $post ) {
    71                 $GLOBALS['post'] = $post;
    72                 $plugin_slug     = $post->post_name;
    73                 $post_id         = $post->ID;
    74 
    75                 // Support returning API data in different locales, even on wordpress.org (for api.wordpress.org usage)
    76                 if ( ! empty( $request['locale'] ) && ! in_array( strtolower( $request['locale'] ), array( 'en_us', 'en' ) ) ) {
    77                         switch_to_locale( $request['locale'] );
    78                 }
     97                global $post;
     98
     99                $plugin_slug = $post->post_name;
     100                $post_id     = $post->ID;
    79101
    80102                $result            = array();
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php

    r13396 r13620  
    10601060         */
    10611061        public static function get_close_reason( $post = null ) {
     1062                return self::get_close_data( $post )['label'] ?? '';
     1063        }
     1064
     1065        /**
     1066         * Returns the close/disable data for a plugin.
     1067         *
     1068         * @param int|\WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
     1069         */
     1070        public static function get_close_data( $post = null ) {
    10621071                $post = get_post( $post );
    1063 
    1064                 $close_reasons = self::get_close_reasons();
    1065                 $close_reason  = (string) get_post_meta( $post->ID, '_close_reason', true );
    1066 
    1067                 if ( isset( $close_reasons[ $close_reason ] ) ) {
    1068                         $reason_label = $close_reasons[ $close_reason ];
    1069                 } else {
    1070                         $reason_label = _x( 'Unknown', 'unknown close reason', 'wporg-plugins' );
    1071                 }
    1072 
    1073                 return $reason_label;
     1072                if ( ! $post || ! in_array( $post->post_status, array( 'closed', 'disabled' ), true ) ) {
     1073                        return false;
     1074                }
     1075
     1076                $result = [
     1077                        'date'      => get_post_meta( $post->ID, 'plugin_closed_date', true ) ?: false,
     1078                        'reason'    => (string) get_post_meta( $post->ID, '_close_reason', true ),
     1079                        'label'     => '',
     1080                        'permanent' => false,
     1081                        'public'    => false,
     1082                ];
     1083
     1084                if (
     1085                        'author-request' === $result['reason'] ||
     1086                        ! Tools::get_plugin_committers( $post->post_name )
     1087                ) {
     1088                        $result['permanent'] = true;
     1089                }
     1090
     1091                $result['label'] = self::get_close_reasons()[ $result['reason'] ] ?? _x( 'Unknown', 'unknown close reason', 'wporg-plugins' );
     1092                $days_closed     = $result['date'] ? (int) ( ( time() - strtotime( $result['date'] ) ) / DAY_IN_SECONDS ) : false;
     1093
     1094                // If it's closed for more than 60 days, it's by author request, or we're unsure about the close date, it's publicly known.
     1095                if ( ! $result['date'] || $days_closed >= 60 || 'author-request' === $result['reason'] ) {
     1096                        $result['public'] = true;
     1097                }
     1098
     1099                return $result;
    10741100        }
    10751101
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/standalone/class-plugins-info-api.php

    r13106 r13620  
    137137                }
    138138
    139                 // Only include the fields requested.
    140                 $response = $this->remove_unexpected_fields( $response, $request, 'plugin_information' );
     139                // Only include the fields requested. If an error is present, we ignore the requested fields.
     140                if ( ! isset( $response['error'] ) ) {
     141                        $response = $this->remove_unexpected_fields( $response, $request, 'plugin_information' );
     142                }
    141143
    142144                $this->output( (object) $response );
    … …  
    256258                                ), true
    257259                        );
     260
     261                        // Don't include unknown plugins OR closed plugins.
    258262                        if ( isset( $plugin['error'] ) ) {
    259263                                unset( $response['plugins'][ $i ] );
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins-2024/inc/template-tags.php

    r13600 r13620  
    209209                case 'disabled':
    210210                case 'closed':
    211                         $closed_date  = get_post_meta( get_the_ID(), 'plugin_closed_date', true );
    212                         $close_reason = Template::get_close_reason( $post );
    213 
    214                         if ( $closed_date ) {
     211                        $close_data = Template::get_close_data( $post );
     212
     213                        if ( $close_data['date'] ) {
    215214                                if ( 'disabled' === $post_status && current_user_can( 'plugin_approve' ) ) {
    216                                         /* translators: %s: plugin closing date */
    217                                         $message = sprintf( __( 'This plugin has been disabled as of %s -- this means it is closed, but actively serving updates.', 'wporg-plugins' ), mysql2date( get_option( 'date_format' ), $closed_date ) );
     215                                        $message = sprintf(
     216                                                /* translators: %s: plugin closing date */
     217                                                __( 'This plugin has been disabled as of %s -- this means it is closed, but actively serving updates.', 'wporg-plugins' ),
     218                                                mysql2date( get_option( 'date_format' ), $close_data['date'] )
     219                                        );
    218220                                } else {
    219                                         /* translators: %s: plugin closing date */
    220                                         $message = sprintf( __( 'This plugin has been closed as of %s and is not available for download.', 'wporg-plugins' ), mysql2date( get_option( 'date_format' ), $closed_date ) );
     221                                        $message = sprintf(
     222                                                /* translators: %s: plugin closing date */
     223                                                __( 'This plugin has been closed as of %s and is not available for download.', 'wporg-plugins' ),
     224                                                mysql2date( get_option( 'date_format' ), $close_data['date'] )
     225                                        );
    221226                                }
    222227
    223                                 // Determine permanence of closure.
    224                                 $committers = Tools::get_plugin_committers( $post->post_name );
    225                                 $permanent  = ( __( 'Author Request', 'wporg-plugins' ) === $close_reason || ! $committers );
    226 
    227                                 $days_passed = (int) ( ( current_time( 'timestamp' ) - mysql2date( 'U', $closed_date ) ) / DAY_IN_SECONDS );
    228 
    229228                                // If we're closed, it may be permanent.
    230                                 if ( $permanent ) {
     229                                if ( $close_data['permanent'] ) {
    231230                                        $message .= ' ' . __( 'This closure is permanent.', 'wporg-plugins' );
    232                                 } elseif ( $days_passed < 60 ) {
     231                                } elseif ( ! $close_data['public'] ) {
    233232                                        $message .= ' ' . __( 'This closure is temporary, pending a full review.', 'wporg-plugins' );
    234233                                }
    235234
    236                                 // Display close reason if more than 60 days have passed.
    237                                 if ( $days_passed >= 60 ) {
     235                                // Display close reason if it's now publicly known.
     236                                if ( $close_data['public'] && $close_data['reason'] ) {
    238237                                        /* translators: %s: plugin close/disable reason */
    239                                         $message .= ' ' . sprintf( __( 'Reason: %s.', 'wporg-plugins' ), $close_reason );
     238                                        $message .= ' ' . sprintf( __( 'Reason: %s.', 'wporg-plugins' ), $close_data['label'] );
    240239                                }
    241240                        } else {
Note: See TracChangeset for help on using the changeset viewer.