1 <?php
  2 
  3 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
  4 
  5 /**
  6  * WC_Cache_Helper class.
  7  *
  8  * @class       WC_Cache_Helper
  9  * @version     2.0.6
 10  * @package     WooCommerce/Classes
 11  * @category    Class
 12  * @author      WooThemes
 13  */
 14 class WC_Cache_Helper {
 15 
 16     /**
 17      * __construct function.
 18      *
 19      * @access public
 20      * @return void
 21      */
 22     public function __construct() {
 23         add_action( 'before_woocommerce_init', array( $this, 'init' ) );
 24         add_action( 'admin_notices', array( $this, 'notices' ) );
 25     }
 26 
 27     /**
 28      * Prevent caching on dynamic pages.
 29      *
 30      * @access public
 31      * @return void
 32      */
 33     public function init() {
 34         if ( false === ( $wc_page_uris = get_transient( 'woocommerce_cache_excluded_uris' ) ) ) {
 35 
 36             if ( wc_get_page_id( 'cart' ) < 1 || wc_get_page_id( 'checkout' ) < 1 || wc_get_page_id( 'myaccount' ) < 1 )
 37                 return;
 38 
 39             $wc_page_uris   = array();
 40 
 41             // Exclude querystring when using page ID
 42             $wc_page_uris[] = 'p=' . wc_get_page_id( 'cart' );
 43             $wc_page_uris[] = 'p=' . wc_get_page_id( 'checkout' );
 44             $wc_page_uris[] = 'p=' . wc_get_page_id( 'myaccount' );
 45 
 46             // Exclude permalinks
 47             $cart_page      = get_post( wc_get_page_id( 'cart' ) );
 48             $checkout_page  = get_post( wc_get_page_id( 'checkout' ) );
 49             $account_page   = get_post( wc_get_page_id( 'myaccount' ) );
 50 
 51             if ( ! is_null( $cart_page ) )
 52                 $wc_page_uris[] = '/' . $cart_page->post_name;
 53             if ( ! is_null( $checkout_page ) )
 54                 $wc_page_uris[] = '/' . $checkout_page->post_name;
 55             if ( ! is_null( $account_page ) )
 56                 $wc_page_uris[] = '/' . $account_page->post_name;
 57 
 58             set_transient( 'woocommerce_cache_excluded_uris', $wc_page_uris );
 59         }
 60 
 61         if ( is_array( $wc_page_uris ) )
 62             foreach( $wc_page_uris as $uri )
 63                 if ( strstr( $_SERVER['REQUEST_URI'], $uri ) ) {
 64                     $this->nocache();
 65                     break;
 66                 }
 67     }
 68 
 69     /**
 70      * Set nocache constants and headers.
 71      *
 72      * @access private
 73      * @return void
 74      */
 75     private function nocache() {
 76         if ( ! defined( 'DONOTCACHEPAGE' ) )
 77             define( "DONOTCACHEPAGE", "true" );
 78 
 79         if ( ! defined( 'DONOTCACHEOBJECT' ) )
 80             define( "DONOTCACHEOBJECT", "true" );
 81 
 82         if ( ! defined( 'DONOTCACHEDB' ) )
 83             define( "DONOTCACHEDB", "true" );
 84 
 85         nocache_headers();
 86     }
 87 
 88     /**
 89      * notices function.
 90      *
 91      * @access public
 92      * @return void
 93      */
 94     public function notices() {
 95         if ( ! function_exists( 'w3tc_pgcache_flush' ) || ! function_exists( 'w3_instance' ) )
 96             return;
 97 
 98         $config   = w3_instance('W3_Config');
 99         $enabled  = $config->get_integer( 'dbcache.enabled' );
100         $settings = $config->get_array( 'dbcache.reject.sql' );
101 
102         if ( $enabled && ! in_array( '_wc_session_', $settings ) ) {
103             ?>
104             <div class="error">
105                 <p><?php printf( __( 'In order for <strong>database caching</strong> to work with WooCommerce you must add <code>_wc_session_</code> to the "Ignored Query Strings" option in W3 Total Cache settings <a href="%s">here</a>.', 'woocommerce' ), admin_url( 'admin.php?page=w3tc_dbcache' ) ); ?></p>
106             </div>
107             <?php
108         }
109     }
110 }
111 
112 new WC_Cache_Helper();
113 
WooCommerce API documentation generated by ApiGen 2.8.0