Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/bdthemes-element-pack/modules/custom-js/module.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 +
3 + namespace ElementPack\Modules\CustomJs;
4 +
5 + use Elementor\Controls_Manager;
6 + use Elementor\Plugin;
7 + use ElementPack;
8 + use ElementPack\Base\Element_Pack_Module_Base;
9 +
10 + if ( !defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
11 +
12 + class Module extends Element_Pack_Module_Base {
13 +
14 + public function __construct() {
15 + parent::__construct();
16 + $this->add_actions();
17 + }
18 +
19 + public function get_name() {
20 + return 'bdt-custom-js';
21 + }
22 +
23 + public function register_controls($section, $section_id) {
24 +
25 + static $layout_sections = ['section_page_style'];
26 +
27 + if ( !in_array( $section_id, $layout_sections ) ) {
28 + return;
29 + }
30 +
31 + $section->start_controls_section(
32 + 'element_pack_custom_js_section',
33 + [
34 + 'tab' => Controls_Manager::TAB_ADVANCED,
35 + 'label' => BDTEP_CP . esc_html__( 'Custom CSS / JS', 'bdthemes-element-pack' ),
36 + ]
37 + );
38 +
39 + $section->add_control(
40 + 'ep_custom_header_script',
41 + [
42 + // translators: %1s and %2s are opening and closing <b> HTML tags used for bolding the word "Header".
43 + 'label' => sprintf(__('%1s Header %2s CSS/Script', 'bdthemes-element-pack'), '<b>', '</b>'),
44 + // translators: %1s is the <script> tag, %2s is the <style> tag, both written as HTML entities for display.
45 + 'description' => sprintf(__('Please write down your custom js script or CSS style on appropriate field as per your need. add %1s tag for javascript or %2s tag for CSS here.', 'bdthemes-element-pack'), '&#x3C;script&#x3E;', '&#x3C;style&#x3E;'),
46 + 'type' => Controls_Manager::CODE,
47 + //'language' => 'js',
48 + 'render_type' => 'ui',
49 + 'separator' => 'none',
50 + ]
51 + );
52 +
53 + $section->add_control(
54 + 'ep_custom_footer_script',
55 + [
56 + // translators: %1s and %2s are opening and closing <b> HTML tags used for bolding the word "Footer".
57 + 'label' => sprintf(__('%1s Footer %2s CSS/Script', 'bdthemes-element-pack'), '<b>', '</b>'),
58 + // translators: %1s is the <script> tag, %2s is the <style> tag, both written as HTML entities for display.
59 + 'description' => sprintf(__('Please write down your custom js script or CSS style on appropriate field as per your need. add %1s tag for javascript or %2s tag for CSS here.', 'bdthemes-element-pack'), '&#x3C;script&#x3E;', '&#x3C;style&#x3E;'),
60 + 'type' => Controls_Manager::CODE,
61 + //'language' => 'js',
62 + 'render_type' => 'ui',
63 + 'separator' => 'none',
64 + ]
65 + );
66 +
67 + $section->end_controls_section();
68 +
69 + }
70 +
71 + public function header_script_render() {
72 +
73 + if ( Plugin::instance()->editor->is_edit_mode() || Plugin::instance()->preview->is_preview_mode() ) {
74 + return;
75 + }
76 +
77 + $document = Plugin::instance()->documents->get( get_the_ID() );
78 +
79 + if ( !$document ) {
80 + return;
81 + }
82 +
83 + $custom_js = $document->get_settings( 'ep_custom_header_script' );
84 +
85 + if ( empty( $custom_js ) ) {
86 + return;
87 + }
88 +
89 + ?>
90 +
91 + <?php echo $custom_js; ?>
92 +
93 + <?php
94 +
95 + }
96 +
97 + public function footer_script_render() {
98 +
99 + if ( Plugin::instance()->editor->is_edit_mode() || Plugin::instance()->preview->is_preview_mode() ) {
100 + return;
101 + }
102 +
103 + $document = Plugin::instance()->documents->get( get_the_ID() );
104 +
105 + if ( !$document ) {
106 + return;
107 + }
108 +
109 + $custom_js = $document->get_settings( 'ep_custom_footer_script' );
110 +
111 + if ( empty( $custom_js ) ) {
112 + return;
113 + }
114 +
115 + ?>
116 +
117 + <?php echo $custom_js; ?>
118 +
119 + <?php
120 +
121 + }
122 +
123 +
124 + protected function add_actions() {
125 +
126 + add_action( 'elementor/element/after_section_end', [$this, 'register_controls'], 10, 2 );
127 + add_action( 'wp_head', [$this, 'header_script_render'], 999 );
128 + add_action( 'wp_footer', [$this, 'footer_script_render'], 999 );
129 +
130 + }
131 +
132 +
133 + }
134 +