Making WordPress.org


Ignore:
Timestamp:
04/30/2024 05:26:07 AM (3 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.

File:
1 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();
Note: See TracChangeset for help on using the changeset viewer.