Making WordPress.org

Changeset 8115


Ignore:
Timestamp:
01/20/2019 11:07:15 PM (8 years ago)
Author:
SergeyBiryukov
Message:

Plugin Directory: Introduce Template::is_plugin_outdated() to check if the plugin was tested with the latest 3 major releases of WordPress.

See #4088.

Location:
sites/trunk/wordpress.org/public_html/wp-content
Files:
3 edited

Legend:

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

    r8114 r8115  
    160160
    161161        /**
     162         * Gets current major WP version to check against "Tested up to" value.
     163         *
     164         * @static
     165         * @global string $wp_version WordPress version.
     166         *
     167         * @return float Current major WP version.
     168         */
     169        public static function get_current_major_wp_version() {
     170                $current_version = '';
     171
     172                // Assume the value stored in a constant (which is set on WP.org), if defined.
     173                if ( defined( 'WP_CORE_LATEST_RELEASE' ) && WP_CORE_LATEST_RELEASE ) {
     174                        $current_version = substr( WP_CORE_LATEST_RELEASE, 0, 3 );
     175                }
     176
     177                // Otherwise, use the version of the running WP instance.
     178                if ( empty( $current_version ) ) {
     179                        global $wp_version;
     180
     181                        $current_version = substr( $wp_version, 0, 3 );
     182
     183                        // However, if the running WP instance appears to not be a release version, assume the latest stable version.
     184                        if ( false !== strpos( $wp_version, '-' ) ) {
     185                                $current_version = (float) $current_version - 0.1;
     186                        }
     187                }
     188
     189                return (float) $current_version;
     190        }
     191
     192        /**
     193         * Checks if the plugin was tested with the latest 3 major releases of WordPress.
     194         *
     195         * @static
     196         *
     197         * @param int|\WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
     198         * @return bool True if the plugin is marked as tested, false otherwise.
     199         */
     200        public static function is_plugin_outdated( $post = null ) {
     201                $tested_up_to             = (string) get_post_meta( get_post( $post )->ID, 'tested', true );
     202                $version_to_check_against = (string) ( self::get_current_major_wp_version() - 0.2 );
     203
     204                return version_compare( $version_to_check_against, $tested_up_to, '>' );
     205        }
     206
     207        /**
    162208         * Returns a string representing the number of active installations for an item.
    163209         *
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/functions.php

    r8114 r8115  
    351351
    352352/**
    353  * Get current major WP version to check against "Tested up to" value.
    354  *
    355  * @global string $wp_version WordPress version.
    356  *
    357  * @return float Current major WP version.
    358  */
    359 function get_current_major_wp_version() {
    360         $current_version = '';
    361 
    362         // Assume the value stored in a constant (which is set on WP.org), if defined.
    363         if ( defined( 'WP_CORE_LATEST_RELEASE' ) && WP_CORE_LATEST_RELEASE ) {
    364                 $current_version = substr( WP_CORE_LATEST_RELEASE, 0, 3 );
    365         }
    366 
    367         // Otherwise, use the version of the running WP instance.
    368         if ( empty( $current_version ) ) {
    369                 global $wp_version;
    370 
    371                 $current_version = substr( $wp_version, 0, 3 );
    372 
    373                 // However, if the running WP instance appears to not be a release version, assume the latest stable version.
    374                 if ( false !== strpos( $wp_version, '-' ) ) {
    375                         $current_version = (float) $current_version - 0.1;
    376                 }
    377         }
    378 
    379         return (float) $current_version;
    380 }
    381 
    382 /**
    383353 * Custom template tags for this theme.
    384354 */
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/inc/template-tags.php

    r7602 r8115  
    179179        switch ( $post_status ) {
    180180                case 'publish':
    181                         $tested_up_to             = (string) get_post_meta( get_post( $post )->ID, 'tested', true );
    182                         $version_to_check_against = (string) ( get_current_major_wp_version() - 0.2 );
    183                         if ( version_compare( $version_to_check_against, $tested_up_to, '>' ) ) {
     181                        if ( Template::is_plugin_outdated( $post ) ) {
    184182                                $message = sprintf(
    185183                                        $warning_notice,
Note: See TracChangeset for help on using the changeset viewer.