PluginProbe
ActivityPub / 9.0.1
ActivityPub v9.0.1
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
activitypub / includes / wp-admin / class-app.php

class-app.php in ActivityPub 9.0.1, at includes/wp-admin/class-app.php

129 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * App admin page file.
4 *
5 * @package Activitypub
6 */
7
8 namespace Activitypub\WP_Admin;
9
10 /**
11 * ActivityPub App Admin Page Class.
12 */
13 class App {
14
15 /**
16 * Initialize the App page.
17 *
18 * Must run early (on admin_init) before the admin bar is initialized.
19 */
20 public static function init() {
21 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
22 if ( isset( $_GET['page'] ) && 'activitypub-social-web' === $_GET['page'] ) {
23 \add_filter( 'wp_admin_bar_class', '__return_false' );
24 }
25 }
26
27 /**
28 * Remove admin notices from the App page.
29 */
30 public static function remove_admin_notices() {
31 \remove_all_actions( 'admin_notices' );
32 \remove_all_actions( 'all_admin_notices' );
33
34 // Add fullscreen mode body class.
35 \add_filter(
36 'admin_body_class',
37 static function ( $classes ) {
38 return "$classes is-fullscreen-mode";
39 }
40 );
41 }
42
43 /**
44 * Enqueue scripts and styles for the App page.
45 */
46 public static function enqueue_scripts() {
47 \wp_dequeue_style( 'colors' );
48 \wp_dequeue_script( 'common' );
49 \wp_dequeue_script( 'svg-painter' );
50
51 // Define paths to preload - must match exact fields from entities.js.
52 $preload_paths = array(
53 '/?_fields=description,gmt_offset,home,name,site_icon,site_icon_url,site_logo,timezone_string,url,page_for_posts,page_on_front,show_on_front',
54 array( '/wp/v2/settings', 'OPTIONS' ),
55 );
56
57 // Use rest_preload_api_request to gather the preloaded data.
58 $preload_data = \array_reduce(
59 $preload_paths,
60 'rest_preload_api_request',
61 array()
62 );
63
64 // Register the preloading middleware with wp-api-fetch.
65 \wp_add_inline_script(
66 'wp-api-fetch',
67 \sprintf( 'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );', \wp_json_encode( $preload_data ) )
68 );
69
70 $router_asset = include \plugin_dir_path( ACTIVITYPUB_PLUGIN_FILE ) . 'build/app/tanstack-router.asset.php';
71 \wp_enqueue_script(
72 'activitypub-app-tanstack-router',
73 \plugins_url( 'build/app/tanstack-router.js', ACTIVITYPUB_PLUGIN_FILE ),
74 $router_asset['dependencies'],
75 $router_asset['version'],
76 true
77 );
78
79 $vendors_asset = include \plugin_dir_path( ACTIVITYPUB_PLUGIN_FILE ) . 'build/app/vendors.asset.php';
80 \wp_enqueue_script(
81 'activitypub-app-vendors',
82 \plugins_url( 'build/app/vendors.js', ACTIVITYPUB_PLUGIN_FILE ),
83 $vendors_asset['dependencies'],
84 $vendors_asset['version'],
85 true
86 );
87
88 $asset_file = include \plugin_dir_path( ACTIVITYPUB_PLUGIN_FILE ) . 'build/app/index.asset.php';
89
90 \wp_enqueue_script(
91 'activitypub-app',
92 \plugins_url( 'build/app/index.js', ACTIVITYPUB_PLUGIN_FILE ),
93 array_merge( $asset_file['dependencies'], array( 'activitypub-app-tanstack-router', 'activitypub-app-vendors' ) ),
94 $asset_file['version'],
95 true
96 );
97
98 \wp_enqueue_style(
99 'activitypub-app',
100 \plugins_url( 'build/app/style-index.css', ACTIVITYPUB_PLUGIN_FILE ),
101 array( 'wp-components', 'wp-edit-site' ),
102 $asset_file['version']
103 );
104
105 \wp_add_inline_script(
106 'activitypub-app',
107 sprintf(
108 'wp.domReady( function() {
109 wp.activitypubApp.initialize( "activitypub-app-root", %s );
110 } );',
111 \wp_json_encode(
112 array(
113 'namespace' => ACTIVITYPUB_REST_NAMESPACE,
114 )
115 )
116 )
117 );
118 }
119
120 /**
121 * Render the App admin page.
122 */
123 public static function render_page() {
124 ?>
125 <div id="activitypub-app-root" class="activitypub-app-layout"></div>
126 <?php
127 }
128 }
129