-3

我在下面的代码中收到 T_Return 语法错误。有什么想法吗?

function wp_support_create_feature( $post ) {
  if ( defined('DOING_AUTOSAVE' && DOING_AUTOSAVE )
    return $post;

  if ( has_post_thumbnail( $post ) )
    return $post

  $first = get_children( array(
            'post_parent'    => $post->ID,
            'post_type'      => 'attachment',
            'post_mime_type' => 'image',
            'posts_per_page' => (int)1,
        ), ARRAY_A
   );
  set_post_thumbnail( $post->ID, $first[0]['ID'] );
}
add_action( 'save_post', 'wp_support_create_feature' );
4

2 回答 2

4
if ( defined('DOING_AUTOSAVE' && DOING_AUTOSAVE ))
                                                 ^

你错过了一个右括号。

于 2013-02-11T17:32:22.650 回答
2
function wp_support_create_feature( $post ) {
   if ( defined('DOING_AUTOSAVE' && DOING_AUTOSAVE )) // closing parens
   return $post;

   if ( has_post_thumbnail( $post ) )
   return $post; // semi-colon

$first = get_children( array(
        'post_parent'    => $post->ID,
        'post_type'      => 'attachment',
        'post_mime_type' => 'image',
        'posts_per_page' => (int)1,
    ), ARRAY_A
);
set_post_thumbnail( $post->ID, $first[0]['ID'] );

} add_action( 'save_post', 'wp_support_create_feature' );
于 2013-02-11T17:33:46.213 回答