PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 3.2.7
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v3.2.7
4.17.2 4.17.1 4.17.0 4.16.19 4.16.18 4.16.17 4.16.16 trunk 1.0 1.0.1 1.0.2 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5a 1.1.6 1.1.7 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4 1.4.1 1.4.2 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.7 1.7.1 1.7.2 1.8 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.1.9 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.2 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 3.0 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10.0 4.10.1 4.10.2 4.10.3 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.13.3 4.13.4 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.15.0 4.15.1 4.15.10 4.15.11 4.15.12 4.15.13 4.15.14 4.15.15 4.15.16 4.15.17 4.15.18 4.15.19 4.15.2 4.15.20 4.15.20.1 4.15.21 4.15.22 4.15.23 4.15.24 4.15.25 4.15.3 4.15.4 4.15.5 4.15.6 4.15.7 4.15.8 4.15.9 4.16.0 4.16.1 4.16.10 4.16.11 4.16.12 4.16.13 4.16.14 4.16.15 4.16.2 4.16.3 4.16.4 4.16.5 4.16.6 4.16.7 4.16.8 4.16.9 4.2.0 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.6.0 4.7.0 4.8.0 4.9.0
wp-user-avatar / src / ContentProtection / SettingsPage.php
wp-user-avatar / src / ContentProtection Last commit date
Frontend 4 years ago views 4 years ago ConditionCallbacks.php 5 years ago ContentConditions.php 5 years ago Init.php 4 years ago SettingsPage.php 4 years ago WPListTable.php 4 years ago index.php 5 years ago
SettingsPage.php
213 lines
1 <?php
2
3 namespace ProfilePress\Core\ContentProtection;
4
5 use ProfilePress\Core\Admin\SettingsPages\AbstractSettingsPage;
6 use ProfilePress\Core\Classes\PROFILEPRESS_sql;
7 use ProfilePress\Custom_Settings_Page_Api;
8
9 class SettingsPage extends AbstractSettingsPage
10 {
11 public $content_protection_rule_errors;
12
13 /** @var WPListTable */
14 private $myListTable;
15
16 const META_DATA_KEY = 'content_restrict_data';
17
18 function __construct()
19 {
20 add_action('ppress_register_menu_page', [$this, 'register_cpf_settings_page']);
21 add_action('ppress_admin_settings_page_content-protection', [$this, 'settings_page_function']);
22
23 add_filter('set-screen-option', [__CLASS__, 'set_screen'], 10, 3);
24 add_filter('set_screen_option_rules_per_page', [__CLASS__, 'set_screen'], 10, 3);
25
26 add_action('admin_init', function () {
27 if (ppressGET_var('page') == PPRESS_CONTENT_PROTECTION_SETTINGS_SLUG) {
28
29 if (isset($_GET['add']) && $_GET['add'] == 'new') {
30 $this->save_rule('add');
31 }
32
33 if (isset($_GET['action']) && $_GET['action'] == 'edit') {
34 $this->save_rule('edit');
35 }
36 }
37 });
38 }
39
40 public function admin_page_title()
41 {
42 $title = esc_html__('Content Protection', 'wp-user-avatar');
43
44 if (isset($_GET['action']) && $_GET['action'] == 'edit') {
45 $title = esc_html__('Edit Protection Rule', 'wp-user-avatar');
46 }
47
48 if (isset($_GET['add']) && $_GET['add'] == 'new') {
49 $title = esc_html__('Add Protection Rule', 'wp-user-avatar');
50 }
51
52 return $title;
53 }
54
55 public function register_cpf_settings_page()
56 {
57 $hook = add_submenu_page(
58 PPRESS_SETTINGS_SLUG,
59 $this->admin_page_title() . ' - ProfilePress',
60 esc_html__('Content Protection', 'wp-user-avatar'),
61 'manage_options',
62 PPRESS_CONTENT_PROTECTION_SETTINGS_SLUG,
63 array($this, 'admin_page_callback'));
64
65 add_action("load-$hook", array($this, 'add_options'));
66 }
67
68 public function default_header_menu()
69 {
70 return 'content-protection';
71 }
72
73 public static function set_screen($status, $option, $value)
74 {
75 return $value;
76 }
77
78 public function add_options()
79 {
80 $args = [
81 'label' => esc_html__('Protection Rules', 'wp-user-avatar'),
82 'default' => 10,
83 'option' => 'rules_per_page'
84 ];
85
86 add_screen_option('per_page', $args);
87
88 add_filter('screen_options_show_screen', '__return_false');
89
90 $this->myListTable = new WPListTable();
91 }
92
93 public function sanitize_data($data)
94 {
95 if (is_string($data)) {
96 return sanitize_text_field($data);
97 }
98
99 $sanitized_data = [];
100
101 foreach ($data as $key => $value) {
102
103 if (is_array($data[$key])) {
104 $sanitized_data[$key] = self::sanitize_data($data[$key]);
105 } else {
106 if ($key == 'noaccess_action_message_custom') {
107 $sanitized_data[$key] = wp_kses_post($data[$key]);
108 } else {
109 $sanitized_data[$key] = sanitize_textarea_field($data[$key]);
110 }
111 }
112 }
113
114 return $sanitized_data;
115 }
116
117 public function save_rule($type)
118 {
119 if ( ! isset($_POST['ppress_save_rule'])) return;
120
121 check_admin_referer('wp-csa-nonce', 'wp_csa_nonce');
122
123 if ( ! current_user_can('manage_options')) return;
124
125 if (empty($_POST['ppress_cc_data']['title'])) {
126 return $this->content_protection_rule_errors = esc_html__('Title cannot be empty.', 'wp-user-avatar');
127 }
128
129 if ('add' == $type) {
130 $id = PROFILEPRESS_sql::add_meta_data(self::META_DATA_KEY, $this->sanitize_data($_POST['ppress_cc_data']));
131
132 if (is_int($id)) {
133 wp_safe_redirect(add_query_arg(['action' => 'edit', 'id' => $id, 'rule-updated' => 'true'], PPRESS_CONTENT_PROTECTION_SETTINGS_PAGE));
134 exit;
135 }
136 }
137
138 if ('edit' == $type) {
139 $rule_id = absint($_GET['id']);
140 $response = PROFILEPRESS_sql::update_meta_value($rule_id, self::META_DATA_KEY, $this->sanitize_data($_POST['ppress_cc_data']));
141
142 if (false !== $response) {
143 wp_safe_redirect(add_query_arg(['action' => 'edit', 'id' => $rule_id, 'rule-updated' => 'true'], PPRESS_CONTENT_PROTECTION_SETTINGS_PAGE));
144 exit;
145 }
146 }
147 }
148
149 public function admin_notices()
150 {
151 if ( ! isset($_GET['rule-updated']) && ! isset($this->content_protection_rule_errors)) return;
152
153 $status = 'updated';
154 if (isset($this->content_protection_rule_errors)) {
155 $message = $this->content_protection_rule_errors;
156 $status = 'error';
157 }
158
159 if (isset($_GET['rule-updated'])) {
160 $message = esc_html__('Changes saved.', 'wp-user-avatar');
161 }
162
163 printf('<div id="message" class="%s notice is-dismissible"><p>%s</strong></p></div>', $status, $message);
164 }
165
166 public function settings_page_function()
167 {
168 add_action('wp_cspa_main_content_area', array($this, 'admin_settings_page_callback'), 10, 2);
169 add_action('wp_cspa_before_closing_header', [$this, 'add_new_button']);
170
171 $instance = Custom_Settings_Page_Api::instance();
172 $instance->option_name('ppview'); // adds ppview css class to #poststuff
173 $instance->page_header($this->admin_page_title());
174 $instance->build(true);
175 }
176
177 public function add_new_button()
178 {
179 if ( ! isset($_GET['add']) && ! isset($_GET['action'])) {
180 $url = esc_url_raw(add_query_arg('add', 'new', PPRESS_CONTENT_PROTECTION_SETTINGS_PAGE));
181 echo "<a class=\"add-new-h2\" href=\"$url\">" . esc_html__('Add a Protection Rule', 'wp-user-avatar') . '</a>';
182 }
183 }
184
185 public function admin_settings_page_callback()
186 {
187 $this->myListTable->prepare_items(); // has to be here.
188
189 if (isset($_GET['add']) || isset($_GET['action'])) {
190 $this->admin_notices();
191 require_once dirname(__FILE__) . '/views/include.view.php';
192
193 return;
194 }
195
196 echo '<form method="post">';
197 $this->myListTable->display();
198 echo '</form>';
199
200 do_action('ppress_content_protection_wp_list_table_bottom');
201 }
202
203 public static function get_instance()
204 {
205 static $instance = null;
206
207 if (is_null($instance)) {
208 $instance = new self();
209 }
210
211 return $instance;
212 }
213 }