$enabled, 'varnish' => $varnish, ); \FLBuilderModel::update_admin_settings_option( '_fl_builder_cache_plugins', $settings, false ); } /** * Get settings. * @since 2.1.5 */ public static function get_settings() { $defaults = array( 'enabled' => true, 'varnish' => false, ); $settings = \FLBuilderModel::get_admin_settings_option( '_fl_builder_cache_plugins', false ); return wp_parse_args( $settings, $defaults ); } /** * Remove actions added by the cache helper plugin. * @since 2.1.5 */ public function unload_helper_plugin() { if ( class_exists( 'FL_Cache_Buster' ) ) { $settings = self::get_settings(); if ( $settings['enabled'] ) { remove_action( 'upgrader_process_complete', array( 'FL_Cache_Buster', 'clear_caches' ) ); remove_action( 'fl_builder_after_save_layout', array( 'FL_Cache_Buster', 'clear_caches' ) ); remove_action( 'fl_builder_after_save_user_template', array( 'FL_Cache_Buster', 'clear_caches' ) ); remove_action( 'fl_builder_cache_cleared', array( 'FL_Cache_Buster', 'clear_caches' ) ); remove_action( 'template_redirect', array( 'FL_Cache_Buster', 'donotcache' ) ); } } } /** * Load the cache plugin files. */ public function load_files() { foreach ( glob( FL_BUILDER_CACHE_HELPER_DIR . 'plugins/*.php' ) as $file ) { $classname = 'FLCacheClear\\' . ucfirst( str_replace( '.php', '', basename( $file ) ) ); if ( ! in_array( pathinfo( $file, PATHINFO_FILENAME ), $this->allowed_plugins ) ) { $this->triggererror( $file ); return false; } else { include_once( $file ); } $class = new $classname(); $actions = isset( $class->actions ) ? $class->actions : $this->actions; $filters = isset( $class->filters ) ? $class->filters : $this->filters; if ( isset( $class->name ) ) { self::$plugins[ $classname ]['name'] = $class->name; } if ( isset( $class->url ) ) { self::$plugins[ $classname ]['url'] = $class->url; } $settings = self::get_settings(); if ( ! $settings['enabled'] ) { return false; } if ( ! empty( $actions ) ) { $this->add_actions( $class, $actions ); } if ( ! empty( $filters ) ) { $this->add_filters( $class, $filters ); } } } /** * @since 2.6.1 */ private function triggererror( $file ) { $filename = basename( $file ); $message = "An unexpected file ($filename) was found, possible malware! File: $file"; ( ! \FLBuilderAJAX::doing_ajax() && ! isset( $_GET['fl_builder'] ) ) ? trigger_error( $message, E_USER_WARNING ) : false; $args = array( 'content' => $message, 'id' => pathinfo( $file, PATHINFO_FILENAME ), 'only' => false, 'class' => 'notice-error', ); \FLBuilderAdminNotices::register_notice( $args ); } /** * Return list of plugins to be used on admin page. */ public static function get_plugins() { $plugins = self::$plugins; $output = ''; foreach ( $plugins as $plugin ) { if ( isset( $plugin['url'] ) ) { $output .= sprintf( '
  • %s', $plugin['url'], $plugin['name'] ); } else { $output .= sprintf( '
  • %s
  • ', $plugin['name'] ); } } return ''; } function add_actions( $class, $actions ) { foreach ( $actions as $action ) { add_action( $action, array( $class, 'run' ) ); } } function add_filters( $class, $filters ) { foreach ( $filters as $filter ) { add_action( $filter, array( $class, 'filters' ) ); } } public static function define( $define, $setting = true ) { if ( ! defined( $define ) ) { define( $define, $setting ); } } } new Plugin;