@wp-operations/wp-ops 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/README.md +6 -3
  2. package/package.json +6 -2
  3. package/src/commands/platform.js +58 -2
  4. package/src/commands/start.js +2 -2
  5. package/src/main.js +19 -8
  6. package/wp-operations/CHANGELOG.md +14 -0
  7. package/wp-operations/README.md +39 -0
  8. package/wp-operations/agents/builder/AGENT.md +15 -0
  9. package/wp-operations/assets/admin.css +631 -0
  10. package/wp-operations/assets/admin.js +614 -0
  11. package/wp-operations/assets/app/app.css +1 -0
  12. package/wp-operations/assets/app/app.js +70 -0
  13. package/wp-operations/assets/app/fonts/inter-medium.woff +0 -0
  14. package/wp-operations/assets/app/fonts/inter-regular.woff +0 -0
  15. package/wp-operations/assets/app/fonts/inter-semibold.woff +0 -0
  16. package/wp-operations/assets/app/login.css +42 -0
  17. package/wp-operations/assets/brand/icon.svg +20 -0
  18. package/wp-operations/assets/brand/mark.svg +19 -0
  19. package/wp-operations/assets/editors/audiobook.css +311 -0
  20. package/wp-operations/assets/editors/audiofile.css +286 -0
  21. package/wp-operations/assets/editors/course.css +701 -0
  22. package/wp-operations/assets/editors/course.js +698 -0
  23. package/wp-operations/assets/editors/faq.css +258 -0
  24. package/wp-operations/assets/editors/faq.js +196 -0
  25. package/wp-operations/assets/editors/interactive.css +220 -0
  26. package/wp-operations/assets/editors/interactive.js +378 -0
  27. package/wp-operations/assets/editors/media-sources.css +3 -0
  28. package/wp-operations/assets/editors/media-sources.js +40 -0
  29. package/wp-operations/assets/editors/open-media.css +114 -0
  30. package/wp-operations/assets/editors/open-media.js +182 -0
  31. package/wp-operations/assets/editors/thumbnails.css +335 -0
  32. package/wp-operations/assets/editors/thumbnails.js +447 -0
  33. package/wp-operations/assets/editors/translator.css +818 -0
  34. package/wp-operations/functions.php +24 -0
  35. package/wp-operations/index.php +14 -0
  36. package/wp-operations/platform.json +1836 -0
  37. package/wp-operations/skills/ai-development-guardrails/SKILL.md +49 -0
  38. package/wp-operations/skills/gutenberg-reference/SKILL.md +45 -0
  39. package/wp-operations/skills/js-tooling-for-themes/SKILL.md +51 -0
  40. package/wp-operations/skills/tailwind-for-wp/SKILL.md +62 -0
  41. package/wp-operations/skills/wp-clean-classic-themes/SKILL.md +112 -0
  42. package/wp-operations/skills/wp-psr4-plugins/SKILL.md +2043 -0
  43. package/wp-operations/skills/wp-security/SKILL.md +90 -0
  44. package/wp-operations/src/Admin.php +78 -0
  45. package/wp-operations/src/App/Access.php +57 -0
  46. package/wp-operations/src/App/Admin.php +442 -0
  47. package/wp-operations/src/App/App.php +157 -0
  48. package/wp-operations/src/App/Apps.php +379 -0
  49. package/wp-operations/src/App/Bundle.php +111 -0
  50. package/wp-operations/src/App/Contents.php +676 -0
  51. package/wp-operations/src/App/Engine.php +554 -0
  52. package/wp-operations/src/App/Github.php +308 -0
  53. package/wp-operations/src/App/Module.php +23 -0
  54. package/wp-operations/src/App/Ops.php +470 -0
  55. package/wp-operations/src/App/Packages.php +289 -0
  56. package/wp-operations/src/App/Rest.php +539 -0
  57. package/wp-operations/src/App/Sandboxes.php +206 -0
  58. package/wp-operations/src/App/Store.php +104 -0
  59. package/wp-operations/src/App/Usage.php +268 -0
  60. package/wp-operations/src/Config.php +249 -0
  61. package/wp-operations/src/Content/Editor.php +223 -0
  62. package/wp-operations/src/Content/Fields.php +681 -0
  63. package/wp-operations/src/Content/Scoring.php +253 -0
  64. package/wp-operations/src/Content/Structure.php +293 -0
  65. package/wp-operations/src/Content/Types.php +150 -0
  66. package/wp-operations/src/Content/Uploads.php +50 -0
  67. package/wp-operations/src/Editors/AudiobookAuthor.php +61 -0
  68. package/wp-operations/src/Editors/AudiobookChapters.php +632 -0
  69. package/wp-operations/src/Editors/AudiobookCover.php +235 -0
  70. package/wp-operations/src/Editors/Audiofile.php +462 -0
  71. package/wp-operations/src/Editors/Course.php +784 -0
  72. package/wp-operations/src/Editors/Ebook.php +242 -0
  73. package/wp-operations/src/Editors/Editors.php +44 -0
  74. package/wp-operations/src/Editors/Faq.php +237 -0
  75. package/wp-operations/src/Editors/Files.php +139 -0
  76. package/wp-operations/src/Editors/Interactive/Builder.php +103 -0
  77. package/wp-operations/src/Editors/Interactive/Card.php +76 -0
  78. package/wp-operations/src/Editors/Interactive/Editor.php +42 -0
  79. package/wp-operations/src/Editors/Interactive/Field.php +272 -0
  80. package/wp-operations/src/Editors/Interactive/Map.php +84 -0
  81. package/wp-operations/src/Editors/Interactive/Models.php +227 -0
  82. package/wp-operations/src/Editors/Interactive/Report.php +59 -0
  83. package/wp-operations/src/Editors/Interactive/Save.php +323 -0
  84. package/wp-operations/src/Editors/Interactive/Scoring.php +244 -0
  85. package/wp-operations/src/Editors/Interactive/Structure.php +195 -0
  86. package/wp-operations/src/Editors/Legal.php +235 -0
  87. package/wp-operations/src/Editors/OpenMedia.php +140 -0
  88. package/wp-operations/src/Editors/OriginalTitle.php +112 -0
  89. package/wp-operations/src/Editors/Sources.php +28 -0
  90. package/wp-operations/src/Editors/Thumbnails/Admin.php +306 -0
  91. package/wp-operations/src/Editors/Thumbnails/Ajax.php +163 -0
  92. package/wp-operations/src/Editors/Thumbnails/Box.php +188 -0
  93. package/wp-operations/src/Editors/Thumbnails/Storage.php +228 -0
  94. package/wp-operations/src/Editors/Translator/Admin.php +913 -0
  95. package/wp-operations/src/Editors/Translator/Api.php +63 -0
  96. package/wp-operations/src/Editors/Translator/Bar.php +83 -0
  97. package/wp-operations/src/Editors/Translator/Fields.php +273 -0
  98. package/wp-operations/src/Editors/Translator/Storage.php +131 -0
  99. package/wp-operations/src/Editors/Translator/Thumbnail.php +215 -0
  100. package/wp-operations/src/Identity.php +104 -0
  101. package/wp-operations/src/Languages.php +45 -0
  102. package/wp-operations/src/Lockdown.php +85 -0
  103. package/wp-operations/src/Modules/Apps/Admin.php +472 -0
  104. package/wp-operations/src/Modules/Apps/Api.php +193 -0
  105. package/wp-operations/src/Modules/Apps/Apps.php +279 -0
  106. package/wp-operations/src/Modules/Apps/Formatters.php +478 -0
  107. package/wp-operations/src/Modules/Apps/Schemes.php +248 -0
  108. package/wp-operations/src/Modules/Apps/Table.php +101 -0
  109. package/wp-operations/src/Modules/Thumbnails.php +68 -0
  110. package/wp-operations/src/Modules/Translations.php +133 -0
  111. package/wp-operations/src/Platform.php +59 -0
  112. package/wp-operations/src/Setup.php +273 -0
  113. package/wp-operations/src/Status.php +99 -0
  114. package/wp-operations/src/Storage/Client.php +168 -0
  115. package/wp-operations/src/Storage/Offload.php +120 -0
  116. package/wp-operations/src/Storage/Settings.php +166 -0
  117. package/wp-operations/src/Storage/Storage.php +35 -0
  118. package/wp-operations/src/Updates.php +151 -0
  119. package/wp-operations/style.css +11 -0
@@ -0,0 +1,215 @@
1
+ <?php
2
+ namespace Platform\Editors\Translator;
3
+
4
+ use Platform\Languages;
5
+ use Platform\Platform;
6
+
7
+ defined( 'ABSPATH' ) || exit;
8
+
9
+ class Thumbnail {
10
+ public static function register(): void {
11
+ add_action( 'add_meta_boxes', [ __CLASS__, 'replace_metabox' ], 20 );
12
+ add_action( 'save_post', [ __CLASS__, 'save_meta' ] );
13
+ add_action( 'admin_enqueue_scripts', [ __CLASS__, 'enqueue' ] );
14
+ }
15
+
16
+ public static function enqueue( string $hook ): void {
17
+ if ( ! in_array( $hook, [ 'post.php', 'post-new.php' ], true ) ) {
18
+ return;
19
+ }
20
+ $screen = get_current_screen();
21
+ if ( ! $screen ) {
22
+ return;
23
+ }
24
+ $post_types = Fields::translatable_post_types();
25
+ if ( ! isset( $post_types[ $screen->post_type ] ) ) {
26
+ return;
27
+ }
28
+ wp_enqueue_media();
29
+ wp_enqueue_style(
30
+ 'lang-thumbnail',
31
+ Platform::url( 'assets/editors/translator.css' ),
32
+ [],
33
+ Platform::asset_version( 'assets/editors/translator.css' )
34
+ );
35
+ }
36
+
37
+ public static function replace_metabox(): void {
38
+ $post_types = Fields::translatable_post_types();
39
+ foreach ( $post_types as $slug => $obj ) {
40
+ remove_meta_box( 'postimagediv', $slug, 'side' );
41
+ add_meta_box(
42
+ 'ct_featured_image',
43
+ __( 'Thumbnails' ),
44
+ [ __CLASS__, 'render_metabox' ],
45
+ $slug,
46
+ 'side',
47
+ 'default'
48
+ );
49
+ }
50
+ }
51
+
52
+ public static function render_metabox( \WP_Post $post ): void {
53
+ $site_lang = Languages::default();
54
+ $languages = Languages::all();
55
+
56
+ $lang_list = [];
57
+ $site_name = $languages[ $site_lang ] ?? strtoupper( $site_lang );
58
+ $lang_list[] = [ 'code' => $site_lang, 'name' => $site_name, 'is_default' => true ];
59
+
60
+ foreach ( $languages as $code => $name ) {
61
+ if ( $code !== $site_lang ) {
62
+ $lang_list[] = [ 'code' => $code, 'name' => $name, 'is_default' => false ];
63
+ }
64
+ }
65
+
66
+ wp_nonce_field( 'ct_thumbnail_save', 'ct_thumbnail_nonce' );
67
+ ?>
68
+ <div class="lang-thumbnail-metabox">
69
+ <?php foreach ( $lang_list as $lang ) :
70
+ $code = $lang['code'];
71
+ $name = $lang['name'];
72
+ $is_def = $lang['is_default'];
73
+
74
+ $meta_key = $is_def ? '_thumbnail_id' : '_thumbnail_id_' . $code;
75
+ $att_id = (int) get_post_meta( $post->ID, $meta_key, true );
76
+ $thumb_url = $att_id ? wp_get_attachment_image_url( $att_id, 'medium' ) : '';
77
+ ?>
78
+ <div class="lang-thumbnail-lang" data-lang="<?php echo esc_attr( $code ); ?>">
79
+ <div class="lang-thumbnail-lang-header">
80
+ <span class="lang-thumbnail-lang-code"><?php echo esc_html( strtoupper( $code ) ); ?></span>
81
+ <span class="lang-thumbnail-lang-name"><?php echo esc_html( $name ); ?></span>
82
+ <?php if ( $is_def ) : ?>
83
+ <span class="lang-thumbnail-lang-default">default</span>
84
+ <?php endif; ?>
85
+ </div>
86
+
87
+ <div class="lang-thumbnail-preview">
88
+ <?php if ( $thumb_url ) : ?>
89
+ <img src="<?php echo esc_url( $thumb_url ); ?>" alt="">
90
+ <?php else : ?>
91
+ <div class="lang-thumbnail-empty"><?php esc_html_e( 'No image' ); ?></div>
92
+ <?php endif; ?>
93
+ </div>
94
+
95
+ <input type="hidden"
96
+ name="ct_thumbnail[<?php echo esc_attr( $code ); ?>]"
97
+ value="<?php echo (int) $att_id; ?>"
98
+ class="lang-thumbnail-input">
99
+
100
+ <div class="lang-thumbnail-actions">
101
+ <button type="button" class="button lang-thumbnail-upload" data-lang="<?php echo esc_attr( $code ); ?>">
102
+ <?php echo $att_id ? 'Replace' : 'Add Image'; ?>
103
+ </button>
104
+ <?php if ( $att_id ) : ?>
105
+ <button type="button" class="button lang-thumbnail-remove" data-lang="<?php echo esc_attr( $code ); ?>">
106
+ Remove
107
+ </button>
108
+ <?php endif; ?>
109
+ </div>
110
+ </div>
111
+ <?php endforeach; ?>
112
+ <?php do_action( 'thumbnail_after_buttons', $post ); ?>
113
+ </div>
114
+
115
+ <script>
116
+ jQuery( function( $ ) {
117
+ $( '.lang-thumbnail-upload' ).on( 'click', function( e ) {
118
+ e.preventDefault();
119
+ var lang = $( this ).data( 'lang' );
120
+ var $block = $( this ).closest( '.lang-thumbnail-lang' );
121
+
122
+ var frame = wp.media( {
123
+ title: 'Select Featured Image - ' + lang.toUpperCase(),
124
+ multiple: false,
125
+ library: { type: 'image' }
126
+ } );
127
+
128
+ frame.on( 'select', function() {
129
+ var att = frame.state().get( 'selection' ).first().toJSON();
130
+ $block.find( '.lang-thumbnail-input' ).val( att.id );
131
+ $block.find( '.lang-thumbnail-preview' ).html(
132
+ '<img src="' + att.sizes?.medium?.url || att.url + '" alt="">'
133
+ );
134
+ $block.find( '.lang-thumbnail-actions' ).html(
135
+ '<button type="button" class="button lang-thumbnail-upload" data-lang="' + lang + '">Replace</button> ' +
136
+ '<button type="button" class="button lang-thumbnail-remove" data-lang="' + lang + '">Remove</button>'
137
+ );
138
+ } );
139
+
140
+ frame.open();
141
+ } );
142
+
143
+ $( document ).on( 'click', '.lang-thumbnail-remove', function( e ) {
144
+ e.preventDefault();
145
+ var lang = $( this ).data( 'lang' );
146
+ var $block = $( this ).closest( '.lang-thumbnail-lang' );
147
+
148
+ $block.find( '.lang-thumbnail-input' ).val( '' );
149
+ $block.find( '.lang-thumbnail-preview' ).html( '<div class="lang-thumbnail-empty">No image</div>' );
150
+ $block.find( '.lang-thumbnail-actions' ).html(
151
+ '<button type="button" class="button lang-thumbnail-upload" data-lang="' + lang + '">Add Image</button>'
152
+ );
153
+ } );
154
+ } );
155
+ </script>
156
+ <?php
157
+ }
158
+
159
+ public static function save_meta( int $post_id ): void {
160
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
161
+ return;
162
+ }
163
+ if ( ! current_user_can( 'edit_post', $post_id ) ) {
164
+ return;
165
+ }
166
+ if ( ! isset( $_POST['ct_thumbnail_nonce'] ) || ! wp_verify_nonce( $_POST['ct_thumbnail_nonce'], 'ct_thumbnail_save' ) ) {
167
+ return;
168
+ }
169
+
170
+ $site_lang = Languages::default();
171
+ $thumbnails = $_POST['ct_thumbnail'] ?? [];
172
+
173
+ foreach ( $thumbnails as $code => $att_id ) {
174
+ $code = sanitize_key( $code );
175
+ $att_id = (int) $att_id;
176
+
177
+ if ( $code === $site_lang ) {
178
+ $meta_key = '_thumbnail_id';
179
+ } else {
180
+ $meta_key = '_thumbnail_id_' . $code;
181
+ }
182
+
183
+ if ( $att_id ) {
184
+ update_post_meta( $post_id, $meta_key, $att_id );
185
+ } else {
186
+ delete_post_meta( $post_id, $meta_key );
187
+ }
188
+ }
189
+ }
190
+
191
+ public static function get_thumbnail_url( int $post_id, string $size = 'large', string $lang = '' ): ?string {
192
+ if ( $lang === '' ) {
193
+ $lang = get_locale();
194
+ $lang = strtolower( strstr( $lang, '_', true ) ?: $lang );
195
+ }
196
+
197
+ $site_lang = Languages::default();
198
+
199
+ if ( $lang === $site_lang ) {
200
+ $att_id = (int) get_post_meta( $post_id, '_thumbnail_id', true );
201
+ } else {
202
+ $att_id = (int) get_post_meta( $post_id, '_thumbnail_id_' . $lang, true );
203
+ if ( ! $att_id ) {
204
+ $att_id = (int) get_post_meta( $post_id, '_thumbnail_id', true );
205
+ }
206
+ }
207
+
208
+ if ( ! $att_id ) {
209
+ return null;
210
+ }
211
+
212
+ $url = wp_get_attachment_image_url( $att_id, $size );
213
+ return $url ?: null;
214
+ }
215
+ }
@@ -0,0 +1,104 @@
1
+ <?php
2
+ /**
3
+ * Platform identity: name, author, logo and icon fallbacks, and the Customizer limited to Site Identity and Additional CSS.
4
+ *
5
+ * @package Platform
6
+ */
7
+
8
+ namespace Platform;
9
+
10
+ defined( 'ABSPATH' ) || exit;
11
+
12
+ final class Identity {
13
+
14
+ const SECTIONS = [ 'title_tagline', 'custom_css' ];
15
+
16
+ public static function register(): void {
17
+ add_action( 'after_setup_theme', [ __CLASS__, 'supports' ] );
18
+ add_filter( 'option_blogname', [ __CLASS__, 'site_name' ] );
19
+ add_filter( 'admin_footer_text', [ __CLASS__, 'footer' ] );
20
+ add_action( 'wp_head', [ __CLASS__, 'icon' ], 99 );
21
+ add_action( 'admin_head', [ __CLASS__, 'icon' ], 99 );
22
+ add_action( 'login_head', [ __CLASS__, 'icon' ], 99 );
23
+ add_action( 'login_head', [ __CLASS__, 'login_logo' ] );
24
+ add_filter( 'login_headerurl', [ __CLASS__, 'login_url' ] );
25
+ add_filter( 'login_headertext', [ __CLASS__, 'name' ] );
26
+ add_action( 'customize_register', [ __CLASS__, 'customizer' ], 1000 );
27
+ add_action( 'admin_menu', [ __CLASS__, 'menu' ] );
28
+ }
29
+
30
+ public static function supports(): void {
31
+ add_theme_support( 'title-tag' );
32
+ add_theme_support( 'custom-logo', [ 'height' => 64, 'width' => 240, 'flex-height' => true, 'flex-width' => true ] );
33
+ }
34
+
35
+ public static function name(): string {
36
+ remove_filter( 'option_blogname', [ __CLASS__, 'site_name' ] );
37
+ $site = trim( (string) get_option( 'blogname' ) );
38
+ add_filter( 'option_blogname', [ __CLASS__, 'site_name' ] );
39
+
40
+ return '' !== $site ? $site : (string) Config::get( 'platform.name', 'Platform' );
41
+ }
42
+
43
+ public static function site_name( $value ): string {
44
+ return '' !== trim( (string) $value ) ? (string) $value : (string) Config::get( 'platform.name', 'Platform' );
45
+ }
46
+
47
+ public static function footer(): string {
48
+ $author = (string) Config::get( 'platform.author', '' );
49
+ $url = (string) Config::get( 'platform.url', '' );
50
+ $credit = '' !== $url ? sprintf( '<a href="%s" target="_blank" rel="noopener">%s</a>', esc_url( $url ), esc_html( $author ?: $url ) ) : esc_html( $author );
51
+
52
+ return esc_html( self::name() ) . ( '' !== $credit ? ' · ' . $credit : '' );
53
+ }
54
+
55
+ public static function icon(): void {
56
+ if ( ! has_site_icon() ) {
57
+ printf( '<link rel="icon" href="%s" type="image/svg+xml" />' . "\n", esc_url( Platform::url( 'assets/brand/icon.svg' ) ) );
58
+ }
59
+ }
60
+
61
+ public static function brand(): array {
62
+ $logo = (int) get_theme_mod( 'custom_logo' );
63
+
64
+ return [
65
+ 'name' => (string) Config::get( 'platform.name', '' ) ?: self::name(),
66
+ 'author' => (string) Config::get( 'platform.author', '' ),
67
+ 'url' => (string) Config::get( 'platform.url', '' ),
68
+ 'logo' => $logo ? (string) wp_get_attachment_image_url( $logo, 'full' ) : '',
69
+ 'mark' => Platform::url( 'assets/brand/mark.svg' ),
70
+ 'icon' => has_site_icon() ? (string) get_site_icon_url( 192 ) : Platform::url( 'assets/brand/icon.svg' ),
71
+ ];
72
+ }
73
+
74
+ public static function login_logo(): void {
75
+ $logo = (int) get_theme_mod( 'custom_logo' );
76
+ $url = $logo ? wp_get_attachment_image_url( $logo, 'full' ) : Platform::url( 'assets/brand/icon.svg' );
77
+ $size = $logo ? 'width:240px;height:64px;' : 'width:72px;height:72px;';
78
+
79
+ printf( '<style>.login h1 a{background-image:url("%s");background-size:contain;background-position:center;%s}</style>' . "\n", esc_url( $url ), esc_attr( $size ) );
80
+ }
81
+
82
+ public static function login_url(): string {
83
+ return home_url( '/' );
84
+ }
85
+
86
+ public static function customizer( \WP_Customize_Manager $customizer ): void {
87
+ foreach ( $customizer->panels() as $id => $panel ) {
88
+ $customizer->remove_panel( $id );
89
+ }
90
+
91
+ foreach ( $customizer->sections() as $id => $section ) {
92
+ if ( ! in_array( $id, self::SECTIONS, true ) ) {
93
+ $customizer->remove_section( $id );
94
+ }
95
+ }
96
+
97
+ $customizer->remove_control( 'blogdescription' );
98
+ $customizer->remove_control( 'display_header_text' );
99
+ }
100
+
101
+ public static function menu(): void {
102
+ add_options_page( 'Site Identity', 'Site Identity', 'customize', 'customize.php?autofocus[section]=title_tagline' );
103
+ }
104
+ }
@@ -0,0 +1,45 @@
1
+ <?php
2
+ /**
3
+ * Content languages from platform.json.
4
+ *
5
+ * @package Platform
6
+ */
7
+
8
+ namespace Platform;
9
+
10
+ defined( 'ABSPATH' ) || exit;
11
+
12
+ final class Languages {
13
+
14
+ public static function all(): array {
15
+ $languages = [];
16
+
17
+ foreach ( (array) Config::get( 'languages', [] ) as $language ) {
18
+ $code = strtolower( substr( trim( (string) ( $language['code'] ?? '' ) ), 0, 2 ) );
19
+
20
+ if ( '' !== $code ) {
21
+ $languages[ $code ] = (string) ( $language['name'] ?? $code );
22
+ }
23
+ }
24
+
25
+ return $languages ?: [ 'en' => 'English' ];
26
+ }
27
+
28
+ public static function default(): string {
29
+ $default = (string) Config::get( 'default_language', '' );
30
+ $all = self::all();
31
+
32
+ return isset( $all[ $default ] ) ? $default : (string) array_key_first( $all );
33
+ }
34
+
35
+ public static function for_type( string $type ): array {
36
+ return self::all();
37
+ }
38
+
39
+ public static function others(): array {
40
+ $all = self::all();
41
+ unset( $all[ self::default() ] );
42
+
43
+ return $all;
44
+ }
45
+ }
@@ -0,0 +1,85 @@
1
+ <?php
2
+ /**
3
+ * Keeps the platform on core WordPress only: no plugins can run or be managed.
4
+ *
5
+ * @package Platform
6
+ */
7
+
8
+ namespace Platform;
9
+
10
+ defined( 'ABSPATH' ) || exit;
11
+
12
+ final class Lockdown {
13
+
14
+ const CAPABILITIES = [
15
+ 'activate_plugins',
16
+ 'install_plugins',
17
+ 'update_plugins',
18
+ 'delete_plugins',
19
+ 'edit_plugins',
20
+ 'upload_plugins',
21
+ 'resume_plugins',
22
+ 'deactivate_plugins',
23
+ 'activate_plugin',
24
+ 'deactivate_plugin',
25
+ 'resume_plugin',
26
+ ];
27
+
28
+ const SCREENS = [ 'plugins.php', 'plugin-install.php', 'plugin-editor.php' ];
29
+
30
+ public static function register(): void {
31
+ add_filter( 'pre_option_active_plugins', '__return_empty_array' );
32
+ add_filter( 'pre_site_option_active_sitewide_plugins', '__return_empty_array' );
33
+ add_filter( 'pre_update_option_active_plugins', '__return_empty_array' );
34
+ add_filter( 'pre_update_site_option_active_sitewide_plugins', '__return_empty_array' );
35
+ add_filter( 'map_meta_cap', [ __CLASS__, 'deny_capabilities' ], 10, 2 );
36
+ add_filter( 'site_transient_update_plugins', '__return_null' );
37
+
38
+ add_action( 'after_setup_theme', [ __CLASS__, 'clear_active_plugins' ], 0 );
39
+ add_action( 'admin_menu', [ __CLASS__, 'remove_menus' ], 999 );
40
+ add_action( 'admin_init', [ __CLASS__, 'block_screens' ], 0 );
41
+ add_action( 'admin_bar_menu', [ __CLASS__, 'remove_admin_bar_items' ], 999 );
42
+ }
43
+
44
+ public static function clear_active_plugins(): void {
45
+ global $wpdb;
46
+
47
+ $active = $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s", 'active_plugins' ) );
48
+
49
+ if ( null !== $active && 'a:0:{}' !== $active ) {
50
+ $wpdb->update( $wpdb->options, [ 'option_value' => 'a:0:{}' ], [ 'option_name' => 'active_plugins' ] );
51
+ wp_cache_delete( 'alloptions', 'options' );
52
+ wp_cache_delete( 'active_plugins', 'options' );
53
+ }
54
+
55
+ if ( is_multisite() ) {
56
+ $network = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM {$wpdb->sitemeta} WHERE meta_key = %s", 'active_sitewide_plugins' ) );
57
+
58
+ if ( null !== $network && 'a:0:{}' !== $network ) {
59
+ $wpdb->update( $wpdb->sitemeta, [ 'meta_value' => 'a:0:{}' ], [ 'meta_key' => 'active_sitewide_plugins' ] );
60
+ wp_cache_delete( get_current_network_id() . ':active_sitewide_plugins', 'site-options' );
61
+ }
62
+ }
63
+ }
64
+
65
+ public static function deny_capabilities( array $caps, string $cap ): array {
66
+ return in_array( $cap, self::CAPABILITIES, true ) ? [ 'do_not_allow' ] : $caps;
67
+ }
68
+
69
+ public static function remove_menus(): void {
70
+ remove_menu_page( 'plugins.php' );
71
+ }
72
+
73
+ public static function block_screens(): void {
74
+ global $pagenow;
75
+
76
+ if ( in_array( $pagenow, self::SCREENS, true ) ) {
77
+ wp_safe_redirect( admin_url() );
78
+ exit;
79
+ }
80
+ }
81
+
82
+ public static function remove_admin_bar_items( \WP_Admin_Bar $bar ): void {
83
+ $bar->remove_node( 'plugins' );
84
+ }
85
+ }