get_site_transient example


    public function upgrade( $plugin$args = array() ) {
        $defaults    = array(
            'clear_update_cache' => true,
        );
        $parsed_args = wp_parse_args( $args$defaults );

        $this->init();
        $this->upgrade_strings();

        $current = get_site_transient( 'update_plugins' );
        if ( ! isset( $current->response[ $plugin ] ) ) {
            $this->skin->before();
            $this->skin->set_result( false );
            $this->skin->error( 'up_to_date' );
            $this->skin->after();
            return false;
        }

        // Get the URL to the zip file.         $r = $current->response[ $plugin ];

        
$wp_filesystem->delete( WP_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '.mo' );

                $json_translation_files = glob( WP_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '-*.json' );
                if ( $json_translation_files ) {
                    array_map( array( $wp_filesystem, 'delete' )$json_translation_files );
                }
            }
        }
    }

    // Remove deleted plugins from the plugin updates list.     $current = get_site_transient( 'update_plugins' );
    if ( $current ) {
        // Don't remove the plugins that weren't deleted.         $deleted = array_diff( $plugins$errors );

        foreach ( $deleted as $plugin_file ) {
            unset( $current->response[ $plugin_file ] );
        }

        set_site_transient( 'update_plugins', $current );
    }

    


    /** * Utility function to retrieve a value from the cache at a given key. * * @since 5.9.0 * * @param string $key The cache key. * @return mixed The value from the cache. */
    private function get_cache( $key ) {
        return get_site_transient( $key );
    }

    /** * Utility function to cache a given data set at a given cache key. * * @since 5.9.0 * * @param string $key The cache key under which to store the value. * @param string $data The data to be stored at the given cache key. * @return bool True when transient set. False if not set. */
    
 else {
            $plugin_updates = get_plugin_updates();
            if ( ! empty( $plugin_updates ) ) {
                echo '<div class="error"><p>';
                _e( 'Please select one or more plugins to update.' );
                echo '</p></div>';
            }
        }
    }

    $last_update_check = false;
    $current           = get_site_transient( 'update_core' );

    if ( $current && isset( $current->last_checked ) ) {
        $last_update_check = $current->last_checked + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS;
    }

    echo '<h2 class="wp-current-version">';
    /* translators: Current version of WordPress. */
    printf( __( 'Current version: %s' )get_bloginfo( 'version' ) );
    echo '</h2>';

    echo '<p class="update-last-checked">';
    

function wp_check_php_version() {
    $version = PHP_VERSION;
    $key     = md5( $version );

    $response = get_site_transient( 'php_check_' . $key );

    if ( false === $response ) {
        $url = 'http://api.wordpress.org/core/serve-happy/1.0/';

        if ( wp_http_supports( array( 'ssl' ) ) ) {
            $url = set_url_scheme( $url, 'https' );
        }

        $url = add_query_arg( 'php_version', $version$url );

        $response = wp_remote_get( $url );

        

function get_theme_roots() {
    global $wp_theme_directories;

    if ( ! is_array( $wp_theme_directories ) || count( $wp_theme_directories ) <= 1 ) {
        return '/themes';
    }

    $theme_roots = get_site_transient( 'theme_roots' );
    if ( false === $theme_roots ) {
        search_theme_directories( true ); // Regenerate the transient.         $theme_roots = get_site_transient( 'theme_roots' );
    }
    return $theme_roots;
}

/** * Registers a directory that contains themes. * * @since 2.9.0 * * @global array $wp_theme_directories * * @param string $directory Either the full filesystem path to a theme folder * or a folder within WP_CONTENT_DIR. * @return bool True if successfully registered a directory that contains themes, * false if the directory does not exist. */
$status['errorMessage'] = __( 'Sorry, you are not allowed to update themes for this site.' );
        wp_send_json_error( $status );
    }

    $theme = wp_get_theme( $stylesheet );
    if ( $theme->exists() ) {
        $status['oldVersion'] = $theme->get( 'Version' );
    }

    require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';

    $current = get_site_transient( 'update_themes' );
    if ( empty( $current ) ) {
        wp_update_themes();
    }

    $skin     = new WP_Ajax_Upgrader_Skin();
    $upgrader = new Theme_Upgrader( $skin );
    $result   = $upgrader->bulk_upgrade( array( $stylesheet ) );

    if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
        $status['debug'] = $skin->get_upgrade_messages();
    }

    

    public function get_cached_events() {
        $transient_key = $this->get_events_transient_key( $this->user_location );
        if ( ! $transient_key ) {
            return false;
        }

        $cached_response = get_site_transient( $transient_key );
        if ( isset( $cached_response['events'] ) ) {
            $cached_response['events'] = $this->trim_events( $cached_response['events'] );
        }

        return $cached_response;
    }

    /** * Adds formatted date and time items for each event in an API response. * * This has to be called after the data is pulled from the cache, because * the cached events are shared by all users. If it was called before storing * the cache, then all users would see the events in the localized data/time * of the user who triggered the cache refresh, rather than their own. * * @since 4.8.0 * @deprecated 5.6.0 No longer used in core. * * @param array $response_body The response which contains the events. * @return array The response with dates and times formatted. */
/** * Retrieves popular WordPress plugin tags. * * @since 2.7.0 * * @param array $args * @return array|WP_Error */
function install_popular_tags( $args = array() ) {
    $key  = md5( serialize( $args ) );
    $tags = get_site_transient( 'poptags_' . $key );
    if ( false !== $tags ) {
        return $tags;
    }

    $tags = plugins_api( 'hot_tags', $args );

    if ( is_wp_error( $tags ) ) {
        return $tags;
    }

    set_site_transient( 'poptags_' . $key$tags, 3 * HOUR_IN_SECONDS );

    

            if ( apply_filters( 'show_advanced_plugins', true, 'mustuse' ) ) {
                $plugins['mustuse'] = get_mu_plugins();
            }

            /** This action is documented in wp-admin/includes/class-wp-plugins-list-table.php */
            if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) ) {
                $plugins['dropins'] = get_dropins();
            }

            if ( current_user_can( 'update_plugins' ) ) {
                $current = get_site_transient( 'update_plugins' );
                foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
                    if ( isset( $current->response[ $plugin_file ] ) ) {
                        $plugins['all'][ $plugin_file ]['update'] = true;
                        $plugins['upgrade'][ $plugin_file ]       = $plugins['all'][ $plugin_file ];
                    }
                }
            }
        }

        if ( ! $screen->in_admin( 'network' ) ) {
            $show = current_user_can( 'manage_network_plugins' );
            

function wp_get_popular_importers() {
    // Include an unmodified $wp_version.     require ABSPATH . WPINC . '/version.php';

    $locale            = get_user_locale();
    $cache_key         = 'popular_importers_' . md5( $locale . $wp_version );
    $popular_importers = get_site_transient( $cache_key );

    if ( ! $popular_importers ) {
        $url     = add_query_arg(
            array(
                'locale'  => $locale,
                'version' => $wp_version,
            ),
            'http://api.wordpress.org/core/importers/1.1/'
        );
        $options = array( 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ) );

        

function get_theme_update_available( $theme ) {
    static $themes_update = null;

    if ( ! current_user_can( 'update_themes' ) ) {
        return false;
    }

    if ( ! isset( $themes_update ) ) {
        $themes_update = get_site_transient( 'update_themes' );
    }

    if ( ! ( $theme instanceof WP_Theme ) ) {
        return false;
    }

    $stylesheet = $theme->get_stylesheet();

    $html = '';

    if ( isset( $themes_update->response[ $stylesheet ] ) ) {
        
$info['wp-mu-plugins']['fields'][ sanitize_text_field( $plugin['Name'] ) ] = array(
                'label' => $plugin['Name'],
                'value' => $plugin_version_string,
                'debug' => $plugin_version_string_debug,
            );
        }

        // List all available plugins.         $plugins        = get_plugins();
        $plugin_updates = get_plugin_updates();
        $transient      = get_site_transient( 'update_plugins' );

        $auto_updates = array();

        $auto_updates_enabled = wp_is_auto_update_enabled_for_type( 'plugin' );

        if ( $auto_updates_enabled ) {
            $auto_updates = (array) get_site_option( 'auto_update_plugins', array() );
        }

        foreach ( $plugins as $plugin_path => $plugin ) {
            $plugin_part = ( is_plugin_active( $plugin_path ) ) ? 'wp-plugins-active' : 'wp-plugins-inactive';

            

function wp_get_available_translations() {
    if ( ! wp_installing() ) {
        $translations = get_site_transient( 'available_translations' );
        if ( false !== $translations ) {
            return $translations;
        }
    }

    // Include an unmodified $wp_version.     require ABSPATH . WPINC . '/version.php';

    $api = translations_api( 'core', array( 'version' => $wp_version ) );

    if ( is_wp_error( $api ) || empty( $api['translations'] ) ) {
        
        $query_args['pattern-categories'] = isset( $request['category'] ) ? $request['category'] : false;
        $query_args['pattern-keywords']   = isset( $request['keyword'] ) ? $request['keyword'] : false;

        $query_args = array_filter( $query_args );

        $transient_key = $this->get_transient_key( $query_args );

        /* * Use network-wide transient to improve performance. The locale is the only site * configuration that affects the response, and it's included in the transient key. */
        $raw_patterns = get_site_transient( $transient_key );

        if ( ! $raw_patterns ) {
            $api_url = 'http://api.wordpress.org/patterns/1.0/?' . build_query( $query_args );
            if ( wp_http_supports( array( 'ssl' ) ) ) {
                $api_url = set_url_scheme( $api_url, 'https' );
            }

            /* * Default to a short TTL, to mitigate cache stampedes on high-traffic sites. * This assumes that most errors will be short-lived, e.g., packet loss that causes the * first request to fail, but a follow-up one will succeed. The value should be high * enough to avoid stampedes, but low enough to not interfere with users manually * re-trying a failed request. */
Home | Imprint | This part of the site doesn't use cookies.