Nessuna descrizione

class-settings.php 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. <?php
  2. /**
  3. * Settings class.
  4. *
  5. * @since 1.0.0
  6. */
  7. class WPForms_Settings {
  8. /**
  9. * The current active tab.
  10. *
  11. * @since 1.3.9
  12. *
  13. * @var string
  14. */
  15. public $view;
  16. /**
  17. * Primary class constructor.
  18. *
  19. * @since 1.0.0
  20. */
  21. public function __construct() {
  22. // Maybe load settings page.
  23. add_action( 'admin_init', array( $this, 'init' ) );
  24. }
  25. /**
  26. * Determine if the user is viewing the settings page, if so, party on.
  27. *
  28. * @since 1.0.0
  29. */
  30. public function init() {
  31. // Only load if we are actually on the settings page.
  32. if ( ! wpforms_is_admin_page( 'settings' ) ) {
  33. return;
  34. }
  35. // Include API callbacks and functions.
  36. require_once WPFORMS_PLUGIN_DIR . 'includes/admin/settings-api.php';
  37. // Watch for triggered save.
  38. $this->save_settings();
  39. // Determine the current active settings tab.
  40. $this->view = isset( $_GET['view'] ) ? sanitize_key( wp_unslash( $_GET['view'] ) ) : 'general'; // phpcs:ignore WordPress.CSRF.NonceVerification
  41. add_action( 'admin_enqueue_scripts', array( $this, 'enqueues' ) );
  42. add_action( 'wpforms_admin_page', array( $this, 'output' ) );
  43. // Monitor custom tables.
  44. $this->monitor_custom_tables();
  45. // Hook for addons.
  46. do_action( 'wpforms_settings_init', $this );
  47. }
  48. /**
  49. * Sanitize and save settings.
  50. *
  51. * @since 1.3.9
  52. */
  53. public function save_settings() {
  54. // Check nonce and other various security checks.
  55. if ( ! isset( $_POST['wpforms-settings-submit'] ) || empty( $_POST['nonce'] ) ) {
  56. return;
  57. }
  58. if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'wpforms-settings-nonce' ) ) {
  59. return;
  60. }
  61. if ( ! wpforms_current_user_can() ) {
  62. return;
  63. }
  64. if ( empty( $_POST['view'] ) ) {
  65. return;
  66. }
  67. $current_view = sanitize_key( $_POST['view'] );
  68. // Get registered fields and current settings.
  69. $fields = $this->get_registered_settings( $current_view );
  70. $settings = get_option( 'wpforms_settings', array() );
  71. // Views excluded from saving list.
  72. $exclude_views = apply_filters( 'wpforms_settings_exclude_view', array(), $fields, $settings );
  73. if ( is_array( $exclude_views ) && in_array( $current_view, $exclude_views, true ) ) {
  74. // Run a custom save processing for excluded views.
  75. do_action( 'wpforms_settings_custom_process', $current_view, $fields, $settings );
  76. return;
  77. }
  78. if ( empty( $fields ) || ! is_array( $fields ) ) {
  79. return;
  80. }
  81. // Sanitize and prep each field.
  82. foreach ( $fields as $id => $field ) {
  83. // Certain field types are not valid for saving and are skipped.
  84. $exclude = apply_filters( 'wpforms_settings_exclude_type', array( 'content', 'license', 'providers' ) );
  85. if ( empty( $field['type'] ) || in_array( $field['type'], $exclude, true ) ) {
  86. continue;
  87. }
  88. // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
  89. $value = isset( $_POST[ $id ] ) ? trim( wp_unslash( $_POST[ $id ] ) ) : false;
  90. $value_prev = isset( $settings[ $id ] ) ? $settings[ $id ] : false;
  91. // Custom filter can be provided for sanitizing, otherwise use defaults.
  92. if ( ! empty( $field['filter'] ) && is_callable( $field['filter'] ) ) {
  93. $value = call_user_func( $field['filter'], $value, $id, $field, $value_prev );
  94. } else {
  95. switch ( $field['type'] ) {
  96. case 'checkbox':
  97. $value = (bool) $value;
  98. break;
  99. case 'image':
  100. $value = esc_url_raw( $value );
  101. break;
  102. case 'color':
  103. $value = wpforms_sanitize_hex_color( $value );
  104. break;
  105. case 'number':
  106. $value = (float) $value;
  107. break;
  108. case 'text':
  109. case 'radio':
  110. case 'select':
  111. default:
  112. $value = sanitize_text_field( $value );
  113. break;
  114. }
  115. }
  116. // Add to settings.
  117. $settings[ $id ] = $value;
  118. }
  119. // Save settings.
  120. wpforms_update_settings( $settings );
  121. \WPForms\Admin\Notice::success( esc_html__( 'Settings were successfully saved.', 'wpforms-lite' ) );
  122. }
  123. /**
  124. * Enqueue assets for the settings page.
  125. *
  126. * @since 1.0.0
  127. */
  128. public function enqueues() {
  129. do_action( 'wpforms_settings_enqueue' );
  130. }
  131. /**
  132. * Return registered settings tabs.
  133. *
  134. * @since 1.3.9
  135. *
  136. * @return array
  137. */
  138. public function get_tabs() {
  139. $tabs = [
  140. 'general' => [
  141. 'name' => esc_html__( 'General', 'wpforms-lite' ),
  142. 'form' => true,
  143. 'submit' => esc_html__( 'Save Settings', 'wpforms-lite' ),
  144. ],
  145. 'email' => [
  146. 'name' => esc_html__( 'Email', 'wpforms-lite' ),
  147. 'form' => true,
  148. 'submit' => esc_html__( 'Save Settings', 'wpforms-lite' ),
  149. ],
  150. 'validation' => [
  151. 'name' => esc_html__( 'Validation', 'wpforms-lite' ),
  152. 'form' => true,
  153. 'submit' => esc_html__( 'Save Settings', 'wpforms-lite' ),
  154. ],
  155. 'integrations' => [
  156. 'name' => esc_html__( 'Integrations', 'wpforms-lite' ),
  157. 'form' => false,
  158. 'submit' => false,
  159. ],
  160. 'geolocation' => [
  161. 'name' => esc_html__( 'Geolocation', 'wpforms-lite' ),
  162. 'form' => false,
  163. 'submit' => false,
  164. ],
  165. 'misc' => [
  166. 'name' => esc_html__( 'Misc', 'wpforms-lite' ),
  167. 'form' => true,
  168. 'submit' => esc_html__( 'Save Settings', 'wpforms-lite' ),
  169. ],
  170. ];
  171. return apply_filters( 'wpforms_settings_tabs', $tabs );
  172. }
  173. /**
  174. * Output tab navigation area.
  175. *
  176. * @since 1.3.9
  177. */
  178. public function tabs() {
  179. $tabs = $this->get_tabs();
  180. echo '<ul class="wpforms-admin-tabs">';
  181. foreach ( $tabs as $id => $tab ) {
  182. $active = $id === $this->view ? 'active' : '';
  183. $link = add_query_arg( 'view', $id, admin_url( 'admin.php?page=wpforms-settings' ) );
  184. echo '<li><a href="' . esc_url_raw( $link ) . '" class="' . esc_attr( $active ) . '">' . esc_html( $tab['name'] ) . '</a></li>';
  185. }
  186. echo '</ul>';
  187. }
  188. /**
  189. * Return all the default registered settings fields.
  190. *
  191. * @since 1.3.9
  192. *
  193. * @param string $view The current view (tab) on Settings page.
  194. *
  195. * @return array
  196. */
  197. public function get_registered_settings( $view = '' ) {
  198. $defaults = [
  199. // General Settings tab.
  200. 'general' => [
  201. 'license-heading' => [
  202. 'id' => 'license-heading',
  203. 'content' => '<h4>' . esc_html__( 'License', 'wpforms-lite' ) . '</h4><p>' . esc_html__( 'Your license key provides access to updates and addons.', 'wpforms-lite' ) . '</p>',
  204. 'type' => 'content',
  205. 'no_label' => true,
  206. 'class' => [ 'section-heading' ],
  207. ],
  208. 'license-key' => [
  209. 'id' => 'license-key',
  210. 'name' => esc_html__( 'License Key', 'wpforms-lite' ),
  211. 'type' => 'license',
  212. ],
  213. 'general-heading' => [
  214. 'id' => 'general-heading',
  215. 'content' => '<h4>' . esc_html__( 'General', 'wpforms-lite' ) . '</h4>',
  216. 'type' => 'content',
  217. 'no_label' => true,
  218. 'class' => [ 'section-heading', 'no-desc' ],
  219. ],
  220. 'disable-css' => [
  221. 'id' => 'disable-css',
  222. 'name' => esc_html__( 'Include Form Styling', 'wpforms-lite' ),
  223. 'desc' => sprintf(
  224. wp_kses( /* translators: %s - WPForms.com form styling setting URL. */
  225. __( 'Determines which CSS files to load and use for the site (<a href="%s" target="_blank" rel="noopener noreferrer">please see our tutorial for full details</a>). "Base and Form Theme Styling" is recommended, unless you are experienced with CSS or instructed by support to change settings. ', 'wpforms-lite' ),
  226. [
  227. 'a' => [
  228. 'href' => [],
  229. 'target' => [],
  230. 'rel' => [],
  231. ],
  232. ]
  233. ),
  234. 'https://wpforms.com/docs/how-to-choose-an-include-form-styling-setting/'
  235. ),
  236. 'type' => 'select',
  237. 'choicesjs' => true,
  238. 'default' => 1,
  239. 'options' => [
  240. 1 => esc_html__( 'Base and form theme styling', 'wpforms-lite' ),
  241. 2 => esc_html__( 'Base styling only', 'wpforms-lite' ),
  242. 3 => esc_html__( 'No styling', 'wpforms-lite' ),
  243. ],
  244. ],
  245. 'global-assets' => [
  246. 'id' => 'global-assets',
  247. 'name' => esc_html__( 'Load Assets Globally', 'wpforms-lite' ),
  248. 'desc' => esc_html__( 'Check this option to load WPForms assets site-wide. Only check if your site is having compatibility issues or instructed to by support.', 'wpforms-lite' ),
  249. 'type' => 'checkbox',
  250. ],
  251. 'gdpr-heading' => [
  252. 'id' => 'GDPR',
  253. 'content' => '<h4>' . esc_html__( 'GDPR', 'wpforms-lite' ) . '</h4>',
  254. 'type' => 'content',
  255. 'no_label' => true,
  256. 'class' => [ 'section-heading', 'no-desc' ],
  257. ],
  258. 'gdpr' => [
  259. 'id' => 'gdpr',
  260. 'name' => esc_html__( 'GDPR Enhancements', 'wpforms-lite' ),
  261. 'desc' => sprintf(
  262. wp_kses( /* translators: %s - WPForms.com GDPR documentation URL. */
  263. __( 'Check this option to enable GDPR related features and enhancements. <a href="%s" target="_blank" rel="noopener noreferrer">Read our GDPR documentation</a> to learn more.', 'wpforms-lite' ),
  264. [
  265. 'a' => [
  266. 'href' => [],
  267. 'target' => [],
  268. 'rel' => [],
  269. ],
  270. ]
  271. ),
  272. 'https://wpforms.com/docs/how-to-create-gdpr-compliant-forms/'
  273. ),
  274. 'type' => 'checkbox',
  275. ],
  276. ],
  277. // Email settings tab.
  278. 'email' => [
  279. 'email-heading' => [
  280. 'id' => 'email-heading',
  281. 'content' => '<h4>' . esc_html__( 'Email', 'wpforms-lite' ) . '</h4>',
  282. 'type' => 'content',
  283. 'no_label' => true,
  284. 'class' => [ 'section-heading', 'no-desc' ],
  285. ],
  286. 'email-async' => [
  287. 'id' => 'email-async',
  288. 'name' => esc_html__( 'Optimize Email Sending', 'wpforms-lite' ),
  289. 'desc' => esc_html__( 'Check this option to enable sending emails asynchronously, which can make submission processing faster.', 'wpforms-lite' ),
  290. 'type' => 'checkbox',
  291. ],
  292. 'email-template' => [
  293. 'id' => 'email-template',
  294. 'name' => esc_html__( 'Template', 'wpforms-lite' ),
  295. 'desc' => esc_html__( 'Determines how email notifications will be formatted. HTML Templates are the default.', 'wpforms-lite' ),
  296. 'type' => 'radio',
  297. 'default' => 'default',
  298. 'options' => [
  299. 'default' => esc_html__( 'HTML Template', 'wpforms-lite' ),
  300. 'none' => esc_html__( 'Plain text', 'wpforms-lite' ),
  301. ],
  302. ],
  303. 'email-header-image' => [
  304. 'id' => 'email-header-image',
  305. 'name' => esc_html__( 'Header Image', 'wpforms-lite' ),
  306. 'desc' => wp_kses( __( 'Upload or choose a logo to be displayed at the top of email notifications.<br>Recommended size is 300x100 or smaller for best support on all devices.', 'wpforms-lite' ), [ 'br' => [] ] ),
  307. 'type' => 'image',
  308. ],
  309. 'email-background-color' => [
  310. 'id' => 'email-background-color',
  311. 'name' => esc_html__( 'Background Color', 'wpforms-lite' ),
  312. 'desc' => esc_html__( 'Customize the background color of the HTML email template.', 'wpforms-lite' ),
  313. 'type' => 'color',
  314. 'default' => '#e9eaec',
  315. ],
  316. 'email-carbon-copy' => [
  317. 'id' => 'email-carbon-copy',
  318. 'name' => esc_html__( 'Carbon Copy', 'wpforms-lite' ),
  319. 'desc' => esc_html__( 'Check this option to enable the ability to CC: email addresses in the form notification settings.', 'wpforms-lite' ),
  320. 'type' => 'checkbox',
  321. ],
  322. ],
  323. // Validation messages settings tab.
  324. 'validation' => [
  325. 'validation-heading' => [
  326. 'id' => 'validation-heading',
  327. 'content' => sprintf( /* translators: %s - WPForms.com smart tags documentation URL. */
  328. esc_html__( '%1$s These messages are displayed to the users as they fill out a form in real-time. Messages can include plain text and/or %2$sSmart Tags%3$s.', 'wpforms-lite' ),
  329. '<h4>' . esc_html__( 'Validation Messages', 'wpforms-lite' )
  330. . '</h4><p>',
  331. '<a href="https://wpforms.com/docs/how-to-use-smart-tags-in-wpforms/#smart-tags" target="_blank" rel="noopener noreferrer">',
  332. '</a>'
  333. ),
  334. 'type' => 'content',
  335. 'no_label' => true,
  336. 'class' => [ 'section-heading' ],
  337. ],
  338. 'validation-required' => [
  339. 'id' => 'validation-required',
  340. 'name' => esc_html__( 'Required', 'wpforms-lite' ),
  341. 'type' => 'text',
  342. 'default' => esc_html__( 'This field is required.', 'wpforms-lite' ),
  343. ],
  344. 'validation-url' => [
  345. 'id' => 'validation-url',
  346. 'name' => esc_html__( 'Website URL', 'wpforms-lite' ),
  347. 'type' => 'text',
  348. 'default' => esc_html__( 'Please enter a valid URL.', 'wpforms-lite' ),
  349. ],
  350. 'validation-email' => [
  351. 'id' => 'validation-email',
  352. 'name' => esc_html__( 'Email', 'wpforms-lite' ),
  353. 'type' => 'text',
  354. 'default' => esc_html__( 'Please enter a valid email address.', 'wpforms-lite' ),
  355. ],
  356. 'validation-email-suggestion' => [
  357. 'id' => 'validation-email-suggestion',
  358. 'name' => esc_html__( 'Email Suggestion', 'wpforms-lite' ),
  359. 'type' => 'text',
  360. 'default' => sprintf( /* translators: %s - suggested email address. */
  361. esc_html__( 'Did you mean %s?', 'wpforms-lite' ),
  362. '{suggestion}'
  363. ),
  364. ],
  365. 'validation-email-restricted' => [
  366. 'id' => 'validation-email-restricted',
  367. 'name' => esc_html__( 'Email Restricted', 'wpforms-lite' ),
  368. 'type' => 'text',
  369. 'default' => esc_html__( 'This email address is not allowed.', 'wpforms-lite' ),
  370. ],
  371. 'validation-number' => [
  372. 'id' => 'validation-number',
  373. 'name' => esc_html__( 'Number', 'wpforms-lite' ),
  374. 'type' => 'text',
  375. 'default' => esc_html__( 'Please enter a valid number.', 'wpforms-lite' ),
  376. ],
  377. 'validation-number-positive' => [
  378. 'id' => 'validation-number-positive',
  379. 'name' => esc_html__( 'Number Positive', 'wpforms-lite' ),
  380. 'type' => 'text',
  381. 'default' => esc_html__( 'Please enter a valid positive number.', 'wpforms-lite' ),
  382. ],
  383. 'validation-confirm' => [
  384. 'id' => 'validation-confirm',
  385. 'name' => esc_html__( 'Confirm Value', 'wpforms-lite' ),
  386. 'type' => 'text',
  387. 'default' => esc_html__( 'Field values do not match.', 'wpforms-lite' ),
  388. ],
  389. 'validation-input-mask-incomplete' => [
  390. 'id' => 'validation-input-mask-incomplete',
  391. 'name' => esc_html__( 'Input Mask Incomplete', 'wpforms-lite' ),
  392. 'type' => 'text',
  393. 'default' => esc_html__( 'Please fill out all blanks.', 'wpforms-lite' ),
  394. ],
  395. 'validation-check-limit' => [
  396. 'id' => 'validation-check-limit',
  397. 'name' => esc_html__( 'Checkbox Selection Limit', 'wpforms-lite' ),
  398. 'type' => 'text',
  399. 'default' => esc_html__( 'You have exceeded the number of allowed selections: {#}.', 'wpforms-lite' ),
  400. ],
  401. 'validation-character-limit' => [
  402. 'id' => 'validation-character-limit',
  403. 'name' => esc_html__( 'Character Limit', 'wpforms-lite' ),
  404. 'type' => 'text',
  405. 'default' => sprintf( /* translators: %1$s - characters limit, %2$s - number of characters left. */
  406. esc_html__( 'Limit is %1$s characters. Characters remaining: %2$s.', 'wpforms-lite' ),
  407. '{limit}',
  408. '{remaining}'
  409. ),
  410. ],
  411. 'validation-word-limit' => [
  412. 'id' => 'validation-word-limit',
  413. 'name' => esc_html__( 'Word Limit', 'wpforms-lite' ),
  414. 'type' => 'text',
  415. 'default' => sprintf( /* translators: %1$s - words limit, %2$s - number of words left. */
  416. esc_html__( 'Limit is %1$s words. Words remaining: %2$s.', 'wpforms-lite' ),
  417. '{limit}',
  418. '{remaining}'
  419. ),
  420. ],
  421. ],
  422. // Provider integrations settings tab.
  423. 'integrations' => [
  424. 'integrations-heading' => [
  425. 'id' => 'integrations-heading',
  426. 'content' => '<h4>' . esc_html__( 'Integrations', 'wpforms-lite' ) . '</h4><p>' . esc_html__( 'Manage integrations with popular providers such as Constant Contact, Mailchimp, Zapier, and more.', 'wpforms-lite' ) . '</p>',
  427. 'type' => 'content',
  428. 'no_label' => true,
  429. 'class' => [ 'section-heading' ],
  430. ],
  431. 'integrations-providers' => [
  432. 'id' => 'integrations-providers',
  433. 'content' => '<h4>' . esc_html__( 'Integrations', 'wpforms-lite' ) . '</h4><p>' . esc_html__( 'Manage integrations with popular providers such as Constant Contact, Mailchimp, Zapier, and more.', 'wpforms-lite' ) . '</p>',
  434. 'type' => 'providers',
  435. 'wrap' => 'none',
  436. ],
  437. ],
  438. // Misc. settings tab.
  439. 'misc' => [
  440. 'misc-heading' => [
  441. 'id' => 'misc-heading',
  442. 'content' => '<h4>' . esc_html__( 'Misc', 'wpforms-lite' ) . '</h4>',
  443. 'type' => 'content',
  444. 'no_label' => true,
  445. 'class' => [ 'section-heading', 'no-desc' ],
  446. ],
  447. 'hide-announcements' => [
  448. 'id' => 'hide-announcements',
  449. 'name' => esc_html__( 'Hide Announcements', 'wpforms-lite' ),
  450. 'desc' => esc_html__( 'Check this option to hide plugin announcements and update details.', 'wpforms-lite' ),
  451. 'type' => 'checkbox',
  452. ],
  453. 'hide-admin-bar' => [
  454. 'id' => 'hide-admin-bar',
  455. 'name' => esc_html__( 'Hide Admin Bar Menu', 'wpforms-lite' ),
  456. 'desc' => esc_html__( 'Check this option to hide the WPForms admin bar menu.', 'wpforms-lite' ),
  457. 'type' => 'checkbox',
  458. ],
  459. 'uninstall-data' => [
  460. 'id' => 'uninstall-data',
  461. 'name' => esc_html__( 'Uninstall WPForms', 'wpforms-lite' ),
  462. 'desc' => esc_html__( 'Check this option to remove ALL WPForms data upon plugin deletion. All forms and settings will be unrecoverable.', 'wpforms-lite' ),
  463. 'type' => 'checkbox',
  464. ],
  465. ],
  466. ];
  467. // TODO: move this to Pro.
  468. if ( wpforms()->pro ) {
  469. $defaults['misc']['uninstall-data']['desc'] = esc_html__( 'Check this option to remove ALL WPForms data upon plugin deletion. All forms, entries, and uploaded files will be unrecoverable.', 'wpforms-lite' );
  470. }
  471. $defaults = apply_filters( 'wpforms_settings_defaults', $defaults );
  472. // Take care of invalid views.
  473. if ( ! empty( $view ) && ! array_key_exists( $view, $defaults ) ) {
  474. $this->view = key( $defaults );
  475. return reset( $defaults );
  476. }
  477. return empty( $view ) ? $defaults : $defaults[ $view ];
  478. }
  479. /**
  480. * Return array containing markup for all the appropriate settings fields.
  481. *
  482. * @since 1.3.9
  483. *
  484. * @param string $view View slug.
  485. *
  486. * @return array
  487. */
  488. public function get_settings_fields( $view = '' ) {
  489. $fields = array();
  490. $settings = $this->get_registered_settings( $view );
  491. foreach ( $settings as $id => $args ) {
  492. $fields[ $id ] = wpforms_settings_output_field( $args );
  493. }
  494. return apply_filters( 'wpforms_settings_fields', $fields, $view );
  495. }
  496. /**
  497. * Build the output for the plugin settings page.
  498. *
  499. * @since 1.0.0
  500. */
  501. public function output() {
  502. $tabs = $this->get_tabs();
  503. $fields = $this->get_settings_fields( $this->view );
  504. ?>
  505. <div id="wpforms-settings" class="wrap wpforms-admin-wrap">
  506. <?php $this->tabs(); ?>
  507. <h1 class="wpforms-h1-placeholder"></h1>
  508. <?php
  509. if ( wpforms()->pro && class_exists( 'WPForms_License', false ) ) {
  510. wpforms()->license->notices( true );
  511. }
  512. ?>
  513. <div class="wpforms-admin-content wpforms-admin-settings wpforms-admin-content-<?php echo esc_attr( $this->view ); ?> wpforms-admin-settings-<?php echo esc_attr( $this->view ); ?>">
  514. <?php
  515. // Some tabs rely on AJAX and do not contain a form, such as Integrations.
  516. if ( ! empty( $tabs[ $this->view ]['form'] ) ) :
  517. ?>
  518. <form class="wpforms-admin-settings-form" method="post">
  519. <input type="hidden" name="action" value="update-settings">
  520. <input type="hidden" name="view" value="<?php echo esc_attr( $this->view ); ?>">
  521. <input type="hidden" name="nonce" value="<?php echo esc_attr( wp_create_nonce( 'wpforms-settings-nonce' ) ); ?>">
  522. <?php endif; ?>
  523. <?php do_action( 'wpforms_admin_settings_before', $this->view, $fields ); ?>
  524. <?php
  525. foreach ( $fields as $field ) {
  526. echo $field; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
  527. }
  528. ?>
  529. <?php if ( ! empty( $tabs[ $this->view ]['submit'] ) ) : ?>
  530. <p class="submit">
  531. <button type="submit" class="wpforms-btn wpforms-btn-md wpforms-btn-orange" name="wpforms-settings-submit">
  532. <?php
  533. // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
  534. echo $tabs[ $this->view ]['submit'];
  535. ?>
  536. </button>
  537. </p>
  538. <?php endif; ?>
  539. <?php do_action( 'wpforms_admin_settings_after', $this->view, $fields ); ?>
  540. <?php if ( ! empty( $tabs[ $this->view ]['form'] ) ) : ?>
  541. </form>
  542. <?php endif; ?>
  543. </div>
  544. </div>
  545. <?php
  546. }
  547. /**
  548. * Monitor that all custom tables exist and recreate if missing.
  549. * This logic works on Settings > General page only.
  550. *
  551. * @since 1.6.2
  552. */
  553. public function monitor_custom_tables() {
  554. // Proceed on Settings plugin admin area page only.
  555. if ( $this->view !== 'general' ) {
  556. return;
  557. }
  558. /*
  559. * Tasks Meta table.
  560. */
  561. $meta = new \WPForms\Tasks\Meta();
  562. if ( $meta->table_exists() ) {
  563. return;
  564. }
  565. $meta->create_table();
  566. }
  567. }
  568. new WPForms_Settings();