这个旧的WordPress插件有什么问题



激活这个旧的Wordpress插件时,我遇到了几个错误。在我不得不替换不推荐使用的replace_function功能之前,插件一直工作得很好。该插件在媒体库中创建一个表单,并在小部件中输出选定的图像。

插件:

<?php
class FreigeistRandomGalleryWidget extends WP_Widget
{
function FreigeistRandomGalleryWidget()
{
$widget_ops = array('classname' => 'FreigeistRandomGalleryWidget', 'description' => __('Displays random images from the gallery.','freigeist') );
$this->WP_Widget('FreigeistRandomGalleryWidget', 'Freigeist Random Sidebar Gallery', $widget_ops);
}

function form($instance)
{
$instance = wp_parse_args( (array) $instance, array( 'title' => '' , 'amount_images' => '') );
$title = $instance['title'];
$amount_images = $instance['amount_images'];
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:','freigeist'); ?></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 attribute_escape($title); ?>" /></p>
<p><label for="<?php echo $this->get_field_id('amount_images'); ?>"><?php _e('Amount Images:','freigeist'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('amount_images'); ?>" name="<?php echo $this->get_field_name('amount_images'); ?>" type="text" value="<?php echo attribute_escape($amount_images); ?>" /></p>
<?php
}

function update($new_instance, $old_instance)
{
$instance = $old_instance;
$instance['title'] = $new_instance['title'];
$instance['amount_images'] = $new_instance['amount_images'];
return $instance;
}

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;;

// WIDGET CODE GOES HERE

if( isset($instance['amount_images'])) {$amount_images = $instance['amount_images'];} else {$amount_images = 5;}
$sidebar_random_array = array();
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'orderby' => 'post_date',
'order' => 'desc',
'posts_per_page' => '9999',
'post_status'    => 'inherit',
'paged' => $paged,
'meta_query' => array(
array  (
'key' => '_show_in_gallery',
'value'=>true
)
)

);
$loopb = new WP_Query( $args ); ?>
<?php while ( $loopb->have_posts() ) : $loopb->the_post(); 
array_push($sidebar_random_array, get_the_ID());
endwhile;
// Shuffle order of images in gallery
shuffle($sidebar_random_array);
// Only take the ... images for the display
$sidebar_random_array = array_slice($sidebar_random_array,0,$amount_images);
foreach ($sidebar_random_array as &$value) {

$value = '<div class="gallery-sidebar-div"><a href="'.wp_get_attachment_image_src($value,"large")[0].'" data-rel="lightbox-gallery-1"><img src="'.wp_get_attachment_image_src($value)[0].'" alt="'.get_the_title($value).' '.__('by','freigeist').' '.$artist.'"></a><a href="'.get_site_url().fr_gallery_url().$value.'"><span><i>'.get_the_title($value).'</i>, '.get_post_meta($value, 'artist_name', true).'</span></a></div>';
}
unset($value,$img,$title);
echo implode('',$sidebar_random_array);

}

}


add_action(
'widgets_init', 
function() {
return register_widget("FreigeistRandomGalleryWidget");
}
);

?>

错误:

Fatal error: Uncaught ArgumentCountError: Too few arguments to function WP_Widget::__construct(), 0 passed in /customers/3/c/f/domain.xy/httpd.www/wp-includes/class-wp-widget-factory.php on line 61 and at least 2 expected in /customers/3/c/f/domain.xy/httpd.www/wp-includes/class-wp-widget.php:162 Stack trace: #0 /customers/3/c/f/domain.xy/httpd.www/wp-includes/class-wp-widget-factory.php(61): WP_Widget->__construct() #1 /customers/3/c/f/domain.xy/httpd.www/wp-includes/widgets.php(115): WP_Widget_Factory->register('FreigeistRandom...') #2 /customers/3/c/f/domain.xy/httpd.www/wp-content/plugins/freigeist-random-gallery-widget.php(119): register_widget('FreigeistRandom...') #3 /customers/3/c/f/domain.xy/httpd.www/wp-includes/class-wp-hook.php(303): {closure}('') #4 /customers/3/c/f/domain.xy/httpd.www/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters(NULL, Array) #5 /customers/3/c/f/domain.xy/httpd.www/wp-includes/plugin.php(470): WP_Hook->do_action(Array) #6 /customers/3/c/f/domain.xy/httpd.www/wp-includes/widgets.php(1809): do_action('widgets_init') #7 /customers/3/c/f/domain.xy/httpd.www/wp-includes/class-wp-hook.php(303): wp_widgets_init('') #8 /customers/3/c/f/domain.xy/httpd.www/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters(NULL, Array) #9 /customers/3/c/f/domain.xy/httpd.www/wp-includes/plugin.php(470): WP_Hook->do_action(Array) #10 /customers/3/c/f/domain.xy/httpd.www/wp-settings.php(578): do_action('init') #11 /customers/3/c/f/domain.xy/httpd.www/wp-config.php(88): require_once('/customers/3/c/...') #12 /customers/3/c/f/domain.xy/httpd.www/wp-load.php(50): require_once('/customers/3/c/...') #13 /customers/3/c/f/domain.xy/httpd.www/wp-blog-header.php(13): require_once('/customers/3/c/...') #14 /customers/3/c/f/domain.xy/httpd.www/index.php(17): require('/customers/3/c/...') #15 {main} thrown in /customers/3/c/f/domain.xy/httpd.www/wp-includes/class-wp-widget.php on line 162 

如果有人能向我解释这些错误的含义以及如何修复它们,我将不胜感激!

此错误表示插件在实例化一个对象时传递的参数太少,而该对象在创建时需要这些值。

假设这是旧的代码,不再适用于新版本的wordpress,那么当WP_Widget最初注册时,这个旧插件代码的机制不会发送新的需求。

查找该文件中的第162行查找/customers/3/c/f/domain.xy/httpd.www/wp-includes/class-wp-widget.php:162,并确保传递的内容在/customers/3/c/f/domain.xy/httpd.www/wp-includes/class-wp-widget-factory.php on line 61中可用

如果你使用的是过时的WordPress插件或核心代码,那么要找出不起作用的地方并进行适当的修改将更加困难。如果你想根据最新的WordPress核心重新编写一个过时的插件,你需要弄清楚核心发生了什么变化,以及如何适当地修改你的插件示例。

这个错误告诉你,你错过了它现在期望的参数。对我来说,这意味着插件中的调用因WordPress核心的更改而被弃用。我只能假设你现在的环境是什么。

最新更新