Base.php
3.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
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
<?php
namespace AIOSEO\Plugin\Common\Standalone\PageBuilders;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Base class for each of our page builder integrations.
*
* @since 4.1.7
*/
abstract class Base {
/**
* The plugin files we can integrate with.
*
* @since 4.1.7
*
* @var array
*/
public $plugins = [];
/**
* The themes names we can integrate with.
*
* @since 4.1.7
*
* @var array
*/
public $themes = [];
/**
* The integration slug.
*
* @since 4.1.7
*
* @var string
*/
public $integrationSlug = '';
/**
* Class constructor.
*
* @since 4.1.7
*
* @return void
*/
public function __construct() {
// We need to delay it to give other plugins a chance to register custom post types.
add_action( 'init', [ $this, '_init' ], PHP_INT_MAX );
}
/**
* The internal init function.
*
* @since 4.1.7
*
* @return void
*/
public function _init() {
// Check if we do have an integration slug.
if ( empty( $this->integrationSlug ) ) {
return;
}
// Check if the plugin or theme to integrate with is active.
if ( ! $this->isPluginActive() && ! $this->isThemeActive() ) {
return;
}
// Check if we can proceed with the integration.
if ( apply_filters( 'aioseo_page_builder_integration_disable', false, $this->integrationSlug ) ) {
return;
}
$this->init();
}
/**
* The init function.
*
* @since 4.1.7
*
* @return void
*/
public function init() {}
/**
* Check whether or not the plugin is active.
*
* @since 4.1.7
*
* @return boolean Whether or not the plugin is active.
*/
public function isPluginActive() {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
foreach ( $this->plugins as $basename ) {
if ( is_plugin_active( $basename ) ) {
return true;
}
}
return false;
}
/**
* Check whether or not the theme is active.
*
* @since 4.1.7
*
* @return boolean Whether or not the theme is active.
*/
public function isThemeActive() {
$theme = wp_get_theme();
foreach ( $this->themes as $name ) {
if ( $name === $theme->stylesheet || $name === $theme->template ) {
return true;
}
}
return false;
}
/**
* Enqueue the scripts and styles.
*
* @since 4.1.7
*
* @return void
*/
public function enqueue() {
$integrationSlug = $this->integrationSlug;
aioseo()->core->assets->load( "src/vue/standalone/$integrationSlug/main.js", [], aioseo()->helpers->getVueData( 'post', $this->getPostId(), $this->integrationSlug ) );
aioseo()->core->assets->enqueueCss( 'src/vue/assets/scss/integrations/main.scss', [], 'src/vue/assets/scss/integrations/main.scss' );
aioseo()->admin->addAioseoModalPortal();
aioseo()->admin->enqueueAioseoModalPortal();
aioseo()->main->enqueueTranslations();
}
/**
* Get the post ID.
*
* @since 4.1.7
*
* @return int|null The post ID or null.
*/
public function getPostId() {
if ( ! empty( $_GET['id'] ) ) {
return (int) $_GET['id'];
}
if ( ! empty( $_GET['post'] ) ) {
return (int) $_GET['post'];
}
if ( ! empty( $GLOBALS['post'] ) ) {
return (int) $GLOBALS['post']->ID;
}
return null;
}
/**
* Returns the page builder edit url for the given Post ID.
*
* @since 4.3.1
*
* @param int $postId The Post ID.
* @return string The Edit URL.
*/
public function getEditUrl( $postId ) { // phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
return '';
}
/**
* Returns whether or not the given Post ID was built with the Page Builder.
*
* @since 4.1.7
*
* @param int $postId The Post ID.
* @return boolean Whether or not the Post was built with the Page Builder.
*/
public function isBuiltWith( $postId ) { // phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
return false;
}
}