| 1 |
<?php |
| 2 |
|
| 3 |
namespace Getwid\Blocks; |
| 4 |
|
| 5 |
class Toggle extends \Getwid\Blocks\AbstractBlock { |
| 6 |
|
| 7 |
protected static $blockName = 'getwid/toggle'; |
| 8 |
|
| 9 |
public function __construct() { |
| 10 |
|
| 11 |
parent::__construct( self::$blockName ); |
| 12 |
|
| 13 |
register_block_type( |
| 14 |
'getwid/toggle', |
| 15 |
array( |
| 16 |
'render_callback' => [ $this, 'render_callback' ] |
| 17 |
) |
| 18 |
); |
| 19 |
|
| 20 |
if ( $this->isEnabled() ) { |
| 21 |
|
| 22 |
add_filter( 'getwid/editor_blocks_js/dependencies', [ $this, 'block_editor_scripts'] ); |
| 23 |
add_filter( 'getwid/blocks_style_css/dependencies', [ $this, 'block_frontend_styles' ] ); |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
public function getLabel() { |
| 28 |
return __('Toggle', 'getwid'); |
| 29 |
} |
| 30 |
|
| 31 |
public function block_editor_scripts($scripts) { |
| 32 |
|
| 33 |
return $scripts; |
| 34 |
} |
| 35 |
|
| 36 |
public function block_frontend_styles($styles) { |
| 37 |
|
| 38 |
//fontawesome |
| 39 |
$styles = getwid()->fontIconsManager()->enqueueFonts( $styles ); |
| 40 |
|
| 41 |
return $styles; |
| 42 |
} |
| 43 |
|
| 44 |
public function block_frontend_assets() { |
| 45 |
|
| 46 |
if ( is_admin() ) { |
| 47 |
return; |
| 48 |
} |
| 49 |
|
| 50 |
if ( FALSE == getwid()->assetsOptimization()->load_assets_on_demand() ) { |
| 51 |
return; |
| 52 |
} |
| 53 |
|
| 54 |
//fontawesome |
| 55 |
$deps = getwid()->fontIconsManager()->enqueueFonts( [] ); |
| 56 |
|
| 57 |
$rtl = is_rtl() ? '.rtl' : ''; |
| 58 |
|
| 59 |
wp_enqueue_style( |
| 60 |
self::$blockName, |
| 61 |
getwid_get_plugin_url( 'assets/blocks/toggle/style' . $rtl . '.css' ), |
| 62 |
$deps, |
| 63 |
getwid()->settings()->getVersion() |
| 64 |
); |
| 65 |
|
| 66 |
wp_enqueue_script( |
| 67 |
self::$blockName, |
| 68 |
getwid_get_plugin_url( 'assets/blocks/toggle/frontend.js' ), |
| 69 |
[ 'jquery' ], |
| 70 |
getwid()->settings()->getVersion(), |
| 71 |
true |
| 72 |
); |
| 73 |
|
| 74 |
} |
| 75 |
|
| 76 |
public function render_callback( $attributes, $content ) { |
| 77 |
|
| 78 |
$this->block_frontend_assets(); |
| 79 |
|
| 80 |
return $content; |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
getwid()->blocksManager()->addBlock( |
| 85 |
new \Getwid\Blocks\Toggle() |
| 86 |
); |
| 87 |
|