Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/bdthemes-element-pack/admin/admin.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
3
+
namespace ElementPack;
4
+
5
+
if (!defined('ABSPATH')) {
6
+
exit;
7
+
} // Exit if accessed directly
8
+
9
+
10
+
require_once BDTEP_ADMIN_PATH . 'class-settings-api.php';
11
+
if (current_user_can('manage_options')) {
12
+
require_once BDTEP_ADMIN_PATH . 'admin-feeds.php';
13
+
}
14
+
// element pack admin settings here
15
+
require_once BDTEP_ADMIN_PATH . 'admin-settings.php';
16
+
// Google OAuth handler
17
+
require_once BDTEP_ADMIN_PATH . 'class-oauth-handler.php';
18
+
19
+
/**
20
+
* Admin class
21
+
*/
22
+
23
+
class Admin {
24
+
25
+
public function __construct() {
26
+
27
+
// Embed the Script on our Plugin's Option Page Only
28
+
29
+
add_action('admin_init', [$this, 'admin_script']);
30
+
add_action('admin_enqueue_scripts', [$this, 'enqueue_styles']);
31
+
32
+
33
+
add_action('upgrader_process_complete', [$this, 'bdthemes_element_pack_plugin_on_upgrade_process_complete'], 10, 2);
34
+
35
+
register_deactivation_hook(BDTEP__FILE__, [$this, 'bdthemes_element_pack_plugin_on_deactivate']);
36
+
37
+
add_action('after_setup_theme', [$this, 'whitelabel']);
38
+
39
+
add_filter('plugin_action_links_' . BDTEP_PBNAME, [$this, 'plugin_action_links']);
40
+
41
+
// register_activation_hook(BDTEP__FILE__, 'install_and_activate');
42
+
43
+
}
44
+
45
+
46
+
function install_and_activate() {
47
+
48
+
// I don't know of any other redirect function, so this'll have to do.
49
+
wp_redirect(admin_url('admin.php?page=element_pack_options'));
50
+
// You could use a header(sprintf('Location: %s', admin_url(...)); here instead too.
51
+
}
52
+
53
+
/**
54
+
* You can easily add white label branding for extended license or multi site license. Don't try for regular license otherwise your license will be invalid.
55
+
* @return [type] [description]
56
+
* Define BDTEP_WL for execute white label branding
57
+
*/
58
+
public function whitelabel() {
59
+
if (defined('BDTEP_WL')) {
60
+
61
+
add_filter('gettext', [$this, 'element_pack_name_change'], 20, 3);
62
+
63
+
if (BDTEP_HIDE) {
64
+
add_action('pre_current_active_plugins', [$this, 'hide_element_pack']);
65
+
}
66
+
} else {
67
+
add_filter('plugin_row_meta', [$this, 'plugin_row_meta'], 10, 2);
68
+
add_filter('plugin_action_links_' . BDTEP_PBNAME, [$this, 'plugin_action_meta']);
69
+
}
70
+
}
71
+
72
+
/**
73
+
* Enqueue styles
74
+
* @access public
75
+
*/
76
+
77
+
public function enqueue_styles() {
78
+
79
+
$direction_suffix = is_rtl() ? '.rtl' : '';
80
+
$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
81
+
82
+
wp_enqueue_style('bdt-uikit', BDTEP_ASSETS_URL . 'css/bdt-uikit' . $direction_suffix . '.css', [], '3.21.7');
83
+
wp_enqueue_style('ep-editor', BDTEP_ASSETS_URL . 'css/ep-editor' . $direction_suffix . '.css', [], BDTEP_VER);
84
+
85
+
wp_enqueue_style('ep-admin', BDTEP_ADMIN_URL . 'assets/css/ep-admin' . $direction_suffix . '.css', [], BDTEP_VER);
86
+
wp_enqueue_script('bdt-uikit', BDTEP_ASSETS_URL . 'js/bdt-uikit' . $suffix . '.js', ['jquery'], '3.21.7');
87
+
}
88
+
89
+
/**
90
+
* Row meta
91
+
* @access public
92
+
* @return array
93
+
*/
94
+
95
+
public function plugin_row_meta($plugin_meta, $plugin_file) {
96
+
if (BDTEP_PBNAME === $plugin_file) {
97
+
$row_meta = [
98
+
'docs' => '<a href="https://elementpack.pro/contact/" aria-label="' . esc_attr(__('Go for Get Support', 'bdthemes-element-pack')) . '" target="_blank">' . __('Get Support', 'bdthemes-element-pack') . '</a>',
99
+
'video' => '<a href="https://www.youtube.com/playlist?list=PLP0S85GEw7DOJf_cbgUIL20qqwqb5x8KA" aria-label="' . esc_attr(__('View Element Pack Video Tutorials', 'bdthemes-element-pack')) . '" target="_blank">' . __('Video Tutorials', 'bdthemes-element-pack') . '</a>',
100
+
];
101
+
102
+
$plugin_meta = array_merge($plugin_meta, $row_meta);
103
+
}
104
+
105
+
return $plugin_meta;
106
+
}
107
+
108
+
/**
109
+
* Action meta
110
+
* @access public
111
+
* @return array
112
+
*/
113
+
114
+
115
+
public function plugin_action_meta($links) {
116
+
117
+
$links = array_merge([sprintf('<a href="%s">%s</a>', element_pack_dashboard_link('#element_pack_welcome'), esc_html__('Settings', 'bdthemes-element-pack'))], $links);
118
+
119
+
$links = array_merge($links, [
120
+
sprintf(
121
+
'<a href="%s">%s</a>',
122
+
element_pack_dashboard_link('#license'),
123
+
esc_html__('License', 'bdthemes-element-pack')
124
+
)
125
+
]);
126
+
127
+
return $links;
128
+
}
129
+
130
+
/**
131
+
* Plugin action links
132
+
* @access public
133
+
* @return array
134
+
*/
135
+
136
+
public function plugin_action_links( $plugin_meta ) {
137
+
138
+
if ( defined( 'BDTEP_HIDE' ) && BDTEP_HIDE ) {
139
+
return $plugin_meta;
140
+
}
141
+
142
+
$row_meta = [
143
+
'settings' => '<a href="'.admin_url( 'admin.php?page=element_pack_options' ) .'" aria-label="' . esc_attr(__('Go to settings', 'bdthemes-element-pack')) . '" >' . __('Settings', 'bdthemes-element-pack') . '</b></a>',
144
+
];
145
+
146
+
$plugin_meta = array_merge($plugin_meta, $row_meta);
147
+
148
+
return $plugin_meta;
149
+
}
150
+
151
+
/**
152
+
* Change Element Pack Name
153
+
* @access public
154
+
* @return string
155
+
*/
156
+
157
+
public function element_pack_name_change($translated_text, $text, $domain) {
158
+
switch ($translated_text) {
159
+
case 'Element Pack Pro':
160
+
$translated_text = BDTEP_TITLE;
161
+
break;
162
+
}
163
+
164
+
return $translated_text;
165
+
}
166
+
167
+
/**
168
+
* Hiding plugins //still in testing purpose
169
+
* @access public
170
+
*/
171
+
172
+
public function hide_element_pack() {
173
+
global $wp_list_table;
174
+
$hide_plg_array = array('bdthemes-element-pack/bdthemes-element-pack.php');
175
+
$all_plugins = $wp_list_table->items;
176
+
177
+
foreach ($all_plugins as $key => $val) {
178
+
if (in_array($key, $hide_plg_array)) {
179
+
unset($wp_list_table->items[$key]);
180
+
}
181
+
}
182
+
}
183
+
184
+
/**
185
+
* Register admin script
186
+
* @access public
187
+
*/
188
+
189
+
public function admin_script() {
190
+
$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
191
+
if (is_admin()) { // for Admin Dashboard Only
192
+
wp_enqueue_script('jquery');
193
+
wp_enqueue_script('jquery-form');
194
+
195
+
if (isset($_GET['page']) && ($_GET['page'] == 'element_pack_options')) {
196
+
wp_enqueue_script('chart', BDTEP_ASSETS_URL . 'vendor/js/chart.min.js', ['jquery'], '3.9.1', true);
197
+
wp_enqueue_script('ep-admin', BDTEP_ADMIN_URL . 'assets/js/ep-admin' . $suffix . '.js', ['jquery', 'chart'], BDTEP_VER, true);
198
+
} else {
199
+
wp_enqueue_script('ep-admin', BDTEP_ADMIN_URL . 'assets/js/ep-admin' . $suffix . '.js', ['jquery'], BDTEP_VER, true);
200
+
}
201
+
}
202
+
}
203
+
204
+
/**
205
+
* Drop Tables on deactivated plugin
206
+
* @access public
207
+
*/
208
+
209
+
public function bdthemes_element_pack_plugin_on_deactivate() {
210
+
global $wpdb;
211
+
212
+
$table_cat = $wpdb->prefix . 'ep_template_library_cat';
213
+
$table_post = $wpdb->prefix . 'ep_template_library_post';
214
+
$table_cat_post = $wpdb->prefix . 'ep_template_library_cat_post';
215
+
216
+
/**
217
+
* Check if the tables exist before attempting to drop them
218
+
*/
219
+
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
220
+
if ($wpdb->get_var("SHOW TABLES LIKE '$table_cat'") == $table_cat) {
221
+
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.SchemaChange
222
+
$wpdb->query("DROP TABLE $table_cat");
223
+
}
224
+
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
225
+
if ($wpdb->get_var("SHOW TABLES LIKE '$table_post'") == $table_post) {
226
+
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.SchemaChange
227
+
$wpdb->query("DROP TABLE $table_post");
228
+
}
229
+
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
230
+
if ($wpdb->get_var("SHOW TABLES LIKE '$table_cat_post'") == $table_cat_post) {
231
+
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.SchemaChange
232
+
$wpdb->query("DROP TABLE $table_cat_post");
233
+
}
234
+
}
235
+
236
+
/**
237
+
* Upgrade Process Complete
238
+
* @access public
239
+
*/
240
+
241
+
public function bdthemes_element_pack_plugin_on_upgrade_process_complete($upgrader_object, $options) {
242
+
if (isset($options['action']) && $options['action'] == 'update' && $options['type'] == 'plugin') {
243
+
if (isset($options['plugins']) && is_array($options['plugins'])) {
244
+
foreach ($options['plugins'] as $each_plugin) {
245
+
if ($each_plugin == BDTEP_PBNAME) {
246
+
@$this->bdthemes_element_pack_plugin_on_deactivate();
247
+
}
248
+
}
249
+
}
250
+
}
251
+
}
252
+
}
253
+