PluginProbe ʕ •ᴥ•ʔ
Strong Testimonials / 3.3.2
Strong Testimonials v3.3.2
3.3.2 3.3.1 trunk 1.0.1 2.30.9 2.31.10 2.32 2.32.1 2.32.2 2.32.3 2.32.4 2.33 2.34 2.35 2.36 2.37 2.38 2.38.1 2.39 2.39.1 2.39.2 2.39.3 2.40.0 2.40.1 2.40.2 2.40.3 2.40.4 2.40.5 2.40.6 2.40.7 2.41.0 2.41.1 2.50.0 2.50.1 2.50.2 2.50.3 2.50.4 2.51.0 2.51.1 2.51.2 2.51.3 2.51.4 2.51.5 2.51.6 2.51.7 2.51.8 2.51.9 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 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.20 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.17 3.2.18 3.2.19 3.2.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0
strong-testimonials / admin / settings / class-strong-testimonials-settings-form.php
strong-testimonials / admin / settings Last commit date
partials 1 month ago class-strong-testimonials-forms.php 1 month ago class-strong-testimonials-general-settings-react.php 1 week ago class-strong-testimonials-settings-form.php 1 month ago
class-strong-testimonials-settings-form.php
259 lines
1 <?php
2 /**
3 * Class Strong_Testimonials_Settings_Form
4 */
5 class Strong_Testimonials_Settings_Form {
6
7 const TAB_NAME = 'form';
8
9 const OPTION_NAME = 'wpmtst_form_options';
10
11 const GROUP_NAME = 'wpmtst-form-group';
12
13 /**
14 * Strong_Testimonials_Settings_Form constructor.
15 */
16 public function __construct() {}
17
18 /**
19 * Initialize.
20 */
21 public static function init() {
22 self::add_actions();
23 }
24
25 /**
26 * Add actions and filters.
27 */
28 public static function add_actions() {
29 add_action( 'admin_init', array( __CLASS__, 'register_settings' ) );
30 add_action( 'wpmtst_form_tabs', array( __CLASS__, 'register_tab' ), 2, 2 );
31 add_filter( 'wpmtst_form_callbacks', array( __CLASS__, 'register_settings_page' ) );
32
33 add_action( 'wp_ajax_wpmtst_restore_default_messages', array( __CLASS__, 'restore_default_messages_function' ) );
34 add_action( 'wp_ajax_wpmtst_restore_default_message', array( __CLASS__, 'restore_default_message_function' ) );
35
36 add_action( 'wp_ajax_wpmtst_add_recipient', array( __CLASS__, 'add_recipient' ) );
37 }
38
39 /**
40 * Register settings tab.
41 *
42 * @param $active_tab
43 * @param $url
44 */
45 public static function register_tab( $active_tab, $url ) {
46 printf(
47 '<a href="%s" class="nav-tab %s">%s</a>',
48 esc_url( add_query_arg( 'tab', self::TAB_NAME, $url ) ),
49 esc_attr( self::TAB_NAME === $active_tab ? 'nav-tab-active' : '' ),
50 esc_html__( 'Settings', 'strong-testimonials' )
51 );
52 }
53
54 /**
55 * Register settings.
56 */
57 public static function register_settings() {
58 register_setting( self::GROUP_NAME, self::OPTION_NAME, array( __CLASS__, 'sanitize_options' ) );
59 }
60
61 /**
62 * Register settings page.
63 *
64 * @param $pages
65 *
66 * @return mixed
67 */
68 public static function register_settings_page( $pages ) {
69 $pages[ self::TAB_NAME ] = array( __CLASS__, 'settings_page' );
70 return $pages;
71 }
72
73 /**
74 * Print settings page.
75 */
76 public static function settings_page() {
77 settings_fields( self::GROUP_NAME );
78 include WPMTST_ADMIN . 'settings/partials/form.php';
79 }
80
81 /**
82 * Sanitize settings.
83 *
84 * @param $input
85 *
86 * @return array
87 */
88 public static function sanitize_options( $input ) {
89 $input['post_status'] = sanitize_text_field( $input['post_status'] );
90 $input['admin_notify'] = wpmtst_sanitize_checkbox( $input, 'admin_notify' );
91 $input['mail_queue'] = wpmtst_sanitize_checkbox( $input, 'mail_queue' );
92 $input['sender_name'] = sanitize_text_field( $input['sender_name'] );
93 $input['sender_site_email'] = intval( $input['sender_site_email'] );
94 $input['sender_email'] = sanitize_email( $input['sender_email'] );
95 if ( ! $input['sender_email'] && ! $input['sender_site_email'] ) {
96 $input['sender_site_email'] = true;
97 }
98
99 /**
100 * Multiple recipients.
101 *
102 * @since 1.18
103 */
104 $new_recipients = array();
105 foreach ( $input['recipients'] as $recipient ) {
106
107 if ( isset( $recipient['primary'] ) ) {
108 $recipient['primary'] = true;
109 if ( isset( $recipient['admin_site_email'] ) && ! $recipient['admin_site_email'] ) {
110 if ( ! $recipient['admin_email'] ) {
111 $recipient['admin_site_email'] = true;
112 }
113 }
114 } else {
115 // Don't save if both fields are empty.
116 if ( ! isset( $recipient['admin_name'] ) && ! isset( $recipient['admin_email'] ) ) {
117 continue;
118 }
119 if ( ! $recipient['admin_name'] && ! $recipient['admin_email'] ) {
120 continue;
121 }
122 }
123
124 if ( isset( $recipient['admin_name'] ) ) {
125 $recipient['admin_name'] = sanitize_text_field( $recipient['admin_name'] );
126 }
127
128 if ( isset( $recipient['admin_email'] ) ) {
129 $recipient['admin_email'] = sanitize_email( $recipient['admin_email'] );
130 }
131
132 $new_recipients[] = $recipient;
133
134 }
135 $input['recipients'] = $new_recipients;
136
137 $input['default_recipient'] = maybe_unserialize( $input['default_recipient'] );
138 $input['email_subject'] = isset( $input['email_subject'] ) ? wp_kses_post( trim( $input['email_subject'] ) ) : '';
139 $input['email_message'] = isset( $input['email_message'] ) ? wp_kses_post( rtrim( $input['email_message'] ) ) : '';
140
141 foreach ( $input['messages'] as $key => $message ) {
142 if ( 'submission-success' === $key ) {
143 $input['messages'][ $key ]['text'] = $message['text'];
144 } else {
145 if ( 'required-field' === $key ) {
146 $input['messages'][ $key ]['enabled'] = wpmtst_sanitize_checkbox( $input['messages'][ $key ], 'enabled' );
147 }
148 $input['messages'][ $key ]['text'] = wp_kses_data( $message['text'] );
149 }
150 }
151 $input['scrolltop_error'] = wpmtst_sanitize_checkbox( $input, 'scrolltop_error' );
152 $input['scrolltop_error_offset'] = intval( sanitize_text_field( $input['scrolltop_error_offset'] ) );
153 $input['scrolltop_success'] = wpmtst_sanitize_checkbox( $input, 'scrolltop_success' );
154 $input['scrolltop_success_offset'] = intval( sanitize_text_field( $input['scrolltop_success_offset'] ) );
155
156 /**
157 * Success redirect
158 * @since 2.18.0
159 */
160
161 $input['success_action'] = sanitize_text_field( $input['success_action'] );
162
163 $input['success_redirect_url'] = esc_url_raw( $input['success_redirect_url'] );
164
165 // Check the "ID or slug" field next
166 if ( isset( $input['success_redirect_2'] ) && $input['success_redirect_2'] ) {
167
168 // is post ID?
169 $id = sanitize_text_field( $input['success_redirect_2'] );
170 if ( is_numeric( $id ) ) {
171 if ( ! get_posts(
172 array(
173 'p' => $id,
174 'post_type' => array( 'page' ),
175 'post_status' => 'publish',
176 )
177 ) ) {
178 $id = null;
179 }
180 } else {
181 // is post slug?
182 $target = get_posts(
183 array(
184 'name' => $id,
185 'post_type' => array( 'page' ),
186 'post_status' => 'publish',
187 )
188 );
189 if ( $target ) {
190 $id = $target[0]->ID;
191 }
192 }
193
194 if ( $id ) {
195 $input['success_redirect_id'] = $id;
196 }
197 } else {
198
199 if ( isset( $input['success_redirect_id'] ) ) {
200 $input['success_redirect_id'] = (int) sanitize_text_field( $input['success_redirect_id'] );
201 }
202 }
203
204 unset( $input['success_redirect_2'] );
205 //ksort( $input );
206
207 return apply_filters( 'wpmtst_sanitize_form_options', $input );
208 }
209
210 /**
211 * [Restore Default Messages] Ajax receiver.
212 *
213 * @since 1.13
214 */
215 public static function restore_default_messages_function() {
216 $default_form_options = Strong_Testimonials_Defaults::get_form_options();
217 $messages = $default_form_options['messages'];
218 echo json_encode( $messages );
219 wp_die();
220 }
221
222 /**
223 * [Restore Default] for single message Ajax receiver.
224 *
225 * @since 1.13
226 */
227 public static function restore_default_message_function() {
228 $input = isset( $_REQUEST['field'] ) ? str_replace( '_', '-', sanitize_text_field( wp_unslash( $_REQUEST['field'] ) ) ) : '';
229 $default_form_options = Strong_Testimonials_Defaults::get_form_options();
230 $message = $default_form_options['messages'][ $input ];
231 echo json_encode( $message );
232 wp_die();
233 }
234
235 /**
236 * [Add Recipient] Ajax receiver
237 */
238 public static function add_recipient() {
239
240 if ( ! wp_verify_nonce( $_POST['nonce'], 'wpmtst-admin-form-script-nonce' ) ) { //phpcs:ignore
241 wp_send_json_error( array( 'message' => __( 'Nonce does not exist.', 'strong-testimonials' ) ) );
242 die();
243 }
244
245 if ( ! current_user_can( 'manage_options' ) ) {
246 wp_send_json_error( array( 'message' => __( 'Insufficient capabilities.', 'strong-testimonials' ) ) );
247 die();
248 }
249
250 $key = isset( $_POST['key'] ) ? sanitize_text_field( wp_unslash( $_POST['key'] ) ) : '';
251 $form_options = get_option( 'wpmtst_form_options' );
252 $recipient = $form_options['default_recipient'];
253 include WPMTST_ADMIN . 'settings/partials/recipient.php';
254 wp_die();
255 }
256 }
257
258 Strong_Testimonials_Settings_Form::init();
259