当我尝试在wordpress中保存帖子时,我收到此消息:
致命错误:无法使用WP_Error类型的对象作为数组 第354行的wp-admin / includes / post.php
我主题中的第354行:
if ( ! empty( $_term ) ) {
$clean_terms[] = intval( $_term[0] ); //Line : 354
} else {
// No existing term was found, so pass the string. A new term will be created.
$clean_terms[] = $term;
}

这是我主题的 function.php :
<?php
require_once 'inc/functions-nav-menu.php';
require_once 'inc/functions-comments.php';
require_once 'inc/functions-custom-header.php';
require_once 'inc/functions-meta.php';
require_once 'inc/functions-sidebar.php';
require_once 'inc/functions-product.php';
/**
* Load theme domain name to enable language support.
*/
load_theme_textdomain( 'smr', get_template_directory() . '/languages' );
/**
* Set post type to main query on home page, because of we are displaying products on front page
* * We use is_front_page() instead of is_home() condition because of if user made choice to
* * display page on frontend and selected two equal pages both in "Posts page" and "Front page"
* * select boxes - we will see list of products like list of pages.
* *
* * See difference between this conditional for more info.
*/
add_action( 'pre_get_posts', function( $query ) {
if ( is_front_page() && $query->is_main_query() )
$query->set( 'post_type', array( 'smr-product' ) );
return $query;
});
/**
* Add editor styles to admin area
* By default editor-style.css is loaded. Depending on "style_schema" option
* we load corresponding stylesheets.
*
* Add theme supports
* * Thumbnails
* Remove page supports
* * Comments
*/
add_action( 'init', function() {
add_editor_style();
/* load editor-style css file in order to used style schema */
$option = get_option( 'smr_theme_options' );
switch ( $option['style_schema'] ) {
case 'red': {
add_editor_style('editor-style-red.css');
break;
}
}
/* Add theme supports thumbnails for post */
add_theme_support( 'post-thumbnails' );
/* Remove comments support for pages */
remove_post_type_support( 'page', 'comments' );
});
/**
* Retrieve protected post password form content.
*
* @return string HTML content for password form for password protected post.
*/
add_filter( 'the_password_form', function() {
$post = get_post();
$label = 'pwbox-' . ( empty( $post->ID ) ? rand() : $post->ID );
return sprintf(
'<form action="%s" method="post" class="post-password-protected">
<p>%s</p>
<input name="post_password" id="%s" type="password" placeholder="Type password here..." size="20" />
<input type="submit" name="Submit" value="%s" />
</form>',
esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ),
__( 'This post is password protected. To view it please enter your password below:', 'smr' ),
$label,
esc_attr__( 'Submit', 'smr' )
);
});
/**
* Registering new section on admin theme customization page to make ability to admin to switch theme styles.
*
* We have two style schemas: 'silver' and 'red'. 'silver' is used by default.
* Admin chose of used schema is saved in option[smr_theme_options][style_schema].
*/
add_action( 'customize_register', function( WP_Customize_Manager $wp_customize ) {
$wp_customize->add_section( 'smr_color_scheme', array(
'title' => __( 'Color Scheme', 'smr' ),
));
$wp_customize->add_setting( 'smr_theme_options[style_schema]', array(
'default' => 'silver',
'capability' => 'edit_theme_options',
'type' => 'option',
));
$wp_customize->add_control( 'example_select_box', array(
'settings' => 'smr_theme_options[style_schema]',
'label' => __( 'Select Style Schema:', 'smr' ),
'section' => 'smr_color_scheme',
'type' => 'select',
'choices' => smr_theme_options_schema_style_get_allowed()
));
});
/**
* Enqueues scripts and styles for front-end.
*
* Theme has choose style schema option, admin can choose it from theme customize menu.
* In order to that choose, we load needed css file.
*
* @see action to hook "customize_register" below for more info about alowed switched styles.
*/
add_action( 'wp_enqueue_scripts', function() {
/* Stylesheet */
global $wp_styles;
wp_enqueue_style( 'smr-stylesheet-bootstrap', get_template_directory_uri() . '/css/bootstrap.css' );
wp_enqueue_style( 'smr-stylesheet-bootstrap-responsive', get_template_directory_uri() . '/css/bootstrap-responsive.css' );
wp_enqueue_style( 'smr-stylesheet-style', get_template_directory_uri() . '/css/style.css' );
wp_enqueue_style( 'smr-stylesheet-form', get_template_directory_uri() . '/css/form.css' );
/* load css file if needs (if theme style is not default) */
$option = get_option( 'smr_theme_options' );
if ( in_array( $option['style_schema'], array_keys( smr_theme_options_schema_style_get_allowed() ) ) &&
file_exists( get_template_directory() . '/css/style-' . $option['style_schema'] . '.css' ) )
wp_enqueue_style( 'smr-stylesheet-style-' . $option['style_schema'], get_template_directory_uri() . '/css/style-' . $option['style_schema'] . '.css' );
wp_enqueue_style( 'smr-stylesheet-style-responsive', get_template_directory_uri() . '/css/style-responsive.css' );
/* Loads main stylesheet */
wp_enqueue_style( 'smr-stylesheet', get_stylesheet_uri() );
/* Loads the Internet Explorer specific stylesheet */
wp_enqueue_style( 'smr-stylesheet-ie', get_template_directory_uri() . '/css/ie.css' );
wp_enqueue_style( 'smr-stylesheet-ie-lt9', get_template_directory_uri() . '/css/ie-lt9.css' );
wp_enqueue_style( 'smr-stylesheet-ie7', get_template_directory_uri() . '/css/ie7.css' );
$wp_styles->add_data( 'smr-stylesheet-ie', 'conditional', 'IE' );
$wp_styles->add_data( 'smr-stylesheet-ie-lt9', 'conditional', 'lt IE 9' );
$wp_styles->add_data( 'smr-stylesheet-ie7', 'conditional', 'IE 7' );
/* Javascript */
wp_enqueue_script( 'smr-javascript-jquery', get_template_directory_uri() . '/js/jquery-1.7.1.min.js', array() );
wp_enqueue_script( 'smr-javascript-bootstrap-min', get_template_directory_uri() . '/js/bootstrap.min.js', array(), FALSE, TRUE );
/* Load script to renew social buttons data ( on front page, on product category page and on single product page ) */
if ( is_home() || 'smr-product-category' === get_query_var('taxonomy') || ( is_single() && 'smr-product' === get_post_type() ) )
wp_enqueue_script( 'smr-javascript-smr-social-buttons', get_template_directory_uri() . '/js/smr-social-buttons.js', array(), FALSE, TRUE );
/* we use jquery.isotope only on front page and product category page */
if ( is_home() || 'smr-product-category' === get_query_var('taxonomy') ) {
wp_enqueue_script( 'smr-javascript-jquery-isotope-min', get_template_directory_uri() . '/js/jquery.isotope.min.js', array(), FALSE, TRUE );
wp_enqueue_script( 'smr-javascript-smr-landing-page', get_template_directory_uri() . '/js/smr-landing-page.js', array(), FALSE, TRUE );
}
/* Load script for single product ( to hide/show "overview", "details" ) */
if ( is_single() && 'smr-product' === get_post_type() )
wp_enqueue_script( 'smr-javascript-smr-product-single', get_template_directory_uri() . '/js/smr-product-single.js', array(), FALSE, TRUE );
wp_enqueue_script( 'smr-javascript-smr-common', get_template_directory_uri() . '/js/smr-common.js', array(), FALSE, TRUE );
wp_enqueue_script( 'comment-reply', array(), FALSE, TRUE );
});
/**
* Returns more button to use in except()
*/
add_filter( 'excerpt_more', function( $more ) {
global $post;
// return ! is_home()
// ? '<div class="right read-more"><a class="btn" href="'. get_permalink( $post->ID ) . '">Read more</a></div>'
// : ' <a href="'. get_permalink( $post->ID ) . '">[Read more...]</a>';
return ' <a href="'. get_permalink( $post->ID ) . '">[Read more...]</a>';
});
/**
* Creates a nicely formatted and more specific title element text
* for output in head of document, based on current view.
*/
add_filter( 'wp_title', function( $title, $sep ) {
global $paged, $page;
if ( is_feed() )
return $title;
/* Add the site name */
$title .= get_bloginfo( 'name' );
/* Add the site description for the home/front page */
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) )
$title = "$title $sep $site_description";
/* Add a page number if necessary */
if ( $paged >= 2 || $page >= 2 )
$title = "$title $sep " . sprintf( __( 'Page %s', 'smr' ), max( $paged, $page ) );
return $title;
}, 10, 2 );
/**
* Return allowed theme color styles array
*/
if ( ! function_exists('smr_theme_options_schema_style_get_allowed') ) {
function smr_theme_options_schema_style_get_allowed() {
return array(
'silver' => 'Silver',
'red' => 'Red'
);
}
}
/**
* Displays navigation to next/previous pages when applicable.
*/
if ( ! function_exists( 'smr_content_pagination' ) ) {
function smr_content_pagination() {
global $wp_query;
if ( $wp_query->max_num_pages > 1 ) : ?>
<nav class="nav-single">
<span class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Previous', 'smr' ) ); ?></span>
<span class="nav-next"><?php previous_posts_link( __( 'Next <span class="meta-nav">→</span>', 'smr' ) ); ?></span>
<div class="clearfix"></div>
</nav>
<?php endif;
}
}
/**
* Returns default image url
*/
if ( ! function_exists('smr_get_default_image_url') ) {
function smr_get_default_image_url( $type = 'smr-product' ) {
$file_url = get_template_directory_uri() . '/images/placeholder_' . $type . '.png';
$file = get_template_directory() . '/images/placeholder_' . $type . '.png';
return ( file_exists( $file ) ) ? $file_url : get_template_directory_uri() . "/images/placeholder_smr-product.png";
}
}
/**
* Display escaped title.
* We add this function because wordpress doesn`t do it.
* It means wordpress function 'the_title()'.
*
* @param $post - post id
*/
if ( ! function_exists('smr_the_title') ) {
function smr_the_title( $post = 0 ) {
echo esc_attr( get_the_title( $post ) );
}
}
&#13;
有人能帮我找到这个错误吗?