HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux vm8 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: afleverb (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //var/www/mussarq_bak2/wp-content/plugins/megamenu/classes/widget-reusable-block.class.php
<?php

if ( ! defined( 'ABSPATH' ) ) {
    exit; // disable direct access
}

if ( ! class_exists('Mega_Menu_Widget_Reusable_Block') ) :

/**
 * Outputs a reusable block
 *
 * Credit: Based on https://wordpress.org/plugins/block-widget/ by Maarten Menten
 */
class Mega_Menu_Widget_Reusable_Block extends WP_Widget {

	/**
	 * Register widget with WordPress.
	 */
	public function __construct() {
		parent::__construct(
			'maxmegamenu_reusable_block', // Base ID
			'Reusable Block', // Name
			array( 'description' => __( 'Outputs a reusable block.', 'megamenu' ) ) // Args
		);
	}


	/**
	 * Front-end display of widget.
	 *
	 * @since 2.7.4
	 * @see WP_Widget::widget()
	 * @param array   $args     Widget arguments.
	 * @param array   $instance Saved values from database.
	 */
	public function widget( $args, $instance ) {
		if ( empty( $instance['block'] ) || ! get_post_type( $instance['block'] ) ) {
			return;
		}

		extract( $args );

		echo $before_widget;

		echo do_blocks( get_post_field( 'post_content', $instance['block'] ) );

		echo $after_widget;
	}


	/**
	 * Sanitize widget form values as they are saved.
	 *
	 * @since 2.7.4
	 * @see WP_Widget::update()
	 * @param array   $new_instance Values just sent to be saved.
	 * @param array   $old_instance Previously saved values from database.
	 * @return array Updated safe values to be saved.
	 */
	public function update( $new_instance, $old_instance ) {
		$instance = array();
		$instance['block'] = ! empty( $new_instance['block'] ) ? $new_instance['block'] : 0;
		
		return $instance;
	}


	/**
	 * Back-end widget form.
	 *
	 * @since 2.7.4
	 * @see WP_Widget::form()
	 * @param array   $instance Previously saved values from database.
	 */
	public function form( $instance ) {
		$block_id = ! empty( $instance['block'] ) ? absint( $instance['block'] ) : 0;
		
		$widget_title = $block_id ? get_post_field( 'post_title', $block_id ) : '';

		$posts = get_posts( array ( 'post_type' => 'wp_block', 'post_status' => 'publish', 'numberposts' => -1 ) );

		// No blocks found.
		if ( empty( $posts ) ) {
			printf( '<p>%s</p>', __( 'No reusable blocks available.', 'megamenu' ) );

			return;
		}

		// Input field with id is required for WordPress to display the title in the widget header.
		?>
		<input type="hidden" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" value="<?php echo esc_attr( $widget_title ); ?>">
		
		<p>
			<label for="<?php echo esc_attr( $this->get_field_id( 'block' ) ); ?>"><?php esc_attr_e( 'Block', 'megamenu' ); ?>:</label> 
			<select id="<?php echo esc_attr( $this->get_field_id( 'block' ) ); ?>" class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'block' ) ); ?>">
				<option value=""><?php esc_html_e( '- Select -', 'megamenu' ); ?></option>
				<?php foreach ( $posts as $post ) : ?>
				<option value="<?php echo esc_attr( $post->ID ); ?>"<?php selected( $post->ID, $block_id ); ?>><?php echo esc_html( $post->post_title ); ?></option>
				<?php endforeach; ?>
			</select>
		</p>

		<?php 
	}

}

endif;