Nav apraksta

Settings.php 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. <?php
  2. /*******************************************************************************
  3. * Copyright (c) 2019, Code Atlantic LLC
  4. ******************************************************************************/
  5. if ( ! defined( 'ABSPATH' ) ) {
  6. exit;
  7. }
  8. /**
  9. * Class PUM_Admin_Settings
  10. */
  11. class PUM_Admin_Settings {
  12. /**
  13. * @var array
  14. */
  15. public static $notices = array();
  16. /**
  17. *
  18. */
  19. public static function init() {
  20. add_action( 'admin_notices', array( __CLASS__, 'notices' ) );
  21. add_action( 'admin_init', array( __CLASS__, 'save' ) );
  22. //add_action( 'pum_license_deactivated', array( __CLASS__, 'license_deactivated' ) );
  23. //add_action( 'pum_license_check_failed', array( __CLASS__, 'license_deactivated' ) );
  24. }
  25. // display default admin notice
  26. /**
  27. * Displays any saved admin notices.
  28. */
  29. public static function notices() {
  30. if ( isset( $_GET['success'] ) && get_option( 'pum_settings_admin_notice' ) ) {
  31. self::$notices[] = array(
  32. 'type' => $_GET['success'] ? 'success' : 'error',
  33. 'message' => get_option( 'pum_settings_admin_notice' ),
  34. );
  35. delete_option( 'pum_settings_admin_notice' );
  36. }
  37. if ( ! empty( self::$notices ) ) {
  38. foreach ( self::$notices as $notice ) { ?>
  39. <div class="notice notice-<?php echo esc_attr( $notice['type'] ); ?> is-dismissible">
  40. <p><strong><?php esc_html_e( $notice['message'] ); ?></strong></p>
  41. <button type="button" class="notice-dismiss">
  42. <span class="screen-reader-text"><?php _e( 'Dismiss this notice.', 'popup-maker' ); ?></span>
  43. </button>
  44. </div>
  45. <?php }
  46. }
  47. }
  48. /**
  49. * Save settings when needed.
  50. */
  51. public static function save() {
  52. if ( ! empty( $_POST['pum_settings'] ) && empty( $_POST['pum_license_activate'] ) && empty( $_POST['pum_license_deactivate'] ) ) {
  53. if ( ! isset( $_POST['pum_settings_nonce'] ) || ! wp_verify_nonce( $_POST['pum_settings_nonce'], basename( __FILE__ ) ) ) {
  54. return;
  55. }
  56. if ( ! current_user_can( 'manage_options' ) ) {
  57. return;
  58. }
  59. $settings = self::sanitize_settings( $_POST['pum_settings'] );
  60. $settings = apply_filters( 'pum_sanitize_settings', $settings );
  61. if ( PUM_Utils_Options::update_all( $settings ) ) {
  62. self::$notices[] = array(
  63. 'type' => 'success',
  64. 'message' => __( 'Settings saved successfully!', 'popup-maker' ),
  65. );
  66. do_action( 'pum_save_settings', $settings );
  67. } else {
  68. self::$notices[] = array(
  69. 'type' => 'error',
  70. 'message' => __( 'There must have been an error, settings not saved successfully!', 'popup-maker' ),
  71. );
  72. }
  73. return;
  74. /**
  75. * Process licensing if set.
  76. *
  77. * // We store the key in wp_options for use by the update & licensing system to keep things cleanly detached.
  78. * $old_license = get_option( 'pum_license_key' );
  79. *
  80. * if ( empty( $settings['pum_license_key'] ) ) {
  81. * delete_option( 'pum_license_key' ); // empty key, remove existing license info.
  82. * delete_option( 'pum_license' ); // empty key, remove existing license info.
  83. * } else if ( $old_license != $settings['pum_license_key'] ) {
  84. * update_option( 'pum_license_key', $settings['pum_license_key'] );
  85. * delete_option( 'pum_license' ); // new license has been entered, so must reactivate
  86. *
  87. * // Prevent additional calls to licensing.
  88. * if ( empty( $_POST['pum_license_activate'] ) ) {
  89. * $message = PUM_Licensing::activate();
  90. *
  91. * if ( $message !== true && ! empty ( $message ) ) {
  92. * self::$notices[] = array(
  93. * 'type' => 'error',
  94. * 'message' => $message,
  95. * );
  96. * } else {
  97. * self::$notices[] = array(
  98. * 'type' => 'success',
  99. * 'message' => __( 'License activated successfully!', 'popup-maker' ),
  100. * );
  101. * }
  102. * }
  103. * }
  104. */
  105. }
  106. }
  107. /**
  108. * @param array $settings
  109. *
  110. * @return array
  111. */
  112. public static function sanitize_settings( $settings = array() ) {
  113. $fields = self::fields();
  114. $fields = PUM_Admin_Helpers::flatten_fields_array( $fields );
  115. foreach ( $fields as $field_id => $field ) {
  116. switch ( $field['type'] ) {
  117. case 'checkbox':
  118. if ( ! isset( $settings[ $field_id ] ) ) {
  119. $settings[ $field_id ] = false;
  120. }
  121. break;
  122. }
  123. }
  124. foreach ( $settings as $key => $value ) {
  125. $field = self::get_field( $key );
  126. if ( $field ) {
  127. // Sanitize every string value.
  128. if ( is_string( $value ) ) {
  129. $settings[ $key ] = sanitize_text_field( $value );
  130. }
  131. switch ( $field['type'] ) {
  132. default:
  133. $settings[ $key ] = is_string( $value ) ? trim( $value ) : $value;
  134. break;
  135. case 'measure':
  136. $settings[ $key ] .= $settings[ $key . '_unit' ];
  137. break;
  138. case 'license_key':
  139. $old = PUM_Utils_Options::get( $key );
  140. $new = trim( $value );
  141. if ( $old && $old != $new ) {
  142. delete_option( str_replace( '_license_key', '_license_active', $key ) );
  143. call_user_func( $field['options']['activation_callback'] );
  144. }
  145. $settings[ $key ] = is_string( $value ) ? trim( $value ) : $value;
  146. // Activate / deactivate license keys maybe?
  147. break;
  148. }
  149. } else {
  150. // Some custom field types include multiple additional fields that do not need to be saved, strip out any non-whitelisted fields.
  151. unset( $settings[ $key ] );
  152. }
  153. }
  154. return $settings;
  155. }
  156. /**
  157. * @param $id
  158. *
  159. * @return bool
  160. */
  161. public static function get_field( $id ) {
  162. $tabs = self::fields();
  163. foreach ( $tabs as $tab => $sections ) {
  164. if ( PUM_Admin_Helpers::is_field( $sections ) ) {
  165. $sections = array(
  166. 'main' => array(
  167. $tab => $sections,
  168. ),
  169. );
  170. }
  171. foreach ( $sections as $section => $fields ) {
  172. foreach ( $fields as $key => $args ) {
  173. if ( $key == $id ) {
  174. return $args;
  175. }
  176. }
  177. }
  178. }
  179. return false;
  180. }
  181. /**
  182. * Returns array of pum settings fields.
  183. *
  184. * @return mixed
  185. */
  186. public static function fields() {
  187. static $fields;
  188. if ( ! isset( $fields ) ) {
  189. $fields = array(
  190. 'general' => array(
  191. 'main' => array(
  192. 'default_theme_id' => array(
  193. 'label' => __( 'Default Popup Theme', 'popup-maker' ),
  194. 'dynamic_desc' => sprintf( '%1$s<br/><a id="edit_theme_link" href="%3$s">%2$s</a>', __( 'Choose the default theme used for new popups', 'popup-maker' ), __( 'Customize This Theme', 'popup-maker' ), admin_url( "post.php?action=edit&post={{data.value}}" ) ),
  195. 'type' => 'select',
  196. 'options' => pum_is_settings_page() ? PUM_Helpers::popup_theme_selectlist() : null,
  197. 'std' => pum_get_default_theme_id(),
  198. ),
  199. 'gutenberg_support_enabled' => array(
  200. 'label' => __( 'Enable Block Editor Support', 'popup-maker' ),
  201. 'desc' => __( 'Enable experimental support for using the block editor to edit popups.', 'popup-maker' ),
  202. 'type' => 'checkbox',
  203. ),
  204. 'google_fonts_api_key' => array(
  205. 'type' => 'text',
  206. 'label' => __( 'Google Fonts API Key *optional', 'popup-maker' ),
  207. 'desc' => __( 'Enter your own Google Fonts API key to always get the latest fonts available.', 'popup-maker' ),
  208. ),
  209. 'telemetry' => array(
  210. 'type' => 'checkbox',
  211. 'label' => __( 'Allow usage tracking?', 'popup-maker' ),
  212. 'desc' => sprintf(
  213. /* translators: 1 & 2 are opening and closing HTML of the link around "Learn more" */
  214. esc_html__( 'Allow data sharing so that we can receive a little information on how it is used and help us make this plugin better? No user data is sent to our servers. No sensitive data is tracked. %1$sLearn more%2$s', 'popup-maker' ),
  215. ' <a target="_blank" rel="noreferrer noopener" href="https://docs.wppopupmaker.com/article/528-the-data-the-popup-maker-plugin-collects?utm_campaign=contextual-help&utm_medium=inline-doclink&utm_source=settings-page&utm_content=telemetry-setting">',
  216. '</a>'
  217. ),
  218. ),
  219. ),
  220. ),
  221. );
  222. // TODO Remove or move externally of this location later.
  223. if ( ! ( class_exists( 'PUM_MCI' ) && version_compare( PUM_MCI::$VER, '1.3.0', '<' ) ) ) {
  224. $fields['subscriptions'] = array(
  225. 'main' => apply_filters( 'pum_newsletter_settings', array(
  226. 'newsletter_default_provider' => array(
  227. 'label' => __( 'Default Newsletter Provider', 'popup-maker' ),
  228. 'desc' => __( 'The default mailing provider used for the subscription form.', 'popup-maker' ),
  229. 'type' => 'select',
  230. 'options' => array_merge( PUM_Newsletter_Providers::dropdown_list(), array(
  231. 'none' => __( 'None', 'popup-maker' ),
  232. ) ),
  233. ),
  234. 'default_success_message' => array(
  235. 'label' => __( 'Success Message', 'popup-maker' ),
  236. 'desc' => __( 'Message to show user when successfuly subscribed.', 'popup-maker' ),
  237. 'type' => 'text',
  238. 'std' => __( 'You have been subscribed!', 'popup-maker' ),
  239. ),
  240. 'default_empty_email_message' => array(
  241. 'label' => __( 'Empty Email Message', 'popup-maker' ),
  242. 'desc' => __( 'Message to show user when no email is entered.', 'popup-maker' ),
  243. 'type' => 'text',
  244. 'std' => __( 'Please enter a valid email.', 'popup-maker' ),
  245. ),
  246. 'default_invalid_email_message' => array(
  247. 'label' => __( 'Invalid Email Message', 'popup-maker' ),
  248. 'desc' => __( 'Message to show user when an invalid email is entered.', 'popup-maker' ),
  249. 'type' => 'text',
  250. 'std' => __( 'Email provided is not a valid email address.', 'popup-maker' ),
  251. ),
  252. 'default_error_message' => array(
  253. 'label' => __( 'Error Message', 'popup-maker' ),
  254. 'desc' => __( 'Message to show user when an error has occurred.', 'popup-maker' ),
  255. 'type' => 'text',
  256. 'std' => __( 'Error occurred when subscribing. Please try again.', 'popup-maker' ),
  257. ),
  258. 'default_already_subscribed_message' => array(
  259. 'label' => __( 'Already Subscribed Message', 'popup-maker' ),
  260. 'desc' => __( 'Message to show user who is already subscribed.', 'popup-maker' ),
  261. 'type' => 'text',
  262. 'std' => __( 'You are already a subscriber.', 'popup-maker' ),
  263. ),
  264. 'default_consent_required_message' => array(
  265. 'label' => __( 'Consent Required Message', 'popup-maker' ),
  266. 'desc' => __( 'Message to show user who is already subscribed.', 'popup-maker' ),
  267. 'type' => 'text',
  268. 'std' => __( 'You must agree to continue.', 'popup-maker' ),
  269. ),
  270. ) ),
  271. );
  272. }
  273. $fields = array_merge( $fields, array(
  274. 'extensions' => array(
  275. 'main' => array(),
  276. ),
  277. 'licenses' => array(
  278. 'main' => array(),
  279. ),
  280. 'privacy' => array(
  281. 'main' => array(
  282. 'disable_popup_open_tracking' => array(
  283. 'type' => 'checkbox',
  284. 'label' => __( 'Disables popup open tracking?', 'popup-maker' ),
  285. 'desc' => __( 'This will disable the built in analytics functionality.', 'popup-maker' ),
  286. ),
  287. ),
  288. 'forms' => array(
  289. 'forms_disclaimer' => array(
  290. 'type' => 'html',
  291. 'content' => "<strong>" . __( 'Disclaimer', 'popup-maker' ) . ":</strong> " . __( 'These settings only pertain to usage of the Popup Maker built in subscription form shortcode, not 3rd party form plugins.', 'popup-maker' ),
  292. ),
  293. 'privacy_consent_always_enabled' => array(
  294. 'label' => __( 'Always enable consent field on subscription forms.', 'popup-maker' ),
  295. 'type' => 'select',
  296. 'options' => array(
  297. 'yes' => __( 'Yes', 'popup-maker' ),
  298. 'no' => __( 'No', 'popup-maker' ),
  299. ),
  300. 'std' => 'yes',
  301. ),
  302. 'default_privacy_consent_label' => array(
  303. 'label' => __( 'Consent Text', 'popup-maker' ),
  304. 'type' => 'text',
  305. 'std' => __( 'Notify me about related content and special offers.', 'popup-maker' ),
  306. 'dependencies' => array(
  307. 'privacy_consent_always_enabled' => 'yes',
  308. ),
  309. ),
  310. 'default_privacy_consent_type' => array(
  311. 'label' => __( 'Consent Field Type', 'popup-maker' ),
  312. 'desc' => __( 'Radio forces the user to make a choice, often resulting in more opt-ins.', 'popup-maker' ),
  313. 'type' => 'select',
  314. 'options' => array(
  315. 'radio' => __( 'Radio', 'popup-maker' ),
  316. 'checkbox' => __( 'Checkbox', 'popup-maker' ),
  317. ),
  318. 'std' => 'radio',
  319. 'dependencies' => array(
  320. 'privacy_consent_always_enabled' => 'yes',
  321. ),
  322. ),
  323. 'default_privacy_consent_required' => array(
  324. 'label' => __( 'Consent Required', 'popup-maker' ),
  325. 'type' => 'checkbox',
  326. 'std' => pum_get_option( 'default_privacy_consent_required' ),
  327. 'private' => true,
  328. 'dependencies' => array(
  329. 'privacy_consent_always_enabled' => 'yes',
  330. ),
  331. ),
  332. 'default_privacy_consent_radio_layout' => array(
  333. 'label' => __( 'Consent Radio Layout', 'popup-maker' ),
  334. 'type' => 'select',
  335. 'options' => array(
  336. 'inline' => __( 'Inline', 'popup-maker' ),
  337. 'stacked' => __( 'Stacked', 'popup-maker' ),
  338. ),
  339. 'std' => __( 'Yes', 'popup-maker' ),
  340. 'dependencies' => array(
  341. 'privacy_consent_always_enabled' => 'yes',
  342. 'default_privacy_consent_type' => 'radio',
  343. ),
  344. ),
  345. 'default_privacy_consent_yes_label' => array(
  346. 'label' => __( 'Consent Yes Label', 'popup-maker' ),
  347. 'type' => 'text',
  348. 'std' => __( 'Yes', 'popup-maker' ),
  349. 'dependencies' => array(
  350. 'privacy_consent_always_enabled' => 'yes',
  351. 'default_privacy_consent_type' => 'radio',
  352. ),
  353. ),
  354. 'default_privacy_consent_no_label' => array(
  355. 'label' => __( 'Consent No Label', 'popup-maker' ),
  356. 'type' => 'text',
  357. 'std' => __( 'No', 'popup-maker' ),
  358. 'dependencies' => array(
  359. 'privacy_consent_always_enabled' => 'yes',
  360. 'default_privacy_consent_type' => 'radio',
  361. ),
  362. ),
  363. 'default_privacy_usage_text' => array(
  364. 'label' => __( 'Consent Usage Text', 'popup-maker' ),
  365. 'desc' => function_exists( 'get_privacy_policy_url' ) ? sprintf( __( 'You can use %1$s%2$s to insert a link to your privacy policy. To customize the link text use %1$s:Link Text%2$s', 'popup-maker' ), '{{privacy_link', '}}' ) : '',
  366. 'type' => 'text',
  367. 'std' => __( 'If you opt in above we use this information send related content, discounts and other special offers.', 'popup-maker' ),
  368. 'dependencies' => array(
  369. 'privacy_consent_always_enabled' => 'yes',
  370. ),
  371. ),
  372. ),
  373. ),
  374. 'misc' => array(
  375. 'main' => array(
  376. 'bypass_adblockers' => array(
  377. 'label' => __( 'Try to bypass ad blockers.', 'popup-maker' ),
  378. 'type' => 'checkbox',
  379. ),
  380. 'adblock_bypass_url_method' => array(
  381. 'label' => __( 'Ad blocker: Naming method', 'popup-maker' ),
  382. 'desc' => __( 'This will help generate unique names for our JavaScript files and the analytics routes.', 'popup-maker' ),
  383. 'type' => 'select',
  384. 'options' => array(
  385. 'random' => __( 'Randomize Names', 'popup-maker' ),
  386. 'custom' => __( 'Custom Names', 'popup-maker' ),
  387. ),
  388. 'std' => 'random',
  389. 'dependencies' => array(
  390. 'bypass_adblockers' => true,
  391. ),
  392. ),
  393. 'adblock_bypass_custom_filename' => array(
  394. 'type' => 'text',
  395. 'placeholder' => 'my-awesome-popups',
  396. 'label' => __( 'Ad blocker: Custom Name', 'popup-maker' ),
  397. 'desc' => __( 'A custom & recognizable name to use for our assets.', 'popup-maker' ),
  398. 'dependencies' => array(
  399. 'bypass_adblockers' => true,
  400. 'adblock_bypass_url_method' => 'custom',
  401. ),
  402. ),
  403. 'adjust_body_padding' => array(
  404. 'type' => 'checkbox',
  405. 'label' => __( 'Adjust the right padding added to the body when popups are shown with an overlay.', 'popup-maker' ),
  406. 'desc' => sprintf(
  407. /* translators: 1 & 2 are opening and closing HTML of the link around "Learn more" */
  408. esc_html__( 'Use this if your popups "jump" or "shift" when opened. %1$sLearn more%2$s', 'popup-maker' ),
  409. '<a target="_blank" rel="noreferrer noopener" href="https://docs.wppopupmaker.com/article/314-why-does-my-site-shift-jump-or-skip-when-a-popup-is-triggered?utm_campaign=contextual-help&utm_medium=inline-doclink&utm_source=settings-page&utm_content=adjust-right-padding">',
  410. '</a>'
  411. ),
  412. ),
  413. 'body_padding_override' => array(
  414. 'type' => 'text',
  415. 'placeholder' => '15px',
  416. 'label' => __( 'Body Padding Override', 'popup-maker' ),
  417. 'dependencies' => array(
  418. 'adjust_body_padding' => true,
  419. ),
  420. 'std' => '15px',
  421. ),
  422. 'disabled_admin_bar' => array(
  423. 'type' => 'checkbox',
  424. 'label' => __( 'Disable Popups Admin Bar', 'popup-maker' ),
  425. 'desc' => __( 'This will disable the admin Popups menu item.', 'popup-maker' ),
  426. ),
  427. 'debug_mode' => array(
  428. 'type' => 'checkbox',
  429. 'label' => __( 'Enable Debug Mode', 'popup-maker' ),
  430. 'desc' => __( 'This will turn on multiple debug tools used to quickly find issues.', 'popup-maker' ),
  431. ),
  432. 'enable_easy_modal_compatibility_mode' => array(
  433. 'type' => 'checkbox',
  434. 'label' => __( 'Enable Easy Modal v2 Compatibility Mode', 'popup-maker' ),
  435. 'desc' => __( 'This will automatically make any eModal classes you have added to your site launch the appropriate Popup after import.', 'popup-maker' ),
  436. ),
  437. 'disable_popup_category_tag' => array(
  438. 'type' => 'checkbox',
  439. 'label' => __( 'Disable categories & tags?', 'popup-maker' ),
  440. 'desc' => __( 'This will disable the popup tags & categories.', 'popup-maker' ),
  441. ),
  442. 'disable_asset_caching' => array(
  443. 'type' => 'checkbox',
  444. 'label' => __( 'Disable asset caching.', 'popup-maker' ),
  445. 'desc' => __( 'By default Popup Maker caches a single JS & CSS file in your Uploads folder. These files include core, extension & user customized styles & scripts in a single set of files.', 'popup-maker' ),
  446. ),
  447. 'disable_shortcode_ui' => array(
  448. 'type' => 'checkbox',
  449. 'label' => __( 'Disable the Popup Maker shortcode button', 'popup-maker' ),
  450. ),
  451. 'disable_tips' => array(
  452. 'type' => 'checkbox',
  453. 'label' => __( 'Disable Popup Maker occasionally showing random tips to improve your popups.', 'popup-maker' ),
  454. ),
  455. 'complete_uninstall' => array(
  456. 'type' => 'checkbox',
  457. 'label' => __( 'Delete all Popup Maker data on deactivation', 'popup-maker' ),
  458. 'desc' => __( 'Check this to completely uninstall Popup Maker.', 'popup-maker' ),
  459. 'priority' => 1000,
  460. ),
  461. ),
  462. 'assets' => array(
  463. 'disable_google_font_loading' => array(
  464. 'type' => 'checkbox',
  465. 'label' => __( "Don't Load Google Fonts", 'popup-maker' ),
  466. 'desc' => __( 'Check this disable loading of google fonts, useful if the fonts you chose are already loaded with your theme.', 'popup-maker' ),
  467. ),
  468. 'disable_popup_maker_core_styles' => array(
  469. 'type' => 'checkbox',
  470. 'label' => __( 'Don\'t load Popup Maker core stylesheet.', 'popup-maker' ),
  471. 'desc' => __( 'Check this if you have copied the Popup Maker core styles to your own stylesheet or are using custom styles.', 'popup-maker' ),
  472. ),
  473. 'disable_popup_theme_styles' => array(
  474. 'type' => 'checkbox',
  475. 'label' => __( 'Don\'t load popup theme styles to the head.', 'popup-maker' ),
  476. 'desc' => __( 'Check this if you have copied the popup theme styles to your own stylesheet or are using custom styles.', 'popup-maker' ),
  477. ),
  478. 'output_pum_styles' => array(
  479. 'id' => 'output_pum_styles',
  480. 'type' => 'html',
  481. 'content' => self::field_pum_styles(),
  482. ),
  483. ),
  484. ),
  485. ) );
  486. $fields = apply_filters( 'pum_settings_fields', $fields );
  487. $fields = PUM_Admin_Helpers::parse_tab_fields( $fields, array(
  488. 'has_subtabs' => true,
  489. 'name' => 'pum_settings[%s]',
  490. ) );
  491. }
  492. return $fields;
  493. }
  494. /**
  495. * @return string
  496. */
  497. public static function field_pum_styles() {
  498. $core_styles = file_get_contents( Popup_Maker::$DIR . 'assets/css/pum-site' . (is_rtl() ? '-rtl' : '') . PUM_Site_Assets::$suffix . '.css' );
  499. $user_styles = PUM_AssetCache::generate_font_imports() . PUM_AssetCache::generate_popup_theme_styles() . PUM_AssetCache::generate_popup_styles();
  500. ob_start();
  501. ?>
  502. <button type="button" id="show_pum_styles" onclick="jQuery('#pum_style_output').slideDown();jQuery(this).hide();"><?php _e( 'Show Popup Maker CSS', 'popup-maker' ); ?></button>
  503. <p class="pum-desc desc"><?php __( "Use this to quickly copy Popup Maker's CSS to your own stylesheet.", 'popup-maker' ); ?></p>
  504. <div id="pum_style_output" style="display:none;">
  505. <label for="pum_core_styles"><?php _e( 'Core Styles', 'popup-maker' ); ?></label> <br />
  506. <textarea id="pum_core_styles" wrap="off" style="white-space: pre; width: 100%;" readonly="readonly"><?php echo $core_styles; ?></textarea>
  507. <br /> <br />
  508. <label for="pum_generated_styles"><?php _e( 'Generated Popup & Popup Theme Styles', 'popup-maker' ); ?></label> <br />
  509. <textarea id="pum_generated_styles" wrap="off" style="white-space: pre; width: 100%; min-height: 200px;" readonly="readonly"><?php echo $user_styles; ?></textarea>
  510. </div>
  511. <?php
  512. return ob_get_clean();
  513. }
  514. /**
  515. * @return array
  516. */
  517. public static function user_role_options() {
  518. global $wp_roles;
  519. $options = array();
  520. foreach ( $wp_roles->roles as $role => $labels ) {
  521. $options[ $role ] = $labels['name'];
  522. }
  523. return $options;
  524. }
  525. /**
  526. * Render settings page with tabs.
  527. */
  528. public static function page() {
  529. $settings = PUM_Utils_Options::get_all();
  530. if ( empty( $settings ) ) {
  531. $settings = self::defaults();
  532. }
  533. ?>
  534. <div class="wrap">
  535. <form id="pum-settings" method="post" action="">
  536. <?php wp_nonce_field( basename( __FILE__ ), 'pum_settings_nonce' ); ?>
  537. <h1><?php _e( 'Popup Maker Settings', 'popup-maker' ); ?></h1>
  538. <div id="pum-settings-container" class="pum-settings-container">
  539. <div class="pum-no-js" style="padding: 0 12px;">
  540. <p><?php printf( __( 'If you are seeing this, the page is still loading or there are Javascript errors on this page. %sView troubleshooting guide%s', 'popup-maker' ), '<a href="https://docs.wppopupmaker.com/article/373-checking-for-javascript-errors" target="_blank">', '</a>' ); ?></p>
  541. </div>
  542. </div>
  543. <script type="text/javascript">
  544. window.pum_settings_editor = <?php echo PUM_Utils_Array::safe_json_encode( apply_filters( 'pum_settings_editor_args', array(
  545. 'form_args' => array(
  546. 'id' => 'pum-settings',
  547. 'tabs' => self::tabs(),
  548. 'sections' => self::sections(),
  549. 'fields' => self::fields(),
  550. 'maintabs' => array(
  551. 'meta' => array(
  552. 'data-min-height' => 0,
  553. ),
  554. ),
  555. ),
  556. 'active_tab' => self::get_active_tab(),
  557. 'active_section' => self::get_active_section(),
  558. 'current_values' => self::parse_values( $settings ),
  559. ) ) ); ?>;
  560. </script>
  561. <button class="button-primary bottom" style="margin-left: 156px;"><?php _e( 'Save', 'popup-maker' ); ?></button>
  562. </form>
  563. </div>
  564. <?php
  565. }
  566. /**
  567. * @return array
  568. */
  569. public static function defaults() {
  570. $tabs = self::fields();
  571. $defaults = array();
  572. foreach ( $tabs as $section_id => $fields ) {
  573. foreach ( $fields as $key => $field ) {
  574. $defaults[ $key ] = isset( $field['std'] ) ? $field['std'] : null;
  575. }
  576. }
  577. return $defaults;
  578. }
  579. /**
  580. * List of tabs & labels for the settings panel.
  581. *
  582. * @return array
  583. */
  584. public static function tabs() {
  585. static $tabs;
  586. if ( ! isset( $tabs ) ) {
  587. $tabs = apply_filters( 'pum_settings_tabs', array(
  588. 'general' => __( 'General', 'popup-maker' ),
  589. 'subscriptions' => __( 'Subscriptions', 'popup-maker' ),
  590. 'extensions' => __( 'Extensions', 'popup-maker' ),
  591. 'licenses' => __( 'Licenses', 'popup-maker' ),
  592. 'privacy' => __( 'Privacy', 'popup-maker' ),
  593. 'misc' => __( 'Misc', 'popup-maker' ),
  594. ) );
  595. /** @deprecated 1.7.0 */
  596. $tabs = apply_filters( 'popmake_settings_tabs', $tabs );
  597. }
  598. return $tabs;
  599. }
  600. /**
  601. * List of tabs & labels for the settings panel.
  602. *
  603. * @return array
  604. */
  605. public static function sections() {
  606. return apply_filters( 'pum_settings_tab_sections', array(
  607. 'general' => array(
  608. 'main' => __( 'General', 'popup-maker' ),
  609. ),
  610. 'subscriptions' => array(
  611. 'main' => __( 'General', 'popup-maker' ),
  612. ),
  613. 'extensions' => array(
  614. 'main' => __( 'Extension Settings', 'popup-maker' ),
  615. ),
  616. 'licenses' => array(
  617. 'main' => __( 'Licenses', 'popup-maker' ),
  618. ),
  619. 'privacy' => array(
  620. 'main' => __( 'General', 'popup-maker' ),
  621. 'forms' => __( 'Subscription Forms', 'popup-maker' ),
  622. ),
  623. 'misc' => array(
  624. 'main' => __( 'Misc', 'popup-maker' ),
  625. 'assets' => __( 'Assets', 'popup-maker' ),
  626. ),
  627. ) );
  628. }
  629. /**
  630. * @return int|null|string
  631. */
  632. public static function get_active_tab() {
  633. $tabs = self::tabs();
  634. return isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $tabs ) ? sanitize_text_field( $_GET['tab'] ) : key( $tabs );
  635. }
  636. /**
  637. * @return bool|int|null|string
  638. */
  639. public static function get_active_section() {
  640. $active_tab = self::get_active_tab();
  641. $sections = self::sections();
  642. $tab_sections = ! empty( $sections[ $active_tab ] ) ? $sections[ $active_tab ] : false;
  643. if ( ! $tab_sections ) {
  644. return false;
  645. }
  646. return isset( $_GET['section'] ) && array_key_exists( $_GET['section'], $tab_sections ) ? sanitize_text_field( $_GET['section'] ) : key( $tab_sections );
  647. }
  648. /**
  649. * Parse values for form rendering.
  650. *
  651. * Add additional data for license_key fields, split the measure fields etc.
  652. *
  653. * @param $settings
  654. *
  655. * @return mixed
  656. */
  657. public static function parse_values( $settings ) {
  658. foreach ( $settings as $key => $value ) {
  659. $field = self::get_field( $key );
  660. if ( $field ) {
  661. /**
  662. * Process fields with specific types.
  663. */
  664. switch ( $field['type'] ) {
  665. case 'measure':
  666. break;
  667. case 'license_key':
  668. $license = get_option( $field['options']['is_valid_license_option'] );
  669. $settings[ $key ] = array(
  670. 'key' => trim( $value ),
  671. 'status' => PUM_Licensing::get_status( $license, ! empty( $value ) ),
  672. 'messages' => PUM_Licensing::get_status_messages( $license, trim( $value ) ),
  673. 'expires' => PUM_Licensing::get_license_expiration( $license ),
  674. 'classes' => PUM_Licensing::get_status_classes( $license ),
  675. );
  676. break;
  677. }
  678. /**
  679. * Process fields with specific ids.
  680. */
  681. switch ( $field['id'] ) {
  682. /*
  683. case 'pum_license_status':
  684. $settings[ $key ] = Licensing::get_status();
  685. break;
  686. */
  687. }
  688. }
  689. }
  690. return $settings;
  691. }
  692. /**
  693. *
  694. */
  695. public static function license_deactivated() {
  696. }
  697. /**
  698. * @param array $meta
  699. *
  700. * @return array
  701. */
  702. public static function sanitize_objects( $meta = array() ) {
  703. if ( ! empty( $meta ) ) {
  704. foreach ( $meta as $key => $value ) {
  705. if ( is_string( $value ) ) {
  706. try {
  707. $value = json_decode( stripslashes( $value ) );
  708. } catch ( Exception $e ) {
  709. }
  710. }
  711. $meta[ $key ] = PUM_Admin_Helpers::object_to_array( $value );
  712. }
  713. }
  714. return $meta;
  715. }
  716. }