Title: Fatal Errors with PHP8
Last modified: August 1, 2022

---

# Fatal Errors with PHP8

 *  Resolved [Webprom Design](https://wordpress.org/support/users/webprom/)
 * (@webprom)
 * [3 years, 9 months ago](https://wordpress.org/support/topic/fatal-errors-with-php8/)
 * Hi!
 * Could you please update this plugin to be compatible with php8?
    There are many
   errors and the whole site has a critical error, even after implementing previously
   mentioned fixes.
 * Please help.
    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [byte666](https://wordpress.org/support/users/byte666/)
 * (@byte666)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/fatal-errors-with-php8/#post-16044170)
 * There are 2 Problems with PHP 8.x. Old style constructor and deprecated create_function().
 * I fix this temporary for my installation. See following Code
    File : wp-content\
   plugins\wordpress-faq-manager\faq-widgets.php Search for // Fix for php 8.1 comment.
   I left old code as comment, maybe autor will use this to fix it official.
 *     ```
       <?php
       /*  
       Keeping a separate file for the widgets for orgaization purposes
       */
   
       	/**
       	 * FAQ Search
       	 *
       	 * @return WP_FAQ_Manager
       	 */
   
       class search_FAQ_Widget extends WP_Widget {
       	// Fix for php 8.1
           //function search_FAQ_Widget() {
           function __construct() {   
       		$widget_ops = array( 'classname' => 'faq-search-widget widget_search', 'description' => 'Puts a search box for just FAQs' );
       		// Fix for php 8.1
               //$this->WP_Widget( 'faq_search', 'FAQ Widget - Search', $widget_ops );
               parent::__construct( 'faq_search', 'FAQ Widget - Search', $widget_ops );
       	}
   
       	function widget( $args, $instance ) {
       		extract( $args, EXTR_SKIP );
       		echo $before_widget;
       		$title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
       		if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };		
   
       		echo '<form class="searchform" role="search" method="get" id="faq-search" action="' . home_url( '/' ) . '" >';
       		echo '<input type="text" value="' . get_search_query() . '" name="s" id="s" class="s" />';
       		echo '<input type="submit" class="searchsubmit" value="'. esc_attr__('Search') .'" />';
       		echo '<input type="hidden" name="post_type" value="question" />';
       		echo '</form>';
   
       		echo $after_widget;
       		?>
   
               <?php }
   
           /** @see WP_Widget::update */
           function update($new_instance, $old_instance) {             
           $instance = $old_instance;
           $instance['title']  = strip_tags($new_instance['title']);
               return $instance;
           }
   
           /** @see WP_Widget::form */
           function form($instance) {              
               $instance = wp_parse_args( (array) $instance, array( 
                   'title' => 'Search FAQs',
                   ));
               $title  = strip_tags($instance['title']);
               ?>
               <p>
                   <label for="<?php echo $this->get_field_id('title'); ?>">Widget Title:</label>
                   <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
               </p>
   
       	<?php }
   
       } // class 
   
       	/**
       	 * Random FAQ widget
       	 *
       	 * @return WP_FAQ_Manager
       	 */
   
       class random_FAQ_Widget extends WP_Widget {
       	// Fix for php 8.1
           //function random_FAQ_Widget() {
           function __construct() {
       		$widget_ops = array( 'classname' => 'faq-random-widget', 'description' => 'Lists a single random FAQ on the sidebar' );
       		// Fix for php 8.1
               //$this->WP_Widget( 'faq_random', 'FAQ Widget - Random', $widget_ops );
               parent::__construct( 'faq_random', 'FAQ Widget - Random', $widget_ops );
       	}
   
       	function widget( $args, $instance ) {
       		extract( $args, EXTR_SKIP );
       		echo $before_widget;
       		$title		= empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
       		$count		= empty($instance['count']) ? 1 : $instance['count'];
       		$seemore	= empty($instance['seemore']) ? 'See the entire answer' : $instance['seemore'];
   
       		if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
       			$args = array(
       				'post_type'		=> 'question',
       				'numberposts'	=> $count,
       				'orderby'		=> 'rand',
       				);
       			$faqs = get_posts( $args );
   
       			foreach( $faqs as $faq ) :
       				$text = wpautop( $faq->post_content );
   
       				echo '<h5 class="faq-widget-title">'.$faq->post_title.'</h5>';
       				echo wp_trim_words( $text, 15, null );
       				echo '<p><a href="'.get_permalink($faq->ID).'">'.$seemore.'</a></p>';
   
               	endforeach;
       		wp_reset_query();
       		echo $after_widget;
       		?>
   
               <?php }
   
           /** @see WP_Widget::update */
           function update($new_instance, $old_instance) {             
           $instance = $old_instance;
           $instance['title']		= strip_tags($new_instance['title']);
           $instance['seemore']	= strip_tags($new_instance['seemore']);
           $instance['count']		= strip_tags($new_instance['count']);
               return $instance;
           }
   
           /** @see WP_Widget::form */
           function form($instance) {              
               $instance = wp_parse_args( (array) $instance, array( 
                   'title'		=> 'Frequently Asked Question',
                   'seemore'	=> 'See the entire answer',
                   'count'		=> '1',
                   ));
               $title		= strip_tags($instance['title']);
               $seemore	= strip_tags($instance['seemore']);
               $count		= strip_tags($instance['count']);
               ?>
               <p>
                   <label for="<?php echo $this->get_field_id('title'); ?>">Widget Title:</label>
                   <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
               </p>
               <p>
                   <label for="<?php echo $this->get_field_id('seemore'); ?>">"See More" text:</label>
                   <input class="widefat" id="<?php echo $this->get_field_id('seemore'); ?>" name="<?php echo $this->get_field_name('seemore'); ?>" type="text" value="<?php echo esc_attr($seemore); ?>" />
               </p>
               <p>
                   <label for="<?php echo $this->get_field_id('count'); ?>">Post Count:</label>
                   <input class="small-text" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" type="text" value="<?php echo esc_attr($count); ?>" />
               </p>
       	<?php }
   
       } // class 
   
       	/**
       	 * Recent FAQ 
       	 *
       	 * @return WP_FAQ_Manager
       	 */
   
       class recent_FAQ_Widget extends WP_Widget {
       	// Fix for php 8.1
           //function recent_FAQ_Widget() {
           function __construct() {
       		$widget_ops = array( 'classname' => 'recent-questions-widget', 'description' => 'List recent questions' );
       		// Fix for php 8.1
               //$this->WP_Widget( 'recent_questions', 'FAQ Widget - Recent', $widget_ops );
               parent::__construct( 'recent_questions', 'FAQ Widget - Recent', $widget_ops );
       	}
   
       	function widget( $args, $instance ) {
       		extract( $args, EXTR_SKIP );
       		echo $before_widget;
       		$title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
       		if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
       			$args = array(
       				'posts_per_page'	=>	$instance['count'],
       				'post_type' 		=> 'question',
       				'post_status'		=> 'publish',
       			);
   
       			$faqs = get_posts( $args );
       		echo '<ul>';
       			foreach( $faqs as $post ) :	setup_postdata($post);
       				global $post;
       				echo '<li><a href="'.get_permalink($post->ID).'" title="'.get_the_title($post->ID).'">'.get_the_title($post->ID).'</a></li>';
   
               	endforeach;
       		echo '</ul>';
       		wp_reset_query();
       		echo $after_widget;
       		?>
   
               <?php }
   
           /** @see WP_Widget::update */
   
           function update($new_instance, $old_instance) {				
       	$instance = $old_instance;
       	$instance['title']	= strip_tags($new_instance['title']);
       	$instance['count']	= strip_tags($new_instance['count']);
               return $instance;
           }
   
           /** @see WP_Widget::form */
           function form($instance) {				
               $instance = wp_parse_args( (array) $instance, array( 
       			'title'		=> 'Recent Questions',
       			'count'		=> '5',
       		));
       		$title	= strip_tags($instance['title']);
       		$count	= strip_tags($instance['count']);
   
               ?>
   
               <p>
                   <label for="<?php echo $this->get_field_id('title'); ?>">Widget Title:</label>
                   <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
               </p>
   
               <p>
                   <label for="<?php echo $this->get_field_id('count'); ?>">Post Count:</label>
                   <input class="widefat" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" type="text" value="<?php echo esc_attr($count); ?>" />
               </p>
       		<?php }
   
       } // class 
   
       	/**
       	 * FAQ taxonomy list
       	 *
       	 * @return WP_FAQ_Manager
       	 */
   
       class topics_FAQ_Widget extends WP_Widget {
       	// Fix for php 8.1
           //function topics_FAQ_Widget() {
           function __construct() {
       		$widget_ops = array( 'classname' => 'recent-faqtax-widget', 'description' => 'List FAQ topics or tags' );
       		// Fix for php 8.1
               //$this->WP_Widget( 'recent_faqtax', 'FAQ Widget - Taxonomies', $widget_ops );
               parent::__construct( 'recent_faqtax', 'FAQ Widget - Taxonomies', $widget_ops );
       	}
   
       	function widget( $args, $instance ) {
       		extract( $args, EXTR_SKIP );
       		echo $before_widget;
       		$title	= empty($instance['title'])	? ''			: apply_filters('widget_title', $instance['title']);
       		$tax	= empty($instance['tax'])	? 'faq-topic'	: $instance['tax'];
   
       		if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
       		echo '<ul>';
       			// set query variables
       			$orderby		= 'name';
       			$show_count		= 0; // 1 for yes, 0 for no
       			$pad_counts		= 0; // 1 for yes, 0 for no
       			$hierarchical	= 1; // 1 for yes, 0 for no
       			$taxonomy		= $tax;
       			$title			= '';
       			$style			= 'list';
   
       			$topic_args = array(
       				'orderby'		=> $orderby,
       				'show_count'	=> $show_count,
       				'pad_counts'	=> $pad_counts,
       				'hierarchical'	=> $hierarchical,
       				'taxonomy'		=> $taxonomy,
       				'title_li'		=> $title,
       				'style'			=> $style
       			);
   
       			wp_list_categories($topic_args);
       		echo '</ul>';
       		echo $after_widget;
       		?>
   
   
   
               <?php }
   
           /** @see WP_Widget::form */
       	function update( $new_instance, $old_instance ) {
       		$instance = $old_instance;
       		$instance['title'] = strip_tags($new_instance['title']);
       			if ( in_array( $new_instance['tax'], array( 'faq-topic', 'faq-tags' ) ) ) {
       				$instance['tax'] = $new_instance['tax'];
       			} else {
       				$instance['tax'] = 'faq-topic';
       			}
       		return $instance;
       	}
   
           /** @see WP_Widget::form */
       	function form( $instance ) {
   
       		//Defaults
       		$instance = wp_parse_args( (array) $instance, array(
       			'tax'	=> 'faq-topic',
       			'title' => '',
       		) );
       		$title = esc_attr( $instance['title'] );
       	?>
   
               <p>
                   <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Widget Title:' ); ?></label>
                   <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
               </p>
   
       		<p>
       			<label for="<?php echo $this->get_field_id('tax'); ?>"><?php _e( 'Taxonomy:' ); ?></label>
       			<select name="<?php echo $this->get_field_name('tax'); ?>" id="<?php echo $this->get_field_id('tax'); ?>" class="widefat">
       				<option value="faq-topic"<?php selected( $instance['tax'], 'faq-topic' ); ?>><?php _e('FAQ Topics'); ?></option>
       				<option value="faq-tags"<?php selected( $instance['tax'], 'faq-tags' ); ?>><?php _e('FAQ Tags'); ?></option>
       			</select>
       		</p>
   
       		<?php }
   
       } // class 
   
       	/**
       	 * FAQ Tag Cloud
       	 *
       	 * @return WP_FAQ_Manager
       	 */
   
       class cloud_FAQ_Widget extends WP_Widget {
       	// Fix for php 8.1
           //function cloud_FAQ_Widget() {
           function __construct() {
       		$widget_ops = array( 'classname' => 'faq-cloud-widget', 'description' => 'A tag cloud of FAQ topics and tags' );
       		// Fix for php 8.1
               //$this->WP_Widget( 'faq_cloud', 'FAQ Widget - Cloud', $widget_ops );
               parent::__construct( 'faq_cloud', 'FAQ Widget - Cloud', $widget_ops );
       	}
   
       	function widget( $args, $instance ) {
       		extract( $args, EXTR_SKIP );
   
       		echo $before_widget;
   
       		$ok_topic	= isset($instance['to_include']) ? $instance['to_include'] : false;
       		$ok_tag		= isset($instance['ta_include']) ? $instance['ta_include'] : false;
       		$title		= empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
   
       		if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
   
       		echo '<div class="faqcloud">';
       			if ($ok_topic)
       				$cloud_args = array('taxonomy' => 'faq-topic' );
   
       			if($ok_tag)
       				$cloud_args = array('taxonomy' => 'faq-tags' );
   
       			if($ok_topic && $ok_tag)
       				$cloud_args = array('taxonomy' => array ('faq-tags', 'faq-topic' ));
   
               echo wp_tag_cloud( $cloud_args ); 
   
       		echo '</div>';
       		echo $after_widget;
           }
   
           /** @see WP_Widget::update */
   
           function update($new_instance, $old_instance) {				
       		$instance = $old_instance;
       		$instance['title'] = strip_tags($new_instance['title']);
       		$instance['to_include'] = !empty($new_instance['to_include']) ? 1 : 0;
       		$instance['ta_include'] = !empty($new_instance['ta_include']) ? 1 : 0;
       	        return $instance;
           }	
   
           /** @see WP_Widget::form */
           function form($instance) {				
               $instance = wp_parse_args( (array) $instance, array( 
       			'title'			=> 'Recent Topics',
       			'to_include'	=> 0,
       			'ta_include'	=> 1,
       		));
   
       		$title = strip_tags($instance['title']);
   
       		foreach ( $instance as $field => $val ) :
       			if ( isset($new_instance[$field]) )
       				$instance[$field] = 1;
   
       		endforeach;
               ?>
   
               <p>
                   <label for="<?php echo $this->get_field_id('title'); ?>">Widget Title:</label>
                   <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
               </p>
   
              	<p>
              		<input class="checkbox" type="checkbox" <?php checked($instance['to_include'], true) ?> id="<?php echo $this->get_field_id('to_include'); ?>" name="<?php echo $this->get_field_name('to_include'); ?>" />
       	        <label for="<?php echo $this->get_field_id('to_include'); ?>"><?php _e('Include FAQ Topics'); ?></label>
       	    </p>
   
              	<p>
              		<input class="checkbox" type="checkbox" <?php checked($instance['ta_include'], true) ?> id="<?php echo $this->get_field_id('ta_include'); ?>" name="<?php echo $this->get_field_name('ta_include'); ?>" />
       			<label for="<?php echo $this->get_field_id('ta_include'); ?>"><?php _e('Include FAQ Tags'); ?></label>
       		</p>
   
       		<?php }
   
       } // class 
   
       	/**
       	 * Register all widgets
       	 *
       	 * @return WP_FAQ_Manager
       	 */
   
       // Fix for php 8.1
       // add_action( 'widgets_init', create_function( '', "register_widget('search_FAQ_Widget');" ) );
       // add_action( 'widgets_init', create_function( '', "register_widget('random_FAQ_Widget');" ) );
       // add_action( 'widgets_init', create_function( '', "register_widget('recent_FAQ_Widget');" ) );
       // add_action( 'widgets_init', create_function( '', "register_widget('topics_FAQ_Widget');" ) );
       // add_action( 'widgets_init', create_function( '', "register_widget('cloud_FAQ_Widget');" ) );
   
       add_action( 'widgets_init', function() {register_widget('search_FAQ_Widget');});;
       add_action( 'widgets_init', function() {register_widget('random_FAQ_Widget');});
       add_action( 'widgets_init', function() {register_widget('recent_FAQ_Widget');});
       add_action( 'widgets_init', function() {register_widget('topics_FAQ_Widget');});
       add_action( 'widgets_init', function() {register_widget('cloud_FAQ_Widget');});
       ```
   
    -  This reply was modified 3 years, 8 months ago by [byte666](https://wordpress.org/support/users/byte666/).
 *  Plugin Author [curtismchale](https://wordpress.org/support/users/curtismchale/)
 * (@curtismchale)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/fatal-errors-with-php8/#post-16252096)
 * [@webprom](https://wordpress.org/support/users/webprom/) [@byte666](https://wordpress.org/support/users/byte666/)
   I’ve taken over this plugin from Andrew and I also need PHP 8. Expect a new 2.0
   version released in the next week or so. It’s already working and clean on PHP
   8 for me just need to do more testing that it all works as intended with a large
   rewrite Andrew started years ago and I picked up when I took over the plugin 
   a month or so back.
 *  Thread Starter [Webprom Design](https://wordpress.org/support/users/webprom/)
 * (@webprom)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/fatal-errors-with-php8/#post-16252267)
 * great!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Fatal Errors with PHP8’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wordpress-faq-manager_e7e7e7.svg)
 * [SFN Easy FAQ Manager](https://wordpress.org/plugins/wordpress-faq-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wordpress-faq-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wordpress-faq-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/wordpress-faq-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wordpress-faq-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wordpress-faq-manager/reviews/)

## Tags

 * [fatal error](https://wordpress.org/support/topic-tag/fatal-error/)

 * 3 replies
 * 3 participants
 * Last reply from: [Webprom Design](https://wordpress.org/support/users/webprom/)
 * Last activity: [3 years, 5 months ago](https://wordpress.org/support/topic/fatal-errors-with-php8/#post-16252267)
 * Status: resolved