Skip to content

Commit

Permalink
Fragment Cache frontend fix (#1016)
Browse files Browse the repository at this point in the history
* Fixed frontend active state and made it so settings page links would show so long as the extension is active.
* Add message to settings page indicating that selecting an engine would enable the FC feature.
* Fixed advanced tab showing for Fragment Cache block on general settings page when extension is not active.
* Add disk usage warning for fragment cache block on general settings.
* Fixed frontend active status when extension is deactivated.
* Hide disk notice by default
* Use toggle instead of show/hide
  • Loading branch information
jacobd91 authored Dec 20, 2024
1 parent 6829a79 commit 01d86c3
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 18 deletions.
15 changes: 14 additions & 1 deletion Extension_FragmentCache_GeneralPage_View.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,25 @@
),
'',
'fragmentcache',
Util_UI::admin_url( 'admin.php?page=w3tc_fragmentcache' )
Util_Environment::is_w3tc_pro( $config ) ? Util_UI::admin_url( 'admin.php?page=w3tc_fragmentcache' ) : ''
);

?>

<table class="form-table">
<div class="fragmentcache_disk_notice notice notice-warning">
<p><b><?php esc_html_e( 'Warning: Disk-Based Fragment Caching Selected', 'w3-total-cache' ); ?></b></p>
<p>
<li style="margin-left:15px;"><?php esc_html_e( 'Using disk as the cache engine for fragment caching is not recommended due to its potential for slow performance depending on storage device types and server configuration.', 'w3-total-cache' ); ?></li>
<li style="margin-left:15px;"><?php esc_html_e( 'This setting can potentially create a large number of files. Please be aware of any inode or disk space limits you may have on your hosting account.', 'w3-total-cache' ); ?></li>
</p>
<p>
<?php esc_html_e( 'For optimal performance, consider using a memory-based caching solution like Redis or Memcached.', 'w3-total-cache' ); ?>
<a target="_blank" href="<?php echo esc_url( 'https://www.boldgrid.com/comparing-disk-redis-memcached-caching/' ); ?>"
title="<?php esc_attr_e( 'Comparing Disk, Redis, and Memcached: Understanding Caching Solutions', 'w3-total-cache' ); ?>">
<?php esc_html_e( 'Learn more', 'w3-total-cache' ); ?> <span class="dashicons dashicons-external"></span></a>
</p>
</div>
<?php
$fragmentcache_config = array(
'key' => array( 'fragmentcache', 'engine' ),
Expand Down
28 changes: 26 additions & 2 deletions Extension_FragmentCache_Page_View.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,32 @@
}
?>
<?php endif; ?>

<?php Util_Ui::pro_wrap_maybe_end2( 'fragmentcache_header' ); ?>
<?php
if ( empty( $engine ) ) {
?>
<p>
<?php
echo wp_kses(
sprintf(
// Translators: 1 opening HTML link to fragment cache block on general settings page, 2 closing HTML link.
__(
'To enable this feature please select an engine for Fragment Cache %1$shere%2$s.',
'w3-total-cache'
),
'<a href="' . esc_url( Util_Ui::admin_url( 'admin.php?page=w3tc_general#fragmentcache' ) ) . '">',
'</a>'
),
array(
'a' => array(
'href' => array(),
),
)
);
?>
</p>
<?php
}
Util_Ui::pro_wrap_maybe_end2( 'fragmentcache_header' ); ?>
</p>

<form action="admin.php?page=w3tc_fragmentcache" method="post">
Expand Down
8 changes: 4 additions & 4 deletions Extension_FragmentCache_Plugin_Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function w3tc_objectcache_addin_required( $addin_required ) {
public function w3tc_extension_plugin_links( $links ) {
$links = array();

if ( $this->_config->is_extension_active_frontend( 'fragmentcache' ) && Util_Environment::is_w3tc_pro( $this->_config ) ) {
if ( $this->_config->is_extension_active( 'fragmentcache' ) && Util_Environment::is_w3tc_pro( $this->_config ) ) {
$links[] = '<a class="edit" href="' . esc_attr( Util_Ui::admin_url( 'admin.php?page=w3tc_fragmentcache' ) ) . '">'
. __( 'Settings', 'w3-total-cache' ) . '</a>';
}
Expand All @@ -102,7 +102,7 @@ public function w3tc_extension_plugin_links( $links ) {


public function w3tc_admin_menu( $menu ) {
if ( $this->_config->is_extension_active_frontend( 'fragmentcache' ) && Util_Environment::is_w3tc_pro( $this->_config ) ) {
if ( $this->_config->is_extension_active( 'fragmentcache' ) && Util_Environment::is_w3tc_pro( $this->_config ) ) {
$menu['w3tc_fragmentcache'] = array(
'page_title' => __( 'Fragment Cache', 'w3-total-cache' ),
'menu_text' => '<span class="w3tc_menu_item_pro">' . __( 'Fragment Cache', 'w3-total-cache' ) . '</span>',
Expand All @@ -117,7 +117,7 @@ public function w3tc_admin_menu( $menu ) {


public function w3tc_admin_bar_menu( $menu_items ) {
if ( $this->_config->is_extension_active_frontend( 'fragmentcache' ) && Util_Environment::is_w3tc_pro( $this->_config ) ) {
if ( $this->_config->is_extension_active( 'fragmentcache' ) && Util_Environment::is_w3tc_pro( $this->_config ) ) {
$menu_items['20510.fragmentcache'] = array(
'id' => 'w3tc_flush_fragmentcache',
'parent' => 'w3tc_flush',
Expand All @@ -139,12 +139,12 @@ public function w3tc_settings_page_w3tc_fragmentcache() {


public function w3tc_config_save( $config ) {
// frontend activity.
$is_frontend_active = (
$config->is_extension_active( 'fragmentcache' ) &&
! empty( $config->get_string( array( 'fragmentcache', 'engine' ) ) ) &&
Util_Environment::is_w3tc_pro( $config )
);

$config->set_extension_active_frontend( 'fragmentcache', $is_frontend_active );
}

Expand Down
2 changes: 1 addition & 1 deletion Generic_WidgetSettings_View.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
),
'fragmentcache' => array(
'label' => esc_html__( 'Fragment Cache', 'w3-total-cache' ),
'enabled' => $config->is_extension_active_frontend( 'fragmentcache' ) && Util_Environment::is_w3tc_pro( $config ),
'enabled' => $config->is_extension_active_frontend( 'fragmentcache' ),
),
'debug' => array(
'label' => esc_html__( 'Debug', 'w3-total-cache' ),
Expand Down
1 change: 1 addition & 0 deletions pub/css/options.css
Original file line number Diff line number Diff line change
Expand Up @@ -1712,6 +1712,7 @@ td .w3tc-control-after span {
margin-left: 5px;
}

.fragmentcache_disk_notice,
.objectcache_disk_notice,
.dbcache_disk_notice {
display: none;
Expand Down
25 changes: 15 additions & 10 deletions pub/js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,11 +488,7 @@ function cdn_cf_bucket_location() {
* @since 2.8.0
*/
function toggle_dbcache_notice() {
if ( jQuery('#dbcache__engine').val() === 'file' && jQuery('#dbcache__enabled').is(':checked') ) {
jQuery('.dbcache_disk_notice').show();
} else {
jQuery('.dbcache_disk_notice').hide();
}
jQuery('.dbcache_disk_notice').toggle(jQuery('#dbcache__engine').val() === 'file' && jQuery('#dbcache__enabled').is(':checked'));
}

/**
Expand All @@ -501,11 +497,16 @@ function toggle_dbcache_notice() {
* @since 2.8.0
*/
function toggle_objectcache_notice() {
if ( jQuery('#objectcache__engine').val() === 'file' && jQuery('#objectcache__enabled').is(':checked') ) {
jQuery('.objectcache_disk_notice').show();
} else {
jQuery('.objectcache_disk_notice').hide();
}
jQuery('.objectcache_disk_notice').toggle(jQuery('#objectcache__engine').val() === 'file' && jQuery('#objectcache__enabled').is(':checked'));
}

/**
* Toggle the disk notice for fragmentcache.
*
* @since 2.8.0
*/
function toggle_fragmentcache_notice() {
jQuery('.fragmentcache_disk_notice').toggle(jQuery('#fragmentcache___engine').val() === 'file');
}

// On document ready.
Expand All @@ -524,6 +525,10 @@ jQuery(function() {
jQuery('#objectcache__enabled').change(toggle_objectcache_notice);
jQuery('#objectcache__engine').change(toggle_objectcache_notice);

// Fragment cache disk usage warning.
toggle_fragmentcache_notice();
jQuery('#fragmentcache___engine').change(toggle_fragmentcache_notice);

// General page.
jQuery('.w3tc_read_technical_info').on('click', function() {
jQuery('.w3tc_technical_info').toggle();
Expand Down

0 comments on commit 01d86c3

Please sign in to comment.