| @@ -1,111 +1,23 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -namespace Getwid\Blocks; | |
| 4 | - | |
| 5 | -class Icon extends \Getwid\Blocks\AbstractBlock { | |
| 6 | - | |
| 7 | - protected static $blockName = 'getwid/icon'; | |
| 8 | - | |
| 9 | - public function __construct() { | |
| 10 | - | |
| 11 | - parent::__construct( self::$blockName ); | |
| 12 | - | |
| 13 | - register_block_type( | |
| 14 | - 'getwid/icon', | |
| 15 | - array( | |
| 16 | - 'render_callback' => [ $this, 'render_callback' ] | |
| 17 | - ) | |
| 18 | - ); | |
| 19 | - | |
| 20 | - if ( $this->isEnabled() ) { | |
| 21 | - | |
| 22 | - add_filter( 'getwid/blocks_style_css/dependencies', [ $this, 'block_frontend_styles' ] ); | |
| 23 | - | |
| 24 | - //Register JS/CSS assets | |
| 25 | - wp_register_style( | |
| 26 | - 'animate', | |
| 27 | - getwid_get_plugin_url( 'vendors/animate.css/animate.min.css' ), | |
| 28 | - [], | |
| 29 | - '3.7.0' | |
| 30 | - ); | |
| 31 | - } | |
| 32 | - } | |
| 33 | - | |
| 34 | - public function getLabel() { | |
| 35 | - return __('Icon', 'getwid'); | |
| 36 | - } | |
| 37 | - | |
| 38 | - public function block_frontend_styles($styles) { | |
| 39 | - | |
| 40 | - //fontawesome | |
| 41 | - $styles = getwid()->fontIconsManager()->enqueueFonts( $styles ); | |
| 42 | - | |
| 43 | - //animate.min.css | |
| 44 | - if ( is_admin() && ! in_array( 'animate', $styles ) ) { | |
| 45 | - array_push( $styles, 'animate' ); | |
| 46 | - } | |
| 47 | - | |
| 48 | - return $styles; | |
| 49 | - } | |
| 50 | - | |
| 51 | - public function block_frontend_assets() { | |
| 52 | - | |
| 53 | - if ( is_admin() ) { | |
| 54 | - return; | |
| 55 | - } | |
| 56 | - | |
| 57 | - if ( ! wp_style_is( 'animate', 'enqueued' ) ) { | |
| 58 | - wp_enqueue_style('animate'); | |
| 59 | - } | |
| 60 | - | |
| 61 | - if ( FALSE == getwid()->assetsOptimization()->load_assets_on_demand() ) { | |
| 62 | - return; | |
| 63 | - } | |
| 64 | - | |
| 65 | - $deps = [ | |
| 66 | - 'animate' | |
| 67 | - ]; | |
| 68 | - | |
| 69 | - add_filter( 'getwid/optimize/assets', | |
| 70 | - function ( $assets ) { | |
| 71 | - $assets[] = getwid()->settings()->getPrefix() . '-blocks-common'; | |
| 72 | - | |
| 73 | - return $assets; | |
| 74 | - } | |
| 75 | - ); | |
| 76 | - | |
| 77 | - add_filter( 'getwid/optimize/should_load_common_css', '__return_true' ); | |
| 78 | - | |
| 79 | - //fontawesome | |
| 80 | - $deps = getwid()->fontIconsManager()->enqueueFonts( $deps ); | |
| 81 | - | |
| 82 | - $rtl = is_rtl() ? '.rtl' : ''; | |
| 83 | - | |
| 84 | - wp_enqueue_style( | |
| 85 | - self::$blockName, | |
| 86 | - getwid_get_plugin_url( 'assets/blocks/icon/style' . $rtl . '.css' ), | |
| 87 | - $deps, | |
| 88 | - getwid()->settings()->getVersion() | |
| 89 | - ); | |
| 90 | - | |
| 91 | - wp_enqueue_script( | |
| 92 | - self::$blockName, | |
| 93 | - getwid_get_plugin_url( 'assets/blocks/icon/frontend.js' ), | |
| 94 | - [ 'jquery' ], | |
| 95 | - getwid()->settings()->getVersion(), | |
| 96 | - true | |
| 97 | - ); | |
| 98 | - | |
| 99 | - } | |
| 100 | - | |
| 101 | - public function render_callback( $attributes, $content ) { | |
| 102 | - | |
| 103 | - $this->block_frontend_assets(); | |
| 104 | - | |
| 105 | - return $content; | |
| 106 | - } | |
| 107 | -} | |
| 108 | - | |
| 109 | -getwid()->blocksManager()->addBlock( | |
| 110 | - new \Getwid\Blocks\Icon() | |
| 111 | -); | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace Getwid\Blocks; | |
| 4 | + | |
| 5 | +class Icon extends AbstractBlock { | |
| 6 | + | |
| 7 | + public function __construct() { | |
| 8 | + | |
| 9 | + parent::__construct( 'getwid/icon' ); | |
| 10 | + | |
| 11 | + register_block_type( | |
| 12 | + getwid_get_plugin_path( 'assets/blocks/icon' ) | |
| 13 | + ); | |
| 14 | + } | |
| 15 | + | |
| 16 | + public function get_label() { | |
| 17 | + return __( 'Icon', 'getwid' ); | |
| 18 | + } | |
| 19 | +} | |
| 20 | + | |
| 21 | +getwid()->blocksManager()->addBlock( | |
| 22 | + new Icon() | |
| 23 | +); | |