Making WordPress.org


Ignore:
Timestamp:
04/30/2024 05:26:07 AM (12 months 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/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
Note: See TracChangeset for help on using the changeset viewer.