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 / Admin / SettingsPages / Forms.php
wp-user-avatar / src / Admin / SettingsPages Last commit date
DragDropBuilder 5 years ago EmailSettings 5 years ago ShortcodeBuilder 5 years ago AbstractSettingsPage.php 5 years ago AddNewForm.php 5 years ago AdminFooter.php 5 years ago ExtensionsSettingsPage.php 5 years ago FormList.php 5 years ago Forms.php 5 years ago GeneralSettings.php 5 years ago IDUserColumn.php 5 years ago MemberDirectories.php 5 years ago MembersDirectoryList.php 5 years ago ToolsSettingsPage.php 5 years ago index.php 5 years ago
Forms.php
393 lines
1 <?php
2
3 namespace ProfilePress\Core\Admin\SettingsPages;
4
5 use ProfilePress\Core\Admin\SettingsPages\DragDropBuilder\DragDropBuilder;
6 use ProfilePress\Core\Admin\SettingsPages\ShortcodeBuilder\EditShortcodeEditProfile\EditShortcodeEditProfile;
7 use ProfilePress\Core\Admin\SettingsPages\ShortcodeBuilder\EditShortcodeLogin\EditShortcodeLogin;
8 use ProfilePress\Core\Admin\SettingsPages\ShortcodeBuilder\EditShortcodePasswordReset\EditShortcodePasswordReset;
9 use ProfilePress\Core\Admin\SettingsPages\ShortcodeBuilder\EditShortcodeMelange\EditShortcodeMelange;
10 use ProfilePress\Core\Admin\SettingsPages\ShortcodeBuilder\EditShortcodeRegistration\EditShortcodeRegistration;
11 use ProfilePress\Core\Admin\SettingsPages\ShortcodeBuilder\EditShortcodeUserProfile\EditShortcodeUserProfile;
12 use ProfilePress\Core\Classes\FormRepository as FR;
13 use ProfilePress\Custom_Settings_Page_Api;
14
15 // Exit if accessed directly
16 if ( ! defined('ABSPATH')) {
17 exit;
18 }
19
20 class Forms extends AbstractSettingsPage
21 {
22 /**
23 * @var FormList
24 */
25 protected $forms_instance;
26
27 protected $EditShortcodeLoginInstance;
28 protected $EditShortcodeRegistrationInstance;
29 protected $EditShortcodePasswordResetInstance;
30 protected $EditShortcodeMelangeInstance;
31 protected $EditShortcodeEditProfileInstance;
32 protected $EditShortcodeUserProfileInstance;
33 protected $DragDropClassInstance;
34
35 public function __construct()
36 {
37 add_action('admin_menu', array($this, 'register_settings_page'));
38
39 add_filter('set-screen-option', array($this, 'set_screen'), 10, 3);
40 add_filter('set_screen_option_forms_per_page', array($this, 'set_screen'), 10, 3);
41
42 $this->EditShortcodeLoginInstance = EditShortcodeLogin::get_instance();
43 $this->EditShortcodeRegistrationInstance = EditShortcodeRegistration::get_instance();
44 $this->EditShortcodePasswordResetInstance = EditShortcodePasswordReset::get_instance();
45 $this->EditShortcodeEditProfileInstance = EditShortcodeEditProfile::get_instance();
46 $this->EditShortcodeMelangeInstance = EditShortcodeMelange::get_instance();
47 $this->EditShortcodeUserProfileInstance = EditShortcodeUserProfile::get_instance();
48
49 $this->DragDropClassInstance = DragDropBuilder::get_instance();
50 }
51
52 public function admin_page_title()
53 {
54 $page_title = esc_html__('Forms & Profiles', 'wp-user-avatar');
55
56 if (isset($_GET['view'])) {
57 $page_title = esc_html__('Edit Form', 'wp-user-avatar');
58 }
59
60 if (isset($_GET['view']) && $_GET['view'] == 'add-new-form') {
61 $page_title = esc_html__('Add Form', 'wp-user-avatar');
62 }
63
64 if (isset($_GET['view']) && $_GET['view'] == 'edit-shortcode-user-profile') {
65 $page_title = esc_html__('Edit Frontend Profile', 'wp-user-avatar');
66 }
67
68 if (isset($_GET['view'], $_GET['form-type']) && $_GET['form-type'] == FR::USER_PROFILE_TYPE) {
69 $page_title = esc_html__('Edit Frontend Profile', 'wp-user-avatar');
70 }
71
72 return $page_title;
73 }
74
75 public function register_settings_page()
76 {
77 $hook = add_submenu_page(
78 PPRESS_SETTINGS_SLUG,
79 $this->admin_page_title() . ' - ProfilePress',
80 esc_html__('Forms & Profiles', 'wp-user-avatar'),
81 'manage_options',
82 PPRESS_FORMS_SETTINGS_SLUG,
83 array($this, 'settings_admin_page_callback')
84 );
85
86 add_action("load-$hook", array($this, 'screen_option'));
87 }
88
89 /**
90 * Sub-menu header for form types.
91 */
92 public function form_sub_header()
93 {
94 if ( ! empty($_GET['page']) && $_GET['page'] == PPRESS_FORMS_SETTINGS_SLUG) {
95 $melange_jbox = esc_html__('Melange combines login, registration & password reset forms in a single form.', 'wp-user-avatar');
96 $login_url = add_query_arg('form-type', FR::LOGIN_TYPE, PPRESS_FORMS_SETTINGS_PAGE);
97 $registration_url = add_query_arg('form-type', FR::REGISTRATION_TYPE, PPRESS_FORMS_SETTINGS_PAGE);
98 $password_reset_url = add_query_arg('form-type', FR::PASSWORD_RESET_TYPE, PPRESS_FORMS_SETTINGS_PAGE);
99 $edit_profile_url = add_query_arg('form-type', FR::EDIT_PROFILE_TYPE, PPRESS_FORMS_SETTINGS_PAGE);
100 $melange_url = add_query_arg('form-type', FR::MELANGE_TYPE, PPRESS_FORMS_SETTINGS_PAGE);
101 $user_profile_url = add_query_arg('form-type', FR::USER_PROFILE_TYPE, PPRESS_FORMS_SETTINGS_PAGE);
102
103 $login_menu_active = (isset($_GET['page']) && ! isset($_GET['form-type'])) || isset($_GET['form-type']) && $_GET['page'] == PPRESS_FORMS_SETTINGS_SLUG && $_GET['form-type'] == FR::LOGIN_TYPE ? 'pp-type-active' : null;
104 $registration_menu_active = isset($_GET['form-type']) && $_GET['page'] == PPRESS_FORMS_SETTINGS_SLUG && $_GET['form-type'] == FR::REGISTRATION_TYPE ? 'pp-type-active' : null;
105 $password_reset_menu_active = isset($_GET['form-type']) && $_GET['page'] == PPRESS_FORMS_SETTINGS_SLUG && $_GET['form-type'] == FR::PASSWORD_RESET_TYPE ? 'pp-type-active' : null;
106 $edit_profile_menu_active = isset($_GET['form-type']) && $_GET['page'] == PPRESS_FORMS_SETTINGS_SLUG && $_GET['form-type'] == FR::EDIT_PROFILE_TYPE ? 'pp-type-active' : null;
107 $melange_menu_active = isset($_GET['form-type']) && $_GET['page'] == PPRESS_FORMS_SETTINGS_SLUG && $_GET['form-type'] == FR::MELANGE_TYPE ? 'pp-type-active' : null;
108 $user_profile_menu_active = isset($_GET['form-type']) && $_GET['page'] == PPRESS_FORMS_SETTINGS_SLUG && $_GET['form-type'] == FR::USER_PROFILE_TYPE ? 'pp-type-active' : null;
109 ?>
110 <div id="pp-sub-bar">
111 <div class="pp-new-toolbar pp-clear">
112 <h4><?php _e('Filter by Type', 'wp-user-avatar'); ?></h4>
113 <ul class="pp-design-options">
114 <li>
115 <a href="<?php echo $login_url; ?>" class="<?php echo $login_menu_active; ?>">
116 <?php _e('Login', 'wp-user-avatar'); ?>
117 </a>
118 </li>
119 <li>
120 <a href="<?php echo $registration_url; ?>" class="<?php echo $registration_menu_active; ?>">
121 <?php _e('Registration', 'wp-user-avatar'); ?>
122 </a>
123 </li>
124 <li>
125 <li>
126 <a href="<?php echo $password_reset_url; ?>" class="<?php echo $password_reset_menu_active; ?>">
127 <?php _e('Password Reset', 'wp-user-avatar'); ?>
128 </a>
129 </li>
130 <li>
131 <a href="<?php echo $edit_profile_url; ?>" class="<?php echo $edit_profile_menu_active; ?>">
132 <?php _e('Edit Profile', 'wp-user-avatar'); ?>
133 </a>
134 </li>
135 <li>
136 <a href="<?php echo $melange_url; ?>" class="<?php echo $melange_menu_active; ?>">
137 <?php _e('Melange', 'wp-user-avatar'); ?>
138 </a>
139 <span class="pp-melange-jbox dashicons dashicons-editor-help" title="<?php echo $melange_jbox; ?>"></span>
140 </li>
141 <li>
142 <a href="<?php echo $user_profile_url; ?>" class="<?php echo $user_profile_menu_active; ?>">
143 <?php _e('User Profile', 'wp-user-avatar'); ?>
144 </a>
145 </li>
146 </ul>
147 </div>
148 </div>
149 <?php }
150 }
151
152
153 /**
154 * Save screen option.
155 *
156 * @param string $status
157 * @param string $option
158 * @param string $value
159 *
160 * @return mixed
161 */
162 public function set_screen($status, $option, $value)
163 {
164 return $value;
165 }
166
167 /**
168 * Screen options
169 */
170 public function screen_option()
171 {
172 if (isset($_GET['page'], $_GET['view']) && strpos($_GET['view'], 'edit-shortcode') !== false) return;
173
174 $args = [
175 'label' => esc_html__('Forms', 'wp-user-avatar'),
176 'default' => 10,
177 'option' => 'forms_per_page',
178 ];
179
180 add_screen_option('per_page', $args);
181
182 $this->forms_instance = FormList::get_instance();
183 }
184
185 public function live_form_preview_btn($echo = true)
186 {
187 if ( ! isset($_GET['view'])) return;
188
189 $form_type = isset($_GET['form-type']) ? sanitize_text_field($_GET['form-type']) : '';
190
191 switch ($_GET['view']) {
192 case 'edit-shortcode-login':
193 $form_type = FR::LOGIN_TYPE;
194 break;
195 case 'edit-shortcode-registration':
196 $form_type = FR::REGISTRATION_TYPE;
197 break;
198 case 'edit-shortcode-password-reset':
199 $form_type = FR::PASSWORD_RESET_TYPE;
200 break;
201 case 'edit-shortcode-melange':
202 $form_type = FR::MELANGE_TYPE;
203 break;
204 case 'edit-shortcode-edit-profile':
205 $form_type = FR::EDIT_PROFILE_TYPE;
206 break;
207 case 'edit-shortcode-user-profile':
208 $form_type = FR::USER_PROFILE_TYPE;
209 break;
210 }
211
212 $preview_url = add_query_arg(
213 ['pp_preview_form' => absint($_GET['id']), 'type' => $form_type],
214 home_url()
215 );
216
217 $html = "<a target='_blank' class=\"add-new-h2\" href=\"$preview_url\">" . esc_html__('Live Preview', 'wp-user-avatar') . '</a>';
218
219 if ($echo === false) {
220 return $html;
221 }
222
223 echo $html;
224 }
225
226 public function no_form_exist_redirect($form_id, $form_type)
227 {
228 if ( ! FR::form_id_exist($form_id, $form_type)) {
229 wp_safe_redirect(add_query_arg('form-type', $form_type, PPRESS_FORMS_SETTINGS_PAGE));
230 exit;
231 }
232 }
233
234 /**
235 * Build the settings page structure. I.e tab, sidebar.
236 *
237 * @return mixed|void
238 */
239 public function settings_admin_page_callback()
240 {
241 remove_all_actions('media_buttons');
242 remove_all_filters('media_buttons_context');
243 remove_all_filters('mce_buttons', 10);
244 remove_all_filters('mce_external_plugins', 10);
245
246 add_action('media_buttons', 'media_buttons');
247
248 if ( ! empty($_GET['view']) && $_GET['view'] == 'add-new-form') {
249 return AddNewForm::get_instance()->settings_admin_page();
250 }
251
252 if ( ! empty($_GET['view'])) {
253
254 $form_id = absint($_GET['id']);
255
256 $page_header = $this->admin_page_title();
257
258 $shortcode_builder_page_header = sprintf(
259 '<div class="wrap ppSCB"><h2>%s %s</h2><form method="post">%s',
260 $page_header,
261 $this->live_form_preview_btn(false),
262 ppress_nonce_field()
263 );
264
265 if ($_GET['view'] == 'edit-shortcode-login') {
266 $this->no_form_exist_redirect($form_id, FR::LOGIN_TYPE);
267 echo $shortcode_builder_page_header;
268 $this->EditShortcodeLoginInstance->edit_screen();
269 echo '</form></div>';
270
271 return;
272 }
273
274 if ($_GET['view'] == 'edit-shortcode-registration') {
275 $this->no_form_exist_redirect($form_id, FR::REGISTRATION_TYPE);
276 echo $shortcode_builder_page_header;
277 $this->EditShortcodeRegistrationInstance->edit_screen();
278 echo '</form></div>';
279
280 return;
281 }
282
283 if ($_GET['view'] == 'edit-shortcode-password-reset') {
284 $this->no_form_exist_redirect($form_id, FR::PASSWORD_RESET_TYPE);
285 echo $shortcode_builder_page_header;
286 $this->EditShortcodePasswordResetInstance->edit_screen();
287 echo '</form></div>';
288
289 return;
290 }
291
292 if ($_GET['view'] == 'edit-shortcode-melange') {
293 $this->no_form_exist_redirect($form_id, FR::MELANGE_TYPE);
294 echo $shortcode_builder_page_header;
295 $this->EditShortcodeMelangeInstance->edit_screen();
296 echo '</form></div>';
297
298 return;
299 }
300
301 if ($_GET['view'] == 'edit-shortcode-edit-profile') {
302 $this->no_form_exist_redirect($form_id, FR::EDIT_PROFILE_TYPE);
303 echo $shortcode_builder_page_header;
304 $this->EditShortcodeEditProfileInstance->edit_screen();
305 echo '</form></div>';
306
307 return;
308 }
309
310 if ($_GET['view'] == 'edit-shortcode-user-profile') {
311 Forms::get_instance()->no_form_exist_redirect($form_id, FR::USER_PROFILE_TYPE);
312 echo $shortcode_builder_page_header;
313 $this->EditShortcodeUserProfileInstance->edit_screen();
314 echo '</form></div>';
315
316 return;
317 }
318
319 add_filter('wp_cspa_settings_page_sidebar', [$this->DragDropClassInstance, 'sidebar_section']);
320 add_action('wp_cspa_before_closing_header', [$this, 'live_form_preview_btn']);
321
322 add_action('wp_cspa_main_content_area', function ($content, $option_name) {
323 if ($option_name != 'pp_edit_form') return $content;
324
325 if ($_GET['view'] == 'drag-drop-builder') {
326 ob_start();
327 $this->DragDropClassInstance->admin_page();
328
329 return ob_get_clean();
330 }
331 }, 10, 2);
332
333 $instance = Custom_Settings_Page_Api::instance();
334 $instance->option_name('pp_edit_form');
335 $instance->add_wrap_classes('pp-dnd-form-builder-wrap');
336 $instance->page_header($this->admin_page_title());
337 $this->register_core_settings($instance);
338
339 return $instance->build();
340 }
341
342 add_action('wp_cspa_main_content_area', array($this, 'wp_list_table'), 10, 2);
343 add_action('wp_cspa_before_post_body_content', array($this, 'form_sub_header'), 10, 2);
344 add_action('wp_cspa_before_closing_header', [$this, 'add_new_form_button']);
345
346 $instance = Custom_Settings_Page_Api::instance();
347 $instance->option_name(PPRESS_FORMS_DB_OPTION_NAME);
348 $instance->page_header($this->admin_page_title());
349 $this->register_core_settings($instance, true);
350 echo '<div class="pp-form-listing pp-forms">';
351 $instance->build(true);
352 echo '</div>';
353 }
354
355 public function add_new_form_button()
356 {
357 $url = add_query_arg('view', 'add-new-form', PPRESS_FORMS_SETTINGS_PAGE);
358 echo "<a class=\"add-new-h2\" href=\"$url\">" . esc_html__('Add New', 'wp-user-avatar') . '</a>';
359 }
360
361 /**
362 * @param string $content
363 * @param string $option_name settings Custom_Settings_Page_Api option name.
364 *
365 * @return string
366 */
367 public function wp_list_table($content, $option_name)
368 {
369 if ($option_name != PPRESS_FORMS_DB_OPTION_NAME) return $content;
370
371 $this->forms_instance->prepare_items();
372
373 ob_start();
374
375 $this->forms_instance->display();
376
377 return ob_get_clean();
378 }
379
380 /**
381 * @return Forms
382 */
383 public static function get_instance()
384 {
385 static $instance = null;
386
387 if (is_null($instance)) {
388 $instance = new self();
389 }
390
391 return $instance;
392 }
393 }