Changeset 4423
- Timestamp:
- 11/26/2016 03:47:38 AM (8 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php
r4422 r4423 50 50 add_filter( 'oembed_providers', array( $this, 'oembed_whitelist' ) ); 51 51 52 // Shim in postmeta support for data which doesn't yet live in postmeta. 53 add_filter( 'get_post_metadata', array( $this, 'filter_shim_postmeta' ), 10, 3 ); 54 52 // Capability mapping 55 53 add_filter( 'map_meta_cap', array( __NAMESPACE__ . '\Capabilities', 'map_meta_cap' ), 10, 4 ); 56 54 … … 951 949 return false; 952 950 } ); 953 }954 955 /**956 * Shim in some postmeta values which get retrieved from other locations temporarily.957 *958 * @param null|array|string $value The value get_metadata() should return - a single metadata value,959 * or an array of values.960 * @param int $object_id Object ID.961 * @param string $meta_key Meta key.962 * @return array963 */964 public function filter_shim_postmeta( $value, $object_id, $meta_key ) {965 switch ( $meta_key ) {966 case 'tested':967 // For the tested field, we bump up the minor release to the latest compatible minor release.968 if ( function_exists( 'wporg_get_version_equivalents' ) ) {969 970 // As we're on a pre-filter, we'll have to detach, fetch and reattach..971 remove_filter( 'get_post_metadata', array( $this, 'filter_shim_postmeta' ) );972 $value = get_metadata( 'post', $object_id, $meta_key );973 add_filter( 'get_post_metadata', array( $this, 'filter_shim_postmeta' ), 10, 3 );974 975 foreach ( wporg_get_version_equivalents() as $latest_compatible_version => $compatible_with ) {976 if ( in_array( (string)$value[0], $compatible_with, true ) ) {977 $value[0] = $latest_compatible_version;978 break;979 }980 }981 }982 break;983 984 case false:985 986 // In the event $meta_key is false, the caller wants all meta fields, so we'll append our custom ones here too.987 remove_filter( 'get_post_metadata', array( $this, 'filter_shim_postmeta' ) );988 989 // Fetch the existing ones from the database990 $value = get_metadata( 'post', $object_id, $meta_key );991 992 // Re-attach ourselves for next time!993 add_filter( 'get_post_metadata', array( $this, 'filter_shim_postmeta' ), 10, 3 );994 995 $custom_meta_fields = array( 'downloads', 'rating', 'ratings', 'tested' );996 $custom_meta_fields = apply_filters( 'wporg_plugins_custom_meta_fields', $custom_meta_fields, $object_id );997 998 foreach ( $custom_meta_fields as $key ) {999 1000 // When WordPress calls `get_post_meta( $post_id, false )` it expects an array of maybe_serialize()'d data.1001 $shimed_data = $this->filter_shim_postmeta( false, $object_id, $key );1002 if ( $shimed_data ) {1003 $value[ $key ][0] = (string) maybe_serialize( $shimed_data[0] );1004 }1005 }1006 break;1007 1008 }1009 1010 return $value;1011 951 } 1012 952 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php
r4389 r4423 147 147 } 148 148 149 // Update the tested-up-to value 150 $tested = $readme->tested; 151 if ( function_exists( 'wporg_get_version_equivalents' ) ) { 152 foreach ( wporg_get_version_equivalents() as $latest_compatible_version => $compatible_with ) { 153 if ( in_array( $readme->tested, $compatible_with, true ) ) { 154 $tested = $latest_compatible_version; 155 break; 156 } 157 } 158 } 159 160 // Update all readme meta 149 161 foreach ( $this->readme_fields as $readme_field ) { 150 // Don't change the tested version if a newer version was specified through wp-admin 151 if ( 'tested' == $readme_field && version_compare( get_post_meta( $plugin->ID, 'tested', true ), $readme->$readme_field, '>' ) ) { 152 continue; 153 } 154 155 update_post_meta( $plugin->ID, $readme_field, wp_slash( $readme->$readme_field ) ); 162 $value = ( 'tested' == $readme_field ) ? $tested : $readme->field; 163 update_post_meta( $plugin->ID, $readme_field, wp_slash( $value ) ); 156 164 } 157 165 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-meta-sync.php
r4420 r4423 24 24 $this->sync_downloads(); 25 25 $this->sync_ratings(); 26 $this->update_tested_up_to(); 26 27 } 27 28 … … 39 40 FROM `{$wpdb->posts}` p 40 41 JOIN `{$bbpress_topic_slug_table}` t ON p.post_name = t.topic_slug 41 LEFTJOIN `{$download_count_table}` c on t.topic_id = c.topic_id42 JOIN `{$download_count_table}` c on t.topic_id = c.topic_id 42 43 LEFT JOIN `{$wpdb->postmeta}` pm ON p.id = pm.post_id AND pm.meta_key = 'downloads' 43 44 … … 96 97 update_option( 'plugin_last_review_sync', $current_review_time, 'no' ); 97 98 } 99 100 /** 101 * After WordPress is released, update the 'tested' meta keys to the latest version as 102 * specified by `wporg_get_version_equivalents()`. 103 */ 104 function update_tested_up_to() { 105 global $wpdb; 106 if ( ! function_exists( 'wporg_get_version_equivalents' ) ) { 107 return; 108 } 109 110 $equivs = wporg_get_version_equivalents(); 111 $equivs_key = md5( serialize( $equivs ) ); 112 if ( $equivs_key === get_option( 'plugin_last_tested_sync' ) ) { 113 return; 114 } 115 116 $latest_equiv = array(); 117 foreach ( $equivs as $latest_compatible_version => $compatible_with ) { 118 foreach ( $compatible_with as $version ) { 119 $latest_equiv[ $version ] = $latest_compatible_version; 120 } 121 } 122 123 $tested_meta_value_esc_sql = '"' . implode( '", "', array_map( 'esc_sql', array_keys( $latest_equiv ) ) ) . '"'; 124 $tested_values = $wpdb->get_results( "SELECT post_id, meta_value FROM {$wpdb->postmeta} WHERE meta_key = 'tested' AND meta_value IN( {$tested_meta_value_esc_sql} )" ); 125 126 foreach ( $tested_values as $row ) { 127 update_post_meta( 128 $row->post_id, 129 'tested', 130 $latest_equiv[ $row->meta_value ] 131 ); 132 } 133 134 update_option( 'plugin_last_tested_sync', $equivs_key ); 135 } 98 136 }
Note: See TracChangeset
for help on using the changeset viewer.