rest_url(), ]); register_block_type( 'notificationx-pro/notificationx', [ 'editor_script' => 'notificationx-block-editor', 'editor_style' => 'notificationx-block-editor', // 'style' => 'notificationx-block', // 'script' => 'notificationx-block-frontend', 'render_callback' => [ $this, 'notificationx_render_callback' ], 'attributes' => array( 'nx_id' => array( 'type' => 'string', ), 'blockId' => array( 'type' => 'string', ), 'product_id' => array( 'type' => 'string', ), ), ] ); register_block_type( 'notificationx-pro/notificationx-render', [ 'render_callback' => [ $this, 'gutenberg_examples_dynamic_render_callback' ], 'attributes' => array( 'nx_id' => array( 'type' => 'string', ), 'blockId' => array( 'type' => 'string', ), 'product_id' => array( 'type' => 'string', ), 'post_type' => array( 'type' => 'string', ), ), ] ); } function notificationx_render_callback( $block_attributes, $content ) { if( ! is_admin() ){ wp_enqueue_style('notificationx-block'); wp_enqueue_script('notificationx-block-frontend'); } if ( is_admin() || $this->isRestUrl() ) { do_action( 'nx_ignore_analytics' ); } $nx_id = ! empty( $block_attributes['nx_id'] ) ? esc_attr($block_attributes['nx_id']) : ''; $product_id = ! empty( $block_attributes['product_id'] ) ? $block_attributes['product_id'] : ''; $block_id = ! empty( $block_attributes['blockId'] ) ? esc_attr($block_attributes['blockId']) : ''; $html = '
'; $html .= do_shortcode( "[notificationx_inline product_id='{$product_id}' id='{$nx_id}']" ); $html .= '
'; return $html; } function gutenberg_examples_dynamic_render_callback( $block_attributes, $content ) { do_action( 'nx_ignore_analytics' ); $nx_id = ! empty( $block_attributes['nx_id'] ) ? esc_attr($block_attributes['nx_id']) : ''; $product_id = ! empty( $block_attributes['product_id'] ) ? $block_attributes['product_id'] : ''; $post_type = ! empty( $block_attributes['post_type'] ) ? $block_attributes['post_type'] : ''; $html = '
'; if( 'wp_template' == $post_type ) { add_filter('nx_is_preview',function(){ return true; }); $product_id = rand(); } $shortcode = do_shortcode( "[notificationx_inline post_type='{$post_type}' product_id='{$product_id}' id='{$nx_id}' show_link=false]" ); if ( $shortcode ) { $html .= $shortcode; } else { $html .= '

' . __( 'There is no data in this notification.', 'notificationx' ) . '

'; } $html .= '
'; return wp_kses($html, Helper::nx_allowed_html()); } function isRestUrl() { if ( empty( $GLOBALS['wp']->query_vars['rest_route'] ) ) { return false; } return true; } }