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