| 1 |
<?php |
| 2 |
/** |
| 3 |
* The provider hooking Admin class methods to WordPress events. |
| 4 |
* |
| 5 |
* @since 0.1.0 |
| 6 |
* |
| 7 |
* @package SolidWP\Performance |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace SolidWP\Performance\Admin; |
| 11 |
|
| 12 |
use SolidWP\Performance\Contracts\Service_Provider; |
| 13 |
|
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* The provider for all Admin related functionality. |
| 20 |
* |
| 21 |
* @since 0.1.0 |
| 22 |
* |
| 23 |
* @package SolidWP\Performance |
| 24 |
*/ |
| 25 |
class Provider extends Service_Provider { |
| 26 |
|
| 27 |
public const PUBLIC_POST_TYPES = 'solidwp.performance.admin.public_post_types'; |
| 28 |
|
| 29 |
/** |
| 30 |
* {@inheritdoc} |
| 31 |
*/ |
| 32 |
public function register(): void { |
| 33 |
$this->container->singleton( Settings_Page::class, Settings_Page::class ); |
| 34 |
|
| 35 |
add_filter( 'admin_bar_menu', $this->container->callback( Admin_Bar::class, 'add_purge_admin_bar_link' ), 100 ); |
| 36 |
add_filter( 'init', $this->container->callback( Purge_Listener::class, 'purge_page_cache' ) ); |
| 37 |
add_filter( 'init', $this->container->callback( Purge_Listener::class, 'purge_single_page_cache' ) ); |
| 38 |
add_filter( 'admin_menu', $this->container->callback( Settings_Page::class, 'add_settings_page' ), 100 ); |
| 39 |
add_action( 'admin_init', $this->container->callback( Settings_Page::class, 'register_settings' ) ); |
| 40 |
add_action( 'rest_api_init', $this->container->callback( Settings_Page::class, 'register_settings' ) ); |
| 41 |
add_action( 'plugin_action_links_' . plugin_basename( SWPSP_PLUGIN_FILE ), $this->container->callback( Settings_Page::class, 'settings_link' ), 10 ); |
| 42 |
|
| 43 |
$this->register_page_cache_exclusion(); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Registers the page cache exclusion meta box. |
| 48 |
* |
| 49 |
* @return void |
| 50 |
*/ |
| 51 |
private function register_page_cache_exclusion(): void { |
| 52 |
// Exclude the meta box from these post types. |
| 53 |
$post_types_to_ignore = (array) apply_filters( |
| 54 |
'solidwp/performance/public_post_type_ignore_array', |
| 55 |
[ |
| 56 |
// Elementor. |
| 57 |
'elementor_library', |
| 58 |
// Beaver Builder. |
| 59 |
'fl-theme-layout', |
| 60 |
// WooCommerce. |
| 61 |
'shop_order', |
| 62 |
// Kadence. |
| 63 |
'kadence_element', |
| 64 |
'kadence_conversions', |
| 65 |
'kadence_wootemplate', |
| 66 |
'ele-product-template', |
| 67 |
'ele-p-arch-template', |
| 68 |
'ele-p-loop-template', |
| 69 |
'ele-check-template', |
| 70 |
'kt_size_chart', |
| 71 |
'kt_cart_notice', |
| 72 |
'kt_reviews', |
| 73 |
'kt_product_tabs', |
| 74 |
// Jet. |
| 75 |
'jet-menu', |
| 76 |
'jet-popup', |
| 77 |
'jet-smart-filters', |
| 78 |
'jet-theme-core', |
| 79 |
'jet-woo-builder', |
| 80 |
'jet-engine', |
| 81 |
// LifterLMS. |
| 82 |
'llms_certificate', |
| 83 |
'llms_my_certificate', |
| 84 |
// LearnDash. |
| 85 |
'sfwd-certificates', |
| 86 |
'sfwd-transactions', |
| 87 |
'reply', |
| 88 |
] |
| 89 |
); |
| 90 |
|
| 91 |
$this->container->when( Post_Cache_Exclusion::class ) |
| 92 |
->needs( '$post_types_to_ignore' ) |
| 93 |
->give( $post_types_to_ignore ); |
| 94 |
|
| 95 |
// Get all public, non-built in post types and manually add post+page. |
| 96 |
$this->container->singleton( |
| 97 |
self::PUBLIC_POST_TYPES, |
| 98 |
static fn() => (array) apply_filters( |
| 99 |
'solidwp/performance/public_post_type_objects', |
| 100 |
array_merge( |
| 101 |
get_post_types( |
| 102 |
[ |
| 103 |
'public' => true, |
| 104 |
'_builtin' => false, |
| 105 |
], |
| 106 |
), |
| 107 |
[ 'post', 'page' ] |
| 108 |
) |
| 109 |
) |
| 110 |
); |
| 111 |
|
| 112 |
$this->container->when( Post_Cache_Exclusion::class ) |
| 113 |
->needs( '$post_types' ) |
| 114 |
->give( $this->container->get( self::PUBLIC_POST_TYPES ) ); |
| 115 |
|
| 116 |
$this->container->singleton( Post_Cache_Exclusion::class, Post_Cache_Exclusion::class ); |
| 117 |
|
| 118 |
add_action( |
| 119 |
'init', |
| 120 |
static function (): void { |
| 121 |
Post_Cache_Exclusion::register_meta(); |
| 122 |
}, |
| 123 |
20 |
| 124 |
); |
| 125 |
add_action( 'admin_init', $this->container->callback( Post_Cache_Exclusion::class, 'register_meta_script' ) ); |
| 126 |
add_action( 'enqueue_block_editor_assets', $this->container->callback( Post_Cache_Exclusion::class, 'script_enqueue' ) ); |
| 127 |
|
| 128 |
// Classic Editor meta box. |
| 129 |
foreach ( [ 'load-post.php', 'load-post-new.php' ] as $action ) { |
| 130 |
add_action( |
| 131 |
$action, |
| 132 |
function () { |
| 133 |
add_action( 'add_meta_boxes', $this->container->callback( Post_Cache_Exclusion::class, 'add_metabox' ) ); |
| 134 |
add_action( 'save_post', $this->container->callback( Post_Cache_Exclusion::class, 'save_metabox' ), 10, 1 ); |
| 135 |
} |
| 136 |
); |
| 137 |
} |
| 138 |
} |
| 139 |
} |
| 140 |
|