array( 'postTemplate' => array( 'type' => 'string', ), //Custom Post Type 'postsToShow' => array( 'type' => 'number', 'default' => 5, ), 'offset' => array( 'type' => 'number', 'default' => 0 ), 'ignoreSticky' => array( 'type' => 'boolean', 'default' => true, ), 'filterById' => array( 'type' => 'string', ), 'excludeById' => array( 'type' => 'string' ), 'excludeCurrentPost' => array( 'type' => 'boolean', 'default' => false ), 'childPagesCurrentPage' => array( 'type' => 'boolean', 'default' => false ), 'parentPageId' => array( 'type' => 'string', ), 'postType' => array( 'type' => 'string', 'default' => 'post', ), 'taxonomy' => array( 'type' => 'array', 'items' => [ 'type' => 'string', ], ), 'terms' => array( 'type' => 'array', 'items' => [ 'type' => 'string', ], ), 'relation' => array( 'type' => 'string', 'default' => 'AND', ), 'order' => array( 'type' => 'string', 'default' => 'desc', ), 'orderBy' => array( 'type' => 'string', 'default' => 'date', ), //Custom Post Type //Content 'minHeight' => array( 'type' => 'string', ), //Posts 'align' => array( 'type' => 'string', ), 'textAlignment' => array( 'type' => 'string', 'default' => 'left', ), //Slider 'sliderAnimationEffect' => array( 'type' => 'string', 'default' => 'slide' ), 'sliderAutoplay' => array( 'type' => 'boolean', 'default' => false ), 'sliderAutoplaySpeed' => array( 'type' => 'string', 'default' => '6000' ), 'sliderInfinite' => array( 'type' => 'boolean', 'default' => true ), 'sliderAnimationSpeed' => array( 'type' => 'string', 'default' => '800' ), 'sliderArrows' => array( 'type' => 'string', 'default' => 'inside' ), 'sliderDots' => array( 'type' => 'string', 'default' => 'inside' ), 'className' => array( 'type' => 'string', ), //Modal 'metaQuery' => array( 'type' => 'array', 'default' => [] ), ), 'render_callback' => [ $this, 'render_callback' ] ) ); /* #endregion */ if ( $this->isEnabled() ) { add_filter( 'getwid/editor_blocks_js/dependencies', [ $this, 'block_editor_scripts'] ); add_filter( 'getwid/blocks_style_css/dependencies', [ $this, 'block_frontend_styles' ] ); //Register JS/CSS assets wp_register_script( 'slick', getwid_get_plugin_url( 'vendors/slick/slick/slick.min.js' ), [ 'jquery' ], '1.9.0', true ); wp_register_style( 'slick', getwid_get_plugin_url( 'vendors/slick/slick/slick.min.css' ), [], '1.9.0' ); wp_register_style( 'slick-theme', getwid_get_plugin_url( 'vendors/slick/slick/slick-theme.min.css' ), [], '1.9.0' ); } } public function getLabel() { return __('Post Slider', 'getwid'); } public function block_editor_scripts($scripts) { //imagesloaded.min.js if ( ! in_array( 'imagesloaded', $scripts ) ) { array_push( $scripts, 'imagesloaded' ); } //slick.min.js if ( ! in_array( 'slick', $scripts ) ) { array_push( $scripts, 'slick' ); } return $scripts; } public function block_frontend_styles($styles) { //fontawesome // for /template-parts/* $styles = getwid()->fontIconsManager()->enqueueFonts( $styles ); //slick.min.css if ( ! in_array( 'slick', $styles ) ) { array_push( $styles, 'slick' ); } //slick-theme.min.css if ( ! in_array( 'slick-theme', $styles ) ) { array_push( $styles, 'slick-theme' ); } return $styles; } public function block_frontend_assets() { if ( is_admin() ) { return; } //slick.min.js if ( ! wp_script_is( 'slick', 'enqueued' ) ) { wp_enqueue_script('slick'); } //imagesloaded.min.js if ( ! wp_script_is( 'imagesloaded', 'enqueued' ) ) { wp_enqueue_script('imagesloaded'); } if ( FALSE == getwid()->assetsOptimization()->load_assets_on_demand() ) { return; } $deps = [ 'slick', 'slick-theme' ]; //fontawesome // for /template-parts/* $deps = getwid()->fontIconsManager()->enqueueFonts( $deps ); add_filter( 'getwid/optimize/assets', function ( $assets ) { $assets[] = 'slick'; $assets[] = 'slick-theme'; $assets[] = getwid()->settings()->getPrefix() . '-blocks-common'; return $assets; } ); add_filter( 'getwid/optimize/should_load_common_css', '__return_true' ); $rtl = is_rtl() ? '.rtl' : ''; wp_enqueue_style( self::$blockName, getwid_get_plugin_url( 'assets/blocks/post-slider/style' . $rtl . '.css' ), $deps, getwid()->settings()->getVersion() ); wp_enqueue_script( self::$blockName, getwid_get_plugin_url( 'assets/blocks/post-slider/frontend.js' ), [ 'jquery', 'imagesloaded', 'slick' ], getwid()->settings()->getVersion(), true ); if ( !$this->assetsAlreadyEnqueued ) { $inline_script = 'var Getwid = Getwid || {};' . 'Getwid["isRTL"] = ' . json_encode( is_rtl() ) . ';'; wp_add_inline_script( self::$blockName, $inline_script, 'before' ); } $this->assetsAlreadyEnqueued = true; } public function render_callback( $attributes, $content ) { //Custom Post Type $query_args = getwid_build_custom_post_type_query( $attributes ); $q = new \WP_Query( $query_args ); //Custom Post Type //Custom Template $use_template = false; $template_part_content = ''; if ( isset( $attributes['postTemplate'] ) && $attributes['postTemplate'] != '' ) { $template_post = get_post($attributes['postTemplate'], ARRAY_A); //If post exist and content not empty if (!is_null($template_post) && $template_post['post_content'] != ''){ $use_template = true; $template_part_content = $template_post['post_content']; } } $block_name = 'wp-block-getwid-post-slider'; $post_type = isset($attributes['postType']) ? $attributes['postType'] : 'post'; $extra_attr = array( 'block_name' => $block_name, 'back_end' => getwid_is_block_editor() ); $class = $block_name; $class .= ' custom-post-type-' . $post_type; if ( isset( $attributes['align'] ) ) { $class .= ' align' . $attributes['align']; } if ( isset( $attributes['className'] ) ) { $class .= ' ' . $attributes['className']; } $content_class = $block_name . '__content'; $slide_style = ''; if ( isset( $attributes['minHeight'] ) ) { $slide_style .= 'min-height:' . $attributes['minHeight'] . ';'; } $class .= ' has-arrows-' . $attributes['sliderArrows']; $class .= ' has-dots-' . $attributes['sliderDots']; $sliderData = array( 'getwid_fade_effect' => $attributes['sliderAnimationEffect'], 'getwid_autoplay' => $attributes['sliderAutoplay'], 'getwid_autoplay_speed' => intval($attributes['sliderAutoplaySpeed']), 'getwid_infinite' => $attributes['sliderInfinite'], 'getwid_animation_speed' => intval($attributes['sliderAnimationSpeed']), 'getwid_arrows' => $attributes['sliderArrows'], 'getwid_dots' => $attributes['sliderDots'], ); $slider_options = json_encode($sliderData); ob_start(); ?>