class-evf-setting-utilities.php
3 months ago
class-evf-settings-advanced.php
4 weeks ago
class-evf-settings-email.php
4 weeks ago
class-evf-settings-general.php
3 months ago
class-evf-settings-integrations.php
3 months ago
class-evf-settings-page.php
3 months ago
class-evf-settings-payments.php
4 weeks ago
class-evf-settings-reporting.php
2 years ago
class-evf-settings-security.php
3 months ago
class-evf-settings-validation.php
11 months ago
class-evf-settings-advanced.php
383 lines
| 1 | <?php |
| 2 | /** |
| 3 | * EverestForms Misc Settings |
| 4 | * |
| 5 | * @package EverestForms\Admin |
| 6 | * @version 1.9.8 |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | if ( class_exists( 'EVF_Settings_Advanced', false ) ) { |
| 12 | return new EVF_Settings_Advanced(); |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * EVF_Settings_Advanced. |
| 17 | */ |
| 18 | class EVF_Settings_Advanced extends EVF_Settings_Page { |
| 19 | |
| 20 | /** |
| 21 | * Constructor. |
| 22 | */ |
| 23 | public function __construct() { |
| 24 | $this->id = 'advanced'; |
| 25 | $this->label = esc_html__( 'Advanced', 'everest-forms' ); |
| 26 | |
| 27 | parent::__construct(); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Get sections. |
| 32 | * |
| 33 | * @return array |
| 34 | */ |
| 35 | public function get_sections() { |
| 36 | $sections = array( |
| 37 | 'general' => esc_html__( 'General', 'everest-forms' ), |
| 38 | 'entry_reports' => esc_html__( 'Entry Reports & Summaries', 'everest-forms' ), |
| 39 | 'plugin_management' => esc_html__( 'Plugin Management', 'everest-forms' ), |
| 40 | ); |
| 41 | |
| 42 | $entries_settings = apply_filters( 'everest_forms_entries_management_settings', array() ); |
| 43 | if ( ! empty( $entries_settings ) ) { |
| 44 | $sections = array( |
| 45 | 'general' => esc_html__( 'General', 'everest-forms' ), |
| 46 | 'entries_management' => esc_html__( 'Entries Management', 'everest-forms' ), |
| 47 | 'entry_reports' => esc_html__( 'Entry Reports & Summaries', 'everest-forms' ), |
| 48 | 'plugin_management' => esc_html__( 'Plugin Management', 'everest-forms' ), |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | return apply_filters( 'everest_forms_get_sections_' . $this->id, $sections ); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Output sections. |
| 57 | */ |
| 58 | public function output_sections() { |
| 59 | global $current_section; |
| 60 | |
| 61 | $sections = $this->get_sections(); |
| 62 | |
| 63 | if ( empty( $sections ) || 1 === count( $sections ) ) { |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | $current_section = isset( $_GET['section'] ) ? sanitize_text_field( wp_unslash( $_GET['section'] ) ) : 'general'; |
| 68 | |
| 69 | echo '<ul class="evf-subsections">'; |
| 70 | |
| 71 | foreach ( $sections as $id => $label ) { |
| 72 | $url = add_query_arg( |
| 73 | array( |
| 74 | 'page' => 'evf-settings', |
| 75 | 'tab' => $this->id, |
| 76 | 'section' => sanitize_title( $id ), |
| 77 | ), |
| 78 | admin_url( 'admin.php' ) |
| 79 | ); |
| 80 | |
| 81 | echo '<li><a href="' . esc_url( $url ) . '" class="' . ( $current_section === $id ? 'current' : '' ) . '">' . esc_html( $label ) . '</a></li>'; |
| 82 | } |
| 83 | |
| 84 | echo '</ul>'; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Get settings array based on current section. |
| 89 | * |
| 90 | * @return array |
| 91 | */ |
| 92 | public function get_settings() { |
| 93 | global $current_section; |
| 94 | |
| 95 | $current_section = isset( $_GET['section'] ) ? sanitize_text_field( wp_unslash( $_GET['section'] ) ) : 'general'; |
| 96 | |
| 97 | switch ( $current_section ) { |
| 98 | case 'entries_management': |
| 99 | $settings = $this->get_entries_management_settings(); |
| 100 | break; |
| 101 | case 'entry_reports': |
| 102 | $settings = $this->get_entry_reports_settings(); |
| 103 | break; |
| 104 | case 'plugin_management': |
| 105 | $settings = $this->get_plugin_management_settings(); |
| 106 | break; |
| 107 | default: |
| 108 | $settings = $this->get_advanced_default_settings(); |
| 109 | break; |
| 110 | } |
| 111 | |
| 112 | return apply_filters( 'everest_forms_get_settings_' . $this->id, $settings, $current_section ); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Get entries management settings. |
| 117 | * |
| 118 | * @return array |
| 119 | */ |
| 120 | public function get_entries_management_settings() { |
| 121 | $base_settings = array( |
| 122 | array( |
| 123 | 'title' => esc_html__( 'Advanced Options', 'everest-forms' ), |
| 124 | 'type' => 'title', |
| 125 | 'desc' => '', |
| 126 | 'id' => 'misc_options', |
| 127 | ), |
| 128 | array( |
| 129 | 'type' => 'sectionend', |
| 130 | 'id' => 'misc_options', |
| 131 | ), |
| 132 | ); |
| 133 | |
| 134 | $settings = apply_filters( 'everest_forms_entries_management_settings', $base_settings ); |
| 135 | |
| 136 | return apply_filters( 'everest_forms_get_settings_' . $this->id, $settings ); |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Get advanced default settings. |
| 141 | * |
| 142 | * @return array |
| 143 | */ |
| 144 | public function get_advanced_default_settings() { |
| 145 | $allow_usage_notice_msg = wp_kses( |
| 146 | __( 'Help us improve the plugin\'s features by sharing <a href="https://docs.everestforms.net/docs/misc-settings-4/#2-toc-title" target="_blank">non-sensitive plugin data</a> with us.', 'everest-forms' ), |
| 147 | array( |
| 148 | 'a' => array( |
| 149 | 'href' => array(), |
| 150 | 'target' => array(), |
| 151 | ), |
| 152 | ) |
| 153 | ); |
| 154 | |
| 155 | return array( |
| 156 | array( |
| 157 | 'title' => esc_html__( 'Advanced Options', 'everest-forms' ), |
| 158 | 'type' => 'title', |
| 159 | 'desc' => '', |
| 160 | 'id' => 'misc_options', |
| 161 | ), |
| 162 | array( |
| 163 | 'title' => esc_html__( 'Enable Log', 'everest-forms' ), |
| 164 | 'desc' => esc_html__( 'store form activity and submission logs for monitoring and troubleshooting.', 'everest-forms' ), |
| 165 | 'id' => 'everest_forms_enable_log', |
| 166 | 'default' => 'no', |
| 167 | 'type' => 'toggle', |
| 168 | 'desc_tip' => true, |
| 169 | ), |
| 170 | array( |
| 171 | 'title' => esc_html__( 'Enable RestApi', 'everest-forms' ), |
| 172 | 'desc' => __( 'Allow form data to be accessed and managed through REST API endpoints.', 'everest-forms' ), |
| 173 | 'id' => 'everest_forms_enable_restapi', |
| 174 | 'type' => 'toggle', |
| 175 | 'default' => 'no', |
| 176 | 'desc_tip' => true, |
| 177 | ), |
| 178 | array( |
| 179 | 'title' => esc_html__( 'RestApi Key', 'everest-forms' ), |
| 180 | 'desc' => __( 'List of api key.These are used to authenticate the request.', 'everest-forms' ), |
| 181 | 'id' => 'everest_forms_restapi_keys', |
| 182 | 'type' => 'restapi_key', |
| 183 | 'default' => '', |
| 184 | 'desc_tip' => true, |
| 185 | 'css' => 'width=500px !important;', |
| 186 | 'class' => 'evf-restapi-key', |
| 187 | ), |
| 188 | array( |
| 189 | 'type' => 'sectionend', |
| 190 | 'id' => 'misc_options', |
| 191 | ), |
| 192 | ); |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Get entry reports settings. |
| 197 | * |
| 198 | * @return array |
| 199 | */ |
| 200 | public function get_entry_reports_settings() { |
| 201 | $evf_form_lists = evf_get_all_forms(); |
| 202 | $evf_test_email = get_option( 'everest_forms_routine_report_send_email_test_to', '' ); |
| 203 | |
| 204 | $schedule_status = ''; |
| 205 | if ( class_exists( 'EVF_Report_Cron' ) ) { |
| 206 | $cron = new EVF_Report_Cron(); |
| 207 | $schedule_status = $cron->get_schedule_status(); |
| 208 | } |
| 209 | |
| 210 | return array( |
| 211 | array( |
| 212 | 'title' => esc_html__( 'Forms Entries Statistics Reporting', 'everest-forms' ), |
| 213 | 'type' => 'title', |
| 214 | 'desc' => ! empty( $schedule_status['message'] ) ? esc_html( $schedule_status['message'] ) : '', |
| 215 | 'id' => 'reporting_options', |
| 216 | ), |
| 217 | array( |
| 218 | 'title' => esc_html__( 'Enable Entries Statistics Reporting', 'everest-forms' ), |
| 219 | 'desc' => esc_html__( 'Enable to send the entries statistics reporting email on routine basis.', 'everest-forms' ), |
| 220 | 'id' => 'everest_forms_enable_entries_reporting', |
| 221 | 'default' => 'no', |
| 222 | 'type' => 'toggle', |
| 223 | 'desc_tip' => true, |
| 224 | ), |
| 225 | array( |
| 226 | 'title' => esc_html__( 'Report Frequency', 'everest-forms' ), |
| 227 | 'type' => 'select', |
| 228 | 'options' => array( |
| 229 | 'Daily' => esc_html__( 'Daily', 'everest-forms' ), |
| 230 | 'Weekly' => esc_html__( 'Weekly', 'everest-forms' ), |
| 231 | 'Monthly' => esc_html__( 'Monthly', 'everest-forms' ), |
| 232 | ), |
| 233 | 'id' => 'everest_forms_entries_reporting_frequency', |
| 234 | 'default' => 'Weekly', |
| 235 | 'desc' => esc_html__( 'How often should the report be emailed?', 'everest-forms' ), |
| 236 | 'desc_tip' => true, |
| 237 | ), |
| 238 | array( |
| 239 | 'title' => esc_html__( 'Day To Send', 'everest-forms' ), |
| 240 | 'type' => 'select', |
| 241 | 'options' => array( |
| 242 | 'sunday' => esc_html__( 'Sunday', 'everest-forms' ), |
| 243 | 'monday' => esc_html__( 'Monday', 'everest-forms' ), |
| 244 | 'tuesday' => esc_html__( 'Tuesday', 'everest-forms' ), |
| 245 | 'wednesday' => esc_html__( 'Wednesday', 'everest-forms' ), |
| 246 | 'thursday' => esc_html__( 'Thursday', 'everest-forms' ), |
| 247 | 'friday' => esc_html__( 'Friday', 'everest-forms' ), |
| 248 | 'saturday' => esc_html__( 'Saturday', 'everest-forms' ), |
| 249 | ), |
| 250 | 'id' => 'everest_forms_entries_reporting_day', |
| 251 | 'default' => 'monday', |
| 252 | 'desc' => esc_html__( 'What day of the week should the weekly report be sent?', 'everest-forms' ), |
| 253 | 'desc_tip' => true, |
| 254 | ), |
| 255 | array( |
| 256 | 'title' => esc_html__( 'Email To', 'everest-forms' ), |
| 257 | 'desc_tip' => esc_html__( 'Email address to send the routine report. Use {admin_email} for the site admin address.', 'everest-forms' ), |
| 258 | 'id' => 'everest_forms_entries_reporting_email', |
| 259 | 'default' => '{admin_email}', |
| 260 | 'type' => 'text', |
| 261 | ), |
| 262 | array( |
| 263 | 'title' => esc_html__( 'Email Subject', 'everest-forms' ), |
| 264 | 'desc_tip' => esc_html__( 'Email subject while sending the routine report.', 'everest-forms' ), |
| 265 | 'id' => 'everest_forms_entries_reporting_subject', |
| 266 | 'default' => esc_html__( 'Everest Forms - Entries summary statistics', 'everest-forms' ), |
| 267 | 'type' => 'text', |
| 268 | ), |
| 269 | array( |
| 270 | 'title' => esc_html__( 'Send Test Report', 'everest-forms' ), |
| 271 | 'desc' => esc_html__( 'Enter the email address to receive the test email for the routine summary report.', 'everest-forms' ), |
| 272 | 'input_id' => 'everest_forms_routine_report_send_email_test_to', |
| 273 | 'input_type' => 'email', |
| 274 | 'input_css' => 'margin-right:0.5rem', |
| 275 | 'placeholder' => 'eg. testemail@gmail.com', |
| 276 | 'value' => ! empty( $evf_test_email ) ? esc_attr( $evf_test_email ) : esc_attr( get_bloginfo( 'admin_email' ) ), |
| 277 | 'button_id' => 'everest_forms_send_routine_report_test_email', |
| 278 | 'type' => 'input_test_button', |
| 279 | 'buttons' => array( |
| 280 | array( |
| 281 | 'title' => __( 'Send Test Email', 'everest-forms' ), |
| 282 | 'href' => 'javascript:;', |
| 283 | 'class' => 'everest_forms_send_routine_report_test_email', |
| 284 | ), |
| 285 | ), |
| 286 | 'desc_tip' => true, |
| 287 | ), |
| 288 | array( |
| 289 | 'title' => esc_html__( 'Report Form Lists', 'everest-forms' ), |
| 290 | 'id' => 'everest_forms_reporting_form_lists', |
| 291 | 'default' => array(), |
| 292 | 'desc' => esc_html__( 'Select specific forms to include in the report. Leave empty to include all published forms.', 'everest-forms' ), |
| 293 | 'desc_tip' => true, |
| 294 | 'type' => 'multiselect', |
| 295 | 'options' => ! empty( $evf_form_lists ) ? $evf_form_lists : array(), |
| 296 | 'class' => 'evf-enhanced-select', |
| 297 | ), |
| 298 | array( |
| 299 | 'type' => 'sectionend', |
| 300 | 'id' => 'reporting_options', |
| 301 | ), |
| 302 | ); |
| 303 | } |
| 304 | |
| 305 | /** |
| 306 | * Get plugin management settings. |
| 307 | * |
| 308 | * @return array |
| 309 | */ |
| 310 | public function get_plugin_management_settings() { |
| 311 | $allow_usage_notice_msg = wp_kses( |
| 312 | __( 'Help us improve the plugin\'s features by sharing <a href="https://docs.everestforms.net/docs/misc-settings-4/#2-toc-title" target="_blank">non-sensitive plugin data</a> with us.', 'everest-forms' ), |
| 313 | array( |
| 314 | 'a' => array( |
| 315 | 'href' => array(), |
| 316 | 'target' => array(), |
| 317 | ), |
| 318 | ) |
| 319 | ); |
| 320 | |
| 321 | $settings = apply_filters( |
| 322 | 'everest_forms_plugin_management_settings', |
| 323 | array( |
| 324 | array( |
| 325 | 'title' => esc_html__( 'Advanced Options', 'everest-forms' ), |
| 326 | 'type' => 'title', |
| 327 | 'desc' => '', |
| 328 | 'id' => 'misc_options', |
| 329 | ), |
| 330 | array( |
| 331 | 'title' => esc_html__( 'Uninstall Everest Forms', 'everest-forms' ), |
| 332 | 'desc' => __( '<strong>Heads Up!</strong> Check this if you would like to remove ALL Everest Forms data upon plugin deletion.', 'everest-forms' ), |
| 333 | 'id' => 'everest_forms_uninstall_option', |
| 334 | 'default' => 'no', |
| 335 | 'type' => 'toggle', |
| 336 | 'desc_tip' => true, |
| 337 | ), |
| 338 | array( |
| 339 | 'title' => esc_html__( 'Allow Usage Tracking', 'everest-forms' ), |
| 340 | 'desc' => $allow_usage_notice_msg, |
| 341 | 'id' => 'everest_forms_allow_usage_tracking', |
| 342 | 'type' => 'toggle', |
| 343 | 'default' => 'no', |
| 344 | 'desc_tip' => true, |
| 345 | ), |
| 346 | array( |
| 347 | 'type' => 'sectionend', |
| 348 | 'id' => 'misc_options', |
| 349 | ), |
| 350 | ) |
| 351 | ); |
| 352 | |
| 353 | return apply_filters( 'everest_forms_get_settings_' . $this->id, $settings ); |
| 354 | } |
| 355 | |
| 356 | /** |
| 357 | * Save settings. |
| 358 | */ |
| 359 | public function save() { |
| 360 | global $current_section; |
| 361 | |
| 362 | $current_section = isset( $_GET['section'] ) ? sanitize_text_field( wp_unslash( $_GET['section'] ) ) : 'general'; |
| 363 | |
| 364 | if ( 'entry_reports' === $current_section && empty( $_POST['everest_forms_reporting_form_lists'] ) ) { |
| 365 | update_option( 'everest_forms_reporting_form_lists', array() ); |
| 366 | } |
| 367 | |
| 368 | if ( 'entry_reports' === $current_section && isset( $_POST['everest_forms_routine_report_send_email_test_to'] ) ) { |
| 369 | $test_email = sanitize_email( wp_unslash( $_POST['everest_forms_routine_report_send_email_test_to'] ) ); |
| 370 | if ( '' === $test_email || is_email( $test_email ) ) { |
| 371 | update_option( 'everest_forms_routine_report_send_email_test_to', $test_email ); |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | EVF_Admin_Settings::save_fields( $this->get_settings() ); |
| 376 | |
| 377 | if ( 'entry_reports' === $current_section && class_exists( 'EVF_Report_Cron' ) ) { |
| 378 | ( new EVF_Report_Cron() )->evf_reschedule(); |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | return new EVF_Settings_Advanced(); |