token = WooBuilder::$token; $this->url = WooBuilder::$url; $this->path = WooBuilder::$path; $this->version = WooBuilder::$version; add_shortcode( 'ppb_product_short_description', function() { ob_start(); woocommerce_template_single_excerpt(); return ob_get_clean(); } ); add_shortcode( 'ppb_product_price', function() { ob_start(); woocommerce_template_single_price(); return ob_get_clean(); } ); add_shortcode( 'ppb_product_title', function() { ob_start(); woocommerce_template_loop_product_title(); return ob_get_clean(); } ); add_shortcode( 'ppb_product_related', function() { ob_start(); woocommerce_related_products(); return ob_get_clean(); } ); add_shortcode( 'ppb_product_images', function() { ob_start(); woocommerce_show_product_images(); return ob_get_clean(); } ); add_shortcode( 'ppb_product_rating', function() { ob_start(); woocommerce_template_single_rating(); return ob_get_clean(); } ); add_shortcode( 'ppb_product_add_to_cart', function() { ob_start(); woocommerce_template_single_add_to_cart(); return ob_get_clean(); } ); add_shortcode( 'ppb_product_tabs', function() { ob_start(); add_filter( 'the_content', 'wpautop' ); woocommerce_output_product_data_tabs(); remove_filter( 'the_content', 'wpautop' ); return ob_get_clean(); } ); add_shortcode( 'ppb_product_reviews', function() { ob_start(); comments_template(); return ob_get_clean(); } ); } // End __construct() /** * Adds front end stylesheet and js * @action wp_enqueue_scripts * @since 1.0.0 */ public function wc_get_template_part( $template, $slug, $name ) { if ( 'content' == $slug && 'single-product' == $name ) { if ( WooBuilder::is_ppb_product() ) { $template = dirname( __FILE__ ) . '/ppb-product-tpl.php'; } else if ( get_post_meta( get_the_ID(), 'woobuilder_used_builder', 'single' ) ) { remove_filter( 'the_content', array( $GLOBALS['Pootle_Page_Builder_Render_Layout'], 'content_filter' ) ); } } return $template; } /** * Sets post meta for ppb product * @param array $page_data * @param int $post_id * @param string $post_type * @return array */ public function set_ppb_product_builder_meta( $page_data, $post_id, $post_type ) { if ( 'product' == $post_type && wp_verify_nonce( filter_input( INPUT_GET, 'woobuilder-nonce' ), 'enable_ppb_product_builder' ) ) { if ( ! pootlepb_uses_pb( $post_id ) ) { global $ppble_new_live_page; require Pootle_Page_Builder_Live_Editor::$path . 'inc/vars.php'; $user = ''; $current_user = wp_get_current_user(); if ( $current_user instanceof WP_User ) { $user = ' ' . ucwords( $current_user->user_login ); } /** * Filters new live page template * * @param int $id Post ID */ $ppb_data = apply_filters( 'woobuilder_live_product_template', $ppble_new_live_page, $post_id, $post_type ); foreach ( $ppb_data['widgets'] as $i => $wid ) { if ( ! empty( $wid['info']['style'] ) ) { $ppb_data['widgets'][ $i ]['info']['style'] = stripslashes( $wid['info']['style'] ); } $ppb_data['widgets'][ $i ]['text'] = html_entity_decode( stripslashes( str_replace( '', $user, str_replace( ' ', ' ', $wid['text'] ) ) ) ); } update_post_meta( $post_id, 'panels_data', $ppb_data ); } update_post_meta( $post_id, 'woobuilder', 1 ); } return $page_data; } /** * @param array $ppb_data WooBuilder product starter template */ public function filter_live_product_template( $ppb_data ) { $id = get_option( 'pootlepb-template-product', 0 ); if ( $id ) { $ppb_meta = get_post_meta( $id, 'panels_data', 'single' ); if ( ! empty( $ppb_meta['grids'] ) && is_array( $ppb_meta['grids'] ) ) { $ppb_data = $ppb_meta; } } return $ppb_data; } /** * Prints live editor scripts * @since 1.0.0 */ public function live_editor_scripts() { add_action( 'wp_footer', function () { ?> token; $url = $this->url; wp_enqueue_style( $token . '-css', $url . '/assets/front-end.css' ); wp_enqueue_script( $token . '-js', $url . '/assets/front-end.js', array( 'jquery' ) ); } /** * Processes the content block setting and renders the short code * @param array $data Content panel data * @since 1.0.0 */ public function process_shortcode( $data ) { if ( ( ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) && // Not doing AJAX ! WooBuilder::is_ppb_product( get_the_ID() ) // And not using product builder ) || empty( $data['info'] ) || empty( $data['info']['style'] ) // Or content block info or style ain't defined ) { return; } $settings = json_decode( $data['info']['style'], 'associative_array' ); if ( ! empty( $settings[ $this->token ] ) ) { global $Pootle_Page_Builder_Render_Layout; if ( has_filter( 'the_content', array( $Pootle_Page_Builder_Render_Layout, 'content_filter' ) ) ) { remove_filter( 'the_content', array( $Pootle_Page_Builder_Render_Layout, 'content_filter' ) ); } if ( $_SERVER['REQUEST_METHOD'] === 'POST' && Pootle_Page_Builder_Live_Editor_Public::is_active() ) { global $post, $product, $withcomments; $withcomments = true; $post = get_post( $_POST['post'] ); $product = wc_get_product( $post ); } $shortcodes = $settings[ $this->token ]; if ( ! is_array( $shortcodes ) ) { $shortcodes = [ $shortcodes, ]; } foreach ( $shortcodes as $shortcode ) { $code = str_replace( array( '[', ']' ), '', $shortcode ); // Remove square brackets $code = explode( ' ', $code )[0]; // Get shortcode name $shortcode = str_replace( '%id%', get_the_ID(), $shortcode ); add_filter( 'woocommerce_gallery_image_size', [ $this, 'woocommerce_gallery_image_size' ] ); ?>