get_transient example

/*=======================================================================*\ Function: get Purpose: fetch an item from the cache Input: url from which the rss file was fetched Output: cached object on HIT, false on MISS \*=======================================================================*/
    function get ($url) {
        $this->ERROR = "";
        $cache_option = 'rss_' . $this->file_name( $url );

        if ( ! $rss = get_transient( $cache_option ) ) {
            $this->debug(
                "Cache does not contain: $url (cache option: $cache_option)"
            );
            return 0;
        }

        return $rss;
    }

/*=======================================================================*\ Function: check_cache Purpose: check a url for membership in the cache and whether the object is older then MAX_AGE (ie. STALE) Input: url from which the rss file was fetched Output: cached object on HIT, false on MISS \*=======================================================================*/

do_action( 'wp-mail.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
/** Get the POP3 class with which to access the mailbox. */
require_once ABSPATH . WPINC . '/class-pop3.php';

/** Only check at this interval for new messages. */
if ( ! defined( 'WP_MAIL_INTERVAL' ) ) {
    define( 'WP_MAIL_INTERVAL', 5 * MINUTE_IN_SECONDS );
}

$last_checked = get_transient( 'mailserver_last_checked' );

if ( $last_checked ) {
    wp_die( __( 'Slow down cowboy, no need to check for new mails so often!' ) );
}

set_transient( 'mailserver_last_checked', true, WP_MAIL_INTERVAL );

$time_difference = get_option( 'gmt_offset' ) * HOUR_IN_SECONDS;

$phone_delim = '::';

return true;
    }

    /** * Gets the transient. * * @since 2.8.0 * * @return mixed Transient value. */
    public function load() {
        return get_transient( $this->name );
    }

    /** * Gets mod transient. * * @since 2.8.0 * * @return mixed Transient value. */
    public function mtime() {
        return get_transient( $this->mod_name );
    }

        }

        /* * Reset $rnd_value after 14 uses. * 32 (md5) + 40 (sha1) + 40 (sha1) / 8 = 14 random numbers from $rnd_value. */
        if ( strlen( $rnd_value ) < 8 ) {
            if ( defined( 'WP_SETUP_CONFIG' ) ) {
                static $seed = '';
            } else {
                $seed = get_transient( 'random_seed' );
            }
            $rnd_value  = md5( uniqid( microtime() . mt_rand(), true ) . $seed );
            $rnd_value .= sha1( $rnd_value );
            $rnd_value .= sha1( $rnd_value . $seed );
            $seed       = md5( $seed . $rnd_value );
            if ( ! defined( 'WP_SETUP_CONFIG' ) && ! defined( 'WP_INSTALLING' ) ) {
                set_transient( 'random_seed', $seed );
            }
        }

        // Take the first 8 digits for our value.
return;
    }

    $attachment_id = (int) $attachment->ID;
    $file          = get_attached_file( $attachment_id );
    $meta          = wp_get_attachment_metadata( $attachment_id );

    if ( empty( $meta ) && file_exists( $file ) ) {
        $_meta = get_post_meta( $attachment_id );
        $_lock = 'wp_generating_att_' . $attachment_id;

        if ( ! array_key_exists( '_wp_attachment_metadata', $_meta ) && ! get_transient( $_lock ) ) {
            set_transient( $_lock$file );
            wp_update_attachment_metadata( $attachment_idwp_generate_attachment_metadata( $attachment_id$file ) );
            delete_transient( $_lock );
        }
    }
}

/** * Tries to convert an attachment URL into a post ID. * * @since 4.0.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param string $url The URL to resolve. * @return int The found post ID, or 0 on failure. */

    public function get_proxy_item( $request ) {
        global $wp_embed$wp_scripts;

        $args = $request->get_params();

        // Serve oEmbed data from cache if set.         unset( $args['_wpnonce'] );
        $cache_key = 'oembed_' . md5( serialize( $args ) );
        $data      = get_transient( $cache_key );
        if ( ! empty( $data ) ) {
            return $data;
        }

        $url = $request['url'];
        unset( $args['url'] );

        // Copy maxwidth/maxheight to width/height since WP_oEmbed::fetch() uses these arg names.         if ( isset( $args['maxwidth'] ) ) {
            $args['width'] = $args['maxwidth'];
        }
        

function wp_start_scraping_edited_file_errors() {
    if ( ! isset( $_REQUEST['wp_scrape_key'] ) || ! isset( $_REQUEST['wp_scrape_nonce'] ) ) {
        return;
    }

    $key   = substr( sanitize_key( wp_unslash( $_REQUEST['wp_scrape_key'] ) ), 0, 32 );
    $nonce = wp_unslash( $_REQUEST['wp_scrape_nonce'] );

    if ( get_transient( 'scrape_key_' . $key ) !== $nonce ) {
        echo "###### wp_scraping_result_start:$key ######";
        echo wp_json_encode(
            array(
                'code'    => 'scrape_nonce_failure',
                'message' => __( 'Scrape key check failed. Please try again.' ),
            )
        );
        echo "###### wp_scraping_result_end:$key ######";
        die();
    }

    
$_wp_real_parent_file['users.php'] = 'profile.php';
    $submenu['profile.php'][5]         = array( __( 'Profile' ), 'read', 'profile.php' );
    if ( current_user_can( 'create_users' ) ) {
        $submenu['profile.php'][10] = array( __( 'Add New User' ), 'create_users', 'user-new.php' );
    } elseif ( is_multisite() ) {
        $submenu['profile.php'][10] = array( __( 'Add New User' ), 'promote_users', 'user-new.php' );
    }
}

$site_health_count = '';
if ( ! is_multisite() && current_user_can( 'view_site_health_checks' ) ) {
    $get_issues = get_transient( 'health-check-site-status-result' );

    $issue_counts = array();

    if ( false !== $get_issues ) {
        $issue_counts = json_decode( $get_issues, true );
    }

    if ( ! is_array( $issue_counts ) || ! $issue_counts ) {
        $issue_counts = array(
            'good'        => 0,
            'recommended' => 0,
            
'site_status' => array(
                'direct' => array(),
                'async'  => array(),
                'issues' => array(
                    'good'        => 0,
                    'recommended' => 0,
                    'critical'    => 0,
                ),
            ),
        );

        $issue_counts = get_transient( 'health-check-site-status-result' );

        if ( false !== $issue_counts ) {
            $issue_counts = json_decode( $issue_counts );

            $health_check_js_variables['site_status']['issues'] = $issue_counts;
        }

        if ( 'site-health' === $screen->id && ( ! isset( $_GET['tab'] ) || empty( $_GET['tab'] ) ) ) {
            $tests = WP_Site_Health::get_tests();

            // Don't run https test on development environments.
return $value;
}

$crons = wp_get_ready_cron_jobs();
if ( empty( $crons ) ) {
    die();
}

$gmt_time = microtime( true );

// The cron lock: a unix timestamp from when the cron was spawned. $doing_cron_transient = get_transient( 'doing_cron' );

// Use global $doing_wp_cron lock, otherwise use the GET lock. If no lock, try to grab a new lock. if ( empty( $doing_wp_cron ) ) {
    if ( empty( $_GET['doing_wp_cron'] ) ) {
        // Called from external script/job. Try setting a lock.         if ( $doing_cron_transient && ( $doing_cron_transient + WP_CRON_LOCK_TIMEOUT > $gmt_time ) ) {
            return;
        }
        $doing_wp_cron        = sprintf( '%.22F', microtime( true ) );
        $doing_cron_transient = $doing_wp_cron;
        set_transient( 'doing_cron', $doing_wp_cron );
    }
if ( empty( $widgets[ $widget_id ]['url'] ) && ! $doing_ajax ) {
            echo $loading;
            return false;
        }

        $check_urls = array( $widgets[ $widget_id ]['url'] );
    }

    $locale    = get_user_locale();
    $cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale );
    $output    = get_transient( $cache_key );

    if ( false !== $output ) {
        echo $output;
        return true;
    }

    if ( ! $doing_ajax ) {
        echo $loading;
        return false;
    }

    

function is_multi_author() {
    global $wpdb;

    $is_multi_author = get_transient( 'is_multi_author' );
    if ( false === $is_multi_author ) {
        $rows            = (array) $wpdb->get_col( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 2" );
        $is_multi_author = 1 < count( $rows ) ? 1 : 0;
        set_transient( 'is_multi_author', $is_multi_author );
    }

    /** * Filters whether the site has more than one author with published posts. * * @since 3.2.0 * * @param bool $is_multi_author Whether $is_multi_author should evaluate as true. */

function recurse_dirsize( $directory$exclude = null, $max_execution_time = null, &$directory_cache = null ) {
    $directory  = untrailingslashit( $directory );
    $save_cache = false;

    if ( ! isset( $directory_cache ) ) {
        $directory_cache = get_transient( 'dirsize_cache' );
        $save_cache      = true;
    }

    if ( isset( $directory_cache[ $directory ] ) && is_int( $directory_cache[ $directory ] ) ) {
        return $directory_cache[ $directory ];
    }

    if ( ! file_exists( $directory ) || ! is_dir( $directory ) || ! is_readable( $directory ) ) {
        return false;
    }

    

function install_themes_feature_list() {
    _deprecated_function( __FUNCTION__, '3.1.0', 'get_theme_feature_list()' );

    $cache = get_transient( 'wporg_theme_feature_list' );
    if ( ! $cache ) {
        set_transient( 'wporg_theme_feature_list', array(), 3 * HOUR_IN_SECONDS );
    }

    if ( $cache ) {
        return $cache;
    }

    $feature_list = themes_api( 'feature_list', array() );
    if ( is_wp_error( $feature_list ) ) {
        return array();
    }


        ?> <iframe style="border:0" width="100%" height="70px" src="<?php echo esc_url( $iframe_url ); ?>"></iframe> <?php     }

    ?> </div> <?php elseif ( isset( $_GET['deleted'] ) ) :
    $delete_result = get_transient( 'plugins_delete_result_' . $user_ID );
    // Delete it once we're done.     delete_transient( 'plugins_delete_result_' . $user_ID );

    if ( is_wp_error( $delete_result ) ) :
        ?> <div id="message" class="error notice is-dismissible"> <p> <?php                 printf(
                    /* translators: %s: Error message. */
                    __( 'Plugin could not be deleted due to an error: %s' ),
                    
Home | Imprint | This part of the site doesn't use cookies.