'ghostkit-reusable-widget', 'description' => esc_html__( 'Display Gutenberg Reusable Blocks.', 'ghostkit' ), ) ); } /** * Outputs the content of the widget * * @param array $args args. * @param array $instance instance. */ public function widget( $args, $instance ) { $title = ! empty( $instance['title'] ) ? apply_filters( 'widget_title', $instance['title'] ) : ''; $block_id = isset( $instance['block'] ) && ! empty( $instance['block'] ) ? $instance['block'] : ''; $post = $block_id ? get_post( $block_id ) : false; if ( $block_id && isset( $post->post_content ) && $post->post_content && function_exists( 'has_blocks' ) && function_exists( 'parse_blocks' ) ) { // phpcs:disable echo $args['before_widget']; if ( ! empty( $title ) ) { echo $args[ 'before_title' ] . $title . $args[ 'after_title' ]; } // fix for bbPress. // filter 'the_content' may not work in bbPress // https://github.com/nk-crew/ghostkit/issues/72. // https://bbpress.org/forums/topic/the_content-filter-is-removed-by-not-restored-on-custom-wp_query/ if ( function_exists( 'is_bbpress' ) && is_bbpress() ) { bbp_restore_all_filters( 'the_content' ); } echo apply_filters( 'the_content', $post->post_content ); if ( function_exists( 'is_bbpress' ) && is_bbpress() ) { bbp_remove_all_filters( 'the_content' ); } echo $args['after_widget']; // phpcs:enable } } /** * Outputs the options form on admin * * @param array $instance The widget options. */ public function form( $instance ) { $title = ! empty( $instance['title'] ) ? $instance['title'] : ''; $selected_block = ! empty( $instance['block'] ) ? $instance['block'] : ''; $blocks = get_posts( array( 'post_type' => 'wp_block', 'numberposts' => -1, ) ); GhostKit_Assets::enqueue_script( 'ghostkit-admin-reusable-widget', 'build/assets/admin/js/reusable-widget', array(), null, false ); ?>

! empty( $new_instance['title'] ) ? sanitize_text_field( $new_instance['title'] ) : '', 'block' => ! empty( $new_instance['block'] ) ? sanitize_text_field( $new_instance['block'] ) : '', ); return $instance; } } /** * Register Widget */ function ghostkit_register_reusable_widget() { register_widget( 'GhostKit_Reusable_Widget' ); } add_action( 'widgets_init', 'ghostkit_register_reusable_widget' );