Making WordPress.org


Ignore:
Timestamp:
11/26/2016 03:47:38 AM (9 years ago)
Author:
dd32
Message:

Plugin Directory: Update the tested postmeta field when new versions of WordPress are released.
This removes the need for having a postmeta display filter.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-meta-sync.php

    r4420 r4423  
    2424        $this->sync_downloads();
    2525        $this->sync_ratings();
     26        $this->update_tested_up_to();
    2627    }
    2728
     
    3940            FROM `{$wpdb->posts}` p
    4041                JOIN `{$bbpress_topic_slug_table}` t ON p.post_name = t.topic_slug
    41                 LEFT JOIN `{$download_count_table}` c on t.topic_id = c.topic_id
     42                JOIN `{$download_count_table}` c on t.topic_id = c.topic_id
    4243                LEFT JOIN `{$wpdb->postmeta}` pm ON p.id = pm.post_id AND pm.meta_key = 'downloads'
    4344
     
    9697        update_option( 'plugin_last_review_sync', $current_review_time, 'no' );
    9798    }
     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    }
    98136}
Note: See TracChangeset for help on using the changeset viewer.