| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Prevent Browser Caching |
| 4 |
* Description: Updates the assets version of all CSS and JS files. Shows the latest changes on the site without asking the client to clear browser cache. |
| 5 |
* Version: 2.3.4 |
| 6 |
* Author: Kostya Tereshchuk, ISRAEL IT |
| 7 |
* Author URI: https://tutori.org/israelit/ |
| 8 |
* License: GPLv2 or later |
| 9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt |
| 10 |
* Text Domain: prevent-browser-caching |
| 11 |
* Domain Path: /lang/ |
| 12 |
*/ |
| 13 |
|
| 14 |
// Exit if accessed directly. |
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit; |
| 17 |
} |
| 18 |
|
| 19 |
if ( ! function_exists( 'prevent_browser_caching_plugin_actions' ) ) { |
| 20 |
/** |
| 21 |
* Add settings to plugin links. |
| 22 |
* @param $actions |
| 23 |
* @return mixed |
| 24 |
*/ |
| 25 |
function prevent_browser_caching_plugin_actions( $actions ) |
| 26 |
{ |
| 27 |
array_unshift( $actions, "<a href=\"" . menu_page_url( 'prevent-browser-caching', false ) . "\">" . esc_html__( "Settings" ) . "</a>" ); |
| 28 |
return $actions; |
| 29 |
} |
| 30 |
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'prevent_browser_caching_plugin_actions', 10, 1 ); |
| 31 |
} |
| 32 |
|
| 33 |
if ( ! function_exists( 'prevent_browser_caching_load_textdomain' ) ) { |
| 34 |
/** |
| 35 |
* Set languages directory. |
| 36 |
*/ |
| 37 |
function prevent_browser_caching_load_textdomain() |
| 38 |
{ |
| 39 |
load_plugin_textdomain( 'prevent-browser-caching', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' ); |
| 40 |
} |
| 41 |
add_action( 'plugins_loaded', 'prevent_browser_caching_load_textdomain' ); |
| 42 |
} |
| 43 |
|
| 44 |
if ( ! function_exists( 'prevent_browser_caching' ) ) { |
| 45 |
/** |
| 46 |
* Changes the version of CSS and JS files. |
| 47 |
* Disables loading Prevent_Browser_Caching class if this function is used before setup theme. |
| 48 |
* |
| 49 |
* @param array $args |
| 50 |
*/ |
| 51 |
function prevent_browser_caching( $args = array() ) { |
| 52 |
if ( ! class_exists( 'Prevent_Browser_Caching_Function' ) ) { |
| 53 |
include_once 'includes/class-prevent-browser-caching-function.php'; |
| 54 |
} |
| 55 |
|
| 56 |
Prevent_Browser_Caching_Function::instance( $args ); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
if ( ! function_exists( 'maybe_load_class_prevent_browser_caching' ) ) { |
| 61 |
/** |
| 62 |
* Load Prevent_Browser_Caching class if the function prevent_browser_caching is not used before setup theme. |
| 63 |
*/ |
| 64 |
function maybe_load_class_prevent_browser_caching() |
| 65 |
{ |
| 66 |
if ( ! class_exists( 'Prevent_Browser_Caching' ) && ! class_exists( 'Prevent_Browser_Caching_Function' ) ) { |
| 67 |
include_once 'includes/class-prevent-browser-caching.php'; |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
add_action( 'after_setup_theme', 'maybe_load_class_prevent_browser_caching' ); |
| 72 |
} |
| 73 |
|
| 74 |
if ( is_admin() ) { |
| 75 |
include_once 'includes/admin/class-prevent-browser-caching-admin-settings.php'; |
| 76 |
} |