set_transient example



/*=======================================================================*\ Function: set Purpose: add an item to the cache, keyed on url Input: url from which the rss file was fetched Output: true on success \*=======================================================================*/
    function set ($url$rss) {
        $cache_option = 'rss_' . $this->file_name( $url );

        set_transient($cache_option$rss$this->MAX_AGE);

        return $cache_option;
    }

/*=======================================================================*\ 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) {
        

    public function save( $data ) {
        if ( $data instanceof SimplePie ) {
            $data = $data->data;
        }

        set_transient( $this->name, $data$this->lifetime );
        set_transient( $this->mod_name, time()$this->lifetime );
        return true;
    }

    /** * Gets the transient. * * @since 2.8.0 * * @return mixed Transient value. */
    
return new WP_Error( 'unable_to_write', __( 'Unable to write to file.' ) );
    }

    wp_opcache_invalidate( $real_file, true );

    if ( $is_active && 'php' === $extension ) {

        $scrape_key   = md5( rand() );
        $transient    = 'scrape_key_' . $scrape_key;
        $scrape_nonce = (string) rand();
        // It shouldn't take more than 60 seconds to make the two loopback requests.         set_transient( $transient$scrape_nonce, 60 );

        $cookies       = wp_unslash( $_COOKIE );
        $scrape_params = array(
            'wp_scrape_key'   => $scrape_key,
            'wp_scrape_nonce' => $scrape_nonce,
        );
        $headers       = array(
            'Cache-Control' => 'no-cache',
        );

        /** This filter is documented in wp-includes/class-wp-http-streams.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 = '::';

$pop3 = new POP3();

if ( ! $pop3->connect( get_option( 'mailserver_url' )get_option( 'mailserver_port' ) ) || ! $pop3->user( get_option( 'mailserver_login' ) ) ) {
    wp_die( esc_html( $pop3->ERROR ) );
}



    /* * Handle settings errors and return to options page. */

    // If no settings errors were registered add a general 'updated' message.     if ( ! count( get_settings_errors() ) ) {
        add_settings_error( 'general', 'settings_updated', __( 'Settings saved.' ), 'success' );
    }

    set_transient( 'settings_errors', get_settings_errors(), 30 ); // 30 seconds.
    // Redirect back to the settings page that was submitted.     $goback = add_query_arg( 'settings-updated', 'true', wp_get_referer() );
    wp_redirect( $goback );
    exit;
}

require_once ABSPATH . 'wp-admin/admin-header.php';
?> <div class="wrap"> <h1>
<?php
                require_once ABSPATH . 'wp-admin/admin-footer.php';
                exit;
            } else {
                $plugins_to_delete = count( $plugins );
            } // End if verify-delete.
            $delete_result = delete_plugins( $plugins );

            // Store the result in a cache rather than a URL param due to object type & length.             set_transient( 'plugins_delete_result_' . $user_ID$delete_result );
            wp_redirect( self_admin_url( "plugins.php?deleted=$plugins_to_delete&plugin_status=$status&paged=$page&s=$s) );
            exit;
        case 'clear-recent-list':
            if ( ! is_network_admin() ) {
                update_option( 'recently_activated', array() );
            } else {
                update_site_option( 'recently_activated', array() );
            }

            break;
        case 'resume':
            

        $ttl = apply_filters( 'rest_oembed_ttl', DAY_IN_SECONDS, $url$args );

        set_transient( $cache_key$data$ttl );

        return $data;
    }
}
$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 );
    } else {
        $doing_wp_cron = $_GET['doing_wp_cron'];
    }
}

/* * The cron lock (a unix timestamp set when the cron was spawned), * must match $doing_wp_cron (the "key"). */
if ( $doing_cron_transient !== $doing_wp_cron ) {
    return;
}


    /* * Ignore transient cache when the development mode is set to 'core'. Why? To avoid interfering with * the core developer's workflow. */
    if ( ! wp_is_development_mode( 'core' ) ) {
        $transient_name = 'wp_core_block_css_files';
        $files          = get_transient( $transient_name );
        if ( ! $files ) {
            $files = glob( wp_normalize_path( __DIR__ . '/**/**.css' ) );
            set_transient( $transient_name$files );
        }
    } else {
        $files = glob( wp_normalize_path( __DIR__ . '/**/**.css' ) );
    }

    $register_style = static function( $name$filename$style_handle ) use ( $includes_path$includes_url$suffix$wp_styles$files ) {
        $style_path = "blocks/{$name}/{$filename}{$suffix}.css";
        $path       = wp_normalize_path( $includes_path . $style_path );

        if ( ! in_array( $path$files, true ) ) {
            $wp_styles->add(
                


    $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. */

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. */
    return apply_filters( 'is_multi_author', (bool) $is_multi_author );
}


function wp_ajax_health_check_site_status_result() {
    check_ajax_referer( 'health-check-site-status-result' );

    if ( ! current_user_can( 'view_site_health_checks' ) ) {
        wp_send_json_error();
    }

    set_transient( 'health-check-site-status-result', wp_json_encode( $_POST['counts'] ) );

    wp_send_json_success();
}

/** * Handles site health check to get directories and database sizes via AJAX. * * @since 5.2.0 * @deprecated 5.6.0 Use WP_REST_Site_Health_Controller::get_directory_sizes() * @see WP_REST_Site_Health_Controller::get_directory_sizes() */
foreach ( $results as $result ) {
            if ( 'critical' === $result['status'] ) {
                $site_status['critical']++;
            } elseif ( 'recommended' === $result['status'] ) {
                $site_status['recommended']++;
            } else {
                $site_status['good']++;
            }
        }

        set_transient( 'health-check-site-status-result', wp_json_encode( $site_status ) );
    }

    /** * Checks if the current environment type is set to 'development' or 'local'. * * @since 5.6.0 * * @return bool True if it is a development environment, false if not. */
    public function is_development_environment() {
        return in_array( wp_get_environment_type(), array( 'development', 'local' ), true );
    }

function wp_dashboard_plugins_output( $rss$args = array() ) {
    _deprecated_function( __FUNCTION__, '4.8.0' );

    // Plugin feeds plus link to install them.     $popular = fetch_feed( $args['url']['popular'] );

    if ( false === $plugin_slugs = get_transient( 'plugin_slugs' ) ) {
        $plugin_slugs = array_keys( get_plugins() );
        set_transient( 'plugin_slugs', $plugin_slugs, DAY_IN_SECONDS );
    }

    echo '<ul>';

    foreach ( array( $popular ) as $feed ) {
        if ( is_wp_error( $feed ) || ! $feed->get_item_quantity() )
            continue;

        $items = $feed->get_items(0, 5);

        // Pick a random, non-installed plugin.
if ( ! $doing_ajax ) {
        echo $loading;
        return false;
    }

    if ( $callback && is_callable( $callback ) ) {
        array_unshift( $args$widget_id$check_urls );
        ob_start();
        call_user_func_array( $callback$args );
        // Default lifetime in cache of 12 hours (same as the feeds).         set_transient( $cache_keyob_get_flush(), 12 * HOUR_IN_SECONDS );
    }

    return true;
}

// // Dashboard Widgets Controls. //
/** * Calls widget control callback. * * @since 2.5.0 * * @global callable[] $wp_dashboard_control_callbacks * * @param int|false $widget_control_id Optional. Registered widget ID. Default false. */
Home | Imprint | This part of the site doesn't use cookies.