【问题标题】:stdClass wordpress plugin errorstdClass wordpress插件错误
【发布时间】:2018-07-04 18:23:54
【问题描述】:

当我访问 wordpress dashbord 以安装新插件时,会出现上述错误

第 150 行 /var/sentora/hostdata/websitenligne/public_html/sme2/wp-includes/class-wp-list-util.php 中的stdClass::$plugin

public function pluck( $field, $index_key = null ) {
		if ( ! $index_key ) {
			/*
			 * This is simple. Could at some point wrap array_column()
			 * if we knew we had an array of arrays.
			 */
			foreach ( $this->output as $key => $value ) {
				if ( is_object( $value ) ) {
					$this->output[ $key ] = $value->$field;
				} else {
					$this->output[ $key ] = $value[ $field ];
				}
			}
			return $this->output;
		}

		/*
		 * When index_key is not set for a particular item, push the value
		 * to the end of the stack. This is how array_column() behaves.
		 */
		$newlist = array();
		foreach ( $this->output as $value ) {
			if ( is_object( $value ) ) {
				if ( isset( $value->$index_key ) ) {
					$newlist[ $value->$index_key ] = $value->$field;
				} else {
					$newlist[] = $value->$field;
				}
			} else {
				if ( isset( $value[ $index_key ] ) ) {
					$newlist[ $value[ $index_key ] ] = $value[ $field ];
				} else {
					$newlist[] = $value[ $field ];
				}
			}
		}

		$this->output = $newlist;

		return $this->output;
	}

错误是什么?

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    这个问题似乎首先是introduced in version 4.7,并且是由于wp-includes/class-wp-list-util.php 没有检查是否设置了对象属性。

    在 WordPress 5.2.1 中看起来像 is still present(在本文发布时最新)。第 152 行应该是这样的:

    $this->output[ $key ] = isset( $value->$field ) ? $value->$field : null;
    

    无论如何...要删除此警告,请编辑您的 wp-config.php 并更改:

    define( 'WP_DEBUG', true );
    

    ...对此(或完全注释掉WP_DEBUG 行):

    define( 'WP_DEBUG', false );
    

    或者,如果您想启用WP_DEBUG,但将其输出限制为wp-content/debug.log,您可以添加它:

    define( 'WP_DEBUG_LOG', true );
    define( 'WP_DEBUG_DISPLAY', false );
    
    • WP_DEBUG(尤其是 WP_DEBUG_LOG 应该在生产环境或任何可公开访问的站点(例如 QA/staging)上启用,除非您知道自己在做什么(否则敏感信息可能会泄露)。

    【讨论】:

    • 很好的答案!我尝试按照您描述的方式解决此问题,但我发现一个插件可能会导致此问题,因为在我的情况下没有遵循 WordPress 标准是 Smart Slider 3 Pro 吗? ,但是如果将其设置为 null 会发生什么?我尝试运行您描述的代码,然后我可以工作,然后我再次输入旧代码,错误消失了
    【解决方案2】:

    这篇文章给了我一些很好的例子来解决这个问题https://www.thetwopercent.co.uk/wordpress-error-solved-notice-undefined-property-stdclass-plugin/ 并且您可以找到导致问题的女巫插件的方法是将这段代码放在该函数上,以确定哪个插件导致了问题。那么结果将是:isvalidEmpty:1 这样你就可以找到导致问题的插件。

    public function pluck( $field, $index_key = null ) {
                $newlist = array();
            
                if ( ! $index_key ) {
                    /*
                     * This is simple. Could at some point wrap array_column()
                     * if we knew we had an array of arrays.
                     */
                    foreach ( $this->output as $key => $value ) {
                        if ( is_object( $value ) ) {
                       //this code to ouput the plugin that causing the problem 
                            echo('<div style="margin-left: 251px;">' );
                            echo('<p>is object</p>' );
                            echo('<h2 style="margin-left: 400px;">'.(string)  $key."</h2> 
                            <br/>" );
                            echo('<h2 style="margin-left: 251px;"> field:'. $field."</h2> 
                            <br/>" );
                            
                            echo('<h2 style="margin-left: 251px;"> 
                             isvalidEmpty:'.empty($value->$field)."</h2><br/>" );
                            echo('</div>' );
    

    【讨论】:

    • 上述解决方案让我可以确定是哪个插件导致了我的问题。就我而言,它是 yoast-seo-wordpress-premium。删除插件后,问题错误通知仍然显示,但是,从数据库中删除瞬态后,错误消失了。直接在数据库上运行删除瞬态的查询有助于避免安装插件来清除瞬态:DELETE FROM wp_options` WHERE option_name LIKE ('_transient_%');从wp_options 删除option_name LIKE ('_site_transient_%');`
    • 只是在我上面的评论中添加:Yoast SEO Premium 支持返回了一个有用的答案,他们确认问题出在他们的插件中,他们将在未来的版本中修复它。同时,他们提供了以下解决方法:“您可以禁用 WordPress 调试模式,这将隐藏相关警告而不影响您网站上的任何内容。或者,您可以忽略相关警告,因为您在 localhost 上运行您的网站;生产站点通常不会在启用调试模式的情况下运行。"
    【解决方案3】:

    尝试通过以下方式更新您的 wordpress:仪表板 -> 更新 如果您有最新版本,请尝试重新安装它,您的问题将得到解决

    【讨论】:

    • 我已经更新了,我现在的版本是4.9.2,问题依旧
    • 所以你应该停用所有插件并测试或设置 wp 的默认模板
    • 我尝试了 26 个或者停用插件,没有任何变化
    【解决方案4】:

    尝试更新所有有可用更新的插件。这解决了我的问题。

    【讨论】:

    • (这篇文章似乎没有为问题提供quality answer。请编辑您的答案并改进它,或者将其作为对该问题的评论发布。)
    【解决方案5】:

    转到 /wp-includes/class-wp-list-util.php 找到公共函数 pluck 函数,然后替换这部分。

    foreach ( $this->output as $key => $value ) {
                    if ( is_object( $value ) ) {
                        if(isset($value->$field)){
                            $newlist[ $key ] = $value->$field;
                        }
    

    如果你稍后更新你的 wordpress,这肯定行不通,你必须重做这个。但是你在这里更新核心是因为你必须并且没有其他选择,不是因为你想要。在我的情况下,错误是造成的通过 elementor 插件。

    【讨论】:

      【解决方案6】:

      警告:未定义的属性:第 166 行 C:\xampp\htdocs\Dressbarn\wp-includes\class-wp-list-util.php 中的 stdClass::$plugin 当我的仪表板中显示此错误消息时--------解决方案--- 更新所有插件有助于此类消息消失。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-12-30
        • 2014-11-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-30
        相关资源
        最近更新 更多