PluginProbe
Floating Button – Easily Create Sticky, Fixed & Floating Buttons / 6.0
Floating Button – Easily Create Sticky, Fixed & Floating Buttons v6.0
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.0, at classes/Publisher/EnqueueScript.php

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