PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / trunk
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress vtrunk
11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 10.3.0 10.4.0 All 60 releases
acymailing / WpInit / Forms.php

Forms.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress trunk, at WpInit/Forms.php

82 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AcyMailing\WpInit;
4
5 defined('ABSPATH') || die('Restricted Access');
6
7 use AcyMailing\Classes\FormClass;
8
9 class Forms
10 {
11 private array $formToDisplay = [];
12
13 public function __construct()
14 {
15 $isPreview = acym_getVar('bool', 'acym_preview', false);
16 if ($isPreview) return;
17
18 if (acym_level(ACYM_ENTERPRISE)) {
19 add_action('wp_head', [$this, 'prepareFormsToDisplay']);
20 add_action('wp_footer', [$this, 'displayForms']);
21 }
22 $this->registerShortcodes();
23 }
24
25 public function prepareFormsToDisplay()
26 {
27 $formClass = new FormClass();
28 $forms = $formClass->getAllFormsToDisplay();
29
30 if (empty($forms)) return;
31
32 $menu = acym_getMenu();
33 if (empty($menu)) return;
34
35 foreach ($forms as $form) {
36 if (!empty($form->pages) && (in_array($menu->ID, $form->pages) || in_array('all', $form->pages))) {
37 $this->formToDisplay[] = $formClass->renderForm($form);
38 }
39 }
40
41 if (!empty($this->formToDisplay)) {
42 acym_initModule();
43 }
44 }
45
46 public function displayForms()
47 {
48 if (empty($this->formToDisplay)) {
49 return;
50 }
51
52 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Generated in partial folder "forms", escaped there.
53 echo implode('', $this->formToDisplay);
54 }
55
56 public function registerShortcodes()
57 {
58 add_shortcode('acymailing_form_shortcode', [$this, 'replaceShortcode']);
59 }
60
61 public function replaceShortcode($params)
62 {
63 extract(
64 shortcode_atts(
65 [
66 'id' => 0,
67 ],
68 $params
69 )
70 );
71
72 if (empty($params['id'])) return;
73
74 $formClass = new FormClass();
75 $form = $formClass->getOneById($params['id']);
76
77 if (empty($form->active)) return;
78
79 return $formClass->renderForm($form, false, true);
80 }
81 }
82