PluginProbe
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution / trunk
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution vtrunk
2.0.1 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.9.0 2.0.0
solid-performance / src / Performance / Admin / Provider.php

Provider.php in Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution trunk, at src/Performance/Admin/Provider.php

170 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 add_action(
44 sprintf( 'update_option_%s', Settings_Page::SETTINGS_SLUG ),
45 static function ( $old_settings, $new_settings ): void {
46 /**
47 * An action to use when our settings have changed.
48 *
49 * @param mixed[] $old_settings The old settings array.
50 * @param mixed[] $new_settings The new settings array.
51 */
52 do_action( 'solidwp/performance/settings/changed', (array) $old_settings, (array) $new_settings );
53 },
54 100,
55 2
56 );
57
58 $this->register_page_cache_exclusion();
59 $this->register_validator();
60 }
61
62 /**
63 * Registers the page cache exclusion meta box.
64 *
65 * @return void
66 */
67 private function register_page_cache_exclusion(): void {
68 // Exclude the meta box from these post types.
69 $post_types_to_ignore = (array) apply_filters(
70 'solidwp/performance/public_post_type_ignore_array',
71 [
72 // Elementor.
73 'elementor_library',
74 // Beaver Builder.
75 'fl-theme-layout',
76 // WooCommerce.
77 'shop_order',
78 // Kadence.
79 'kadence_element',
80 'kadence_conversions',
81 'kadence_wootemplate',
82 'ele-product-template',
83 'ele-p-arch-template',
84 'ele-p-loop-template',
85 'ele-check-template',
86 'kt_size_chart',
87 'kt_cart_notice',
88 'kt_reviews',
89 'kt_product_tabs',
90 // Jet.
91 'jet-menu',
92 'jet-popup',
93 'jet-smart-filters',
94 'jet-theme-core',
95 'jet-woo-builder',
96 'jet-engine',
97 // LifterLMS.
98 'llms_certificate',
99 'llms_my_certificate',
100 // LearnDash.
101 'sfwd-certificates',
102 'sfwd-transactions',
103 'reply',
104 ]
105 );
106
107 $this->container->when( Post_Cache_Exclusion::class )
108 ->needs( '$post_types_to_ignore' )
109 ->give( $post_types_to_ignore );
110
111 // Get all public, non-built in post types and manually add post+page.
112 $this->container->singleton(
113 self::PUBLIC_POST_TYPES,
114 static fn() => (array) apply_filters(
115 'solidwp/performance/public_post_type_objects',
116 array_merge(
117 get_post_types(
118 [
119 'public' => true,
120 '_builtin' => false,
121 ],
122 ),
123 [ 'post', 'page' ]
124 )
125 )
126 );
127
128 $this->container->when( Post_Cache_Exclusion::class )
129 ->needs( '$post_types' )
130 ->give( $this->container->get( self::PUBLIC_POST_TYPES ) );
131
132 $this->container->singleton( Post_Cache_Exclusion::class, Post_Cache_Exclusion::class );
133
134 add_action(
135 'init',
136 static function (): void {
137 Post_Cache_Exclusion::register_meta();
138 },
139 20
140 );
141 add_action( 'admin_init', $this->container->callback( Post_Cache_Exclusion::class, 'register_meta_script' ) );
142 add_action( 'enqueue_block_editor_assets', $this->container->callback( Post_Cache_Exclusion::class, 'script_enqueue' ) );
143
144 // Classic Editor meta box.
145 foreach ( [ 'load-post.php', 'load-post-new.php' ] as $action ) {
146 add_action(
147 $action,
148 function () {
149 add_action( 'add_meta_boxes', $this->container->callback( Post_Cache_Exclusion::class, 'add_metabox' ) );
150 add_action( 'save_post', $this->container->callback( Post_Cache_Exclusion::class, 'save_metabox' ), 10, 1 );
151 }
152 );
153 }
154 }
155
156 /**
157 * Register the Settings Validator Handler.
158 *
159 * @return void
160 */
161 private function register_validator(): void {
162 add_filter(
163 'rest_request_before_callbacks',
164 $this->container->callback( Rest_Validator::class, 'validate' ),
165 10,
166 3
167 );
168 }
169 }
170