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