Making WordPress.org

Changeset 4297


Ignore:
Timestamp:
10/26/2016 10:39:43 PM (8 years ago)
Author:
coffee2code
Message:

Support Forums, Directory Compat: Split bulk of get_object() off into static get_object_by_slug_and_type() to facilitate use elsewhere to fetch plugin or theme object by slug.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-directory-compat.php

    r4235 r4297  
    650650        }
    651651
     652        return self::get_object_by_slug_and_type( $slug, $this->compat() );
     653    }
     654
     655    /**
     656     * Get and cache object based on slug and type (plugin or theme).
     657     *
     658     * Suitable for use outside of the class.
     659     *
     660     * @param string $slug The object slug.
     661     * @param string $type The type of the object. Either 'plugin' or 'theme'.
     662     * @return array
     663     */
     664    public static function get_object_by_slug_and_type( $slug, $type ) {
     665        global $wpdb;
     666
    652667        // Check the cache.
    653668        $cache_key = $slug;
    654         $cache_group = $this->compat() . '-objects';
     669        $cache_group = $type . '-objects';
    655670        $compat_object = wp_cache_get( $cache_key, $cache_group );
    656671        if ( false === $compat_object ) {
    657672
    658673            // Get the object information from the correct table.
    659             if ( $this->compat() == 'theme' ) {
     674            if ( $type == 'theme' ) {
    660675                $compat_object = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->base_prefix}%d_posts WHERE post_name = %s AND post_type = 'repopackage' LIMIT 1", WPORG_THEME_DIRECTORY_BLOGID, $slug ) );
    661             } elseif ( $this->compat() == 'plugin' ) {
     676            } elseif ( $type == 'plugin' ) {
    662677                // @todo Update this when the Plugin Directory switches over to WordPress.
    663678                $_compat_topic = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . PLUGINS_TABLE_PREFIX . "topics WHERE topic_slug = %s", $slug ) );
Note: See TracChangeset for help on using the changeset viewer.