| 1 |
<?php |
| 2 |
|
| 3 |
namespace FloatingButton; |
| 4 |
|
| 5 |
defined( 'ABSPATH' ) || exit; |
| 6 |
|
| 7 |
use FloatingButton\Dashboard\DBManager; |
| 8 |
use FloatingButton\Publisher\Conditions; |
| 9 |
use FloatingButton\Publisher\Display; |
| 10 |
use FloatingButton\Publisher\EnqueueScript; |
| 11 |
use FloatingButton\Publisher\EnqueueStyle; |
| 12 |
use FloatingButton\Publisher\PageTemplate; |
| 13 |
use FloatingButton\Publisher\Shortcodes; |
| 14 |
use FloatingButton\Publisher\Singleton; |
| 15 |
|
| 16 |
class WOWP_Public { |
| 17 |
|
| 18 |
public function __construct() { |
| 19 |
|
| 20 |
add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_styles' ], 50 ); |
| 21 |
add_action( 'wp_footer', [ $this, 'display' ], 50 ); |
| 22 |
add_shortcode( WOW_Plugin::SHORTCODE, [ $this, 'shortcode' ] ); |
| 23 |
$this->includes(); |
| 24 |
|
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
public function enqueue_styles(): void { |
| 29 |
$display = Display::init(); |
| 30 |
foreach ( $display as $id => $result ) { |
| 31 |
$style = new EnqueueStyle($result); |
| 32 |
$style->init(); |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
public function includes(): void { |
| 37 |
require_once 'class-menu-maker.php'; |
| 38 |
} |
| 39 |
|
| 40 |
public function display(): void { |
| 41 |
|
| 42 |
$singleton = Singleton::getInstance(); |
| 43 |
$shortcodes = $singleton->getValue(); |
| 44 |
$display = Display::init(); |
| 45 |
|
| 46 |
foreach ( $display as $id => $result ) { |
| 47 |
if ( array_key_exists( $id, $shortcodes ) ) { |
| 48 |
continue; |
| 49 |
} |
| 50 |
|
| 51 |
echo do_shortcode( '[' . esc_attr( WOW_Plugin::SHORTCODE ) . ' id=' . absint( $id ) . ']' ); |
| 52 |
|
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
public function shortcode( $atts ) { |
| 57 |
|
| 58 |
$atts = shortcode_atts( |
| 59 |
[ 'id' => "" ], |
| 60 |
$atts, |
| 61 |
WOW_Plugin::SHORTCODE |
| 62 |
); |
| 63 |
|
| 64 |
if ( ! empty( $atts['id'] ) ) { |
| 65 |
$result = DBManager::get_data_by_id( $atts['id'] ); |
| 66 |
} else { |
| 67 |
return false; |
| 68 |
} |
| 69 |
|
| 70 |
if ( empty( $result ) ) { |
| 71 |
return false; |
| 72 |
} |
| 73 |
|
| 74 |
$param = maybe_unserialize( $result->param ); |
| 75 |
$walker = new Menu_Maker( $atts['id'], $param, $result->title ); |
| 76 |
$menu = $walker->init(); |
| 77 |
|
| 78 |
$style = new EnqueueStyle($result); |
| 79 |
$style->init(); |
| 80 |
|
| 81 |
$singleton = Singleton::getInstance(); |
| 82 |
$singleton->setValue( $result->id, $result ); |
| 83 |
|
| 84 |
return $menu; |
| 85 |
|
| 86 |
} |
| 87 |
|
| 88 |
} |