Plugin Directory

Changeset 802207


Ignore:
Timestamp:
11/10/2013 11:54:34 PM (12 years ago)
Author:
mglaman
Message:

Apply hook to clear an albums cache on save_post

File:
1 edited

Legend:

Unmodified
Added
Removed
  • facebook-albums/trunk/fbalbum.php

    r802182 r802207  
    4343register_activation_hook(__FILE__, array('FB_Album', 'activate'));
    4444add_action('init', array('FB_Album', 'set_facebook_sdk'), 0);
     45add_action( 'save_post', array('FB_Album', 'save_post') );
    4546class FB_Album {
    4647
     
    141142  }
    142143
     144  public static function save_post($post_id) {
     145    if ( wp_is_post_revision( $post_id ) )
     146      return;
     147
     148    $post = get_post($post_id);
     149    if(strpos($post->post_content, '[fbalbum ') !== FALSE) {
     150      preg_match("/[fbalbum [^>]*url=(.+) /", $post->post_content, $output);
     151      $facebook_album_url = str_replace('"', '', $output[1]);
     152      error_log($facebook_album_url);
     153      FB_Album::_set_album_url($facebook_album_url);
     154      $album_id = FB_Album::_get_album_id();
     155      FB_Album::clear_cache($album_id);
     156    }
     157  }
     158
    143159  /**
    144160    * Builds HTML string to output album photos
     
    355371    $cahce_lifetime = (isset(self::$options['cache'])) ? self::$options['cache'] * DAY_IN_SECONDS : DAY_IN_SECONDS;
    356372
    357     set_transient("fbalbum_".self::$album_id, $json, DAY_IN_SECONDS); //caching for 24 hours
     373    set_transient("fbalbum_".self::$album_id, $json, 12 * HOUR_IN_SECONDS); //caching for 12 hours
    358374  }
    359375
Note: See TracChangeset for help on using the changeset viewer.