警告:非法字符串偏移' custom_css_post_id'

时间:2016-12-17 12:47:54

标签: php wordpress

请帮我解决此错误。我是新编码,我有一个wordpress网站,它显示以下错误

  

警告:非法字符串偏移' custom_css_post_id'在/home/content/n3pnexwpnas02_data02/18/3031418/html/wp-includes/theme.php第905行

我应该从哪里开始。因为我是菜鸟,所以有人可以帮助我。

以下是它在theme.php中指出的代码

function wp_get_custom_css_post( $stylesheet = '' ) {
if ( empty( $stylesheet ) ) {
    $stylesheet = get_stylesheet();
}

$custom_css_query_vars = array(
    'post_type'              => 'custom_css',
    'post_status'            => get_post_stati(),
    'name'                   => sanitize_title( $stylesheet ),
    'posts_per_page'         => 1,
    'no_found_rows'          => true,
    'cache_results'          => true,
    'update_post_meta_cache' => false,
    'update_term_meta_cache' => false,
);

$post = null;
if ( get_stylesheet() === $stylesheet ) {
    $post_id = get_theme_mod( 'custom_css_post_id' );

    if ( $post_id > 0 && get_post( $post_id ) ) {
        $post = get_post( $post_id );
    } else {
        $query = new WP_Query( $custom_css_query_vars );
        $post = $query->post;
        /*
         * Cache the lookup. See WP_Customize_Custom_CSS_Setting::update().
         * @todo This should get cleared if a custom_css post is added/removed.
         */
        if ( $post ) {
            set_theme_mod( 'custom_css_post_id', $post->ID );
        } elseif ( -1 !== $post_id ) {
            set_theme_mod( 'custom_css_post_id', -1 );
        }
    }
} else {
    $query = new WP_Query( $custom_css_query_vars );
    $post = $query->post;
}

return $post;

}

2 个答案:

答案 0 :(得分:1)

我是如何解决这个问题的

  1. 切换到另一个默认主题(我使用了 29 个)并重新分配一个主菜单。
  2. 跳入数据库并在“theme_mods_”选项中搜索,那里的每个主题都应该有一个。一个是您损坏的主题,您应该对另一个 129 进行罚款。
  3. 复制 29 中的选项值并将其设置为您损坏的主题的值。然后将其切回并再次分配主菜单。

这可能不是最好的解决方案,但确实有效。

答案 1 :(得分:0)

我遇到了同样的问题,并在此链接上找到了一些内容:

https://wordpress.org/support/topic/illegal-string-offset-warning-4/

我从中得不到什么。但也许你可以从中得到一些东西。

如果你发现有用的东西,请回复。 :)

感谢。

现在很多网站上都显示了一个不必要的WordPress警告,之前从未发布任何问题。

所以我用了一个技巧来阻止wordpress在生产服务器上显示这些问题。

但您可以在开发服务器上删除此技巧。看看:

之后把这个放在下面的代码中
define('WP_DEBUG', false);

在wp-config.php中

ini_set('log_errors','On');
ini_set('display_errors','Off');
ini_set('error_reporting', E_ALL );
define('WP_DEBUG', false);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);