PluginProbe ʕ •ᴥ•ʔ
Backup Migration / 2.1.2
Backup Migration v2.1.2
2.1.7 2.1.6 2.1.5.2 trunk 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.6.1 1.4.7 1.4.8 1.4.9 1.4.9.1 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.5.1
backup-backup / analyst / src / Mutator.php
backup-backup / analyst / src Last commit date
Account 5 months ago Cache 5 months ago Contracts 5 months ago Core 5 months ago Http 5 months ago Notices 5 months ago Storage 5 months ago Analyst.php 5 months ago ApiRequestor.php 5 months ago ApiResponse.php 5 months ago Collector.php 5 months ago Mutator.php 5 months ago helpers.php 5 months ago
Mutator.php
139 lines
1 <?php
2
3
4 namespace Analyst;
5
6 use Analyst\Cache\DatabaseCache;
7 use Analyst\Contracts\CacheContract;
8 use Analyst\Notices\NoticeFactory;
9
10 if ( ! defined( 'ABSPATH' ) ) exit;
11
12 /**
13 * Class Mutator mutates (modifies) UX with additional
14 * functional
15 */
16 class Mutator
17 {
18 protected $notices = [];
19
20 /**
21 * @var NoticeFactory
22 */
23 protected $factory;
24
25 /**
26 * @var CacheContract
27 */
28 protected $cache;
29
30 public function __construct()
31 {
32 $this->factory = NoticeFactory::instance();
33
34 $this->notices = $this->factory->getNotices();
35
36 $this->cache = DatabaseCache::getInstance();
37 }
38
39 /**
40 * Register filters all necessary stuff.
41 * Can be invoked only once.
42 *
43 * @return void
44 */
45 public function initialize()
46 {
47 $this->registerLinks();
48 $this->registerAssets();
49 $this->registerHooks();
50 }
51
52 /**
53 * Register all necessary filters and templates
54 *
55 * @return void
56 */
57 protected function registerLinks()
58 {
59 add_action('admin_footer', function () {
60 analyst_require_template('optout.php', [
61 'shieldImage' => analyst_assets_url('img/shield_question.png')
62 ]);
63
64 analyst_require_template('optin.php');
65
66 analyst_require_template('forms/deactivate.php', [
67 'pencilImage' => analyst_assets_url('img/pencil.png'),
68 'smileImage' => analyst_assets_url('img/smile.png'),
69 ]);
70
71 analyst_require_template('forms/install.php', [
72 'pluginToInstall' => $this->cache->get('plugin_to_install'),
73 'shieldImage' => analyst_assets_url('img/shield_success.png'),
74 ]);
75 });
76
77 add_action('admin_notices',function () {
78 foreach ($this->notices as $notice) {
79 analyst_require_template('notice.php', ['notice' => $notice]);
80 }
81 });
82 }
83
84 /**
85 * Register all assets
86 */
87 public function registerAssets()
88 {
89 add_action('admin_enqueue_scripts', function () {
90 wp_enqueue_style('analyst_custom', analyst_assets_url('/css/customize.css'));
91 wp_enqueue_script('analyst_custom', analyst_assets_url('/js/customize.js'));
92 wp_localize_script('analyst_custom', 'analyst_opt_localize', array(
93 'analyst_nonce' => wp_create_nonce('analyst_opt_ajax_nonce')
94 ));
95 });
96 }
97
98 /**
99 * Register action hooks
100 */
101 public function registerHooks()
102 {
103 add_action('wp_ajax_analyst_notification_dismiss', function () {
104 $capabilities = [
105 'activate_plugins',
106 'edit_plugins',
107 'install_plugins',
108 'update_plugins',
109 'delete_plugins',
110 'manage_network_plugins',
111 'upload_plugins'
112 ];
113
114 // Allow if has any of above permissions
115 $hasPerms = false;
116 foreach ($capabilities as $i => $cap) {
117 if (current_user_can($cap)) {
118 $hasPerms = true;
119 break;
120 }
121 }
122
123 if ($hasPerms == false) {
124 wp_send_json_error(['message' => 'no_permissions']);
125 die;
126 }
127
128 if (!isset($_POST['analyst_nonce']) || !wp_verify_nonce(sanitize_text_field($_POST['analyst_nonce']), 'analyst_opt_ajax_nonce')) {
129 wp_send_json_error(['message' => 'invalid_nonce']);
130 die;
131 }
132
133 $this->factory->remove(sanitize_text_field($_POST['id']));
134
135 $this->factory->sync();
136 });
137 }
138 }
139