FlyoutMenu.php
1.79 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
<?php
namespace AIOSEO\Plugin\Common\Standalone;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Handles the flyout menu.
*
* @since 4.2.0
*/
class FlyoutMenu {
/**
* Class constructor.
*
* @since 4.2.0
*/
public function __construct() {
if (
! is_admin() ||
wp_doing_ajax() ||
wp_doing_cron() ||
! $this->isEnabled()
) {
return;
}
add_action( 'admin_enqueue_scripts', [ $this, 'enqueueAssets' ], 11 );
add_filter( 'admin_body_class', [ $this, 'addBodyClass' ] );
}
/**
* Enqueues the required assets.
*
* @since 4.2.0
*
* @return void
*/
public function enqueueAssets() {
if ( ! $this->shouldEnqueue() ) {
return;
}
aioseo()->core->assets->load( 'src/vue/standalone/flyout-menu/main.js' );
}
/**
* Filters the CSS classes for the body tag in the admin.
*
* @since 4.2.0
*
* @param string $classes Space-separated list of CSS classes.
* @return string Space-separated list of CSS classes.
*/
public function addBodyClass( $classes ) {
if ( $this->shouldEnqueue() ) {
// This adds a bottom margin to our menu so that we push the footer down and prevent the flyout menu from overlapping the "Save Changes" button.
$classes .= ' aioseo-flyout-menu-enabled ';
}
return $classes;
}
/**
* Checks whether the flyout menu script should be enqueued.
*
* @since 4.2.0
*
* @return bool Whether the flyout menu script should be enqueued.
*/
private function shouldEnqueue() {
if ( aioseo()->admin->isAioseoScreen() ) {
return true;
}
return false;
}
/**
* Checks whether the flyout menu is enabled.
*
* @since 4.2.0
*
* @return bool Whether the flyout menu is enabled.
*/
public function isEnabled() {
return apply_filters( 'aioseo_flyout_menu_enable', true );
}
}