Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




wp_update_plugins [ WordPress Function ]

wp_update_plugins ( No parameters )
Uses:
  • $wp_version
Returns:
  • (mixed) Returns null if update is unsupported. Returns false if check is too soon.
Defined at:



Check plugin versions against the latest versions hosted on WordPress.org.

The WordPress version, PHP version, and Locale is sent along with a list of all plugins installed. Checks against the WordPress server at api.wordpress.org. Will only check if WordPress isn't installing.

Source


<?php
function wp_update_plugins() {
    include 
ABSPATH WPINC '/version.php'// include an unmodified $wp_version

    
if ( defined('WP_INSTALLING') )
        return 
false;

    
// If running blog-side, bail unless we've not checked in the last 12 hours
    
if ( !function_exists'get_plugins' ) )
        require_once( 
ABSPATH 'wp-admin/includes/plugin.php' );

    
$plugins get_plugins();
    
$active  get_option'active_plugins', array() );
    
$current get_site_transient'update_plugins' );
    if ( ! 
is_object($current) )
        
$current = new stdClass;

    
$new_option = new stdClass;
    
$new_option->last_checked time();

    
// Check for update on a different schedule, depending on the page.
    
switch ( current_filter() ) {
        case 
'load-update-core.php' :
            
$timeout 60// 1 min
            
break;
        case 
'load-plugins.php' :
        case 
'load-update.php' :
            
$timeout 3600// 1 hour
            
break;
        default :
            
$timeout 43200// 12 hours
    
}

    
$time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked );

    if ( 
$time_not_changed ) {
        
$plugin_changed false;
        foreach ( 
$plugins as $file => $p ) {
            
$new_option->checked$file ] = $p['Version'];

            if ( !isset( 
$current->checked$file ] ) || strval($current->checked$file ]) !== strval($p['Version']) )
                
$plugin_changed true;
        }

        if ( isset ( 
$current->response ) && is_array$current->response ) ) {
            foreach ( 
$current->response as $plugin_file => $update_details ) {
                if ( ! isset(
$plugins$plugin_file ]) ) {
                    
$plugin_changed true;
                    break;
                }
            }
        }

        
// Bail if we've checked recently and if nothing has changed
        
if ( ! $plugin_changed )
            return 
false;
    }

    
// Update last_checked for current to prevent multiple blocking requests if request hangs
    
$current->last_checked time();
    
set_site_transient'update_plugins'$current );

    
$to_send = (object) compact('plugins''active');

    
$options = array(
        
'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 3),
        
'body' => array( 'plugins' => serialize$to_send ) ),
        
'user-agent' => 'WordPress/' $wp_version '; ' get_bloginfo'url' )
    );

    
$raw_response wp_remote_post('http://api.wordpress.org/plugins/update-check/1.0/'$options);

    if ( 
is_wp_error$raw_response ) || 200 != wp_remote_retrieve_response_code$raw_response ) )
        return 
false;

    
$response maybe_unserializewp_remote_retrieve_body$raw_response ) );

    if ( 
is_array$response ) )
        
$new_option->response $response;
    else
        
$new_option->response = array();

    
set_site_transient'update_plugins'$new_option );
}
?>

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

Gebruikersdiscussies [ wordpress.org ]

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics