-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.php
More file actions
258 lines (227 loc) · 6.11 KB
/
app.php
File metadata and controls
258 lines (227 loc) · 6.11 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
<?php
/**
* @package Content Aware Sidebars
* @author Joachim Jensen <joachim@dev.institute>
* @license GPLv3
* @copyright 2024 by Joachim Jensen
*/
defined('ABSPATH') || exit;
final class CAS_App
{
const PLUGIN_VERSION_KEY = 'cas_db_version';
const PLUGIN_VERSION = '3.21.2';
/**
* Prefix for sidebar id
*/
const SIDEBAR_PREFIX = 'ca-sidebar-';
/**
* Post Type for sidebars
*/
const TYPE_SIDEBAR = 'sidebar';
/**
* Sidebar statuses
*/
const STATUS_ACTIVE = 'publish';
const STATUS_INACTIVE = 'draft';
const STATUS_SCHEDULED = 'future';
const ACTION_REPLACE = 0;
const ACTION_MERGE = 1;
const ACTION_SHORTCODE = 2;
const ACTION_REPLACE_FORCED = 3;
/**
* Capability to manage sidebars
*/
const CAPABILITY = 'edit_theme_options';
/**
* Base admin screen name
*/
const BASE_SCREEN = 'wpcas';
/**
* Prefix for metadata keys
*/
const META_PREFIX = '_ca_';
/**
* @var CAS_Sidebar_Manager
*/
private $manager;
/**
* @var WP_DB_Updater
*/
private $db_updater;
/**
* @var CAS_App
*/
private static $_instance;
/**
* Instantiates and returns class singleton
*
* @return CAS_App
*/
public static function instance()
{
if (!self::$_instance) {
self::$_instance = new self();
}
return self::$_instance;
}
public function __construct()
{
$this->manager = new CAS_Sidebar_Manager();
$this->db_updater = new WP_DB_Updater(self::PLUGIN_VERSION_KEY, self::PLUGIN_VERSION, true);
if (is_admin()) {
new CAS_Sidebar_Overview();
new CAS_Sidebar_Edit();
new CAS_Quick_Select();
new CAS_Admin_Screen_Widgets();
new CAS_Admin_Settings();
} else {
new CAS_Admin_Bar();
}
$this->add_actions();
$this->add_filters();
}
/**
* @since 3.7.8
* @return WP_DB_Updater
*/
public function get_updater()
{
return $this->db_updater;
}
/**
* @return CAS_Sidebar_Manager
*/
public function manager()
{
return $this->manager;
}
/**
* Add actions to queues
*
* @since 3.1
* @return void
*/
protected function add_actions()
{
add_action(
'init',
[$this,'load_textdomain']
);
add_action(
'cas/event/deactivate',
[$this,'scheduled_deactivation']
);
if (is_admin()) {
add_action(
'plugins_loaded',
[$this,'redirect_revision_link']
);
add_action(
'admin_menu',
[$this, 'admin_menu_upsell'],
999
);
}
}
public function admin_menu_upsell()
{
$cas_fs = cas_fs();
if (!$cas_fs->can_use_premium_code()) {
global $submenu;
$submenu['wpcas'][] = [
__('Widget Cleaner', 'content-aware-sidebars') . ' (Pro)',
CAS_App::CAPABILITY,
$cas_fs->get_upgrade_url()
];
}
}
/**
* Add filters to queues
*
* @since 3.1
* @return void
*/
protected function add_filters()
{
if (is_admin()) {
$file = plugin_basename(plugin_dir_path(__FILE__)) . '/content-aware-sidebars.php';
add_filter(
'plugin_action_links_' . $file,
[$this,'plugin_action_links'],
99,
4
);
/**
* gutenberg disables widgets screen without user consent,
* reenable by popular demand for now
*/
add_filter('gutenberg_use_widgets_block_editor', '__return_false');
}
}
/**
* Load textdomain
*
* @since 3.0
* @return void
*/
public function load_textdomain()
{
load_plugin_textdomain('content-aware-sidebars', false, dirname(plugin_basename(__FILE__)) . '/lang/');
}
/**
* Add actions to plugin in Plugins screen
*
* @version 2.4
* @param array $actions
* @param string $plugin_file
* @param [type] $plugin_data
* @param [type] $context
* @return array
*/
public function plugin_action_links($actions, $plugin_file, $plugin_data, $context)
{
global $cas_fs;
$new_actions = [];
$new_actions['docs'] = '<a href="https://dev.institute/docs/content-aware-sidebars/?utm_source=plugin&utm_medium=referral&utm_content=plugin-list&utm_campaign=cas" target="_blank" rel="noopener">' . __('Docs & FAQ', 'content-aware-sidebars') . '</a>';
$new_actions['support'] = '<a href="' . esc_url($cas_fs->contact_url()) . '">' . __('Premium Support', 'content-aware-sidebars') . '</a>';
if (!$cas_fs->has_active_valid_license()) {
$new_actions['support'] = '<a href="' . esc_url($cas_fs->get_upgrade_url()) . '">' . __('Premium Support', 'content-aware-sidebars') . '</a>';
unset($actions['upgrade']);
}
unset($actions['addons']);
return array_merge($new_actions, $actions);
}
/**
* Callback for scheduled deactivation
*
* @since 3.4
* @param int $post_id
* @return void
*/
public function scheduled_deactivation($post_id)
{
$success = wp_update_post([
'ID' => $post_id,
'post_status' => self::STATUS_INACTIVE
]);
if ($success) {
delete_post_meta($post_id, self::META_PREFIX . 'deactivate_time');
}
}
/**
* Redirect revision link to upgrade
*
* @since 3.2
* @return void
*/
public function redirect_revision_link()
{
global $pagenow;
if ($pagenow == 'post.php'
&& isset($_GET['action'],$_GET['post'])
&& $_GET['action'] == 'cas-revisions') {
wp_safe_redirect(cas_fs()->get_upgrade_url());
exit;
}
}
}