PluginProbe
Floating Button – Easily Create Sticky, Fixed & Floating Buttons / 6.1
Floating Button – Easily Create Sticky, Fixed & Floating Buttons v6.1
trunk 2.0.2 3.0 4.0 4.1.2 4.3 5.0 5.0.1 5.1 5.1.1 5.2 5.3 5.3.1 6.0 6.0.1 6.0.10 6.0.11 6.0.12 6.0.13 6.0.2 6.0.3 6.0.4 6.0.5 6.0.6 6.0.7 All 31 releases
floating-button / classes / Publisher / EnqueueScript.php

EnqueueScript.php in Floating Button – Easily Create Sticky, Fixed & Floating Buttons 6.1, at classes/Publisher/EnqueueScript.php

94 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 FloatingButton\Publisher;
4
5 defined( 'ABSPATH' ) || exit;
6
7 use FloatingButton\Dashboard\DBManager;
8 use FloatingButton\Optimization\Obfuscator;
9 use FloatingButton\WOW_Plugin;
10
11 class EnqueueScript {
12
13 /**
14 * @var mixed
15 */
16 private $id;
17 private $param;
18
19 public function __construct( $result ) {
20 $this->id = $result->id;
21 $this->param = maybe_unserialize( $result->param );
22 }
23
24 /**
25 * @throws \JsonException
26 */
27 public function init(): void {
28
29 $slug = WOW_Plugin::SLUG;
30 $version = WOW_Plugin::info( 'version' );
31 $asset = WOW_Plugin::url() . 'assets/';
32
33 $pre_suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
34
35 $url_script = $asset . 'js/script' . $pre_suffix . '.js';
36 wp_enqueue_script( $slug, $url_script, array( 'jquery' ), $version, true );
37
38 $inline_script = $this->inline();
39 wp_add_inline_script( $slug, $inline_script, 'before' );
40
41 wp_localize_script( $slug, 'wowp_flBtn', array(
42 'ajax_url' => admin_url( 'admin-ajax.php' ),
43 'nonce' => wp_create_nonce( '_wowp_likes' ),
44 ) );
45 }
46
47 /**
48 * @throws \JsonException
49 */
50 public function inline(): string {
51 $param = $this->param;
52
53 $arg = [
54 'element' => 'floatBtn-' . absint( $this->id ),
55 ];
56
57 if ( ! empty( $param['showAfterPosition'] ) ) {
58 $arg['showAfterPosition'] = (int) $param['showAfterPosition'];
59 }
60
61 if ( ! empty( $param['hideAfterPosition'] ) ) {
62 $arg['hideAfterPosition'] = (int) $param['hideAfterPosition'];
63 }
64
65 if ( ! empty( $param['showAfterTimer'] ) ) {
66 $arg['showAfterTimer'] = (int) $param['showAfterTimer'];
67 }
68
69 if ( ! empty( $param['hideAfterTimer'] ) ) {
70 $arg['hideAfterTimer'] = (int) $param['hideAfterTimer'];
71 }
72
73 if ( ! empty( $param['uncheckedBtn'] ) ) {
74 $arg['uncheckedBtn'] = true;
75 }
76
77 if ( ! empty( $param['uncheckedSubBtn'] ) ) {
78 $arg['uncheckedSubBtn'] = true;
79 }
80
81 if ( ! empty( $param['hideBtns'] ) ) {
82 $arg['hideBtns'] = true;
83 }
84
85 if ( is_singular() ) {
86 $arg['pageId'] = get_the_ID();
87 }
88
89 return 'var FloatingButton_' . absint( $this->id ) . ' = ' . wp_json_encode( $arg );
90
91 }
92
93
94 }