settings-page.php 17.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582
<?php
/**
 * This is the HTML template for the plugin settings page.
 *
 * These variables are provided by the plugin:
 * @var array $settings Plugin settings.
 * @var string $editor_page_url A fully qualified URL of the admin menu editor page.
 * @var string $settings_page_url
 * @var string $db_option_name
 */

$currentUser = wp_get_current_user();
$isMultisite = is_multisite();
$isSuperAdmin = is_super_admin();
$formActionUrl = add_query_arg('noheader', 1, $settings_page_url);
$isProVersion = apply_filters('admin_menu_editor_is_pro', false);
?>

<?php do_action('admin_menu_editor-display_header'); ?>

	<form method="post" action="<?php echo esc_url($formActionUrl); ?>" id="ws_plugin_settings_form">

		<table class="form-table">
			<tbody>
			<tr>
				<th scope="row">
					Who can access this plugin
				</th>
				<td>
					<fieldset>
						<p>
							<label>
								<input type="radio" name="plugin_access" value="super_admin"
									<?php checked('super_admin', $settings['plugin_access']); ?>
									<?php disabled( !$isSuperAdmin ); ?>>
								Super Admin

								<?php if ( !$isMultisite ) : ?>
									<br><span class="description">
										On a single site installation this is usually
										the same as the Administrator role.
									</span>
								<?php endif; ?>
							</label>
						</p>

						<p>
							<label>
								<input type="radio" name="plugin_access" value="manage_options"
									<?php checked('manage_options', $settings['plugin_access']); ?>
									<?php disabled( !current_user_can('manage_options') ); ?>>
								Anyone with the "manage_options" capability

								<br><span class="description">
									By default only Administrators have this capability.
								</span>
							</label>
						</p>

						<p>
							<label>
								<input type="radio" name="plugin_access" value="specific_user"
									<?php checked('specific_user', $settings['plugin_access']); ?>
									<?php disabled( $isMultisite && !$isSuperAdmin ); ?>>
								Only the current user

								<br>
								<span class="description">
									Login: <?php echo esc_html($currentUser->user_login); ?>,
								 	user ID: <?php echo esc_html(get_current_user_id()); ?>
								</span>
							</label>
						</p>
					</fieldset>

					<p>
						<label>
							<input type="checkbox" name="hide_plugin_from_others" value="1"
								<?php checked( $settings['plugins_page_allowed_user_id'] !== null ); ?>
								<?php disabled( !$isProVersion || ($isMultisite && !is_super_admin()) ); ?>
							>
							Hide "Admin Menu Editor<?php if ( $isProVersion ) { echo ' Pro'; } ?>"
							<?php if ( defined('WS_ADMIN_BAR_EDITOR_FILE') || defined('AME_BRANDING_ADD_ON_FILE') ) {
								echo 'and its add-ons';
							} ?>
							from the "Plugins" page for other users
							<?php if ( !$isProVersion ) {
								echo '(Pro version only)';
							} ?>
						</label>
					</p>
				</td>
			</tr>

			<tr>
				<th scope="row">
					Multisite settings
				</th>
				<td>
					<fieldset id="ame-menu-scope-settings">
						<p>
							<label>
								<input type="radio" name="menu_config_scope" value="global"
								       id="ame-menu-config-scope-global"
									<?php checked('global', $settings['menu_config_scope']); ?>
									<?php disabled(!$isMultisite || !$isSuperAdmin); ?>>
								Global &mdash;
								Use the same admin menu settings for all network sites.
							</label>
						</p>

						<p>
							<label>
								<input type="radio" name="menu_config_scope" value="site"
									<?php checked('site', $settings['menu_config_scope']); ?>
									<?php disabled(!$isMultisite || !$isSuperAdmin); ?>>
								Per-site &mdash;
								Use different admin menu settings for each site.
							</label>
						</p>
					</fieldset>
				</td>
			</tr>

			<?php do_action('admin-menu-editor-display_addons'); ?>

			<tr id="ame-available-modules">
				<th scope="row">
					Modules
					<a class="ws_tooltip_trigger"
					   title="Modules are plugin features that can be turned on or off.
					&lt;br&gt;
					Turning off unused features will slightly increase performance and may help with certain compatibility issues.
					">
						<div class="dashicons dashicons-info"></div>
					</a>
				</th>
				<td>
					<fieldset>
						<?php
						global $wp_menu_editor;
						foreach ($wp_menu_editor->get_available_modules() as $moduleId => $module) {
							if ( !empty($module['isAlwaysActive']) ) {
								continue;
							}

							$isCompatible = $wp_menu_editor->is_module_compatible($module);
							$compatibilityNote = '';
							if ( !$isCompatible && !empty($module['requiredPhpVersion']) ) {
								if ( version_compare(phpversion(), $module['requiredPhpVersion'], '<') ) {
									$compatibilityNote = sprintf(
										'Required PHP version: %1$s or later. Installed PHP version: %2$s',
										esc_html($module['requiredPhpVersion']),
										esc_html(phpversion())
									);
								}
							}

							echo '<p>';
							/** @noinspection HtmlUnknownAttribute */
							printf(
								'<label>
									<input type="checkbox" name="active_modules[]" value="%1$s" %2$s %3$s>
								    %4$s
								</label>',
								esc_attr($moduleId),
								$wp_menu_editor->is_module_active($moduleId, $module) ? 'checked="checked"' : '',
								// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Constant strings.
								$isCompatible ? '' : 'disabled="disabled"',
								esc_html(!empty($module['title']) ? $module['title'] : $moduleId)
							);

							if ( !empty($compatibilityNote) ) {
								// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $compatibilityNote was escaped when generated.
								printf('<br><span class="description">%s</span>', $compatibilityNote);
							}

							echo '</p>';
						}
						?>
					</fieldset>
				</td>
			</tr>

			<tr>
				<th scope="row">Interface</th>
				<td>
					<p>
						<label>
							<input type="checkbox" name="hide_advanced_settings"
								<?php checked($settings['hide_advanced_settings']); ?>>
							Hide advanced menu options by default
						</label>
					</p>

					<?php if ($isProVersion): ?>
						<p>
						<label>
							<input type="checkbox" name="show_deprecated_hide_button"
								<?php checked($settings['show_deprecated_hide_button']); ?>>
							Enable the "Hide (cosmetic)" toolbar button
						</label>
						<br><span class="description">
							This button hides the selected menu item without making it inaccessible.
						</span>
						</p>
					<?php endif; ?>
				</td>
			</tr>

			<tr>
				<th scope="row">Editor colour scheme</th>
				<td>
					<fieldset>
						<p>
							<label>
								<input type="radio" name="ui_colour_scheme" value="classic"
									<?php checked('classic', $settings['ui_colour_scheme']); ?>>
								Blue and yellow
							</label>
						</p>

						<p>
							<label>
								<input type="radio" name="ui_colour_scheme" value="modern-one"
									<?php checked('modern-one', $settings['ui_colour_scheme']); ?>>
								Modern
							</label>
						</p>

						<p>
							<label>
								<input type="radio" name="ui_colour_scheme" value="wp-grey"
									<?php checked('wp-grey', $settings['ui_colour_scheme']); ?>>
								Grey
							</label>
						</p>
					</fieldset>
				</td>
			</tr>

			<?php if ($isProVersion): ?>
			<tr>
				<th scope="row">Show submenu icons</th>
				<td>
					<fieldset id="ame-submenu-icons-settings">
						<p>
							<label>
								<input type="radio" name="submenu_icons_enabled" value="always"
									<?php checked('always', $settings['submenu_icons_enabled']); ?>>
								Always
							</label>
						</p>

						<p>
							<label>
								<input type="radio" name="submenu_icons_enabled" value="if_custom"
									<?php checked('if_custom', $settings['submenu_icons_enabled']); ?>>
								Only when manually selected
							</label>
						</p>

						<p>
							<label>
								<input type="radio" name="submenu_icons_enabled" value="never"
									<?php checked('never', $settings['submenu_icons_enabled']); ?>>
								Never
							</label>
						</p>
					</fieldset>
				</td>
			</tr>

				<tr>
					<th scope="row">
						New menu visibility
						<a class="ws_tooltip_trigger"
						   title="This setting controls the default permissions of menu items that are
						    not present in the last saved menu configuration.
							&lt;br&gt;&lt;br&gt;
							This includes new menus added by plugins and themes.
							In Multisite, it also applies to menus that exist on some sites but not others.
							It doesn't affect menu items that you add through the Admin Menu Editor interface.">
							<div class="dashicons dashicons-info"></div>
						</a>
					</th>
					<td>
						<fieldset>
							<p>
								<label>
									<input type="radio" name="unused_item_permissions" value="unchanged"
										<?php checked('unchanged', $settings['unused_item_permissions']); ?>>
									Leave unchanged (default)

									<br><span class="description">
										No special restrictions. Visibility will depend on the plugin
										that added the menus.
									</span>
								</label>
							</p>

							<p>
								<label>
									<input type="radio" name="unused_item_permissions" value="match_plugin_access"
										<?php checked('match_plugin_access', $settings['unused_item_permissions']); ?>>
									Show only to users who can access this plugin

									<br><span class="description">
										Automatically hides all new and unrecognized menus from regular users.
										To make new menus visible, you have to manually enable them in the menu editor.
									</span>
								</label>
							</p>

						</fieldset>
					</td>
				</tr>
			<?php endif; ?>

			<tr>
			<th scope="row">
				New menu position
				<a class="ws_tooltip_trigger"
				   title="This setting controls the position of menu items that are not present in the last saved menu
					configuration.
					&lt;br&gt;&lt;br&gt;
					This includes new menus added by plugins and themes.
					In Multisite, it also applies to menus that exist only on certain sites but not on all sites.
					It doesn't affect menu items that you add through the Admin Menu Editor interface.">
					<div class="dashicons dashicons-info"></div>
				</a>
			</th>
			<td>
				<fieldset>
					<p>
						<label>
							<input type="radio" name="unused_item_position" value="relative"
								<?php checked('relative', $settings['unused_item_position']); ?>>
							Maintain relative order

							<br><span class="description">
								Attempts to put new items in the same relative positions
								as they would be in in the default admin menu.
							</span>
						</label>
					</p>

					<p>
						<label>
							<input type="radio" name="unused_item_position" value="bottom"
								<?php checked('bottom', $settings['unused_item_position']); ?>>
							Bottom

							<br><span class="description">
								Puts new items at the bottom of the admin menu.
							</span>
						</label>
					</p>

				</fieldset>
			</td>
			</tr>

			<?php
			//The free version lacks the ability to render deeply nested menus in the dashboard, so the nesting
			//options are hidden by default. However, if the user somehow acquires a configuration where this
			//feature is enabled (e.g. by importing config from the Pro version), the free version can display
			//and even edit that configuration to a limited extent.
			if ( $isProVersion || !empty($settings['was_nesting_ever_changed']) ):
				?>
				<tr>
					<th scope="row">
						Three level menus
						<a class="ws_tooltip_trigger ame-warning-tooltip"
						   title="Caution: Experimental feature.&lt;br&gt;
						   This feature might not work as expected and it could cause conflicts with other plugins or themes.">
							<div class="dashicons dashicons-admin-tools"></div>
						</a>
					</th>
					<td>
						<fieldset>
							<?php
							$nestingOptions = array(
								'Ask on first use'                                     => null,
								'Enabled' . ($isProVersion ? '' : ' (only in editor)') => true,
								'Disabled'                                             => false,
							);
							foreach ($nestingOptions as $label => $nestingSetting):
								?>
								<p>
									<label>
										<input type="radio" name="deep_nesting_enabled"
										       value="<?php echo esc_attr(wp_json_encode($nestingSetting)); ?>"
											<?php
											if ( $settings['deep_nesting_enabled'] === $nestingSetting ) {
												echo ' checked="checked"';
											}
											?>>
										<?php echo esc_html($label); ?>
									</label>
								</p>
							<?php endforeach; ?>
						</fieldset>
					</td>
				</tr>
			<?php endif; ?>

			<tr>
				<th scope="row">
					WPML support
				</th>
				<td>
					<p>
						<label>
							<input type="checkbox" name="wpml_support_enabled"
								<?php checked($settings['wpml_support_enabled']); ?>>
							Make edited menu titles translatable with WPML

							<br><span class="description">
								The titles will appear in the "Strings" section in WPML.
								If you don't use WPML or a similar translation plugin,
								you can safely disable this option.
							</span>
						</label>
					</p>
				</td>
			</tr>

			<tr>
				<th scope="row">
					bbPress override
				</th>
				<td>
					<p>
						<label>
							<input type="checkbox" name="bbpress_override_enabled"
								<?php checked($settings['bbpress_override_enabled']); ?>>
							Prevent bbPress from resetting role capabilities

							<br><span class="description">
								By default, bbPress will automatically undo any changes that are made to dynamic
								bbPress roles. Enable this option to override that behaviour and make it possible
								to change bbPress role capabilities.
							</span>
						</label>
					</p>
				</td>
			</tr>

			<tr>
				<th scope="row">Error verbosity level</th>
				<td>
					<fieldset id="ame-submenu-icons-settings">
						<p>
							<label>
								<input type="radio" name="error_verbosity" value="<?php echo esc_attr(WPMenuEditor::VERBOSITY_LOW); ?>>"
									<?php checked(WPMenuEditor::VERBOSITY_LOW, $settings['error_verbosity']); ?>>
								Low

								<br><span class="description">
									Shows a generic error message without any details.
								</span>
							</label>
						</p>

						<p>
							<label>
								<input type="radio" name="error_verbosity" value="<?php echo esc_attr(WPMenuEditor::VERBOSITY_NORMAL); ?>>"
									<?php checked(WPMenuEditor::VERBOSITY_NORMAL, $settings['error_verbosity']); ?>>
								Normal

								<br><span class="description">
									Shows a one or two sentence explanation. For example: "The current user doesn't have
									the "manage_options" capability that is required to access the "Settings" menu item."
								</span>
							</label>
						</p>

						<p>
							<label>
								<input type="radio" name="error_verbosity" value="<?php echo esc_attr(WPMenuEditor::VERBOSITY_VERBOSE); ?>>"
									<?php checked(WPMenuEditor::VERBOSITY_VERBOSE, $settings['error_verbosity']); ?>>
								Verbose

								<br><span class="description">
									Like "normal", but also includes a log of menu settings and permissions that
									caused the current menu to be hidden. Useful for debugging.
								</span>
							</label>
						</p>
					</fieldset>
				</td>
			</tr>

			<tr>
				<th scope="row">Debugging</th>
				<td>
					<p>
					<label>
						<input type="checkbox" name="security_logging_enabled"
							<?php checked($settings['security_logging_enabled']); ?>>
						Show menu access checks performed by the plugin on every admin page
					</label>
					<br><span class="description">
						This can help track down configuration problems and figure out why
						your menu permissions don't work the way they should.

						Note: It's not recommended to use this option on a live site as
						it can reveal information about your menu configuration.
					</span>
					</p>

					<p>
						<label>
							<input type="checkbox" name="force_custom_dashicons"
								<?php checked($settings['force_custom_dashicons']); ?>>
							Attempt to override menu icon CSS that was added by other plugins
						</label>
					</p>

					<p>
						<label>
							<input type="checkbox" name="compress_custom_menu"
								<?php checked($settings['compress_custom_menu']); ?>>
							Compress menu configuration data that's stored in the database
						</label>
						<br><span class="description">
							Significantly reduces the size of
							the <code><?php echo esc_html($db_option_name); ?></code> DB option,
							but adds decompression overhead to every page.
						</span>
					</p>
				</td>
			</tr>

			<tr>
				<th scope="row">Server info</th>
				<td>
					<figure>
						<figcaption>PHP error log:</figcaption>

						<code><?php
						echo esc_html(ini_get('error_log'));
						?></code>
					</figure>

					<figure>
						<figcaption>PHP memory usage:</figcaption>

						<?php
						printf(
							'%.2f MiB of %s',
							// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- We're using sprintf() to format a float.
							memory_get_peak_usage() / (1024 * 1024),
							esc_html(ini_get('memory_limit'))
						);
						?>
					</figure>
				</td>
			</tr>
			</tbody>
		</table>

		<input type="hidden" name="action" value="save_settings">
		<?php
		wp_nonce_field('save_settings');
		submit_button();
		?>
	</form>

<?php do_action('admin_menu_editor-display_footer'); ?>

<script type="text/javascript">
	jQuery(function($) {
		//Set up tooltips
		$('.ws_tooltip_trigger').qtip({
			style: {
				classes: 'qtip qtip-rounded ws_tooltip_node ws_wide_tooltip'
			}
		});
	});
</script>