PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 3.1
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v3.1
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 5 years ago views 5 years ago ConditionCallbacks.php 5 years ago ContentConditions.php 5 years ago Init.php 5 years ago SettingsPage.php 5 years ago WPListTable.php 5 years ago index.php 5 years ago
SettingsPage.php
196 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('admin_menu', array($this, 'register_cpf_settings_page'));
21 add_filter('set-screen-option', [__CLASS__, 'set_screen'], 10, 3);
22 add_filter('set_screen_option_rules_per_page', [__CLASS__, 'set_screen'], 10, 3);
23 }
24
25 public function admin_page_title()
26 {
27 $title = esc_html__('Content Protection', 'wp-user-avatar');
28
29 if (isset($_GET['action']) && $_GET['action'] == 'edit') {
30 $title = esc_html__('Edit Protection Rule', 'wp-user-avatar');
31 }
32
33 if (isset($_GET['add']) && $_GET['add'] == 'new') {
34 $title = esc_html__('Add Protection Rule', 'wp-user-avatar');
35 }
36
37 return $title;
38 }
39
40 public function register_cpf_settings_page()
41 {
42 $hook = add_submenu_page(
43 PPRESS_SETTINGS_SLUG,
44 $this->admin_page_title() . ' - ProfilePress',
45 esc_html__('Content Protection', 'wp-user-avatar'),
46 'manage_options',
47 PPRESS_CONTENT_PROTECTION_SETTINGS_SLUG,
48 array($this, 'settings_page_function'));
49
50 add_action("load-$hook", array($this, 'add_options'));
51 }
52
53 public static function set_screen($status, $option, $value)
54 {
55 return $value;
56 }
57
58 public function add_options()
59 {
60 $args = [
61 'label' => esc_html__('Protection Rules', 'wp-user-avatar'),
62 'default' => 10,
63 'option' => 'rules_per_page'
64 ];
65
66 add_screen_option('per_page', $args);
67
68 $this->myListTable = new WPListTable();
69 }
70
71 public function sanitize_data($data)
72 {
73 if (is_string($data)) {
74 return sanitize_text_field($data);
75 }
76
77 $sanitized_data = [];
78
79 foreach ($data as $key => $value) {
80
81 if (is_array($data[$key])) {
82 $sanitized_data[$key] = self::sanitize_data($data[$key]);
83 } else {
84 $sanitized_data[$key] = sanitize_text_field($data[$key]);
85 }
86 }
87
88 return $sanitized_data;
89 }
90
91 public function save_rule($type)
92 {
93 if ( ! isset($_POST['ppress_save_rule'])) return;
94
95 check_admin_referer('wp-csa-nonce', 'wp_csa_nonce');
96
97 if ( ! current_user_can('manage_options')) return;
98
99 if (empty($_POST['ppress_cc_data']['title'])) {
100 return $this->content_protection_rule_errors = esc_html__('Title cannot be empty.', 'wp-user-avatar');
101 }
102
103 if ('add' == $type) {
104 $id = PROFILEPRESS_sql::add_meta_data(self::META_DATA_KEY, $this->sanitize_data($_POST['ppress_cc_data']));
105
106 if (is_int($id)) {
107 wp_safe_redirect(add_query_arg(['action' => 'edit', 'id' => $id, 'rule-updated' => 'true'], PPRESS_CONTENT_PROTECTION_SETTINGS_PAGE));
108 exit;
109 }
110 }
111
112 if ('edit' == $type) {
113 $rule_id = absint($_GET['id']);
114 $response = PROFILEPRESS_sql::update_meta_value($rule_id, self::META_DATA_KEY, $this->sanitize_data($_POST['ppress_cc_data']));
115
116 if (false !== $response) {
117 wp_safe_redirect(add_query_arg(['action' => 'edit', 'id' => $rule_id, 'rule-updated' => 'true'], PPRESS_CONTENT_PROTECTION_SETTINGS_PAGE));
118 exit;
119 }
120 }
121 }
122
123 public function admin_notices()
124 {
125 if ( ! isset($_GET['rule-updated']) && ! isset($this->content_protection_rule_errors)) return;
126
127 $status = 'updated';
128 if (isset($this->content_protection_rule_errors)) {
129 $message = $this->content_protection_rule_errors;
130 $status = 'error';
131 }
132
133 if (isset($_GET['rule-updated'])) {
134 $message = esc_html__('Changes saved.', 'wp-user-avatar');
135 }
136
137 printf('<div id="message" class="%s notice is-dismissible"><p>%s</strong></p></div>', $status, $message);
138 }
139
140 public function settings_page_function()
141 {
142 add_action('wp_cspa_main_content_area', array($this, 'admin_page_callback'), 10, 2);
143 add_action('wp_cspa_before_closing_header', [$this, 'add_new_button']);
144
145 $instance = Custom_Settings_Page_Api::instance();
146 $instance->option_name('ppview'); // adds ppview css class to #poststuff
147 $instance->page_header($this->admin_page_title());
148 $this->register_core_settings($instance, true);
149 $instance->build(true);
150 }
151
152 public function add_new_button()
153 {
154 if ( ! isset($_GET['add']) && ! isset($_GET['action'])) {
155 $url = esc_url_raw(add_query_arg('add', 'new', PPRESS_CONTENT_PROTECTION_SETTINGS_PAGE));
156 echo "<a class=\"add-new-h2\" href=\"$url\">" . esc_html__('Add a Protection Rule', 'wp-user-avatar') . '</a>';
157 }
158 }
159
160 public function admin_page_callback()
161 {
162 $this->myListTable->prepare_items(); // has to be here.
163
164 if (isset($_GET['add']) && $_GET['add'] == 'new') {
165 $this->save_rule('add');
166 }
167
168 if (isset($_GET['action']) && $_GET['action'] == 'edit') {
169 $this->save_rule('edit');
170 }
171
172 if (isset($_GET['add']) || isset($_GET['action'])) {
173 $this->admin_notices();
174 require_once dirname(__FILE__) . '/views/include.view.php';
175
176 return;
177 }
178
179 echo '<form method="post">';
180 $this->myListTable->display();
181 echo '</form>';
182
183 do_action('ppress_content_protection_wp_list_table_bottom');
184 }
185
186 public static function get_instance()
187 {
188 static $instance = null;
189
190 if (is_null($instance)) {
191 $instance = new self();
192 }
193
194 return $instance;
195 }
196 }