plugin_name = $plugin_name; $this->version = $version; $this->settings = $this->get_settings(); $this->load_dependencies(); } /** * Load the required dependencies for this plugin. * * Include the following files that make up the plugin: * * - Woo_Scratch_Coupon_Card_Default. * * @since 1.0.0 * @access private */ private function load_dependencies() { /** * The class responsible for defining default value * of the plugin. */ } /** * Register the stylesheets for the public-facing side of the site. * * @since 1.0.0 */ public function enqueue_styles() { if ( $this->needs_popup() ) { wp_enqueue_style( $this->plugin_name . '-dialog', plugins_url( '/public/css/viewer.css', THREED_PLUGIN_FILE ), array(), $this->version ); } } /** * Register the JavaScript for the public-facing side of the site. * * @since 1.0.0 */ public function enqueue_scripts() { if ( $this->needs_popup() ) { wp_enqueue_script( $this->plugin_name . '-dialog', plugins_url( '/public/js/viewer.js', THREED_PLUGIN_FILE ), array(), $this->version, true ); wp_localize_script( $this->plugin_name . '-dialog', 'threedViewerLabels', array( 'close' => __( 'Close 3D viewer', '3dvieweronline-wp' ), 'title' => __( 'Interactive 3D model', '3dvieweronline-wp' ), ) ); } } private function needs_popup() { return function_exists( 'is_product' ) && is_product() && isset( $this->settings['threed_enable_product_icon'] ) && 'on' === $this->settings['threed_enable_product_icon'] && '' !== threedvieweronline_url( get_post_meta( get_queried_object_id(), 'threed_model_url', true ) ); } /** * Footer callback to add fancybox script. * * @since 1.0.0 */ /** * Retrieve the settings of the plugin. * * @since 1.0.0 * @return array The settings of the plugin. */ public function get_settings() { $settings = get_option( 'settings-threed-iframe', array() ); $this->settings = is_array( $settings ) ? $settings : array(); return $this->settings; } /** * Initialize threedvieweronline. * * @since 1.0.0 * @return void. */ public function threedvieweronline_init_callback() { add_shortcode( '3Dvo-model', array( $this, 'threedvieweronline_shortcode' ) ); } /** * Outputs the data for the shortcode. * * @since 1.0.0 * @param array $atts The attributes passed. * @return html. */ public function threedvieweronline_shortcode( $atts ) { $atts = shortcode_atts( array( 'url' => '', 'id' => '', 'width' => '100%', 'height' => '500px', 'autosize' => 'yes', 'border' => '0', 'scroll' => 'no', 'title' => __( 'Interactive 3D model', '3dvieweronline-wp' ), ), is_array( $atts ) ? $atts : array(), '3Dvo-model' ); return threedvieweronline_iframe( $atts['url'], $atts ); } /** * Initialize product tab. * * @since 1.0.0 * @param array $tabs The tabs array. * @return html. */ public function threed_woo_new_product_tab( $tabs ) { if ( isset( $this->settings['threed_enable_product_tab'] ) && 'on' === $this->settings['threed_enable_product_tab'] ) { $title = '3D model'; if ( isset( $this->settings['threed_tab_title'] ) && '' !== $this->settings['threed_tab_title'] ) { $title = $this->settings['threed_tab_title']; } global $product; if ( ! is_a( $product, 'WC_Product' ) ) { return $tabs; } $id = $product->get_id(); $value = get_post_meta( $id, 'threed_model_url', true ); if ( '' !== $value ) { $tabs['desc_tab'] = array( 'title' => esc_html( $title ), 'priority' => 50, 'callback' => array( $this, 'threed_woo_new_product_tab_content' ), ); } } return $tabs; } /** * Display content for the custom WooCommerce product tab. * * This function is responsible for rendering the content inside the custom tab * on the WooCommerce single product page. * * @return void */ public function threed_woo_new_product_tab_content() { global $product; if ( ! is_a( $product, 'WC_Product' ) ) { return; } $id = $product->get_id(); echo wp_kses( threedvieweronline_iframe( get_post_meta( $id, 'threed_model_url', true ), array( 'width' => get_post_meta( $id, 'threed_piframe_width', true ) ?: ( isset( $this->settings['threed_iframe_width'] ) ? $this->settings['threed_iframe_width'] : '100%' ), 'height' => get_post_meta( $id, 'threed_piframe_height', true ) ?: ( isset( $this->settings['threed_iframe_height'] ) ? $this->settings['threed_iframe_height'] : '500px' ), ) ), array( 'iframe' => array( 'class' => true, 'id' => true, 'src' => true, 'title' => true, 'style' => true, 'loading' => true, 'allowfullscreen' => true ) ) ); } /** * Callback function for the WooCommerce single product summary. * * Add Icon to product summary if that is selected in settings. * * @return void */ public function woocommerce_single_product_summary_callback() { if ( isset( $this->settings['threed_icon_display'] ) && 'after-product-title' === $this->settings['threed_icon_display'] ) { $this->add_threed_icon(); } } /** * Callback function for the WooCommerce before add to cart form hook. * * Add Icon to product before add to cart if that is selected in settings. * * @return void */ public function woocommerce_before_add_to_cart_form_callback() { if ( isset( $this->settings['threed_icon_display'] ) && 'after-product-short-description' === $this->settings['threed_icon_display'] ) { $this->add_threed_icon(); } } /** * Callback function for the WooCommerce after add to cart form hook. * * Add Icon to product after add to cart if that is selected in settings. * * @return void */ public function woocommerce_after_add_to_cart_form_callback() { if ( isset( $this->settings['threed_icon_display'] ) && 'after-add-to-cart-button' === $this->settings['threed_icon_display'] ) { $this->add_threed_icon(); } } /** * Add icon. * * Outputs the icon html. * * @return void */ public function add_threed_icon() { global $product; if ( ! is_a( $product, 'WC_Product' ) || ! isset( $this->settings['threed_enable_product_icon'] ) || 'on' !== $this->settings['threed_enable_product_icon'] ) { return; } $id = $product->get_id(); $url = threedvieweronline_url( get_post_meta( $id, 'threed_model_url', true ) ); if ( '' === $url ) { return; } $icon = isset( $this->settings['threed_icon'] ) ? threedvieweronline_url( $this->settings['threed_icon'] ) : ''; if ( '' === $icon ) { $icon = plugins_url( 'assets/images/logo.png', THREED_PLUGIN_FILE ); } $width = threedvieweronline_dimension( get_post_meta( $id, 'threed_piframe_width', true ), isset( $this->settings['threed_iframe_width'] ) ? threedvieweronline_dimension( $this->settings['threed_iframe_width'], '100%' ) : '100%' ); $height = threedvieweronline_dimension( get_post_meta( $id, 'threed_piframe_height', true ), isset( $this->settings['threed_iframe_height'] ) ? threedvieweronline_dimension( $this->settings['threed_iframe_height'], '500px' ) : '500px' ); echo '' . esc_attr__( '3D model', '3dvieweronline-wp' ) . ''; } }