Нет описания

Subscribe.php 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. <?php
  2. /*******************************************************************************
  3. * Copyright (c) 2019, Code Atlantic LLC
  4. ******************************************************************************/
  5. if ( ! defined( 'ABSPATH' ) ) {
  6. exit;
  7. }
  8. /**
  9. * Class PUM_Shortcode_Subscribe
  10. */
  11. class PUM_Shortcode_Subscribe extends PUM_Shortcode {
  12. /**
  13. * @var int
  14. */
  15. public $version = 2;
  16. /**
  17. * @var bool
  18. */
  19. public $ajax_rendering = true;
  20. /**
  21. * The shortcode tag.
  22. *
  23. * @return string
  24. */
  25. public function tag() {
  26. return 'pum_sub_form';
  27. }
  28. /**
  29. * @return string
  30. */
  31. public function label() {
  32. return __( 'Subscription Form', 'popup-maker' );
  33. }
  34. /**
  35. * @return string
  36. */
  37. public function description() {
  38. return __( 'A customizable newsletter subscription form.', 'popup-maker' );
  39. }
  40. /**
  41. * @return array
  42. */
  43. public function post_types() {
  44. return array( 'page', 'post', 'popup' );
  45. }
  46. /**
  47. * @return array
  48. */
  49. public function tabs() {
  50. $tabs = array(
  51. 'general' => __( 'General', 'popup-maker' ),
  52. 'form' => __( 'Form', 'popup-maker' ),
  53. 'privacy' => __( 'Privacy', 'popup-maker' ),
  54. 'actions' => __( 'Actions', 'popup-maker' ),
  55. );
  56. // Deprecated filter
  57. $tabs = apply_filters( 'pum_sub_form_shortcode_sections', $tabs );
  58. $tabs = apply_filters( 'pum_sub_form_shortcode_tabs', $tabs );
  59. return $this->resort_provider_tabs( $tabs );
  60. }
  61. /**
  62. * @return array
  63. */
  64. public function subtabs() {
  65. $subtabs = apply_filters( 'pum_sub_form_shortcode_subtabs', array(
  66. 'general' => array(
  67. 'main' => __( 'General', 'popup-maker' ),
  68. ),
  69. 'privacy' => array(
  70. 'main' => __( 'General', 'popup-maker' ),
  71. ),
  72. 'form' => array(
  73. 'appearance' => __( 'Appearance', 'popup-maker' ),
  74. 'fields' => __( 'Fields', 'popup-maker' ),
  75. 'labels' => __( 'Labels', 'popup-maker' ),
  76. 'placeholders' => __( 'Placeholders', 'popup-maker' ),
  77. 'privacy' => __( 'Privacy', 'popup-maker' ),
  78. ),
  79. 'actions' => array(
  80. 'popup' => __( 'Popup', 'popup-maker' ),
  81. 'redirect' => __( 'Redirect', 'popup-maker' ),
  82. ),
  83. ) );
  84. return $this->resort_provider_tabs( $subtabs );
  85. }
  86. /**
  87. * @return array
  88. */
  89. public function fields() {
  90. $select_args = array();
  91. if ( isset( $_GET['post'] ) && is_int( (int) $_GET['post'] ) && isset( $_GET['action'] ) && $_GET['action'] == 'edit' ) {
  92. $select_args['post__not_in'] = wp_parse_id_list( array( get_the_ID(), $_GET['post'] ) );
  93. }
  94. $privacy_always_enabled = pum_get_option( 'privacy_consent_always_enabled', 'no' ) == 'yes';
  95. $privacy_enabled_dependency = array(
  96. 'privacy_consent_enabled' => 'yes',
  97. );
  98. $fields = apply_filters( 'pum_sub_form_shortcode_fields', array(
  99. 'general' => array(
  100. 'main' => array(
  101. 'provider' => array(
  102. 'label' => __( 'Service Provider', 'popup-maker' ),
  103. 'desc' => __( 'Choose which service provider to submit to.', 'popup-maker' ),
  104. 'type' => 'select',
  105. 'options' => array_merge( array( '' => __( 'Default', 'popup-maker' ) ), PUM_Newsletter_Providers::dropdown_list(), array( 'none' => __( 'None', 'popup-maker' ) ) ),
  106. 'std' => '',
  107. ),
  108. ),
  109. ),
  110. 'form' => array(
  111. 'fields' => array(
  112. 'name_field_type' => array(
  113. 'label' => __( 'Name Field Type', 'popup-maker' ),
  114. 'type' => 'select',
  115. 'options' => array(
  116. 'disabled' => __( 'None', 'popup-maker' ),
  117. 'fullname' => __( 'Full', 'popup-maker' ),
  118. 'first_only' => __( 'First Only', 'popup-maker' ),
  119. 'first_last' => __( 'First & Last', 'popup-maker' ),
  120. ),
  121. 'std' => 'fullname',
  122. 'private' => true,
  123. ),
  124. 'name_optional' => array(
  125. 'label' => __( 'Name Optional', 'popup-maker' ),
  126. 'desc' => __( 'Makes the name field optional.', 'popup-maker' ),
  127. 'type' => 'checkbox',
  128. 'dependencies' => array(
  129. 'name_field_type' => array( 'fullname', 'first_only', 'first_last' ),
  130. ),
  131. 'private' => true,
  132. ),
  133. 'name_disabled' => array(
  134. 'label' => __( 'Name Disabled', 'popup-maker' ),
  135. 'desc' => __( 'Removes the name field.', 'popup-maker' ),
  136. 'type' => 'checkbox',
  137. 'dependencies' => array(
  138. 'name_field_type' => false,
  139. ),
  140. 'private' => true,
  141. ),
  142. ),
  143. 'labels' => array(
  144. 'disable_labels' => array(
  145. 'label' => __( 'Disable Labels', 'popup-maker' ),
  146. 'desc' => __( 'Disables the display of field labels.', 'popup-maker' ),
  147. 'type' => 'checkbox',
  148. 'private' => true,
  149. ),
  150. 'heading_labels' => array(
  151. 'label' => __( 'Labels', 'popup-maker' ),
  152. 'desc' => __( 'Field label text', 'popup-maker' ),
  153. 'type' => 'heading',
  154. 'private' => true,
  155. ),
  156. 'label_name' => array(
  157. 'label' => __( 'Full Name', 'popup-maker' ),
  158. 'dependencies' => array(
  159. 'disable_labels' => false,
  160. 'name_field_type' => array( 'fullname' ),
  161. ),
  162. 'std' => __( 'Name', 'popup-maker' ),
  163. 'private' => true,
  164. ),
  165. 'label_fname' => array(
  166. 'label' => __( 'First Name', 'popup-maker' ),
  167. 'dependencies' => array(
  168. 'disable_labels' => false,
  169. 'name_field_type' => array( 'first_only', 'first_last' ),
  170. ),
  171. 'std' => __( 'First Name', 'popup-maker' ),
  172. 'private' => true,
  173. ),
  174. 'label_lname' => array(
  175. 'label' => __( 'Last Name', 'popup-maker' ),
  176. 'dependencies' => array(
  177. 'disable_labels' => false,
  178. 'name_field_type' => array( 'first_last' ),
  179. ),
  180. 'std' => __( 'Last Name', 'popup-maker' ),
  181. 'private' => true,
  182. ),
  183. 'label_email' => array(
  184. 'label' => __( 'Email', 'popup-maker' ),
  185. 'dependencies' => array(
  186. 'disable_labels' => false,
  187. ),
  188. 'std' => __( 'Email', 'popup-maker' ),
  189. 'private' => true,
  190. ),
  191. 'label_submit' => array(
  192. 'label' => __( 'Submit Button', 'popup-maker' ),
  193. 'std' => __( 'Subscribe', 'popup-maker' ),
  194. 'private' => true,
  195. ),
  196. // Deprecated fields.
  197. 'name_text' => array(
  198. 'type' => 'hidden',
  199. 'private' => true,
  200. ),
  201. 'email_text' => array(
  202. 'private' => true,
  203. 'type' => 'hidden',
  204. ),
  205. 'button_text' => array(
  206. 'type' => 'hidden',
  207. 'private' => true,
  208. ),
  209. ),
  210. 'placeholders' => array(
  211. 'placeholder_name' => array(
  212. 'label' => __( 'Full Name', 'popup-maker' ),
  213. 'dependencies' => array(
  214. 'name_field_type' => array( 'fullname' ),
  215. ),
  216. 'std' => __( 'Name', 'popup-maker' ),
  217. 'private' => true,
  218. ),
  219. 'placeholder_fname' => array(
  220. 'label' => __( 'First Name', 'popup-maker' ),
  221. 'dependencies' => array(
  222. 'name_field_type' => array( 'first_only', 'first_last' ),
  223. ),
  224. 'std' => __( 'First Name', 'popup-maker' ),
  225. 'private' => true,
  226. ),
  227. 'placeholder_lname' => array(
  228. 'label' => __( 'Last Name', 'popup-maker' ),
  229. 'dependencies' => array(
  230. 'name_field_type' => array( 'first_last' ),
  231. ),
  232. 'std' => __( 'Last Name', 'popup-maker' ),
  233. 'private' => true,
  234. ),
  235. 'placeholder_email' => array(
  236. 'label' => __( 'Email', 'popup-maker' ),
  237. 'std' => __( 'Email', 'popup-maker' ),
  238. 'private' => true,
  239. ),
  240. ),
  241. 'appearance' => array(
  242. 'form_layout' => array(
  243. 'label' => __( 'Form Layout', 'popup-maker' ),
  244. 'desc' => __( 'Choose a form layout.', 'popup-maker' ),
  245. 'type' => 'select',
  246. 'options' => array(
  247. 'block' => __( 'Block', 'popup-maker' ),
  248. 'inline' => __( 'Inline', 'popup-maker' ),
  249. ),
  250. 'std' => 'block',
  251. 'private' => true,
  252. ),
  253. 'form_alignment' => array(
  254. 'label' => __( 'Form Alignment', 'popup-maker' ),
  255. 'desc' => __( 'Choose a form alignment.', 'popup-maker' ),
  256. 'type' => 'select',
  257. 'options' => array(
  258. 'left' => __( 'Left', 'popup-maker' ),
  259. 'center' => __( 'Center', 'popup-maker' ),
  260. 'right' => __( 'Right', 'popup-maker' ),
  261. ),
  262. 'std' => 'center',
  263. 'private' => true,
  264. ),
  265. 'form_style' => array(
  266. 'label' => __( 'Form Style', 'popup-maker' ),
  267. 'desc' => __( 'Choose how you want your form styled.', 'popup-maker' ),
  268. 'type' => 'select',
  269. 'options' => array(
  270. '' => __( 'None', 'popup-maker' ),
  271. 'default' => __( 'Default', 'popup-maker' ),
  272. ),
  273. 'std' => 'default',
  274. ),
  275. 'layout' => array(
  276. 'type' => 'hidden',
  277. 'private' => true,
  278. ),
  279. 'style' => array(
  280. 'type' => 'hidden',
  281. 'private' => true,
  282. ),
  283. ),
  284. ),
  285. 'privacy' => array(
  286. 'main' => array(
  287. 'privacy_consent_enabled' => array(
  288. 'label' => __( 'Enabled', 'popup-maker' ),
  289. 'desc' => __( 'When enabled, the successful completion will result in normal success actions, but if they do not opt-in no records will be made.', 'popup-maker' ),
  290. 'type' => $privacy_always_enabled ? 'hidden' : 'select',
  291. 'options' => array(
  292. 'yes' => __( 'Yes', 'popup-maker' ),
  293. 'no' => __( 'No', 'popup-maker' ),
  294. ),
  295. 'std' => 'yes',
  296. 'value' => $privacy_always_enabled ? 'yes' : null,
  297. 'private' => true,
  298. ),
  299. 'privacy_consent_label' => array(
  300. 'label' => __( 'Consent Field Label', 'popup-maker' ),
  301. 'type' => 'text',
  302. 'std' => pum_get_option( 'default_privacy_consent_label', __( 'Notify me about related content and special offers.', 'popup-maker' ) ),
  303. 'private' => true,
  304. 'dependencies' => $privacy_enabled_dependency,
  305. ),
  306. 'privacy_consent_required' => array(
  307. 'label' => __( 'Consent Required', 'popup-maker' ),
  308. 'desc' => __( 'Note: Requiring consent may not be compliant with GDPR for all situations. Be sure to do your research or check with legal council.', 'popup-maker' ),
  309. 'type' => 'checkbox',
  310. 'std' => pum_get_option( 'default_privacy_consent_required' ),
  311. 'private' => true,
  312. 'dependencies' => $privacy_enabled_dependency,
  313. ),
  314. 'privacy_consent_type' => array(
  315. 'label' => __( 'Field Type', 'popup-maker' ),
  316. 'desc' => __( 'Radio forces the user to make a choice, often resulting in more optins.', 'popup-maker' ),
  317. 'type' => 'select',
  318. 'options' => array(
  319. 'radio' => __( 'Radio', 'popup-maker' ),
  320. 'checkbox' => __( 'Checkbox', 'popup-maker' ),
  321. ),
  322. 'std' => pum_get_option( 'default_privacy_consent_type', 'radio' ),
  323. 'private' => true,
  324. 'dependencies' => $privacy_enabled_dependency,
  325. ),
  326. 'privacy_consent_radio_layout' => array(
  327. 'label' => __( 'Consent Radio Layout', 'popup-maker' ),
  328. 'type' => 'select',
  329. 'options' => array(
  330. 'inline' => __( 'Inline', 'popup-maker' ),
  331. 'stacked' => __( 'Stacked', 'popup-maker' ),
  332. ),
  333. 'std' => pum_get_option( 'default_privacy_consent_radio_layout', 'inline' ),
  334. 'private' => true,
  335. 'dependencies' => array_merge( $privacy_enabled_dependency, array(
  336. 'privacy_consent_type' => 'radio',
  337. ) ),
  338. ),
  339. 'privacy_consent_yes_label' => array(
  340. 'label' => __( 'Consent Yes Label', 'popup-maker' ),
  341. 'type' => 'text',
  342. 'std' => pum_get_option( 'default_privacy_consent_yes_label', __( 'Yes', 'popup-maker' ) ),
  343. 'private' => true,
  344. 'dependencies' => array_merge( $privacy_enabled_dependency, array(
  345. 'privacy_consent_type' => 'radio',
  346. ) ),
  347. ),
  348. 'privacy_consent_no_label' => array(
  349. 'label' => __( 'Consent No Label', 'popup-maker' ),
  350. 'type' => 'text',
  351. 'std' => pum_get_option( 'default_privacy_consent_no_label', __( 'No', 'popup-maker' ) ),
  352. 'private' => true,
  353. 'dependencies' => array_merge( $privacy_enabled_dependency, array(
  354. 'privacy_consent_type' => 'radio',
  355. ) ),
  356. ),
  357. 'privacy_usage_text' => array(
  358. 'label' => __( 'Consent Usage Text', 'popup-maker' ),
  359. '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', '}}' ) : '',
  360. 'type' => 'text',
  361. 'std' => pum_get_option( 'default_privacy_usage_text', __( 'If you opt in above we use this information send related content, discounts and other special offers.', 'popup-maker' ) ),
  362. 'dependencies' => $privacy_enabled_dependency,
  363. ),
  364. ),
  365. ),
  366. 'actions' => array(
  367. 'popup' => array(
  368. 'closepopup' => array(
  369. 'label' => __( 'Close Popup', 'popup-maker' ),
  370. 'type' => 'checkbox',
  371. ),
  372. 'closedelay' => array(
  373. 'label' => __( 'Delay', 'popup-maker' ),
  374. 'type' => 'rangeslider',
  375. 'min' => 0,
  376. 'max' => 180,
  377. 'step' => 1,
  378. 'unit' => 's',
  379. 'std' => 0,
  380. 'dependencies' => array(
  381. 'closepopup' => true,
  382. ),
  383. ),
  384. 'openpopup' => array(
  385. 'label' => __( 'Open Popup', 'popup-maker' ),
  386. 'type' => 'checkbox',
  387. ),
  388. 'openpopup_id' => array(
  389. 'label' => __( 'Popup ID', 'popup-maker' ),
  390. 'type' => 'select',
  391. 'options' => array(
  392. 0 => __( 'Select a popup', 'popup-maker' ),
  393. ) + PUM_Helpers::popup_selectlist( $select_args ),
  394. 'std' => 0,
  395. 'dependencies' => array(
  396. 'openpopup' => true,
  397. ),
  398. ),
  399. ),
  400. 'redirect' => array(
  401. 'redirect_enabled' => array(
  402. 'label' => __( 'Redirect', 'popup-maker' ),
  403. 'desc' => __( 'Enable refreshing the page or redirecting after success.', 'popup-maker' ),
  404. 'type' => 'checkbox',
  405. ),
  406. 'redirect' => array(
  407. 'label' => __( 'Redirect URL', 'popup-maker' ),
  408. 'desc' => __( 'Leave blank to refresh, or enter a url that users will be taken to after success.', 'popup-maker' ),
  409. 'std' => '',
  410. 'dependencies' => array(
  411. 'redirect_enabled' => true,
  412. ),
  413. ),
  414. ),
  415. ),
  416. ) );
  417. return $this->resort_provider_tabs( $fields );
  418. }
  419. /**
  420. * Sorts tabs so that providers come first.
  421. *
  422. * @param array $tabs
  423. *
  424. * @return array
  425. */
  426. public function resort_provider_tabs( $tabs = array() ) {
  427. $sorted_tabs = $tabs;
  428. foreach ( $tabs as $tab_id => $tab ) {
  429. if ( strpos( $tab_id, 'provider_' ) === 0 ) {
  430. PUM_Utils_Array::move_item( $sorted_tabs, $tab_id, 'down', 'general' );
  431. }
  432. }
  433. return $sorted_tabs;
  434. }
  435. /**
  436. * Shortcode handler
  437. *
  438. * @param array $atts shortcode attributes
  439. * @param string $content shortcode content
  440. *
  441. * @return string
  442. */
  443. public function handler( $atts, $content = null ) {
  444. $atts = $this->shortcode_atts( $atts );
  445. static $instance = 0;
  446. $instance ++;
  447. $atts['instance'] = $instance;
  448. ob_start();
  449. $data_attr = $this->data_attr( $atts );
  450. $classes = implode( ' ', array(
  451. 'pum_sub_form',
  452. $atts['provider'],
  453. $atts['form_layout'],
  454. $atts['form_style'],
  455. 'pum-sub-form',
  456. 'pum-form',
  457. 'pum-sub-form--provider-' . $atts['provider'],
  458. 'pum-form--layout-' . $atts['form_layout'],
  459. 'pum-form--style-' . $atts['form_style'],
  460. 'pum-form--alignment-' . $atts['form_alignment'],
  461. ) ); ?>
  462. <form class="<?php echo esc_attr( $classes ); ?>" data-settings="<?php echo esc_attr( PUM_Utils_Array::safe_json_encode( $data_attr ) ); ?>">
  463. <?php do_action( 'pum_sub_form_before', $atts ); ?>
  464. <?php
  465. if ( ! $atts['name_field_type'] != 'disabled' ) :
  466. $required = ! $atts['name_optional'] ? 'required' : '';
  467. switch ( $atts['name_field_type'] ) {
  468. case 'fullname': ?>
  469. <div class="pum-form__field pum-form__field--name pum-sub-form-field pum-sub-form-field--name">
  470. <?php if ( ! $atts['disable_labels'] ) : ?>
  471. <label class="pum-form__label pum-sub-form-label"><?php echo $atts['label_name']; ?></label>
  472. <?php endif; ?>
  473. <input type="text" name="name" <?php echo $required; ?> placeholder="<?php echo esc_attr( $atts['placeholder_name'] ); ?>" />
  474. </div>
  475. <?php
  476. break;
  477. case 'first_only': ?>
  478. <div class="pum-form__field pum-form__field--fname pum-sub-form-field pum-sub-form-field--fname">
  479. <?php if ( ! $atts['disable_labels'] ) : ?>
  480. <label class="pum-form__label pum-sub-form-label"><?php echo $atts['label_fname']; ?></label>
  481. <?php endif; ?>
  482. <input type="text" name="fname" <?php echo $required; ?> placeholder="<?php echo esc_attr( $atts['placeholder_fname'] ); ?>" />
  483. </div>
  484. <?php
  485. break;
  486. case 'first_last': ?>
  487. <div class="pum-form__field pum-form__field--fname pum-sub-form-field pum-sub-form-field--fname">
  488. <?php if ( ! $atts['disable_labels'] ) : ?>
  489. <label class="pum-form__label pum-sub-form-label"><?php echo $atts['label_fname']; ?></label>
  490. <?php endif; ?>
  491. <input type="text" name="fname" <?php echo $required; ?> placeholder="<?php echo esc_attr( $atts['placeholder_fname'] ); ?>" />
  492. </div>
  493. <div class="pum-form__field pum-form__field--lname pum-sub-form-field pum-sub-form-field--lname">
  494. <?php if ( ! $atts['disable_labels'] ) : ?>
  495. <label class="pum-form__label pum-sub-form-label"><?php echo $atts['label_lname']; ?></label>
  496. <?php endif; ?>
  497. <input type="text" name="lname" <?php echo $required; ?> placeholder="<?php echo esc_attr( $atts['placeholder_lname'] ); ?>" />
  498. </div>
  499. <?php
  500. break;
  501. } ?>
  502. <?php endif; ?>
  503. <div class="pum-form__field pum-form__field--email pum-sub-form-field pum-sub-form-field--email">
  504. <?php if ( ! $atts['disable_labels'] ) : ?>
  505. <label class="pum-form__label pum-sub-form-label"><?php echo $atts['label_email']; ?></label>
  506. <?php endif; ?>
  507. <input type="email" name="email" required placeholder="<?php echo esc_attr( $atts['placeholder_email'] ); ?>" />
  508. </div>
  509. <?php do_action( 'pum_sub_form_fields', $atts ); ?>
  510. <?php do_action( 'pum_newsletter_fields', $atts ); ?>
  511. <input type="hidden" name="provider" value="<?php echo $atts['provider']; ?>" />
  512. <?php if ( $atts['privacy_consent_enabled'] == 'yes' ) :
  513. $consent_text = trim( $atts['privacy_consent_label'] );
  514. $consent_args = array(
  515. 'enabled' => 'yes',
  516. 'required' => isset( $atts['privacy_consent_required'] ) && $atts['privacy_consent_required'],
  517. 'text' => ! empty( $consent_text ) ? $consent_text : ( ! empty( $atts['privacy_consent_yes_label'] ) ? $atts['privacy_consent_yes_label'] : '' ),
  518. );
  519. ?>
  520. <input type="hidden" name="consent_args" value="<?php echo esc_attr( PUM_Utils_Array::safe_json_encode( $consent_args ) ); ?>" />
  521. <div class="pum-form__field pum-form__field--<?php echo esc_attr( $atts['privacy_consent_type'] ); ?> pum-form__field--consent pum-sub-form-field">
  522. <?php switch ( $atts['privacy_consent_type'] ) {
  523. case 'checkbox': ?>
  524. <label class="pum-form__label pum-sub-form-label">
  525. <input type="checkbox" value="yes" name="consent" <?php echo $consent_args['required'] ? 'required="required"' : ''; ?> /> <?php echo wp_kses( $consent_text, array() ); ?>
  526. </label>
  527. <?php
  528. break;
  529. case 'radio': ?>
  530. <?php if ( ! empty( $consent_text ) ) : ?>
  531. <label class="pum-form__label pum-sub-form-label"><?php echo wp_kses( $consent_text, array() ); ?></label>
  532. <?php endif; ?>
  533. <div class="pum-form__consent-radios pum-form__consent-radios--<?php echo esc_attr( $atts['privacy_consent_radio_layout'] ); ?>">
  534. <label class="pum-form__label pum-sub-form-label">
  535. <input type="radio" value="yes" name="consent" <?php echo $consent_args['required'] ? 'required="required"' : ''; ?> /> <?php echo wp_kses( $atts['privacy_consent_yes_label'], array() ); ?>
  536. </label>
  537. <label class="pum-form__label pum-sub-form-label">
  538. <input type="radio" value="no" name="consent" /> <?php echo wp_kses( $atts['privacy_consent_no_label'], array() ); ?>
  539. </label>
  540. </div>
  541. <?php
  542. break;
  543. }
  544. if ( ! empty( $atts['privacy_usage_text'] ) ) :
  545. $usage_text = trim( $atts['privacy_usage_text'] );
  546. if ( strpos( $usage_text, '{{privacy_link' ) !== false && function_exists( 'get_privacy_policy_url' ) && get_privacy_policy_url() !== '' ) {
  547. preg_match_all( "/{{privacy_link:?(.*)}}/", $usage_text, $matches );
  548. $link = '<a href="' . get_privacy_policy_url() . '" target="_blank">%s</a>';
  549. foreach ( $matches[0] as $key => $value ) {
  550. $usage_text = str_replace( $matches[0][ $key ], sprintf( $link, $matches[1][ $key ] ), $usage_text );
  551. }
  552. }
  553. ?>
  554. <p>
  555. <small><?php echo wp_kses( $usage_text, array( 'a' => array( 'target' => true, 'href' => true ) ) ); ?></small>
  556. </p>
  557. <?php endif; ?>
  558. </div>
  559. <?php endif; ?>
  560. <div class="pum-form__field pum-form__field--submit pum-sub-form-field pum-sub-form-field--submit">
  561. <button class="pum-form__submit pum-sub-form-submit"><?php echo $atts['label_submit']; ?></button>
  562. </div>
  563. <?php do_action( 'pum_sub_form_after', $atts ); ?>
  564. </form>
  565. <?php
  566. //return content
  567. return ob_get_clean();
  568. }
  569. /**
  570. * Process shortcode attributes.
  571. *
  572. * Also remaps and cleans old ones.
  573. *
  574. * @param $atts
  575. *
  576. * @return array
  577. */
  578. public function shortcode_atts( $atts ) {
  579. $atts = parent::shortcode_atts( $atts );
  580. if ( empty( $atts['provider'] ) ) {
  581. $atts['provider'] = pum_get_option( 'newsletter_default_provider' );
  582. }
  583. // Remap old atts.
  584. if ( ! empty( $atts['layout'] ) ) {
  585. $atts['form_layout'] = $atts['layout'];
  586. }
  587. if ( ! empty( $atts['style'] ) ) {
  588. $atts['form_style'] = $atts['style'];
  589. }
  590. if ( ! empty( $atts['name_text'] ) ) {
  591. $atts['label_name'] = $atts['name_text'];
  592. }
  593. if ( ! empty( $atts['email_text'] ) ) {
  594. $atts['label_email'] = $atts['email_text'];
  595. }
  596. if ( ! empty( $atts['button_text'] ) ) {
  597. $atts['label_submit'] = $atts['button_text'];
  598. }
  599. unset( $atts['layout'], $atts['style'], $atts['name_text'], $atts['email_text'], $atts['button_text'] );
  600. /**
  601. * Remap v1.7 core shortcode attributes starting here.
  602. */
  603. if ( ! empty( $atts['name_disabled'] ) && $atts['name_disabled'] ) {
  604. $atts['name_field_type'] = 'disabled';
  605. }
  606. unset( $atts['name_disabled'] );
  607. return $atts;
  608. }
  609. /**
  610. * Returns array of fields & values that will be passed into data attr of the form.
  611. *
  612. * @param array $atts
  613. *
  614. * @return array
  615. */
  616. public function data_attr( $atts = array() ) {
  617. $data = array();
  618. $data_attr_fields = $this->data_attr_fields();
  619. foreach ( $atts as $key => $value ) {
  620. if ( in_array( $key, $data_attr_fields ) ) {
  621. $data[ $key ] = $value;
  622. if ( $key == 'redirect' ) {
  623. $data[ $key ] = base64_encode( $value );
  624. }
  625. }
  626. }
  627. return $data;
  628. }
  629. /**
  630. * Returns array of fields that will be passed into data attr of the form.
  631. *
  632. * @return mixed
  633. */
  634. public function data_attr_fields() {
  635. return apply_filters( 'pum_sub_form_data_attr_fields', array(
  636. 'closepopup',
  637. 'closedelay',
  638. 'openpopup',
  639. 'openpopup_id',
  640. 'redirect_enabled',
  641. 'redirect',
  642. ) );
  643. }
  644. /**
  645. *
  646. */
  647. public function template() { ?>
  648. <p class="pum-sub-form-desc">
  649. <?php _e( 'Subscription Form Placeholder', 'popup-maker' ); ?>
  650. </p>
  651. <?php
  652. }
  653. }