Changeset 13620
- Timestamp:
- 04/30/2024 05:26:07 AM (10 months ago)
- 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 7 7 use WordPressdotorg\Plugin_Directory\Tools; 8 8 use WordPressdotorg\Plugin_Directory\API\Base; 9 use function WordPressdotorg\Plugin_Directory\Theme\get_plugin_status_notice; 9 10 use WP_REST_Server; 10 11 … … 39 40 */ 40 41 function plugin_info( $request ) { 42 global $post; 41 43 $post = Plugin_Directory::get_plugin_post( $request['plugin_slug'] ); 42 44 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 ) { 44 70 // Copy what the REST API does if the param is incorrect 45 71 return new \WP_Error( … … 69 95 */ 70 96 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; 79 101 80 102 $result = array(); -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php
r13396 r13620 1060 1060 */ 1061 1061 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 ) { 1062 1071 $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; 1074 1100 } 1075 1101 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/standalone/class-plugins-info-api.php
r13106 r13620 137 137 } 138 138 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 } 141 143 142 144 $this->output( (object) $response ); … … 256 258 ), true 257 259 ); 260 261 // Don't include unknown plugins OR closed plugins. 258 262 if ( isset( $plugin['error'] ) ) { 259 263 unset( $response['plugins'][ $i ] ); -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins-2024/inc/template-tags.php
r13600 r13620 209 209 case 'disabled': 210 210 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'] ) { 215 214 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 ); 218 220 } 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 ); 221 226 } 222 227 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 229 228 // If we're closed, it may be permanent. 230 if ( $ permanent) {229 if ( $close_data['permanent'] ) { 231 230 $message .= ' ' . __( 'This closure is permanent.', 'wporg-plugins' ); 232 } elseif ( $days_passed < 60) {231 } elseif ( ! $close_data['public'] ) { 233 232 $message .= ' ' . __( 'This closure is temporary, pending a full review.', 'wporg-plugins' ); 234 233 } 235 234 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'] ) { 238 237 /* 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'] ); 240 239 } 241 240 } else {
Note: See TracChangeset
for help on using the changeset viewer.