installed plugin W3 Total Cache
version 2.3.2
This commit is contained in:
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
namespace W3TCExample;
|
||||
|
||||
|
||||
|
||||
class Extension_Example {
|
||||
/**
|
||||
* W3 Total cache config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Runs extension
|
||||
*/
|
||||
function run() {
|
||||
// obtain w3tc config
|
||||
$this->config = w3tc_config();
|
||||
|
||||
// get value of config option and use it
|
||||
if ( $this->config->get_boolean( array( 'example' , 'is_title_postfix' ) ) )
|
||||
add_filter( 'the_title', array( $this, 'the_title' ), 10, 2 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* the_title filter handler.
|
||||
* This extension adds specified postfix to each post title if extensions
|
||||
* is configured so on its settings page
|
||||
*/
|
||||
public function the_title( $title, $id ) {
|
||||
return $title .
|
||||
$this->config->get_string( array( 'example' , 'title_postfix' ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
This file is simply loaded by W3 Total Cache in a case if extension is active.
|
||||
Its up to extension what will it do or which way will it do.
|
||||
*/
|
||||
$p = new Extension_Example();
|
||||
$p->run();
|
||||
|
||||
if ( is_admin() ) {
|
||||
$p = new Extension_Example_Admin();
|
||||
$p->run();
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
namespace W3TCExample;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Backend functionality of an extension.
|
||||
* This class is loaded only for wp-admin/ requests
|
||||
*/
|
||||
class Extension_Example_Admin {
|
||||
/**
|
||||
* w3tc_extensions filter handler
|
||||
*
|
||||
* @param array $extensions array of extension descriptors to fill
|
||||
* @param Config $config w3-total-cache configuration
|
||||
* @return array
|
||||
*/
|
||||
static public function w3tc_extensions( $extensions, $config ) {
|
||||
$extensions['example'] = array (
|
||||
'name' => 'Example Extension',
|
||||
'author' => 'W3 EDGE',
|
||||
'description' => __( 'Example extension' ),
|
||||
'author_uri' => 'https://www.w3-edge.com/',
|
||||
'extension_uri' => 'https://www.w3-edge.com/',
|
||||
'extension_id' => 'example',
|
||||
'settings_exists' => true,
|
||||
'version' => '1.0',
|
||||
'enabled' => true,
|
||||
'requirements' => '',
|
||||
'path' => 'w3-total-cache-example/Extension_Example.php'
|
||||
);
|
||||
|
||||
return $extensions;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Entry point of extension for wp-admin/ requests
|
||||
* Called from Extension_Example.php
|
||||
*/
|
||||
public function run() {
|
||||
// handle settings page of this extension
|
||||
add_action( 'w3tc_extension_page_example', array(
|
||||
$this,
|
||||
'w3tc_extension_page'
|
||||
) );
|
||||
|
||||
// get control when configuration is changed by user
|
||||
add_action( 'w3tc_config_ui_save', array(
|
||||
$this,
|
||||
'w3tc_config_ui_save'
|
||||
), 10, 2 );
|
||||
|
||||
// Register widget on W3 Total Cache Dashboard page
|
||||
add_action( 'w3tc_widget_setup', array(
|
||||
$this,
|
||||
'w3tc_widget_setup'
|
||||
) );
|
||||
|
||||
// get control when extension is deactivated
|
||||
add_action( 'w3tc_deactivate_extension_example', array(
|
||||
$this, 'w3tc_deactivate_extension' ) );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Show settings page
|
||||
*/
|
||||
public function w3tc_extension_page() {
|
||||
include dirname( __FILE__ ) . '/Extension_Example_Page_View.php';
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get control when configuration is changed by user
|
||||
*/
|
||||
public function w3tc_config_ui_save( $config, $old_config ) {
|
||||
if ( $config->get( array( 'example', 'is_title_postfix' ) ) !=
|
||||
$old_config->get( array( 'example', 'is_title_postfix' ) ) ||
|
||||
$config->get( array( 'example', 'title_postfix' ) ) !=
|
||||
$old_config->get( array( 'example', 'title_postfix' ) ) ) {
|
||||
// flush all content caches, since our extension will now alter
|
||||
// content
|
||||
w3tc_flush_posts();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Registers widget on W3 Total Cache Dashboard page
|
||||
*/
|
||||
public function w3tc_widget_setup() {
|
||||
$screen = get_current_screen();
|
||||
add_meta_box( 'example', 'example', array( $this, 'widget_content' ),
|
||||
$screen, 'normal', 'core' );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Renders content of widget
|
||||
*/
|
||||
public function widget_content() {
|
||||
echo "Example extension's widget";
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Called when extension is deactivated.
|
||||
* Perform a cleanup here
|
||||
*/
|
||||
public function w3tc_deactivate_extension() {
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace W3TCExample;
|
||||
|
||||
if ( ! defined( 'W3TC' ) ) {
|
||||
die();
|
||||
}
|
||||
?>
|
||||
<p>
|
||||
<?php esc_html_e( 'Jump to:', 'w3-total-cache' ); ?>
|
||||
<a href="admin.php?page=w3tc_general"><?php esc_html_e( 'Main Menu', 'w3-total-cache' ); ?></a> |
|
||||
<a href="admin.php?page=w3tc_extensions"><?php esc_html_e( 'Extensions', 'w3-total-cache' ); ?></a>
|
||||
</p>
|
||||
<p><?php esc_html_e( 'Example extension is currently ', 'w3-total-cache' ); ?><span class="w3tc-enabled"><?php esc_html_e( 'enabled', 'w3-total-cache' ); ?></span></p>
|
||||
|
||||
<div class="metabox-holder">
|
||||
<?php
|
||||
// render settings box header.
|
||||
\W3TC\Util_Ui::postbox_header( 'Example extension' );
|
||||
?>
|
||||
<table class="form-table">
|
||||
<?php
|
||||
// render controls showing content of w3tc configuration options.
|
||||
\W3TC\Util_Ui::config_item(
|
||||
array(
|
||||
'key' => array( 'example', 'is_title_postfix' ),
|
||||
'control' => 'checkbox',
|
||||
'label' => __( 'Add postfix to page titles', 'w3-total-cache' ),
|
||||
'checkbox_label' => __( 'Enable', 'w3-total-cache' ),
|
||||
'description' => __( 'Check if you want to add postfix to each post title.', 'w3-total-cache' ),
|
||||
)
|
||||
);
|
||||
\W3TC\Util_Ui::config_item(
|
||||
array(
|
||||
'key' => array( 'example', 'title_postfix' ),
|
||||
'control' => 'textbox',
|
||||
'label' => __( 'Postfix to page titles', 'w3-total-cache' ),
|
||||
)
|
||||
);
|
||||
?>
|
||||
</table>
|
||||
<?php
|
||||
// render save button for ::config_item controls.
|
||||
\W3TC\Util_Ui::button_config_save( 'extension_example' );
|
||||
// render settings box footer.
|
||||
\W3TC\Util_Ui::postbox_footer();
|
||||
?>
|
||||
</div>
|
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/*
|
||||
Plugin Name: W3 Total Cache Example Extension
|
||||
Description: W3 Total Cache Example Extension
|
||||
Version: 1.0
|
||||
Plugin URI: https://www.w3-edge.com/wordpress-plugins/w3-total-cache/
|
||||
Author: Frederick Townes
|
||||
Author URI: http://www.linkedin.com/in/fredericktownes
|
||||
Network: True
|
||||
*/
|
||||
|
||||
/* Copyright (c) 2009 Frederick Townes <ftownes@w3-edge.com>
|
||||
|
||||
W3 Total Cache is distributed under the GNU General Public License, Version 2,
|
||||
June 1991. Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin
|
||||
St, Fifth Floor, Boston, MA 02110, USA
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
if ( !defined( 'ABSPATH' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Class autoloader
|
||||
*
|
||||
* @param string $class Classname
|
||||
*/
|
||||
function w3tc_example_class_autoload( $class ) {
|
||||
if ( substr( $class, 0, 12 ) == 'W3TCExample\\' ) {
|
||||
$filename = dirname( __FILE__ ) . DIRECTORY_SEPARATOR .
|
||||
substr( $class, 12 ) . '.php';
|
||||
|
||||
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
|
||||
if ( !file_exists( $filename ) ) {
|
||||
debug_print_backtrace();
|
||||
}
|
||||
}
|
||||
|
||||
require $filename;
|
||||
}
|
||||
}
|
||||
|
||||
spl_autoload_register( 'w3tc_example_class_autoload' );
|
||||
|
||||
add_action( 'w3tc_extensions', array(
|
||||
'\W3TCExample\Extension_Example_Admin',
|
||||
'w3tc_extensions'
|
||||
), 10, 2 );
|
Reference in New Issue
Block a user