$style ){ $new = ''; foreach( $style as $property => $value ){ if( $value == '' ){ $new .= $property; }else { $new .= " $property: $value;"; } } $output .= "$selector { $new }"; } return $output; } } // 3D Viewer Block class TDVB3DViewerBlock{ function __construct(){ add_action( 'enqueue_block_assets', [$this, 'enqueueBlockAssets'] ); add_action( 'init', [$this, 'onInit'] ); add_filter( 'upload_mimes', [$this, 'uploadMimes'] ); if ( version_compare( $GLOBALS['wp_version'], '5.1' ) >= 0 ) { add_filter( 'wp_check_filetype_and_ext', [$this, 'wpCheckFiletypeAndExt'], 10, 5 ); } else { add_filter( 'wp_check_filetype_and_ext', [$this, 'wpCheckFiletypeAndExt'], 10, 4 ); } } function enqueueBlockAssets(){ echo wp_get_script_tag( [ 'src' => TDVB_ASSETS_DIR . 'js/model-viewer.min.js', 'type' => 'module', ] ); } function onInit() { wp_register_style( 'tdvb-td-viewer-editor-style', plugins_url( 'dist/editor.css', __FILE__ ), [ 'wp-edit-blocks' ], TDVB_PLUGIN_VERSION ); // Backend Style wp_register_style( 'tdvb-td-viewer-style', plugins_url( 'dist/style.css', __FILE__ ), [ 'wp-editor' ], TDVB_PLUGIN_VERSION ); // Both Style register_block_type( __DIR__, [ 'editor_style' => 'tdvb-td-viewer-editor-style', 'style' => 'tdvb-td-viewer-style', 'render_callback' => [$this, 'render'], ] ); // Register Block wp_set_script_translations( 'tdvb_editor_script', '3d-viewer-block', plugin_dir_path( __FILE__ ) . 'languages' ); // Translate } function render( $attributes ){ extract( $attributes ); $tDViewerStyle = new TDVBStyleGenerator(); // Generate Styles $tDViewerStyle::addStyle( "#tdvb3DViewerBlock-$cId .tdvb3DViewerBlock", [ 'text-align' => $alignment ] ); $tDViewerStyle::addStyle( "#tdvb3DViewerBlock-$cId .tdvb3DViewerBlock .tdvbModel", [ 'width' => '0px' === $width || '0%' === $width || '0em' === $width ? 'auto' : $width, 'height' => '0px' === $height || '0%' === $height || '0em' === $height ? '350px' : $height, ] ); $jsonData = wp_json_encode( [ 'isTouchMove' => $isTouchMove, 'isZoom' => $isZoom ] ); ob_start(); ?>
' id='tdvb3DViewerBlock-' data-model=''>
' alt='' camera-controls loading='' auto-rotate >