fusion_settings = awb_get_fusion_settings(); add_filter( 'fusion_attr_related-component-carousel', [ $this, 'carousel_attr' ] ); // Ajax mechanism for query related part. add_action( 'wp_ajax_get_fusion_related_posts', [ $this, 'ajax_query' ] ); } /** * Check if component should render * * @access public * @since 2.2 * @return boolean */ public function should_render() { return is_singular() || wp_is_json_request(); } /** * Gets the default values. * * @static * @access public * @since 2.2 * @return array */ public static function get_element_defaults() { $fusion_settings = awb_get_fusion_settings(); return [ 'number_related_posts' => $fusion_settings->get( 'number_related_posts' ), 'related_posts_image_size' => $fusion_settings->get( 'related_posts_image_size' ), 'related_posts_columns' => $fusion_settings->get( 'related_posts_columns' ), 'related_posts_layout' => $fusion_settings->get( 'related_posts_layout' ), 'related_posts_navigation' => $fusion_settings->get( 'related_posts_navigation' ), 'related_posts_autoplay' => $fusion_settings->get( 'related_posts_autoplay' ), 'related_posts_swipe' => $fusion_settings->get( 'related_posts_swipe' ), 'related_posts_column_spacing' => $fusion_settings->get( 'related_posts_column_spacing' ), 'related_posts_swipe_items' => $fusion_settings->get( 'related_posts_swipe_items' ), 'heading_enable' => 'yes', 'heading_size' => '3', 'margin_bottom' => '', 'margin_left' => '', 'margin_right' => '', 'margin_top' => '', 'hide_on_mobile' => fusion_builder_default_visibility( 'string' ), 'class' => '', 'id' => '', 'animation_type' => '', 'animation_direction' => 'down', 'animation_speed' => '0.1', 'animation_delay' => '', 'animation_offset' => $fusion_settings->get( 'animation_offset' ), 'animation_color' => '', ]; } /** * Maps settings to param variables. * * @static * @access public * @since 2.2 * @return array */ public static function settings_to_params() { return [ 'number_related_posts' => 'number_related_posts', 'related_posts_image_size' => 'related_posts_image_size', 'related_posts_columns' => 'related_posts_columns', 'related_posts_navigation' => 'related_posts_navigation', 'related_posts_autoplay' => 'related_posts_autoplay', 'related_posts_swipe' => 'related_posts_swipe', 'related_posts_column_spacing' => 'related_posts_column_spacing', 'related_posts_swipe_items' => 'related_posts_swipe_items', 'animation_offset' => 'animation_offset', ]; } /** * Used to set any other variables for use on front-end editor template. * * @static * @access public * @since 2.2 * @return array */ public static function get_element_extras() { $fusion_settings = awb_get_fusion_settings(); return [ 'title_margin' => $fusion_settings->get( 'title_margin' ), 'title_border_color' => $fusion_settings->get( 'title_border_color' ), 'title_style_type' => $fusion_settings->get( 'title_style_type' ), 'content_width' => apply_filters( 'fusion_library_content_width', 1170 ), ]; } /** * Maps settings to extra variables. * * @static * @access public * @since 2.2 * @return array */ public static function settings_to_extras() { return [ 'title_margin' => 'title_margin', 'title_border_color' => 'title_border_color', 'title_style_type' => 'title_style_type', ]; } /** * Gets the query data. * * @access public * @since 2.2 * @return void */ public function ajax_query() { check_ajax_referer( 'fusion_load_nonce', 'fusion_load_nonce' ); if ( isset( $_POST['model'] ) && isset( $_POST['model']['params'] ) && ! apply_filters( 'fusion_builder_live_request', false ) ) { // phpcs:ignore WordPress.Security.NonceVerification $defaults = $_POST['model']['params']; // phpcs:ignore WordPress.Security fusion_set_live_data(); add_filter( 'fusion_builder_live_request', '__return_true' ); $this->emulate_post(); $this->post_type = get_post_type( $this->get_target_post() ); $fusion_query = $this->query( $defaults ); $this->restore_post(); // Build live query response. $return_data = []; // There are no related posts, return placeholder. if ( ! $fusion_query->have_posts() ) { echo wp_json_encode( $return_data ); wp_die(); } /** * Get the correct image size. */ $featured_image_size = ( 'cropped' === $defaults['related_posts_image_size'] ) ? 'fixed' : 'full'; $data_image_size = ( 'cropped' === $defaults['related_posts_image_size'] ) ? 'fixed' : 'auto'; /** * Loop through related posts. */ while ( $fusion_query->have_posts() ) : $fusion_query->the_post(); $post_id = get_the_ID(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride // $content .= '