0

I'm having a problem with setting feature image, I am using the similar submit several times in the same page to submit post outside the admin area and not getting any errors, only this submit form.

After tracing errors report I found the problem with _get_non_cached_ids function which is in wp-includes/functions.php on line 3816 (twentyeleven theme)

Error says: Object of class WP_Error could not be converted to int

When I test it I got that it is not int, then I try to discover the function casing that error

Below the _get_non_cached_ids function with my test code

/**
 * Retrieve ids that are not already present in the cache
 *
 * @since 3.4.0
 *
 * @param array $object_ids ID list
 * @param string $cache_key The cache bucket to check against
 *
 * @return array
 */
function _get_non_cached_ids( $object_ids, $cache_key ) {
    $clean = array();
    foreach ( $object_ids as $id ) {

        /* my test start */
        if ( is_wp_error( $id ) ) {
            $error_string = $id->get_error_message();
            echo '<div id="message" class="error"><p>' . $error_string . '</p></div>';
            exit; 
        }else{
            echo 'id is ok';
            exit;
        }
        /* my test end */

        $id = (int) $id;
        if ( !wp_cache_get( $id, $cache_key ) ) {
            $clean[] = $id;
        }
    }

    return $clean;
}

I tried the code and got a message saying:

No file was uploaded.

HOW NO FILE WAS UPLOADED even the image uploaded successfully and attached to the post, but it didn't appear as Featured image

and in the admin area for edit post I got an error in the Feature image area says:

Object of class WP_Error could not be converted to int in SITE_ROOT/public_html/wp-includes/post.php on line 4294

I test if is_int and it was int

Note that in the _get_non_cached_ids, exit happening only if there is a problem, which means that if there is no problem the code don't enter to _get_non_cached_ids function at all

4

1 回答 1

0

经过数百次测试后,我的代码的每个块都可以正常工作,最后is_wp_error($id) returns id is ok

从 PC 功能上传图像时出现未知错误,这与从链接上传图像发生冲突,但现在它正在工作,这就是为什么我收到错误消息说:No file was uploaded

于 2013-10-01T16:18:15.020 回答