PluginProbe
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution / 1.1.0
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution v1.1.0
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 1.1.0, at src/Performance/Admin/Provider.php

109 lines 3.4 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 /**
28 * {@inheritdoc}
29 */
30 public function register(): void {
31 $this->container->singleton( Settings_Page::class, Settings_Page::class );
32
33 add_filter( 'admin_bar_menu', $this->container->callback( Admin_Bar::class, 'add_purge_admin_bar_link' ), 100 );
34 add_filter( 'init', $this->container->callback( Purge_Listener::class, 'purge_page_cache' ) );
35 add_filter( 'init', $this->container->callback( Purge_Listener::class, 'purge_single_page_cache' ) );
36 add_filter( 'admin_menu', $this->container->callback( Settings_Page::class, 'add_settings_page' ), 100 );
37 add_action( 'admin_init', $this->container->callback( Settings_Page::class, 'register_settings' ) );
38 add_action( 'rest_api_init', $this->container->callback( Settings_Page::class, 'register_settings' ) );
39 add_action( 'plugin_action_links_' . plugin_basename( SWPSP_PLUGIN_FILE ), $this->container->callback( Settings_Page::class, 'settings_link' ), 10 );
40 add_filter( 'init', $this->container->callback( Post_Cache_Exclusion::class, 'register_meta' ), 20 );
41 add_action( 'admin_init', $this->container->callback( Post_Cache_Exclusion::class, 'register_meta_script' ) );
42 add_action( 'admin_init', $this->container->callback( Post_Cache_Exclusion::class, 'load_classic' ) );
43 add_action( 'enqueue_block_editor_assets', $this->container->callback( Post_Cache_Exclusion::class, 'script_enqueue' ) );
44
45 $this->register_option_purger();
46 }
47
48 /**
49 * Configure the Option Purger with the different WP option names can trigger a cache flush.
50 *
51 * @return void
52 */
53 private function register_option_purger(): void {
54 $this->container->singleton( Option_Purger::class, Option_Purger::class );
55 $this->container->when( Option_Purger::class )
56 ->needs( '$option_names' )
57 ->give(
58 // Different WP option names that will force a cache flush.
59 static fn(): array => array_fill_keys(
60 [
61 // options-general.php.
62 'blogname',
63 'blogdescription',
64 'site_icon',
65 'WPLANG',
66 'timezone_string',
67 'gmt_offset',
68 'date_format',
69 'time_format',
70 'start_of_week',
71
72 // options-reading.php.
73 'page_for_posts',
74 'page_on_front',
75 'posts_per_page',
76 'blog_public',
77
78 // options-discussion.php.
79 'require_name_email',
80 'comment_registration',
81 'close_comments_for_old_posts',
82 'show_comments_cookies_opt_in',
83 'thread_comments',
84 'thread_comments_depth',
85 'page_comments',
86 'comments_per_page',
87 'default_comments_page',
88 'comment_order',
89 'show_avatars',
90 'avatar_rating',
91 'avatar_default',
92
93 // options-permalink.php.
94 'permalink_structure',
95 'category_base',
96 'tag_base',
97
98 // Appearance: themes.php.
99 'template',
100 'stylesheet',
101 ],
102 true
103 )
104 );
105
106 add_action( 'updated_option', $this->container->callback( Option_Purger::class, 'collect' ), 10, 3 );
107 }
108 }
109