PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.1.4
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.1.4
11.1.1 11.1.0 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 All 62 releases
acymailing / WpInit / Forms.php

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

74 lines 1.7 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 use AcyMailing\Classes\FormClass;
6
7 class Forms
8 {
9 var $formToDisplay = [];
10 var $formClass;
11
12 public function __construct()
13 {
14 $isPreview = acym_getVar('bool', 'acym_preview', false);
15 if ($isPreview) return;
16
17 add_action('wp_head', [$this, 'prepareFormsToDisplay']);
18 add_action('wp_footer', [$this, 'displayForms']);
19 $this->registerShortcodes();
20 }
21
22 public function prepareFormsToDisplay()
23 {
24 $formClass = new FormClass();
25 $forms = $formClass->getAllFormsToDisplay();
26
27 if (empty($forms)) return;
28
29 $menu = acym_getMenu();
30 if (empty($menu)) return;
31
32 foreach ($forms as $form) {
33 if (!empty($form->pages) && (in_array($menu->ID, $form->pages) || in_array('all', $form->pages))) {
34 $this->formToDisplay[] = $formClass->renderForm($form);
35 }
36 }
37
38 if (!empty($this->formToDisplay)) acym_initModule();
39 }
40
41 public function displayForms()
42 {
43 if (empty($this->formToDisplay)) return;
44
45 echo implode('', $this->formToDisplay);
46 }
47
48 public function registerShortcodes()
49 {
50 add_shortcode('acymailing_form_shortcode', [$this, 'replaceShortcode']);
51 }
52
53 public function replaceShortcode($params)
54 {
55 extract(
56 shortcode_atts(
57 [
58 'id' => 0,
59 ],
60 $params
61 )
62 );
63
64 if (empty($params['id'])) return;
65
66 $formClass = new FormClass();
67 $form = $formClass->getOneById($params['id']);
68
69 if (empty($form) || empty($form->active)) return;
70
71 return $formClass->renderForm($form, false, true);
72 }
73 }
74