簡體   English   中英

這個舊的 Wordpress 插件有什么問題

[英]What's wrong with this old Wordpress Plugin

激活這個舊的 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 

如果有人可以向我解釋錯誤的含義以及如何解決它們,我將不勝感激!

此錯誤表示您的插件在實例化 object 時傳遞的 arguments 太少,現在它在創建時需要這些值。

假設這是舊代碼不再適用於 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 核心重新創作一個過時的插件,您需要弄清楚核心中發生了什么變化以及如何適當地修改您的插件示例。

該錯誤告訴您您缺少它現在期望的 arguments 。 對我來說,這表示插件中的調用已被 WordPress 核心的更改棄用。 我只能假設此時您的環境是什么。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM