'; /** * Instance Control */ public static function get_instance() { if ( is_null( self::$instance ) ) { self::$instance = new self(); } return self::$instance; } /** * Builds CSS for block. * * @param array $attributes the blocks attributes. * @param Kadence_Blocks_CSS $css the css class for blocks. * @param string $unique_id the blocks attr ID. * @param string $unique_style_id the blocks alternate ID for queries. */ public function build_css( $attributes, $css, $unique_id, $unique_style_id ) { $css->set_style_id( 'kb-' . $this->block_name . $unique_style_id ); $css->set_selector( '.kb-vector-container' . $unique_id ); $css->render_measure_output( $attributes, 'margin', 'margin'); $css->render_measure_output( $attributes, 'padding', 'padding' ); // Center the SVG when alignment is not set if ( empty( $attributes['align'] ) ) { $css->add_property( 'display', 'flex' ); $css->add_property( 'justify-content', 'center' ); } $css->set_selector( '.kb-vector-container' . $unique_id . ' svg' ); $css->render_responsive_range( $attributes, 'maxWidth', 'max-width', 'maxWidthUnit' ); return $css->css_output(); } /** * Return dynamically generated HTML for block * * @param $attributes * @param $unique_id * @param $content * @param WP_Block $block_instance The instance of the WP_Block class that represents the block being rendered. * * @return mixed */ public function build_html( $attributes, $unique_id, $content, $block_instance ) { $classes = [ 'kb-vector-container', 'kb-vector-container' . esc_attr( $unique_id ), ]; if ( ! empty( $attributes['align'] ) ) { $classes[] = 'align' . esc_attr( $attributes['align'] ); } $wrapper_attributes = get_block_wrapper_attributes( [ 'class' => implode( ' ', $classes ), 'id' => !empty( $attributes['anchor'] ) ? esc_attr( $attributes['anchor'] ) : '', ] ); $svg = $this->get_vector_svg( $attributes ); return sprintf( '
%2$s
', $wrapper_attributes, $svg ); } /** * Get the SVG content * * @param array $attributes Block attributes. * @return string */ private function get_vector_svg( $attributes ) { $svg_content = $this->placeholder_svg; if ( isset( $attributes['id'] ) && ! empty( $attributes['id'] ) ) { $post_id = $attributes['id']; if ( ! empty( $post_id ) ) { $post = get_post( $post_id ); if ( $post && 'kadence_vector' === $post->post_type ) { $svg_content = $post->post_content; } } } return $svg_content; } } Kadence_Blocks_Vector_Block::get_instance();