WordPress.org

Plugin Directory

Changeset 634171


Ignore:
Timestamp:
12/04/12 20:43:33 (17 months ago)
Author:
mitchoyoshitaka
Message:

+ delete_transient, and use it for yarpp_version_info

Location:
yet-another-related-posts-plugin/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • yet-another-related-posts-plugin/trunk/class-core.php

    r634103 r634171  
    325325        if ( $last_version && version_compare('3.6b7', $last_version) > 0 ) 
    326326            $this->upgrade_3_6b7(); 
     327        if ( $last_version && version_compare('4.0.1', $last_version) > 0 ) 
     328            $this->upgrade_4_0_1(); 
    327329         
    328330        $this->cache->upgrade($last_version); 
     
    334336     
    335337        update_option('yarpp_version',YARPP_VERSION); 
    336         delete_transient( 'yarpp_optin' ); 
     338        $this->delete_transient( 'yarpp_optin' ); 
    337339    } 
    338340     
     
    546548    } 
    547549     
     550    function upgrade_4_0_1() { 
     551        delete_transient('yarpp_version_info'); 
     552    } 
     553     
    548554    private $post_types = null; 
    549555    function get_post_types( $field = 'name' ) { 
     
    10901096    // @since 3.3: use PHP serialized format instead of JSON 
    10911097    function version_info( $enforce_cache = false ) { 
    1092         if (false === ($result = get_transient('yarpp_version_info')) || $enforce_cache) { 
     1098        if (false === ($result = $this->get_transient('yarpp_version_info')) || $enforce_cache) { 
    10931099            $version = YARPP_VERSION; 
    10941100            $remote = wp_remote_post("http://yarpp.org/checkversion.php?format=php&version={$version}"); 
     
    10981104             
    10991105            if ( $result = @unserialize($remote['body']) ) 
    1100                 set_transient('yarpp_version_info', $result, 60*60*12); 
     1106                $this->set_transient('yarpp_version_info', $result, 60 * 60 * 24); 
    11011107        } 
    11021108        return $result; 
     
    11051111    // @since 4: optional data collection (default off) 
    11061112    function optin_ping() { 
    1107         if ( $this->get_timeout( 'yarpp_optin' ) ) 
     1113        if ( $this->get_transient( 'yarpp_optin' ) ) 
    11081114            return true; 
    11091115 
     
    11111117        if ( is_wp_error($remote) || !isset($remote['body']) || $remote['body'] != 'ok' ) { 
    11121118            // try again later 
    1113             $this->set_timeout( 'yarpp_optin', 60 * 60 ); 
     1119            $this->set_transient( 'yarpp_optin', null, 60 * 60 ); 
    11141120            return false; 
    11151121        } 
    1116         $this->set_timeout( 'yarpp_optin', 60 * 60 * 24 * 7 ); 
     1122        $this->set_transient( 'yarpp_optin', null, 60 * 60 * 24 * 7 ); 
    11171123        return true; 
    11181124    } 
    11191125     
    11201126    // a version of the transient functions which is unaffected by caching plugin behavior. 
    1121     // we want to store this long. 
    1122     private function get_timeout( $transient ) { 
     1127    // we want to control the lifetime of data. 
     1128    private function get_transient( $transient ) { 
    11231129        $transient_timeout = $transient . '_timeout'; 
    11241130        if ( intval( get_option( $transient_timeout ) ) < time() ) { 
     
    11261132            return false; // timed out 
    11271133        } 
    1128         return true; // still ok 
    1129     } 
    1130  
    1131     private function set_timeout( $transient, $expiration = 0 ) { 
     1134        return get_option( $transient, true ); // still ok 
     1135    } 
     1136 
     1137    private function set_transient( $transient, $data = null, $expiration = 0 ) { 
    11321138        $transient_timeout = $transient . '_timeout'; 
    11331139        if ( false === get_option( $transient_timeout ) ) { 
    11341140            add_option( $transient_timeout, time() + $expiration, '', 'no' ); 
     1141            if ( !is_null( $data ) ) 
     1142                add_option( $transient, $data, '', 'no' ); 
    11351143        } else { 
    11361144            update_option( $transient_timeout, time() + $expiration ); 
    1137         } 
     1145            if ( !is_null( $data ) ) 
     1146                update_option( $transient, $data ); 
     1147        } 
     1148    } 
     1149     
     1150    private function delete_transient( $transient ) { 
     1151        delete_option( $transient ); 
     1152        delete_option( $transient . '_timeout' ); 
    11381153    } 
    11391154     
  • yet-another-related-posts-plugin/trunk/yarpp.php

    r634118 r634171  
    44Plugin URI: http://yarpp.org/ 
    55Description: Returns a list of related entries based on a unique algorithm for display on your blog and RSS feeds. Now with Now with thumbnail support built-in! 
    6 Version: 4.0.1b2 
     6Version: 4.0.1b3 
    77Author: mitcho (Michael Yoshitaka Erlewine) 
    88Author URI: http://mitcho.com/ 
     
    1010*/ 
    1111 
    12 define('YARPP_VERSION', '4.0.1b2'); 
     12define('YARPP_VERSION', '4.0.1b3'); 
    1313define('YARPP_DIR', dirname(__FILE__)); 
    1414define('YARPP_NO_RELATED', ':('); 
Note: See TracChangeset for help on using the changeset viewer.