Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance/press7-79 adding performance link in wp > settings menu and remove old settings #31

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 20 additions & 48 deletions includes/Performance.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

namespace NewfoldLabs\WP\Module\Performance;

use NewfoldLabs\WP\Module\Performance\CacheTypes\Browser;
use NewfoldLabs\WP\Module\Performance\CacheTypes\File;
use NewfoldLabs\WP\Module\Performance\CacheTypes\Skip404;
use NewfoldLabs\WP\ModuleLoader\Container;

/**
Expand Down Expand Up @@ -72,10 +69,9 @@ public function __construct( Container $container ) {
$cacheManager = new CacheManager( $container );
$cachePurger = new CachePurgingService( $cacheManager->getInstances() );

// Ensure that purgeable cache types are enabled before showing the UI.
if ( $cachePurger->canPurge() ) {
add_action( 'admin_bar_menu', array( $this, 'adminBarMenu' ), 100 );
}
add_action( 'admin_bar_menu', array( $this, 'adminBarMenu' ), 100 );

add_action( 'admin_menu', array( $this, 'add_sub_menu_page' ) );

$container->set( 'cachePurger', $cachePurger );

Expand Down Expand Up @@ -105,12 +101,8 @@ function () {

/**
* Add hooks.
*
* @param Container $container the container
*/
public function hooks( Container $container ) {

add_action( 'admin_init', array( $this, 'registerSettings' ), 11 );
public function hooks() {

new OptionListener( self::OPTION_CACHE_LEVEL, array( $this, 'onCacheLevelChange' ) );

Expand Down Expand Up @@ -149,11 +141,9 @@ function () {
* @hooked action_scheduler_retention_period
* @see ActionScheduler_QueueCleaner::delete_old_actions()
*
* @param int $retention_period Minimum scheduled age in seconds of the actions to be deleted.
*
* @return int New retention period in seconds.
*/
public function nfd_asr_default( $retention_period ) {
public function nfd_asr_default() {
return 5 * constant( 'DAY_IN_SECONDS' );
}

Expand Down Expand Up @@ -208,39 +198,6 @@ public function onCacheLevelChange( $cacheLevel ) {
}
}

/**
* Register settings
*/
public function registerSettings() {

global $wp_settings_fields;

$section_name = self::SETTINGS_SECTION;

add_settings_section(
$section_name,
'<span id="' . self::SETTINGS_ID . '">' . esc_html__( 'Caching', 'newfold-performance-module' ) . '</span>',
'__return_false',
'general'
);

add_settings_field(
self::OPTION_CACHE_LEVEL,
__( 'Cache Level', 'newfold-performance-module' ),
__NAMESPACE__ . '\\getCacheLevelDropdown',
'general',
$section_name
);

register_setting( 'general', self::OPTION_CACHE_LEVEL );

// Remove the setting from EPC if it exists - TODO: Remove when no longer using EPC
if ( $this->container->get( 'hasMustUsePlugin' ) ) {
unset( $wp_settings_fields['general']['epc_settings_section'] );
unregister_setting( 'general', 'endurance_cache_level' );
}
}

/**
* Add options to the WordPress admin bar.
*
Expand Down Expand Up @@ -292,4 +249,19 @@ public function adminBarMenu( \WP_Admin_Bar $wp_admin_bar ) {
);
}
}

/**
* Add performance menu in WP/Settings
*/
public function add_sub_menu_page() {
$brand = $this->container->get( 'plugin' )['id'];
add_options_page(
__( 'Performance', 'newfold-performance-module' ),
__( 'Performance', 'newfold-performance-module' ),
'manage_options',
admin_url( "admin.php?page=$brand#/performance" ),
null,
5
);
}
}
Loading