| @@ -43,8 +43,9 @@ | ||
| 43 | 43 | $this->rest->register(); |
| 44 | 44 | |
| 45 | 45 | if (is_admin()) { |
| 46 | 46 | add_action('admin_menu', [$this, 'registerMenu']); |
| 47 | + add_action('network_admin_menu', [$this, 'registerNetworkMenu']); | |
| 47 | 48 | } |
| 48 | 49 | } |
| 49 | 50 | |
| 50 | 51 | /** |
| @@ -68,8 +69,34 @@ | ||
| 68 | 69 | } |
| 69 | 70 | } |
| 70 | 71 | |
| 71 | 72 | /** |
| 73 | + * Adds the network entry, for the defaults a new site starts with. | |
| 74 | + * | |
| 75 | + * Under the network's own Settings and behind manage_network_options: a | |
| 76 | + * site administrator configures their own site, a super administrator | |
| 77 | + * decides what the next site begins with. Two different questions, two | |
| 78 | + * different capabilities. | |
| 79 | + * | |
| 80 | + * @return void | |
| 81 | + */ | |
| 82 | + public function registerNetworkMenu(): void | |
| 83 | + { | |
| 84 | + $hook = add_submenu_page( | |
| 85 | + 'settings.php', | |
| 86 | + _x('CryptX', 'CryptX network defaults page', 'cryptx'), | |
| 87 | + _x('CryptX', 'CryptX network defaults menu', 'cryptx'), | |
| 88 | + 'manage_network_options', | |
| 89 | + self::MENU_SLUG, | |
| 90 | + [$this, 'renderNetwork'] | |
| 91 | + ); | |
| 92 | + | |
| 93 | + if ($hook) { | |
| 94 | + add_action('load-' . $hook, [$this, 'onLoad']); | |
| 95 | + } | |
| 96 | + } | |
| 97 | + | |
| 98 | + /** | |
| 72 | 99 | * Runs only when our own screen is being loaded. |
| 73 | 100 | * |
| 74 | 101 | * @return void |
| 75 | 102 | */ |
| @@ -116,9 +143,16 @@ | ||
| 116 | 143 | } |
| 117 | 144 | |
| 118 | 145 | // The media library picker for the "image from the media library" |
| 119 | 146 | // option needs the classic media modal to be present. |
| 120 | - wp_enqueue_media(); | |
| 147 | + // | |
| 148 | + // Not in the network backend: the one field that needs it is left out | |
| 149 | + // of the network defaults on purpose -- an attachment id means nothing | |
| 150 | + // on another site -- and there is no media library there to pick from | |
| 151 | + // either. | |
| 152 | + if (!is_network_admin()) { | |
| 153 | + wp_enqueue_media(); | |
| 154 | + } | |
| 121 | 155 | } |
| 122 | 156 | |
| 123 | 157 | /** |
| 124 | 158 | * Shown when the plugin was installed without its built assets. |
| @@ -142,12 +176,43 @@ | ||
| 142 | 176 | if (!current_user_can('manage_options')) { |
| 143 | 177 | wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'cryptx')); |
| 144 | 178 | } |
| 145 | 179 | |
| 146 | - echo '<div class="wrap cryptx-settings-root" id="cryptx-settings-root">'; | |
| 180 | + $this->renderRoot('site', __('Loading the settings…', 'cryptx')); | |
| 181 | + } | |
| 182 | + | |
| 183 | + /** | |
| 184 | + * The same application, told that it is editing the network defaults. | |
| 185 | + * | |
| 186 | + * @return void | |
| 187 | + */ | |
| 188 | + public function renderNetwork(): void | |
| 189 | + { | |
| 190 | + if (!current_user_can('manage_network_options')) { | |
| 191 | + wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'cryptx')); | |
| 192 | + } | |
| 193 | + | |
| 194 | + $this->renderRoot('network', __('Loading the network defaults…', 'cryptx')); | |
| 195 | + } | |
| 196 | + | |
| 197 | + /** | |
| 198 | + * The container the application mounts into. | |
| 199 | + * | |
| 200 | + * @param string $scope Either 'site' or 'network'. | |
| 201 | + * @param string $loading What to show until the application takes over. | |
| 202 | + * | |
| 203 | + * @return void | |
| 204 | + */ | |
| 205 | + private function renderRoot(string $scope, string $loading): void | |
| 206 | + { | |
| 207 | + printf( | |
| 208 | + '<div class="wrap cryptx-settings-root" id="cryptx-settings-root" data-cryptx-scope="%s">', | |
| 209 | + esc_attr($scope) | |
| 210 | + ); | |
| 211 | + | |
| 147 | 212 | // Shown until the application takes over, and the only thing left if |
| 148 | 213 | // JavaScript is unavailable. |
| 149 | 214 | echo '<h1>' . esc_html__('CryptX', 'cryptx') . '</h1>'; |
| 150 | - echo '<p>' . esc_html__('Loading the settings…', 'cryptx') . '</p>'; | |
| 215 | + echo '<p>' . esc_html($loading) . '</p>'; | |
| 151 | 216 | echo '</div>'; |
| 152 | 217 | } |
| 153 | 218 | } |