Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (7 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r42228 r42343  
    1919 */
    2020function create_initial_post_types() {
    21     register_post_type( 'post', array(
    22         'labels' => array(
    23             'name_admin_bar' => _x( 'Post', 'add new from admin bar' ),
    24         ),
    25         'public'  => true,
    26         '_builtin' => true, /* internal use only. don't use this when registering your own post type. */
    27         '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
    28         'capability_type' => 'post',
    29         'map_meta_cap' => true,
    30         'menu_position' => 5,
    31         'hierarchical' => false,
    32         'rewrite' => false,
    33         'query_var' => false,
    34         'delete_with_user' => true,
    35         'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ),
    36         'show_in_rest' => true,
    37         'rest_base' => 'posts',
    38         'rest_controller_class' => 'WP_REST_Posts_Controller',
    39     ) );
    40 
    41     register_post_type( 'page', array(
    42         'labels' => array(
    43             'name_admin_bar' => _x( 'Page', 'add new from admin bar' ),
    44         ),
    45         'public' => true,
    46         'publicly_queryable' => false,
    47         '_builtin' => true, /* internal use only. don't use this when registering your own post type. */
    48         '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
    49         'capability_type' => 'page',
    50         'map_meta_cap' => true,
    51         'menu_position' => 20,
    52         'hierarchical' => true,
    53         'rewrite' => false,
    54         'query_var' => false,
    55         'delete_with_user' => true,
    56         'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions' ),
    57         'show_in_rest' => true,
    58         'rest_base' => 'pages',
    59         'rest_controller_class' => 'WP_REST_Posts_Controller',
    60     ) );
    61 
    62     register_post_type( 'attachment', array(
    63         'labels' => array(
    64             'name' => _x('Media', 'post type general name'),
    65             'name_admin_bar' => _x( 'Media', 'add new from admin bar' ),
    66             'add_new' => _x( 'Add New', 'add new media' ),
    67             'edit_item' => __( 'Edit Media' ),
    68             'view_item' => __( 'View Attachment Page' ),
    69             'attributes' => __( 'Attachment Attributes' ),
    70         ),
    71         'public' => true,
    72         'show_ui' => true,
    73         '_builtin' => true, /* internal use only. don't use this when registering your own post type. */
    74         '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
    75         'capability_type' => 'post',
    76         'capabilities' => array(
    77             'create_posts' => 'upload_files',
    78         ),
    79         'map_meta_cap' => true,
    80         'hierarchical' => false,
    81         'rewrite' => false,
    82         'query_var' => false,
    83         'show_in_nav_menus' => false,
    84         'delete_with_user' => true,
    85         'supports' => array( 'title', 'author', 'comments' ),
    86         'show_in_rest' => true,
    87         'rest_base' => 'media',
    88         'rest_controller_class' => 'WP_REST_Attachments_Controller',
    89     ) );
     21    register_post_type(
     22        'post', array(
     23            'labels'                => array(
     24                'name_admin_bar' => _x( 'Post', 'add new from admin bar' ),
     25            ),
     26            'public'                => true,
     27            '_builtin'              => true, /* internal use only. don't use this when registering your own post type. */
     28            '_edit_link'            => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
     29            'capability_type'       => 'post',
     30            'map_meta_cap'          => true,
     31            'menu_position'         => 5,
     32            'hierarchical'          => false,
     33            'rewrite'               => false,
     34            'query_var'             => false,
     35            'delete_with_user'      => true,
     36            'supports'              => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ),
     37            'show_in_rest'          => true,
     38            'rest_base'             => 'posts',
     39            'rest_controller_class' => 'WP_REST_Posts_Controller',
     40        )
     41    );
     42
     43    register_post_type(
     44        'page', array(
     45            'labels'                => array(
     46                'name_admin_bar' => _x( 'Page', 'add new from admin bar' ),
     47            ),
     48            'public'                => true,
     49            'publicly_queryable'    => false,
     50            '_builtin'              => true, /* internal use only. don't use this when registering your own post type. */
     51            '_edit_link'            => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
     52            'capability_type'       => 'page',
     53            'map_meta_cap'          => true,
     54            'menu_position'         => 20,
     55            'hierarchical'          => true,
     56            'rewrite'               => false,
     57            'query_var'             => false,
     58            'delete_with_user'      => true,
     59            'supports'              => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions' ),
     60            'show_in_rest'          => true,
     61            'rest_base'             => 'pages',
     62            'rest_controller_class' => 'WP_REST_Posts_Controller',
     63        )
     64    );
     65
     66    register_post_type(
     67        'attachment', array(
     68            'labels'                => array(
     69                'name'           => _x( 'Media', 'post type general name' ),
     70                'name_admin_bar' => _x( 'Media', 'add new from admin bar' ),
     71                'add_new'        => _x( 'Add New', 'add new media' ),
     72                'edit_item'      => __( 'Edit Media' ),
     73                'view_item'      => __( 'View Attachment Page' ),
     74                'attributes'     => __( 'Attachment Attributes' ),
     75            ),
     76            'public'                => true,
     77            'show_ui'               => true,
     78            '_builtin'              => true, /* internal use only. don't use this when registering your own post type. */
     79            '_edit_link'            => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
     80            'capability_type'       => 'post',
     81            'capabilities'          => array(
     82                'create_posts' => 'upload_files',
     83            ),
     84            'map_meta_cap'          => true,
     85            'hierarchical'          => false,
     86            'rewrite'               => false,
     87            'query_var'             => false,
     88            'show_in_nav_menus'     => false,
     89            'delete_with_user'      => true,
     90            'supports'              => array( 'title', 'author', 'comments' ),
     91            'show_in_rest'          => true,
     92            'rest_base'             => 'media',
     93            'rest_controller_class' => 'WP_REST_Attachments_Controller',
     94        )
     95    );
    9096    add_post_type_support( 'attachment:audio', 'thumbnail' );
    9197    add_post_type_support( 'attachment:video', 'thumbnail' );
    9298
    93     register_post_type( 'revision', array(
    94         'labels' => array(
    95             'name' => __( 'Revisions' ),
    96             'singular_name' => __( 'Revision' ),
    97         ),
    98         'public' => false,
    99         '_builtin' => true, /* internal use only. don't use this when registering your own post type. */
    100         '_edit_link' => 'revision.php?revision=%d', /* internal use only. don't use this when registering your own post type. */
    101         'capability_type' => 'post',
    102         'map_meta_cap' => true,
    103         'hierarchical' => false,
    104         'rewrite' => false,
    105         'query_var' => false,
    106         'can_export' => false,
    107         'delete_with_user' => true,
    108         'supports' => array( 'author' ),
    109     ) );
    110 
    111     register_post_type( 'nav_menu_item', array(
    112         'labels' => array(
    113             'name' => __( 'Navigation Menu Items' ),
    114             'singular_name' => __( 'Navigation Menu Item' ),
    115         ),
    116         'public' => false,
    117         '_builtin' => true, /* internal use only. don't use this when registering your own post type. */
    118         'hierarchical' => false,
    119         'rewrite' => false,
    120         'delete_with_user' => false,
    121         'query_var' => false,
    122     ) );
    123 
    124     register_post_type( 'custom_css', array(
    125         'labels' => array(
    126             'name'          => __( 'Custom CSS' ),
    127             'singular_name' => __( 'Custom CSS' ),
    128         ),
    129         'public'           => false,
    130         'hierarchical'     => false,
    131         'rewrite'          => false,
    132         'query_var'        => false,
    133         'delete_with_user' => false,
    134         'can_export'       => true,
    135         '_builtin'         => true, /* internal use only. don't use this when registering your own post type. */
    136         'supports'         => array( 'title', 'revisions' ),
    137         'capabilities'     => array(
    138             'delete_posts'           => 'edit_theme_options',
    139             'delete_post'            => 'edit_theme_options',
    140             'delete_published_posts' => 'edit_theme_options',
    141             'delete_private_posts'   => 'edit_theme_options',
    142             'delete_others_posts'    => 'edit_theme_options',
    143             'edit_post'              => 'edit_css',
    144             'edit_posts'             => 'edit_css',
    145             'edit_others_posts'      => 'edit_css',
    146             'edit_published_posts'   => 'edit_css',
    147             'read_post'              => 'read',
    148             'read_private_posts'     => 'read',
    149             'publish_posts'          => 'edit_theme_options',
    150         ),
    151     ) );
    152 
    153     register_post_type( 'customize_changeset', array(
    154         'labels' => array(
    155             'name'               => _x( 'Changesets', 'post type general name' ),
    156             'singular_name'      => _x( 'Changeset', 'post type singular name' ),
    157             'menu_name'          => _x( 'Changesets', 'admin menu' ),
    158             'name_admin_bar'     => _x( 'Changeset', 'add new on admin bar' ),
    159             'add_new'            => _x( 'Add New', 'Customize Changeset' ),
    160             'add_new_item'       => __( 'Add New Changeset' ),
    161             'new_item'           => __( 'New Changeset' ),
    162             'edit_item'          => __( 'Edit Changeset' ),
    163             'view_item'          => __( 'View Changeset' ),
    164             'all_items'          => __( 'All Changesets' ),
    165             'search_items'       => __( 'Search Changesets' ),
    166             'not_found'          => __( 'No changesets found.' ),
    167             'not_found_in_trash' => __( 'No changesets found in Trash.' ),
    168         ),
    169         'public' => false,
    170         '_builtin' => true, /* internal use only. don't use this when registering your own post type. */
    171         'map_meta_cap' => true,
    172         'hierarchical' => false,
    173         'rewrite' => false,
    174         'query_var' => false,
    175         'can_export' => false,
    176         'delete_with_user' => false,
    177         'supports' => array( 'title', 'author' ),
    178         'capability_type' => 'customize_changeset',
    179         'capabilities' => array(
    180             'create_posts' => 'customize',
    181             'delete_others_posts' => 'customize',
    182             'delete_post' => 'customize',
    183             'delete_posts' => 'customize',
    184             'delete_private_posts' => 'customize',
    185             'delete_published_posts' => 'customize',
    186             'edit_others_posts' => 'customize',
    187             'edit_post' => 'customize',
    188             'edit_posts' => 'customize',
    189             'edit_private_posts' => 'customize',
    190             'edit_published_posts' => 'do_not_allow',
    191             'publish_posts' => 'customize',
    192             'read' => 'read',
    193             'read_post' => 'customize',
    194             'read_private_posts' => 'customize',
    195         ),
    196     ) );
    197 
    198     register_post_type( 'oembed_cache', array(
    199         'labels' => array(
    200             'name'          => __( 'oEmbed Responses' ),
    201             'singular_name' => __( 'oEmbed Response' ),
    202         ),
    203         'public'           => false,
    204         'hierarchical'     => false,
    205         'rewrite'          => false,
    206         'query_var'        => false,
    207         'delete_with_user' => false,
    208         'can_export'       => false,
    209         '_builtin'         => true, /* internal use only. don't use this when registering your own post type. */
    210         'supports'         => array(),
    211     ) );
    212 
    213     register_post_status( 'publish', array(
    214         'label'       => _x( 'Published', 'post status' ),
    215         'public'      => true,
    216         '_builtin'    => true, /* internal use only. */
    217         'label_count' => _n_noop( 'Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>' ),
    218     ) );
    219 
    220     register_post_status( 'future', array(
    221         'label'       => _x( 'Scheduled', 'post status' ),
    222         'protected'   => true,
    223         '_builtin'    => true, /* internal use only. */
    224         'label_count' => _n_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>' ),
    225     ) );
    226 
    227     register_post_status( 'draft', array(
    228         'label'       => _x( 'Draft', 'post status' ),
    229         'protected'   => true,
    230         '_builtin'    => true, /* internal use only. */
    231         'label_count' => _n_noop( 'Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>' ),
    232     ) );
    233 
    234     register_post_status( 'pending', array(
    235         'label'       => _x( 'Pending', 'post status' ),
    236         'protected'   => true,
    237         '_builtin'    => true, /* internal use only. */
    238         'label_count' => _n_noop( 'Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>' ),
    239     ) );
    240 
    241     register_post_status( 'private', array(
    242         'label'       => _x( 'Private', 'post status' ),
    243         'private'     => true,
    244         '_builtin'    => true, /* internal use only. */
    245         'label_count' => _n_noop( 'Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>' ),
    246     ) );
    247 
    248     register_post_status( 'trash', array(
    249         'label'       => _x( 'Trash', 'post status' ),
    250         'internal'    => true,
    251         '_builtin'    => true, /* internal use only. */
    252         'label_count' => _n_noop( 'Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>' ),
    253         'show_in_admin_status_list' => true,
    254     ) );
    255 
    256     register_post_status( 'auto-draft', array(
    257         'label'    => 'auto-draft',
    258         'internal' => true,
    259         '_builtin' => true, /* internal use only. */
    260     ) );
    261 
    262     register_post_status( 'inherit', array(
    263         'label'    => 'inherit',
    264         'internal' => true,
    265         '_builtin' => true, /* internal use only. */
    266         'exclude_from_search' => false,
    267     ) );
     99    register_post_type(
     100        'revision', array(
     101            'labels'           => array(
     102                'name'          => __( 'Revisions' ),
     103                'singular_name' => __( 'Revision' ),
     104            ),
     105            'public'           => false,
     106            '_builtin'         => true, /* internal use only. don't use this when registering your own post type. */
     107            '_edit_link'       => 'revision.php?revision=%d', /* internal use only. don't use this when registering your own post type. */
     108            'capability_type'  => 'post',
     109            'map_meta_cap'     => true,
     110            'hierarchical'     => false,
     111            'rewrite'          => false,
     112            'query_var'        => false,
     113            'can_export'       => false,
     114            'delete_with_user' => true,
     115            'supports'         => array( 'author' ),
     116        )
     117    );
     118
     119    register_post_type(
     120        'nav_menu_item', array(
     121            'labels'           => array(
     122                'name'          => __( 'Navigation Menu Items' ),
     123                'singular_name' => __( 'Navigation Menu Item' ),
     124            ),
     125            'public'           => false,
     126            '_builtin'         => true, /* internal use only. don't use this when registering your own post type. */
     127            'hierarchical'     => false,
     128            'rewrite'          => false,
     129            'delete_with_user' => false,
     130            'query_var'        => false,
     131        )
     132    );
     133
     134    register_post_type(
     135        'custom_css', array(
     136            'labels'           => array(
     137                'name'          => __( 'Custom CSS' ),
     138                'singular_name' => __( 'Custom CSS' ),
     139            ),
     140            'public'           => false,
     141            'hierarchical'     => false,
     142            'rewrite'          => false,
     143            'query_var'        => false,
     144            'delete_with_user' => false,
     145            'can_export'       => true,
     146            '_builtin'         => true, /* internal use only. don't use this when registering your own post type. */
     147            'supports'         => array( 'title', 'revisions' ),
     148            'capabilities'     => array(
     149                'delete_posts'           => 'edit_theme_options',
     150                'delete_post'            => 'edit_theme_options',
     151                'delete_published_posts' => 'edit_theme_options',
     152                'delete_private_posts'   => 'edit_theme_options',
     153                'delete_others_posts'    => 'edit_theme_options',
     154                'edit_post'              => 'edit_css',
     155                'edit_posts'             => 'edit_css',
     156                'edit_others_posts'      => 'edit_css',
     157                'edit_published_posts'   => 'edit_css',
     158                'read_post'              => 'read',
     159                'read_private_posts'     => 'read',
     160                'publish_posts'          => 'edit_theme_options',
     161            ),
     162        )
     163    );
     164
     165    register_post_type(
     166        'customize_changeset', array(
     167            'labels'           => array(
     168                'name'               => _x( 'Changesets', 'post type general name' ),
     169                'singular_name'      => _x( 'Changeset', 'post type singular name' ),
     170                'menu_name'          => _x( 'Changesets', 'admin menu' ),
     171                'name_admin_bar'     => _x( 'Changeset', 'add new on admin bar' ),
     172                'add_new'            => _x( 'Add New', 'Customize Changeset' ),
     173                'add_new_item'       => __( 'Add New Changeset' ),
     174                'new_item'           => __( 'New Changeset' ),
     175                'edit_item'          => __( 'Edit Changeset' ),
     176                'view_item'          => __( 'View Changeset' ),
     177                'all_items'          => __( 'All Changesets' ),
     178                'search_items'       => __( 'Search Changesets' ),
     179                'not_found'          => __( 'No changesets found.' ),
     180                'not_found_in_trash' => __( 'No changesets found in Trash.' ),
     181            ),
     182            'public'           => false,
     183            '_builtin'         => true, /* internal use only. don't use this when registering your own post type. */
     184            'map_meta_cap'     => true,
     185            'hierarchical'     => false,
     186            'rewrite'          => false,
     187            'query_var'        => false,
     188            'can_export'       => false,
     189            'delete_with_user' => false,
     190            'supports'         => array( 'title', 'author' ),
     191            'capability_type'  => 'customize_changeset',
     192            'capabilities'     => array(
     193                'create_posts'           => 'customize',
     194                'delete_others_posts'    => 'customize',
     195                'delete_post'            => 'customize',
     196                'delete_posts'           => 'customize',
     197                'delete_private_posts'   => 'customize',
     198                'delete_published_posts' => 'customize',
     199                'edit_others_posts'      => 'customize',
     200                'edit_post'              => 'customize',
     201                'edit_posts'             => 'customize',
     202                'edit_private_posts'     => 'customize',
     203                'edit_published_posts'   => 'do_not_allow',
     204                'publish_posts'          => 'customize',
     205                'read'                   => 'read',
     206                'read_post'              => 'customize',
     207                'read_private_posts'     => 'customize',
     208            ),
     209        )
     210    );
     211
     212    register_post_type(
     213        'oembed_cache', array(
     214            'labels'           => array(
     215                'name'          => __( 'oEmbed Responses' ),
     216                'singular_name' => __( 'oEmbed Response' ),
     217            ),
     218            'public'           => false,
     219            'hierarchical'     => false,
     220            'rewrite'          => false,
     221            'query_var'        => false,
     222            'delete_with_user' => false,
     223            'can_export'       => false,
     224            '_builtin'         => true, /* internal use only. don't use this when registering your own post type. */
     225            'supports'         => array(),
     226        )
     227    );
     228
     229    register_post_status(
     230        'publish', array(
     231            'label'       => _x( 'Published', 'post status' ),
     232            'public'      => true,
     233            '_builtin'    => true, /* internal use only. */
     234            'label_count' => _n_noop( 'Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>' ),
     235        )
     236    );
     237
     238    register_post_status(
     239        'future', array(
     240            'label'       => _x( 'Scheduled', 'post status' ),
     241            'protected'   => true,
     242            '_builtin'    => true, /* internal use only. */
     243            'label_count' => _n_noop( 'Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>' ),
     244        )
     245    );
     246
     247    register_post_status(
     248        'draft', array(
     249            'label'       => _x( 'Draft', 'post status' ),
     250            'protected'   => true,
     251            '_builtin'    => true, /* internal use only. */
     252            'label_count' => _n_noop( 'Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>' ),
     253        )
     254    );
     255
     256    register_post_status(
     257        'pending', array(
     258            'label'       => _x( 'Pending', 'post status' ),
     259            'protected'   => true,
     260            '_builtin'    => true, /* internal use only. */
     261            'label_count' => _n_noop( 'Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>' ),
     262        )
     263    );
     264
     265    register_post_status(
     266        'private', array(
     267            'label'       => _x( 'Private', 'post status' ),
     268            'private'     => true,
     269            '_builtin'    => true, /* internal use only. */
     270            'label_count' => _n_noop( 'Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>' ),
     271        )
     272    );
     273
     274    register_post_status(
     275        'trash', array(
     276            'label'                     => _x( 'Trash', 'post status' ),
     277            'internal'                  => true,
     278            '_builtin'                  => true, /* internal use only. */
     279            'label_count'               => _n_noop( 'Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>' ),
     280            'show_in_admin_status_list' => true,
     281        )
     282    );
     283
     284    register_post_status(
     285        'auto-draft', array(
     286            'label'    => 'auto-draft',
     287            'internal' => true,
     288            '_builtin' => true, /* internal use only. */
     289        )
     290    );
     291
     292    register_post_status(
     293        'inherit', array(
     294            'label'               => 'inherit',
     295            'internal'            => true,
     296            '_builtin'            => true, /* internal use only. */
     297            'exclude_from_search' => false,
     298        )
     299    );
    268300}
    269301
     
    322354 */
    323355function update_attached_file( $attachment_id, $file ) {
    324     if ( !get_post( $attachment_id ) )
     356    if ( ! get_post( $attachment_id ) ) {
    325357        return false;
     358    }
    326359
    327360    /**
     
    335368    $file = apply_filters( 'update_attached_file', $file, $attachment_id );
    336369
    337     if ( $file = _wp_relative_upload_path( $file ) )
     370    if ( $file = _wp_relative_upload_path( $file ) ) {
    338371        return update_post_meta( $attachment_id, '_wp_attached_file', $file );
    339     else
     372    } else {
    340373        return delete_post_meta( $attachment_id, '_wp_attached_file' );
     374    }
    341375}
    342376
     
    426460    if ( empty( $args ) ) {
    427461        if ( isset( $GLOBALS['post'] ) ) {
    428             $args = array('post_parent' => (int) $GLOBALS['post']->post_parent );
     462            $args = array( 'post_parent' => (int) $GLOBALS['post']->post_parent );
    429463        } else {
    430464            return $kids;
    431465        }
    432466    } elseif ( is_object( $args ) ) {
    433         $args = array('post_parent' => (int) $args->post_parent );
     467        $args = array( 'post_parent' => (int) $args->post_parent );
    434468    } elseif ( is_numeric( $args ) ) {
    435         $args = array('post_parent' => (int) $args);
     469        $args = array( 'post_parent' => (int) $args );
    436470    }
    437471
    438472    $defaults = array(
    439         'numberposts' => -1, 'post_type' => 'any',
    440         'post_status' => 'any', 'post_parent' => 0,
     473        'numberposts' => -1,
     474        'post_type'   => 'any',
     475        'post_status' => 'any',
     476        'post_parent' => 0,
    441477    );
    442478
     
    445481    $children = get_posts( $r );
    446482
    447     if ( ! $children )
     483    if ( ! $children ) {
    448484        return $kids;
    449 
    450     if ( ! empty( $r['fields'] ) )
     485    }
     486
     487    if ( ! empty( $r['fields'] ) ) {
    451488        return $children;
    452 
    453     update_post_cache($children);
    454 
    455     foreach ( $children as $key => $child )
    456         $kids[$child->ID] = $children[$key];
     489    }
     490
     491    update_post_cache( $children );
     492
     493    foreach ( $children as $key => $child ) {
     494        $kids[ $child->ID ] = $children[ $key ];
     495    }
    457496
    458497    if ( $output == OBJECT ) {
     
    461500        $weeuns = array();
    462501        foreach ( (array) $kids as $kid ) {
    463             $weeuns[$kid->ID] = get_object_vars($kids[$kid->ID]);
     502            $weeuns[ $kid->ID ] = get_object_vars( $kids[ $kid->ID ] );
    464503        }
    465504        return $weeuns;
     
    467506        $babes = array();
    468507        foreach ( (array) $kids as $kid ) {
    469             $babes[$kid->ID] = array_values(get_object_vars($kids[$kid->ID]));
     508            $babes[ $kid->ID ] = array_values( get_object_vars( $kids[ $kid->ID ] ) );
    470509        }
    471510        return $babes;
     
    493532function get_extended( $post ) {
    494533    //Match the new style more links.
    495     if ( preg_match('/<!--more(.*?)?-->/', $post, $matches) ) {
    496         list($main, $extended) = explode($matches[0], $post, 2);
    497         $more_text = $matches[1];
     534    if ( preg_match( '/<!--more(.*?)?-->/', $post, $matches ) ) {
     535        list($main, $extended) = explode( $matches[0], $post, 2 );
     536        $more_text             = $matches[1];
    498537    } else {
    499         $main = $post;
    500         $extended = '';
     538        $main      = $post;
     539        $extended  = '';
    501540        $more_text = '';
    502541    }
    503542
    504543    //  leading and trailing whitespace.
    505     $main = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $main);
    506     $extended = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $extended);
    507     $more_text = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $more_text);
    508 
    509     return array( 'main' => $main, 'extended' => $extended, 'more_text' => $more_text );
     544    $main      = preg_replace( '/^[\s]*(.*)[\s]*$/', '\\1', $main );
     545    $extended  = preg_replace( '/^[\s]*(.*)[\s]*$/', '\\1', $extended );
     546    $more_text = preg_replace( '/^[\s]*(.*)[\s]*$/', '\\1', $more_text );
     547
     548    return array(
     549        'main'      => $main,
     550        'extended'  => $extended,
     551        'more_text' => $more_text,
     552    );
    510553}
    511554
     
    529572 */
    530573function get_post( $post = null, $output = OBJECT, $filter = 'raw' ) {
    531     if ( empty( $post ) && isset( $GLOBALS['post'] ) )
     574    if ( empty( $post ) && isset( $GLOBALS['post'] ) ) {
    532575        $post = $GLOBALS['post'];
     576    }
    533577
    534578    if ( $post instanceof WP_Post ) {
     
    547591    }
    548592
    549     if ( ! $_post )
     593    if ( ! $_post ) {
    550594        return null;
     595    }
    551596
    552597    $_post = $_post->filter( $filter );
    553598
    554     if ( $output == ARRAY_A )
     599    if ( $output == ARRAY_A ) {
    555600        return $_post->to_array();
    556     elseif ( $output == ARRAY_N )
     601    } elseif ( $output == ARRAY_N ) {
    557602        return array_values( $_post->to_array() );
     603    }
    558604
    559605    return $_post;
     
    571617    $post = get_post( $post );
    572618
    573     if ( ! $post || empty( $post->post_parent ) || $post->post_parent == $post->ID )
     619    if ( ! $post || empty( $post->post_parent ) || $post->post_parent == $post->ID ) {
    574620        return array();
     621    }
    575622
    576623    $ancestors = array();
     
    580627    while ( $ancestor = get_post( $id ) ) {
    581628        // Loop detection: If the ancestor has been seen before, break.
    582         if ( empty( $ancestor->post_parent ) || ( $ancestor->post_parent == $post->ID ) || in_array( $ancestor->post_parent, $ancestors ) )
     629        if ( empty( $ancestor->post_parent ) || ( $ancestor->post_parent == $post->ID ) || in_array( $ancestor->post_parent, $ancestors ) ) {
    583630            break;
     631        }
    584632
    585633        $id = $ancestors[] = $ancestor->post_parent;
     
    612660    $post = get_post( $post );
    613661
    614     if ( !$post )
     662    if ( ! $post ) {
    615663        return '';
    616 
    617     if ( !isset($post->$field) )
     664    }
     665
     666    if ( ! isset( $post->$field ) ) {
    618667        return '';
    619 
    620     return sanitize_post_field($field, $post->$field, $post->ID, $context);
     668    }
     669
     670    return sanitize_post_field( $field, $post->$field, $post->ID, $context );
    621671}
    622672
     
    633683 */
    634684function get_post_mime_type( $ID = '' ) {
    635     $post = get_post($ID);
    636 
    637     if ( is_object($post) )
     685    $post = get_post( $ID );
     686
     687    if ( is_object( $post ) ) {
    638688        return $post->post_mime_type;
     689    }
    639690
    640691    return false;
     
    653704 */
    654705function get_post_status( $ID = '' ) {
    655     $post = get_post($ID);
    656 
    657     if ( !is_object($post) )
     706    $post = get_post( $ID );
     707
     708    if ( ! is_object( $post ) ) {
    658709        return false;
     710    }
    659711
    660712    if ( 'attachment' == $post->post_type ) {
    661         if ( 'private' == $post->post_status )
     713        if ( 'private' == $post->post_status ) {
    662714            return 'private';
     715        }
    663716
    664717        // Unattached attachments are assumed to be published.
    665         if ( ( 'inherit' == $post->post_status ) && ( 0 == $post->post_parent) )
     718        if ( ( 'inherit' == $post->post_status ) && ( 0 == $post->post_parent ) ) {
    666719            return 'publish';
     720        }
    667721
    668722        // Inherit status from the parent.
     
    675729            }
    676730        }
    677 
    678731    }
    679732
     
    704757        'pending' => __( 'Pending Review' ),
    705758        'private' => __( 'Private' ),
    706         'publish' => __( 'Published' )
     759        'publish' => __( 'Published' ),
    707760    );
    708761
     
    724777        'draft'   => __( 'Draft' ),
    725778        'private' => __( 'Private' ),
    726         'publish' => __( 'Published' )
     779        'publish' => __( 'Published' ),
    727780    );
    728781
     
    776829    global $wp_post_statuses;
    777830
    778     if (!is_array($wp_post_statuses))
     831    if ( ! is_array( $wp_post_statuses ) ) {
    779832        $wp_post_statuses = array();
     833    }
    780834
    781835    // Args prefixed with an underscore are reserved for internal use.
    782836    $defaults = array(
    783         'label' => false,
    784         'label_count' => false,
    785         'exclude_from_search' => null,
    786         '_builtin' => false,
    787         'public' => null,
    788         'internal' => null,
    789         'protected' => null,
    790         'private' => null,
    791         'publicly_queryable' => null,
     837        'label'                     => false,
     838        'label_count'               => false,
     839        'exclude_from_search'       => null,
     840        '_builtin'                  => false,
     841        'public'                    => null,
     842        'internal'                  => null,
     843        'protected'                 => null,
     844        'private'                   => null,
     845        'publicly_queryable'        => null,
    792846        'show_in_admin_status_list' => null,
    793         'show_in_admin_all_list' => null,
     847        'show_in_admin_all_list'    => null,
    794848    );
    795     $args = wp_parse_args($args, $defaults);
    796     $args = (object) $args;
    797 
    798     $post_status = sanitize_key($post_status);
    799     $args->name = $post_status;
     849    $args     = wp_parse_args( $args, $defaults );
     850    $args     = (object) $args;
     851
     852    $post_status = sanitize_key( $post_status );
     853    $args->name  = $post_status;
    800854
    801855    // Set various defaults.
    802     if ( null === $args->public && null === $args->internal && null === $args->protected && null === $args->private )
     856    if ( null === $args->public && null === $args->internal && null === $args->protected && null === $args->private ) {
    803857        $args->internal = true;
    804 
    805     if ( null === $args->public  )
     858    }
     859
     860    if ( null === $args->public ) {
    806861        $args->public = false;
    807 
    808     if ( null === $args->private  )
     862    }
     863
     864    if ( null === $args->private ) {
    809865        $args->private = false;
    810 
    811     if ( null === $args->protected  )
     866    }
     867
     868    if ( null === $args->protected ) {
    812869        $args->protected = false;
    813 
    814     if ( null === $args->internal  )
     870    }
     871
     872    if ( null === $args->internal ) {
    815873        $args->internal = false;
    816 
    817     if ( null === $args->publicly_queryable )
     874    }
     875
     876    if ( null === $args->publicly_queryable ) {
    818877        $args->publicly_queryable = $args->public;
    819 
    820     if ( null === $args->exclude_from_search )
     878    }
     879
     880    if ( null === $args->exclude_from_search ) {
    821881        $args->exclude_from_search = $args->internal;
    822 
    823     if ( null === $args->show_in_admin_all_list )
    824         $args->show_in_admin_all_list = !$args->internal;
    825 
    826     if ( null === $args->show_in_admin_status_list )
    827         $args->show_in_admin_status_list = !$args->internal;
    828 
    829     if ( false === $args->label )
     882    }
     883
     884    if ( null === $args->show_in_admin_all_list ) {
     885        $args->show_in_admin_all_list = ! $args->internal;
     886    }
     887
     888    if ( null === $args->show_in_admin_status_list ) {
     889        $args->show_in_admin_status_list = ! $args->internal;
     890    }
     891
     892    if ( false === $args->label ) {
    830893        $args->label = $post_status;
    831 
    832     if ( false === $args->label_count )
     894    }
     895
     896    if ( false === $args->label_count ) {
    833897        $args->label_count = _n_noop( $args->label, $args->label );
    834 
    835     $wp_post_statuses[$post_status] = $args;
     898    }
     899
     900    $wp_post_statuses[ $post_status ] = $args;
    836901
    837902    return $args;
     
    853918    global $wp_post_statuses;
    854919
    855     if ( empty($wp_post_statuses[$post_status]) )
     920    if ( empty( $wp_post_statuses[ $post_status ] ) ) {
    856921        return null;
    857 
    858     return $wp_post_statuses[$post_status];
     922    }
     923
     924    return $wp_post_statuses[ $post_status ];
    859925}
    860926
     
    879945    global $wp_post_statuses;
    880946
    881     $field = ('names' == $output) ? 'name' : false;
    882 
    883     return wp_filter_object_list($wp_post_statuses, $args, $operator, $field);
     947    $field = ( 'names' == $output ) ? 'name' : false;
     948
     949    return wp_filter_object_list( $wp_post_statuses, $args, $operator, $field );
    884950}
    885951
     
    897963 */
    898964function is_post_type_hierarchical( $post_type ) {
    899     if ( ! post_type_exists( $post_type ) )
     965    if ( ! post_type_exists( $post_type ) ) {
    900966        return false;
     967    }
    901968
    902969    $post_type = get_post_type_object( $post_type );
     
    927994 */
    928995function get_post_type( $post = null ) {
    929     if ( $post = get_post( $post ) )
     996    if ( $post = get_post( $post ) ) {
    930997        return $post->post_type;
     998    }
    931999
    9321000    return false;
     
    9771045    global $wp_post_types;
    9781046
    979     $field = ('names' == $output) ? 'name' : false;
    980 
    981     return wp_filter_object_list($wp_post_types, $args, $operator, $field);
     1047    $field = ( 'names' == $output ) ? 'name' : false;
     1048
     1049    return wp_filter_object_list( $wp_post_types, $args, $operator, $field );
    9821050}
    9831051
     
    12591327 */
    12601328function get_post_type_capabilities( $args ) {
    1261     if ( ! is_array( $args->capability_type ) )
     1329    if ( ! is_array( $args->capability_type ) ) {
    12621330        $args->capability_type = array( $args->capability_type, $args->capability_type . 's' );
     1331    }
    12631332
    12641333    // Singular base for meta capabilities, plural base for primitive capabilities.
     
    12671336    $default_capabilities = array(
    12681337        // Meta capabilities
    1269         'edit_post'          => 'edit_'         . $singular_base,
    1270         'read_post'          => 'read_'         . $singular_base,
    1271         'delete_post'        => 'delete_'       . $singular_base,
     1338        'edit_post'          => 'edit_' . $singular_base,
     1339        'read_post'          => 'read_' . $singular_base,
     1340        'delete_post'        => 'delete_' . $singular_base,
    12721341        // Primitive capabilities used outside of map_meta_cap():
    1273         'edit_posts'         => 'edit_'         . $plural_base,
    1274         'edit_others_posts'  => 'edit_others_'  . $plural_base,
    1275         'publish_posts'      => 'publish_'      . $plural_base,
     1342        'edit_posts'         => 'edit_' . $plural_base,
     1343        'edit_others_posts'  => 'edit_others_' . $plural_base,
     1344        'publish_posts'      => 'publish_' . $plural_base,
    12761345        'read_private_posts' => 'read_private_' . $plural_base,
    12771346    );
     
    12811350        $default_capabilities_for_mapping = array(
    12821351            'read'                   => 'read',
    1283             'delete_posts'           => 'delete_'           . $plural_base,
    1284             'delete_private_posts'   => 'delete_private_'   . $plural_base,
     1352            'delete_posts'           => 'delete_' . $plural_base,
     1353            'delete_private_posts'   => 'delete_private_' . $plural_base,
    12851354            'delete_published_posts' => 'delete_published_' . $plural_base,
    1286             'delete_others_posts'    => 'delete_others_'    . $plural_base,
    1287             'edit_private_posts'     => 'edit_private_'     . $plural_base,
    1288             'edit_published_posts'   => 'edit_published_'   . $plural_base,
     1355            'delete_others_posts'    => 'delete_others_' . $plural_base,
     1356            'edit_private_posts'     => 'edit_private_' . $plural_base,
     1357            'edit_published_posts'   => 'edit_published_' . $plural_base,
    12891358        );
    1290         $default_capabilities = array_merge( $default_capabilities, $default_capabilities_for_mapping );
     1359        $default_capabilities             = array_merge( $default_capabilities, $default_capabilities_for_mapping );
    12911360    }
    12921361
     
    12941363
    12951364    // Post creation capability simply maps to edit_posts by default:
    1296     if ( ! isset( $capabilities['create_posts'] ) )
     1365    if ( ! isset( $capabilities['create_posts'] ) ) {
    12971366        $capabilities['create_posts'] = $capabilities['edit_posts'];
     1367    }
    12981368
    12991369    // Remember meta capabilities for future reference.
    1300     if ( $args->map_meta_cap )
     1370    if ( $args->map_meta_cap ) {
    13011371        _post_type_meta_capabilities( $capabilities );
     1372    }
    13021373
    13031374    return (object) $capabilities;
     
    13821453 */
    13831454function get_post_type_labels( $post_type_object ) {
    1384     $nohier_vs_hier_defaults = array(
    1385         'name' => array( _x('Posts', 'post type general name'), _x('Pages', 'post type general name') ),
    1386         'singular_name' => array( _x('Post', 'post type singular name'), _x('Page', 'post type singular name') ),
    1387         'add_new' => array( _x('Add New', 'post'), _x('Add New', 'page') ),
    1388         'add_new_item' => array( __('Add New Post'), __('Add New Page') ),
    1389         'edit_item' => array( __('Edit Post'), __('Edit Page') ),
    1390         'new_item' => array( __('New Post'), __('New Page') ),
    1391         'view_item' => array( __('View Post'), __('View Page') ),
    1392         'view_items' => array( __('View Posts'), __('View Pages') ),
    1393         'search_items' => array( __('Search Posts'), __('Search Pages') ),
    1394         'not_found' => array( __('No posts found.'), __('No pages found.') ),
    1395         'not_found_in_trash' => array( __('No posts found in Trash.'), __('No pages found in Trash.') ),
    1396         'parent_item_colon' => array( null, __('Parent Page:') ),
    1397         'all_items' => array( __( 'All Posts' ), __( 'All Pages' ) ),
    1398         'archives' => array( __( 'Post Archives' ), __( 'Page Archives' ) ),
    1399         'attributes' => array( __( 'Post Attributes' ), __( 'Page Attributes' ) ),
    1400         'insert_into_item' => array( __( 'Insert into post' ), __( 'Insert into page' ) ),
     1455    $nohier_vs_hier_defaults              = array(
     1456        'name'                  => array( _x( 'Posts', 'post type general name' ), _x( 'Pages', 'post type general name' ) ),
     1457        'singular_name'         => array( _x( 'Post', 'post type singular name' ), _x( 'Page', 'post type singular name' ) ),
     1458        'add_new'               => array( _x( 'Add New', 'post' ), _x( 'Add New', 'page' ) ),
     1459        'add_new_item'          => array( __( 'Add New Post' ), __( 'Add New Page' ) ),
     1460        'edit_item'             => array( __( 'Edit Post' ), __( 'Edit Page' ) ),
     1461        'new_item'              => array( __( 'New Post' ), __( 'New Page' ) ),
     1462        'view_item'             => array( __( 'View Post' ), __( 'View Page' ) ),
     1463        'view_items'            => array( __( 'View Posts' ), __( 'View Pages' ) ),
     1464        'search_items'          => array( __( 'Search Posts' ), __( 'Search Pages' ) ),
     1465        'not_found'             => array( __( 'No posts found.' ), __( 'No pages found.' ) ),
     1466        'not_found_in_trash'    => array( __( 'No posts found in Trash.' ), __( 'No pages found in Trash.' ) ),
     1467        'parent_item_colon'     => array( null, __( 'Parent Page:' ) ),
     1468        'all_items'             => array( __( 'All Posts' ), __( 'All Pages' ) ),
     1469        'archives'              => array( __( 'Post Archives' ), __( 'Page Archives' ) ),
     1470        'attributes'            => array( __( 'Post Attributes' ), __( 'Page Attributes' ) ),
     1471        'insert_into_item'      => array( __( 'Insert into post' ), __( 'Insert into page' ) ),
    14011472        'uploaded_to_this_item' => array( __( 'Uploaded to this post' ), __( 'Uploaded to this page' ) ),
    1402         'featured_image' => array( _x( 'Featured Image', 'post' ), _x( 'Featured Image', 'page' ) ),
    1403         'set_featured_image' => array( _x( 'Set featured image', 'post' ), _x( 'Set featured image', 'page' ) ),
     1473        'featured_image'        => array( _x( 'Featured Image', 'post' ), _x( 'Featured Image', 'page' ) ),
     1474        'set_featured_image'    => array( _x( 'Set featured image', 'post' ), _x( 'Set featured image', 'page' ) ),
    14041475        'remove_featured_image' => array( _x( 'Remove featured image', 'post' ), _x( 'Remove featured image', 'page' ) ),
    1405         'use_featured_image' => array( _x( 'Use as featured image', 'post' ), _x( 'Use as featured image', 'page' ) ),
    1406         'filter_items_list' => array( __( 'Filter posts list' ), __( 'Filter pages list' ) ),
     1476        'use_featured_image'    => array( _x( 'Use as featured image', 'post' ), _x( 'Use as featured image', 'page' ) ),
     1477        'filter_items_list'     => array( __( 'Filter posts list' ), __( 'Filter pages list' ) ),
    14071478        'items_list_navigation' => array( __( 'Posts list navigation' ), __( 'Pages list navigation' ) ),
    1408         'items_list' => array( __( 'Posts list' ), __( 'Pages list' ) ),
     1479        'items_list'            => array( __( 'Posts list' ), __( 'Pages list' ) ),
    14091480    );
    14101481    $nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name'];
     
    14501521    $object->labels = (array) $object->labels;
    14511522
    1452     if ( isset( $object->label ) && empty( $object->labels['name'] ) )
     1523    if ( isset( $object->label ) && empty( $object->labels['name'] ) ) {
    14531524        $object->labels['name'] = $object->label;
    1454 
    1455     if ( !isset( $object->labels['singular_name'] ) && isset( $object->labels['name'] ) )
     1525    }
     1526
     1527    if ( ! isset( $object->labels['singular_name'] ) && isset( $object->labels['name'] ) ) {
    14561528        $object->labels['singular_name'] = $object->labels['name'];
    1457 
    1458     if ( ! isset( $object->labels['name_admin_bar'] ) )
     1529    }
     1530
     1531    if ( ! isset( $object->labels['name_admin_bar'] ) ) {
    14591532        $object->labels['name_admin_bar'] = isset( $object->labels['singular_name'] ) ? $object->labels['singular_name'] : $object->name;
    1460 
    1461     if ( !isset( $object->labels['menu_name'] ) && isset( $object->labels['name'] ) )
     1533    }
     1534
     1535    if ( ! isset( $object->labels['menu_name'] ) && isset( $object->labels['name'] ) ) {
    14621536        $object->labels['menu_name'] = $object->labels['name'];
    1463 
    1464     if ( !isset( $object->labels['all_items'] ) && isset( $object->labels['menu_name'] ) )
     1537    }
     1538
     1539    if ( ! isset( $object->labels['all_items'] ) && isset( $object->labels['menu_name'] ) ) {
    14651540        $object->labels['all_items'] = $object->labels['menu_name'];
    1466 
    1467     if ( !isset( $object->labels['archives'] ) && isset( $object->labels['all_items'] ) ) {
     1541    }
     1542
     1543    if ( ! isset( $object->labels['archives'] ) && isset( $object->labels['all_items'] ) ) {
    14681544        $object->labels['archives'] = $object->labels['all_items'];
    14691545    }
     
    14711547    $defaults = array();
    14721548    foreach ( $nohier_vs_hier_defaults as $key => $value ) {
    1473         $defaults[$key] = $object->hierarchical ? $value[1] : $value[0];
    1474     }
    1475     $labels = array_merge( $defaults, $object->labels );
     1549        $defaults[ $key ] = $object->hierarchical ? $value[1] : $value[0];
     1550    }
     1551    $labels         = array_merge( $defaults, $object->labels );
    14761552    $object->labels = (object) $object->labels;
    14771553
     
    14891565        $ptype_obj = get_post_type_object( $ptype );
    14901566        // Sub-menus only.
    1491         if ( ! $ptype_obj->show_in_menu || $ptype_obj->show_in_menu === true )
     1567        if ( ! $ptype_obj->show_in_menu || $ptype_obj->show_in_menu === true ) {
    14921568            continue;
     1569        }
    14931570        add_submenu_page( $ptype_obj->show_in_menu, $ptype_obj->labels->name, $ptype_obj->labels->all_items, $ptype_obj->cap->edit_posts, "edit.php?post_type=$ptype" );
    14941571    }
     
    15191596
    15201597    $features = (array) $feature;
    1521     foreach ($features as $feature) {
    1522         if ( func_num_args() == 2 )
    1523             $_wp_post_type_features[$post_type][$feature] = true;
    1524         else
    1525             $_wp_post_type_features[$post_type][$feature] = array_slice( func_get_args(), 2 );
     1598    foreach ( $features as $feature ) {
     1599        if ( func_num_args() == 2 ) {
     1600            $_wp_post_type_features[ $post_type ][ $feature ] = true;
     1601        } else {
     1602            $_wp_post_type_features[ $post_type ][ $feature ] = array_slice( func_get_args(), 2 );
     1603        }
    15261604    }
    15271605}
     
    15561634    global $_wp_post_type_features;
    15571635
    1558     if ( isset( $_wp_post_type_features[$post_type] ) )
    1559         return $_wp_post_type_features[$post_type];
     1636    if ( isset( $_wp_post_type_features[ $post_type ] ) ) {
     1637        return $_wp_post_type_features[ $post_type ];
     1638    }
    15601639
    15611640    return array();
     
    15761655    global $_wp_post_type_features;
    15771656
    1578     return ( isset( $_wp_post_type_features[$post_type][$feature] ) );
     1657    return ( isset( $_wp_post_type_features[ $post_type ][ $feature ] ) );
    15791658}
    15801659
     
    16181697    global $wpdb;
    16191698
    1620     $post_type = sanitize_post_field('post_type', $post_type, $post_id, 'db');
    1621     $return = $wpdb->update( $wpdb->posts, array('post_type' => $post_type), array('ID' => $post_id) );
     1699    $post_type = sanitize_post_field( 'post_type', $post_type, $post_id, 'db' );
     1700    $return    = $wpdb->update( $wpdb->posts, array( 'post_type' => $post_type ), array( 'ID' => $post_id ) );
    16221701
    16231702    clean_post_cache( $post_id );
     
    16761755function get_posts( $args = null ) {
    16771756    $defaults = array(
    1678         'numberposts' => 5,
    1679         'category' => 0, 'orderby' => 'date',
    1680         'order' => 'DESC', 'include' => array(),
    1681         'exclude' => array(), 'meta_key' => '',
    1682         'meta_value' =>'', 'post_type' => 'post',
    1683         'suppress_filters' => true
     1757        'numberposts'      => 5,
     1758        'category'         => 0,
     1759        'orderby'          => 'date',
     1760        'order'            => 'DESC',
     1761        'include'          => array(),
     1762        'exclude'          => array(),
     1763        'meta_key'         => '',
     1764        'meta_value'       => '',
     1765        'post_type'        => 'post',
     1766        'suppress_filters' => true,
    16841767    );
    16851768
    16861769    $r = wp_parse_args( $args, $defaults );
    1687     if ( empty( $r['post_status'] ) )
     1770    if ( empty( $r['post_status'] ) ) {
    16881771        $r['post_status'] = ( 'attachment' == $r['post_type'] ) ? 'inherit' : 'publish';
    1689     if ( ! empty($r['numberposts']) && empty($r['posts_per_page']) )
     1772    }
     1773    if ( ! empty( $r['numberposts'] ) && empty( $r['posts_per_page'] ) ) {
    16901774        $r['posts_per_page'] = $r['numberposts'];
    1691     if ( ! empty($r['category']) )
     1775    }
     1776    if ( ! empty( $r['category'] ) ) {
    16921777        $r['cat'] = $r['category'];
    1693     if ( ! empty($r['include']) ) {
    1694         $incposts = wp_parse_id_list( $r['include'] );
    1695         $r['posts_per_page'] = count($incposts);  // only the number of posts included
    1696         $r['post__in'] = $incposts;
    1697     } elseif ( ! empty($r['exclude']) )
     1778    }
     1779    if ( ! empty( $r['include'] ) ) {
     1780        $incposts            = wp_parse_id_list( $r['include'] );
     1781        $r['posts_per_page'] = count( $incposts );  // only the number of posts included
     1782        $r['post__in']       = $incposts;
     1783    } elseif ( ! empty( $r['exclude'] ) ) {
    16981784        $r['post__not_in'] = wp_parse_id_list( $r['exclude'] );
     1785    }
    16991786
    17001787    $r['ignore_sticky_posts'] = true;
    1701     $r['no_found_rows'] = true;
     1788    $r['no_found_rows']       = true;
    17021789
    17031790    $get_posts = new WP_Query;
    1704     return $get_posts->query($r);
     1791    return $get_posts->query( $r );
    17051792
    17061793}
     
    17261813function add_post_meta( $post_id, $meta_key, $meta_value, $unique = false ) {
    17271814    // Make sure meta is added to the post, not a revision.
    1728     if ( $the_post = wp_is_post_revision($post_id) )
     1815    if ( $the_post = wp_is_post_revision( $post_id ) ) {
    17291816        $post_id = $the_post;
     1817    }
    17301818
    17311819    $added = add_metadata( 'post', $post_id, $meta_key, $meta_value, $unique );
     
    17531841function delete_post_meta( $post_id, $meta_key, $meta_value = '' ) {
    17541842    // Make sure meta is added to the post, not a revision.
    1755     if ( $the_post = wp_is_post_revision($post_id) )
     1843    if ( $the_post = wp_is_post_revision( $post_id ) ) {
    17561844        $post_id = $the_post;
     1845    }
    17571846
    17581847    $deleted = delete_metadata( 'post', $post_id, $meta_key, $meta_value );
     
    17781867 */
    17791868function get_post_meta( $post_id, $key = '', $single = false ) {
    1780     return get_metadata('post', $post_id, $key, $single);
     1869    return get_metadata( 'post', $post_id, $key, $single );
    17811870}
    17821871
     
    18011890function update_post_meta( $post_id, $meta_key, $meta_value, $prev_value = '' ) {
    18021891    // Make sure meta is added to the post, not a revision.
    1803     if ( $the_post = wp_is_post_revision($post_id) )
     1892    if ( $the_post = wp_is_post_revision( $post_id ) ) {
    18041893        $post_id = $the_post;
     1894    }
    18051895
    18061896    $updated = update_metadata( 'post', $post_id, $meta_key, $meta_value, $prev_value );
     
    18401930function get_post_custom( $post_id = 0 ) {
    18411931    $post_id = absint( $post_id );
    1842     if ( ! $post_id )
     1932    if ( ! $post_id ) {
    18431933        $post_id = get_the_ID();
     1934    }
    18441935
    18451936    return get_post_meta( $post_id );
     
    18591950    $custom = get_post_custom( $post_id );
    18601951
    1861     if ( !is_array($custom) )
     1952    if ( ! is_array( $custom ) ) {
    18621953        return;
    1863 
    1864     if ( $keys = array_keys($custom) )
     1954    }
     1955
     1956    if ( $keys = array_keys( $custom ) ) {
    18651957        return $keys;
     1958    }
    18661959}
    18671960
     
    18791972 */
    18801973function get_post_custom_values( $key = '', $post_id = 0 ) {
    1881     if ( !$key )
     1974    if ( ! $key ) {
    18821975        return null;
    1883 
    1884     $custom = get_post_custom($post_id);
    1885 
    1886     return isset($custom[$key]) ? $custom[$key] : null;
     1976    }
     1977
     1978    $custom = get_post_custom( $post_id );
     1979
     1980    return isset( $custom[ $key ] ) ? $custom[ $key ] : null;
    18871981}
    18881982
     
    19011995    $post_id = absint( $post_id );
    19021996
    1903     if ( ! $post_id )
     1997    if ( ! $post_id ) {
    19041998        $post_id = get_the_ID();
     1999    }
    19052000
    19062001    $stickies = get_option( 'sticky_posts' );
    19072002
    1908     if ( ! is_array( $stickies ) )
     2003    if ( ! is_array( $stickies ) ) {
    19092004        return false;
    1910 
    1911     if ( in_array( $post_id, $stickies ) )
     2005    }
     2006
     2007    if ( in_array( $post_id, $stickies ) ) {
    19122008        return true;
     2009    }
    19132010
    19142011    return false;
     
    19332030 */
    19342031function sanitize_post( $post, $context = 'display' ) {
    1935     if ( is_object($post) ) {
     2032    if ( is_object( $post ) ) {
    19362033        // Check if post already filtered for this context.
    1937         if ( isset($post->filter) && $context == $post->filter )
     2034        if ( isset( $post->filter ) && $context == $post->filter ) {
    19382035            return $post;
    1939         if ( !isset($post->ID) )
     2036        }
     2037        if ( ! isset( $post->ID ) ) {
    19402038            $post->ID = 0;
    1941         foreach ( array_keys(get_object_vars($post)) as $field )
    1942             $post->$field = sanitize_post_field($field, $post->$field, $post->ID, $context);
     2039        }
     2040        foreach ( array_keys( get_object_vars( $post ) ) as $field ) {
     2041            $post->$field = sanitize_post_field( $field, $post->$field, $post->ID, $context );
     2042        }
    19432043        $post->filter = $context;
    19442044    } elseif ( is_array( $post ) ) {
    19452045        // Check if post already filtered for this context.
    1946         if ( isset($post['filter']) && $context == $post['filter'] )
     2046        if ( isset( $post['filter'] ) && $context == $post['filter'] ) {
    19472047            return $post;
    1948         if ( !isset($post['ID']) )
     2048        }
     2049        if ( ! isset( $post['ID'] ) ) {
    19492050            $post['ID'] = 0;
    1950         foreach ( array_keys($post) as $field )
    1951             $post[$field] = sanitize_post_field($field, $post[$field], $post['ID'], $context);
     2051        }
     2052        foreach ( array_keys( $post ) as $field ) {
     2053            $post[ $field ] = sanitize_post_field( $field, $post[ $field ], $post['ID'], $context );
     2054        }
    19522055        $post['filter'] = $context;
    19532056    }
     
    19732076 */
    19742077function sanitize_post_field( $field, $value, $post_id, $context = 'display' ) {
    1975     $int_fields = array('ID', 'post_parent', 'menu_order');
    1976     if ( in_array($field, $int_fields) )
     2078    $int_fields = array( 'ID', 'post_parent', 'menu_order' );
     2079    if ( in_array( $field, $int_fields ) ) {
    19772080        $value = (int) $value;
     2081    }
    19782082
    19792083    // Fields which contain arrays of integers.
    19802084    $array_int_fields = array( 'ancestors' );
    1981     if ( in_array($field, $array_int_fields) ) {
    1982         $value = array_map( 'absint', $value);
     2085    if ( in_array( $field, $array_int_fields ) ) {
     2086        $value = array_map( 'absint', $value );
    19832087        return $value;
    19842088    }
    19852089
    1986     if ( 'raw' == $context )
     2090    if ( 'raw' == $context ) {
    19872091        return $value;
     2092    }
    19882093
    19892094    $prefixed = false;
    1990     if ( false !== strpos($field, 'post_') ) {
    1991         $prefixed = true;
    1992         $field_no_prefix = str_replace('post_', '', $field);
     2095    if ( false !== strpos( $field, 'post_' ) ) {
     2096        $prefixed        = true;
     2097        $field_no_prefix = str_replace( 'post_', '', $field );
    19932098    }
    19942099
    19952100    if ( 'edit' == $context ) {
    1996         $format_to_edit = array('post_content', 'post_excerpt', 'post_title', 'post_password');
     2101        $format_to_edit = array( 'post_content', 'post_excerpt', 'post_title', 'post_password' );
    19972102
    19982103        if ( $prefixed ) {
     
    20272132        }
    20282133
    2029         if ( in_array($field, $format_to_edit) ) {
    2030             if ( 'post_content' == $field )
    2031                 $value = format_to_edit($value, user_can_richedit());
    2032             else
    2033                 $value = format_to_edit($value);
     2134        if ( in_array( $field, $format_to_edit ) ) {
     2135            if ( 'post_content' == $field ) {
     2136                $value = format_to_edit( $value, user_can_richedit() );
     2137            } else {
     2138                $value = format_to_edit( $value );
     2139            }
    20342140        } else {
    2035             $value = esc_attr($value);
     2141            $value = esc_attr( $value );
    20362142        }
    20372143    } elseif ( 'db' == $context ) {
     
    21202226 */
    21212227function stick_post( $post_id ) {
    2122     $stickies = get_option('sticky_posts');
    2123 
    2124     if ( !is_array($stickies) )
    2125         $stickies = array($post_id);
    2126 
    2127     if ( ! in_array($post_id, $stickies) )
     2228    $stickies = get_option( 'sticky_posts' );
     2229
     2230    if ( ! is_array( $stickies ) ) {
     2231        $stickies = array( $post_id );
     2232    }
     2233
     2234    if ( ! in_array( $post_id, $stickies ) ) {
    21282235        $stickies[] = $post_id;
     2236    }
    21292237
    21302238    $updated = update_option( 'sticky_posts', $stickies );
     
    21522260 */
    21532261function unstick_post( $post_id ) {
    2154     $stickies = get_option('sticky_posts');
    2155 
    2156     if ( !is_array($stickies) )
     2262    $stickies = get_option( 'sticky_posts' );
     2263
     2264    if ( ! is_array( $stickies ) ) {
    21572265        return;
    2158 
    2159     if ( ! in_array($post_id, $stickies) )
     2266    }
     2267
     2268    if ( ! in_array( $post_id, $stickies ) ) {
    21602269        return;
    2161 
    2162     $offset = array_search($post_id, $stickies);
    2163     if ( false === $offset )
     2270    }
     2271
     2272    $offset = array_search( $post_id, $stickies );
     2273    if ( false === $offset ) {
    21642274        return;
    2165 
    2166     array_splice($stickies, $offset, 1);
     2275    }
     2276
     2277    array_splice( $stickies, $offset, 1 );
    21672278
    21682279    $updated = update_option( 'sticky_posts', $stickies );
     
    22222333    global $wpdb;
    22232334
    2224     if ( ! post_type_exists( $type ) )
     2335    if ( ! post_type_exists( $type ) ) {
    22252336        return new stdClass;
     2337    }
    22262338
    22272339    $cache_key = _count_posts_cache_key( $type, $perm );
     
    22352347    $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";
    22362348    if ( 'readable' == $perm && is_user_logged_in() ) {
    2237         $post_type_object = get_post_type_object($type);
     2349        $post_type_object = get_post_type_object( $type );
    22382350        if ( ! current_user_can( $post_type_object->cap->read_private_posts ) ) {
    2239             $query .= $wpdb->prepare( " AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))",
     2351            $query .= $wpdb->prepare(
     2352                " AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))",
    22402353                get_current_user_id()
    22412354            );
     
    22452358
    22462359    $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
    2247     $counts = array_fill_keys( get_post_stati(), 0 );
     2360    $counts  = array_fill_keys( get_post_stati(), 0 );
    22482361
    22492362    foreach ( $results as $row ) {
     
    22872400    global $wpdb;
    22882401
    2289     $and = wp_post_mime_type_where( $mime_type );
     2402    $and   = wp_post_mime_type_where( $mime_type );
    22902403    $count = $wpdb->get_results( "SELECT post_mime_type, COUNT( * ) AS num_posts FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' $and GROUP BY post_mime_type", ARRAY_A );
    22912404
     
    22942407        $counts[ $row['post_mime_type'] ] = $row['num_posts'];
    22952408    }
    2296     $counts['trash'] = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status = 'trash' $and");
     2409    $counts['trash'] = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status = 'trash' $and" );
    22972410
    22982411    /**
     
    23172430 */
    23182431function get_post_mime_types() {
    2319     $post_mime_types = array(   //  array( adj, noun )
    2320         'image' => array(__('Images'), __('Manage Images'), _n_noop('Image <span class="count">(%s)</span>', 'Images <span class="count">(%s)</span>')),
    2321         'audio' => array(__('Audio'), __('Manage Audio'), _n_noop('Audio <span class="count">(%s)</span>', 'Audio <span class="count">(%s)</span>')),
    2322         'video' => array(__('Video'), __('Manage Video'), _n_noop('Video <span class="count">(%s)</span>', 'Video <span class="count">(%s)</span>')),
     2432    $post_mime_types = array(   //  array( adj, noun )
     2433        'image' => array( __( 'Images' ), __( 'Manage Images' ), _n_noop( 'Image <span class="count">(%s)</span>', 'Images <span class="count">(%s)</span>' ) ),
     2434        'audio' => array( __( 'Audio' ), __( 'Manage Audio' ), _n_noop( 'Audio <span class="count">(%s)</span>', 'Audio <span class="count">(%s)</span>' ) ),
     2435        'video' => array( __( 'Video' ), __( 'Manage Video' ), _n_noop( 'Video <span class="count">(%s)</span>', 'Video <span class="count">(%s)</span>' ) ),
    23232436    );
    23242437
     
    23572470
    23582471    $patternses = array();
    2359     $wild = '[-._a-z0-9]*';
     2472    $wild       = '[-._a-z0-9]*';
    23602473
    23612474    foreach ( (array) $wildcard_mime_types as $type ) {
    23622475        $mimes = array_map( 'trim', explode( ',', $type ) );
    23632476        foreach ( $mimes as $mime ) {
    2364             $regex = str_replace( '__wildcard__', $wild, preg_quote( str_replace( '*', '__wildcard__', $mime ) ) );
    2365             $patternses[][$type] = "^$regex$";
     2477            $regex                 = str_replace( '__wildcard__', $wild, preg_quote( str_replace( '*', '__wildcard__', $mime ) ) );
     2478            $patternses[][ $type ] = "^$regex$";
    23662479            if ( false === strpos( $mime, '/' ) ) {
    2367                 $patternses[][$type] = "^$regex/";
    2368                 $patternses[][$type] = $regex;
     2480                $patternses[][ $type ] = "^$regex/";
     2481                $patternses[][ $type ] = $regex;
    23692482            }
    23702483        }
     
    23752488        foreach ( $patterns as $type => $pattern ) {
    23762489            foreach ( (array) $real_mime_types as $real ) {
    2377                 if ( preg_match( "#$pattern#", $real ) && ( empty( $matches[$type] ) || false === array_search( $real, $matches[$type] ) ) ) {
    2378                     $matches[$type][] = $real;
     2490                if ( preg_match( "#$pattern#", $real ) && ( empty( $matches[ $type ] ) || false === array_search( $real, $matches[ $type ] ) ) ) {
     2491                    $matches[ $type ][] = $real;
    23792492                }
    23802493            }
     
    23962509 */
    23972510function wp_post_mime_type_where( $post_mime_types, $table_alias = '' ) {
    2398     $where = '';
    2399     $wildcards = array('', '%', '%/%');
    2400     if ( is_string($post_mime_types) )
    2401         $post_mime_types = array_map('trim', explode(',', $post_mime_types));
     2511    $where     = '';
     2512    $wildcards = array( '', '%', '%/%' );
     2513    if ( is_string( $post_mime_types ) ) {
     2514        $post_mime_types = array_map( 'trim', explode( ',', $post_mime_types ) );
     2515    }
    24022516
    24032517    $wheres = array();
    24042518
    24052519    foreach ( (array) $post_mime_types as $mime_type ) {
    2406         $mime_type = preg_replace('/\s/', '', $mime_type);
    2407         $slashpos = strpos($mime_type, '/');
     2520        $mime_type = preg_replace( '/\s/', '', $mime_type );
     2521        $slashpos  = strpos( $mime_type, '/' );
    24082522        if ( false !== $slashpos ) {
    2409             $mime_group = preg_replace('/[^-*.a-zA-Z0-9]/', '', substr($mime_type, 0, $slashpos));
    2410             $mime_subgroup = preg_replace('/[^-*.+a-zA-Z0-9]/', '', substr($mime_type, $slashpos + 1));
    2411             if ( empty($mime_subgroup) )
     2523            $mime_group    = preg_replace( '/[^-*.a-zA-Z0-9]/', '', substr( $mime_type, 0, $slashpos ) );
     2524            $mime_subgroup = preg_replace( '/[^-*.+a-zA-Z0-9]/', '', substr( $mime_type, $slashpos + 1 ) );
     2525            if ( empty( $mime_subgroup ) ) {
    24122526                $mime_subgroup = '*';
    2413             else
    2414                 $mime_subgroup = str_replace('/', '', $mime_subgroup);
     2527            } else {
     2528                $mime_subgroup = str_replace( '/', '', $mime_subgroup );
     2529            }
    24152530            $mime_pattern = "$mime_group/$mime_subgroup";
    24162531        } else {
    2417             $mime_pattern = preg_replace('/[^-*.a-zA-Z0-9]/', '', $mime_type);
    2418             if ( false === strpos($mime_pattern, '*') )
     2532            $mime_pattern = preg_replace( '/[^-*.a-zA-Z0-9]/', '', $mime_type );
     2533            if ( false === strpos( $mime_pattern, '*' ) ) {
    24192534                $mime_pattern .= '/*';
    2420         }
    2421 
    2422         $mime_pattern = preg_replace('/\*+/', '%', $mime_pattern);
    2423 
    2424         if ( in_array( $mime_type, $wildcards ) )
     2535            }
     2536        }
     2537
     2538        $mime_pattern = preg_replace( '/\*+/', '%', $mime_pattern );
     2539
     2540        if ( in_array( $mime_type, $wildcards ) ) {
    24252541            return '';
    2426 
    2427         if ( false !== strpos($mime_pattern, '%') )
    2428             $wheres[] = empty($table_alias) ? "post_mime_type LIKE '$mime_pattern'" : "$table_alias.post_mime_type LIKE '$mime_pattern'";
    2429         else
    2430             $wheres[] = empty($table_alias) ? "post_mime_type = '$mime_pattern'" : "$table_alias.post_mime_type = '$mime_pattern'";
    2431     }
    2432     if ( !empty($wheres) )
    2433         $where = ' AND (' . join(' OR ', $wheres) . ') ';
     2542        }
     2543
     2544        if ( false !== strpos( $mime_pattern, '%' ) ) {
     2545            $wheres[] = empty( $table_alias ) ? "post_mime_type LIKE '$mime_pattern'" : "$table_alias.post_mime_type LIKE '$mime_pattern'";
     2546        } else {
     2547            $wheres[] = empty( $table_alias ) ? "post_mime_type = '$mime_pattern'" : "$table_alias.post_mime_type = '$mime_pattern'";
     2548        }
     2549    }
     2550    if ( ! empty( $wheres ) ) {
     2551        $where = ' AND (' . join( ' OR ', $wheres ) . ') ';
     2552    }
    24342553    return $where;
    24352554}
     
    25002619    do_action( 'before_delete_post', $postid );
    25012620
    2502     delete_post_meta($postid,'_wp_trash_meta_status');
    2503     delete_post_meta($postid,'_wp_trash_meta_time');
    2504 
    2505     wp_delete_object_term_relationships($postid, get_object_taxonomies($post->post_type));
    2506 
    2507     $parent_data = array( 'post_parent' => $post->post_parent );
     2621    delete_post_meta( $postid, '_wp_trash_meta_status' );
     2622    delete_post_meta( $postid, '_wp_trash_meta_time' );
     2623
     2624    wp_delete_object_term_relationships( $postid, get_object_taxonomies( $post->post_type ) );
     2625
     2626    $parent_data  = array( 'post_parent' => $post->post_parent );
    25082627    $parent_where = array( 'post_parent' => $postid );
    25092628
     
    25112630        // Point children of this page to its parent, also clean the cache of affected children.
    25122631        $children_query = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_parent = %d AND post_type = %s", $postid, $post->post_type );
    2513         $children = $wpdb->get_results( $children_query );
     2632        $children       = $wpdb->get_results( $children_query );
    25142633        if ( $children ) {
    25152634            $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => $post->post_type ) );
     
    25202639    $revision_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $postid ) );
    25212640    // Use wp_delete_post (via wp_delete_post_revision) again. Ensures any meta/misplaced data gets cleaned up.
    2522     foreach ( $revision_ids as $revision_id )
     2641    foreach ( $revision_ids as $revision_id ) {
    25232642        wp_delete_post_revision( $revision_id );
     2643    }
    25242644
    25252645    // Point all attachments to this post up one level.
     
    25282648    wp_defer_comment_counting( true );
    25292649
    2530     $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $postid ));
     2650    $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $postid ) );
    25312651    foreach ( $comment_ids as $comment_id ) {
    25322652        wp_delete_comment( $comment_id, true );
     
    25352655    wp_defer_comment_counting( false );
    25362656
    2537     $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $postid ));
    2538     foreach ( $post_meta_ids as $mid )
     2657    $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $postid ) );
     2658    foreach ( $post_meta_ids as $mid ) {
    25392659        delete_metadata_by_mid( 'post', $mid );
     2660    }
    25402661
    25412662    /**
     
    25642685
    25652686    if ( is_post_type_hierarchical( $post->post_type ) && $children ) {
    2566         foreach ( $children as $child )
     2687        foreach ( $children as $child ) {
    25672688            clean_post_cache( $child );
    2568     }
    2569 
    2570     wp_clear_scheduled_hook('publish_future_post', array( $postid ) );
     2689        }
     2690    }
     2691
     2692    wp_clear_scheduled_hook( 'publish_future_post', array( $postid ) );
    25712693
    25722694    /**
     
    25982720    $post = get_post( $post_id );
    25992721    if ( 'page' == $post->post_type ) {
    2600         /*
    2601         * If the page is defined in option page_on_front or post_for_posts,
    2602         * adjust the corresponding options.
    2603         */
     2722        /*
     2723          * If the page is defined in option page_on_front or post_for_posts,
     2724          * adjust the corresponding options.
     2725          */
    26042726        if ( get_option( 'page_on_front' ) == $post->ID ) {
    26052727            update_option( 'show_on_front', 'posts' );
     
    26662788    add_post_meta( $post_id, '_wp_trash_meta_time', time() );
    26672789
    2668     wp_update_post( array( 'ID' => $post_id, 'post_status' => 'trash' ) );
     2790    wp_update_post(
     2791        array(
     2792            'ID'          => $post_id,
     2793            'post_status' => 'trash',
     2794        )
     2795    );
    26692796
    26702797    wp_trash_post_comments( $post_id );
     
    27282855    delete_post_meta( $post_id, '_wp_trash_meta_time' );
    27292856
    2730     wp_update_post( array( 'ID' => $post_id, 'post_status' => $post_status ) );
     2857    wp_update_post(
     2858        array(
     2859            'ID'          => $post_id,
     2860            'post_status' => $post_status,
     2861        )
     2862    );
    27312863
    27322864    wp_untrash_post_comments( $post_id );
     
    27572889    global $wpdb;
    27582890
    2759     $post = get_post($post);
    2760     if ( empty($post) )
     2891    $post = get_post( $post );
     2892    if ( empty( $post ) ) {
    27612893        return;
     2894    }
    27622895
    27632896    $post_id = $post->ID;
     
    27722905    do_action( 'trash_post_comments', $post_id );
    27732906
    2774     $comments = $wpdb->get_results( $wpdb->prepare("SELECT comment_ID, comment_approved FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id) );
    2775     if ( empty($comments) )
     2907    $comments = $wpdb->get_results( $wpdb->prepare( "SELECT comment_ID, comment_approved FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ) );
     2908    if ( empty( $comments ) ) {
    27762909        return;
     2910    }
    27772911
    27782912    // Cache current status for each comment.
    27792913    $statuses = array();
    2780     foreach ( $comments as $comment )
    2781         $statuses[$comment->comment_ID] = $comment->comment_approved;
    2782     add_post_meta($post_id, '_wp_trash_meta_comments_status', $statuses);
     2914    foreach ( $comments as $comment ) {
     2915        $statuses[ $comment->comment_ID ] = $comment->comment_approved;
     2916    }
     2917    add_post_meta( $post_id, '_wp_trash_meta_comments_status', $statuses );
    27832918
    27842919    // Set status for all comments to post-trashed.
    2785     $result = $wpdb->update($wpdb->comments, array('comment_approved' => 'post-trashed'), array('comment_post_ID' => $post_id));
    2786 
    2787     clean_comment_cache( array_keys($statuses) );
     2920    $result = $wpdb->update( $wpdb->comments, array( 'comment_approved' => 'post-trashed' ), array( 'comment_post_ID' => $post_id ) );
     2921
     2922    clean_comment_cache( array_keys( $statuses ) );
    27882923
    27892924    /**
     
    28132948    global $wpdb;
    28142949
    2815     $post = get_post($post);
    2816     if ( empty($post) )
     2950    $post = get_post( $post );
     2951    if ( empty( $post ) ) {
    28172952        return;
     2953    }
    28182954
    28192955    $post_id = $post->ID;
    28202956
    2821     $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
    2822 
    2823     if ( empty($statuses) )
     2957    $statuses = get_post_meta( $post_id, '_wp_trash_meta_comments_status', true );
     2958
     2959    if ( empty( $statuses ) ) {
    28242960        return true;
     2961    }
    28252962
    28262963    /**
     
    28352972    // Restore each comment to its original status.
    28362973    $group_by_status = array();
    2837     foreach ( $statuses as $comment_id => $comment_status )
    2838         $group_by_status[$comment_status][] = $comment_id;
     2974    foreach ( $statuses as $comment_id => $comment_status ) {
     2975        $group_by_status[ $comment_status ][] = $comment_id;
     2976    }
    28392977
    28402978    foreach ( $group_by_status as $status => $comments ) {
     
    28472985    }
    28482986
    2849     clean_comment_cache( array_keys($statuses) );
    2850 
    2851     delete_post_meta($post_id, '_wp_trash_meta_comments_status');
     2987    clean_comment_cache( array_keys( $statuses ) );
     2988
     2989    delete_post_meta( $post_id, '_wp_trash_meta_comments_status' );
    28522990
    28532991    /**
     
    28833021    $post_id = (int) $post_id;
    28843022
    2885     $defaults = array('fields' => 'ids');
    2886     $args = wp_parse_args( $args, $defaults );
    2887 
    2888     $cats = wp_get_object_terms($post_id, 'category', $args);
     3023    $defaults = array( 'fields' => 'ids' );
     3024    $args     = wp_parse_args( $args, $defaults );
     3025
     3026    $cats = wp_get_object_terms( $post_id, 'category', $args );
    28893027    return $cats;
    28903028}
     
    29073045 */
    29083046function wp_get_post_tags( $post_id = 0, $args = array() ) {
    2909     return wp_get_post_terms( $post_id, 'post_tag', $args);
     3047    return wp_get_post_terms( $post_id, 'post_tag', $args );
    29103048}
    29113049
     
    29303068    $post_id = (int) $post_id;
    29313069
    2932     $defaults = array('fields' => 'all');
    2933     $args = wp_parse_args( $args, $defaults );
    2934 
    2935     $tags = wp_get_object_terms($post_id, $taxonomy, $args);
     3070    $defaults = array( 'fields' => 'all' );
     3071    $args     = wp_parse_args( $args, $defaults );
     3072
     3073    $tags = wp_get_object_terms( $post_id, $taxonomy, $args );
    29363074
    29373075    return $tags;
     
    29603098    // Set default arguments.
    29613099    $defaults = array(
    2962         'numberposts' => 10, 'offset' => 0,
    2963         'category' => 0, 'orderby' => 'post_date',
    2964         'order' => 'DESC', 'include' => '',
    2965         'exclude' => '', 'meta_key' => '',
    2966         'meta_value' =>'', 'post_type' => 'post', 'post_status' => 'draft, publish, future, pending, private',
    2967         'suppress_filters' => true
     3100        'numberposts'      => 10,
     3101        'offset'           => 0,
     3102        'category'         => 0,
     3103        'orderby'          => 'post_date',
     3104        'order'            => 'DESC',
     3105        'include'          => '',
     3106        'exclude'          => '',
     3107        'meta_key'         => '',
     3108        'meta_value'       => '',
     3109        'post_type'        => 'post',
     3110        'post_status'      => 'draft, publish, future, pending, private',
     3111        'suppress_filters' => true,
    29683112    );
    29693113
     
    29733117
    29743118    // Backward compatibility. Prior to 3.1 expected posts to be returned in array.
    2975     if ( ARRAY_A == $output ){
     3119    if ( ARRAY_A == $output ) {
    29763120        foreach ( $results as $key => $result ) {
    2977             $results[$key] = get_object_vars( $result );
     3121            $results[ $key ] = get_object_vars( $result );
    29783122        }
    29793123        return $results ? $results : array();
     
    30503194
    30513195    $defaults = array(
    3052         'post_author' => $user_id,
    3053         'post_content' => '',
     3196        'post_author'           => $user_id,
     3197        'post_content'          => '',
    30543198        'post_content_filtered' => '',
    3055         'post_title' => '',
    3056         'post_excerpt' => '',
    3057         'post_status' => 'draft',
    3058         'post_type' => 'post',
    3059         'comment_status' => '',
    3060         'ping_status' => '',
    3061         'post_password' => '',
    3062         'to_ping' => '',
    3063         'pinged' => '',
    3064         'post_parent' => 0,
    3065         'menu_order' => 0,
    3066         'guid' => '',
    3067         'import_id' => 0,
    3068         'context' => '',
     3199        'post_title'            => '',
     3200        'post_excerpt'          => '',
     3201        'post_status'           => 'draft',
     3202        'post_type'             => 'post',
     3203        'comment_status'        => '',
     3204        'ping_status'           => '',
     3205        'post_password'         => '',
     3206        'to_ping'               => '',
     3207        'pinged'                => '',
     3208        'post_parent'           => 0,
     3209        'menu_order'            => 0,
     3210        'guid'                  => '',
     3211        'import_id'             => 0,
     3212        'context'               => '',
    30693213    );
    30703214
    3071     $postarr = wp_parse_args($postarr, $defaults);
    3072 
    3073     unset( $postarr[ 'filter' ] );
    3074 
    3075     $postarr = sanitize_post($postarr, 'db');
     3215    $postarr = wp_parse_args( $postarr, $defaults );
     3216
     3217    unset( $postarr['filter'] );
     3218
     3219    $postarr = sanitize_post( $postarr, 'db' );
    30763220
    30773221    // Are we updating or creating?
    30783222    $post_ID = 0;
    3079     $update = false;
    3080     $guid = $postarr['guid'];
     3223    $update  = false;
     3224    $guid    = $postarr['guid'];
    30813225
    30823226    if ( ! empty( $postarr['ID'] ) ) {
     
    30843228
    30853229        // Get the post ID and GUID.
    3086         $post_ID = $postarr['ID'];
     3230        $post_ID     = $postarr['ID'];
    30873231        $post_before = get_post( $post_ID );
    30883232        if ( is_null( $post_before ) ) {
     
    30933237        }
    30943238
    3095         $guid = get_post_field( 'guid', $post_ID );
    3096         $previous_status = get_post_field('post_status', $post_ID );
     3239        $guid            = get_post_field( 'guid', $post_ID );
     3240        $previous_status = get_post_field( 'post_status', $post_ID );
    30973241    } else {
    30983242        $previous_status = 'new';
     
    31013245    $post_type = empty( $postarr['post_type'] ) ? 'post' : $postarr['post_type'];
    31023246
    3103     $post_title = $postarr['post_title'];
     3247    $post_title   = $postarr['post_title'];
    31043248    $post_content = $postarr['post_content'];
    31053249    $post_excerpt = $postarr['post_excerpt'];
     
    31553299        // 'post' requires at least one category.
    31563300        if ( 'post' == $post_type && 'auto-draft' != $post_status ) {
    3157             $post_category = array( get_option('default_category') );
     3301            $post_category = array( get_option( 'default_category' ) );
    31583302        } else {
    31593303            $post_category = array();
     
    31623306
    31633307    // Don't allow contributors to set the post slug for pending review posts.
    3164     if ( 'pending' == $post_status && !current_user_can( 'publish_posts' ) ) {
     3308    if ( 'pending' == $post_status && ! current_user_can( 'publish_posts' ) ) {
    31653309        $post_name = '';
    31663310    }
     
    31703314     * an empty post name.
    31713315     */
    3172     if ( empty($post_name) ) {
    3173         if ( !in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) {
    3174             $post_name = sanitize_title($post_title);
     3316    if ( empty( $post_name ) ) {
     3317        if ( ! in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) {
     3318            $post_name = sanitize_title( $post_title );
    31753319        } else {
    31763320            $post_name = '';
     
    31823326            $post_name = $check_name;
    31833327        } else { // new post, or slug has changed.
    3184             $post_name = sanitize_title($post_name);
     3328            $post_name = sanitize_title( $post_name );
    31853329        }
    31863330    }
     
    32013345
    32023346    // Validate the date.
    3203     $mm = substr( $post_date, 5, 2 );
    3204     $jj = substr( $post_date, 8, 2 );
    3205     $aa = substr( $post_date, 0, 4 );
     3347    $mm         = substr( $post_date, 5, 2 );
     3348    $jj         = substr( $post_date, 8, 2 );
     3349    $aa         = substr( $post_date, 0, 4 );
    32063350    $valid_date = wp_checkdate( $mm, $jj, $aa, $post_date );
    32073351    if ( ! $valid_date ) {
     
    32333377    if ( 'attachment' !== $post_type ) {
    32343378        if ( 'publish' == $post_status ) {
    3235             $now = gmdate('Y-m-d H:i:59');
    3236             if ( mysql2date('U', $post_date_gmt, false) > mysql2date('U', $now, false) ) {
     3379            $now = gmdate( 'Y-m-d H:i:59' );
     3380            if ( mysql2date( 'U', $post_date_gmt, false ) > mysql2date( 'U', $now, false ) ) {
    32373381                $post_status = 'future';
    32383382            }
    32393383        } elseif ( 'future' == $post_status ) {
    3240             $now = gmdate('Y-m-d H:i:59');
    3241             if ( mysql2date('U', $post_date_gmt, false) <= mysql2date('U', $now, false) ) {
     3384            $now = gmdate( 'Y-m-d H:i:59' );
     3385            if ( mysql2date( 'U', $post_date_gmt, false ) <= mysql2date( 'U', $now, false ) ) {
    32423386                $post_status = 'publish';
    32433387            }
     
    32583402    // These variables are needed by compact() later.
    32593403    $post_content_filtered = $postarr['post_content_filtered'];
    3260     $post_author = isset( $postarr['post_author'] ) ? $postarr['post_author'] : $user_id;
    3261     $ping_status = empty( $postarr['ping_status'] ) ? get_default_comment_status( $post_type, 'pingback' ) : $postarr['ping_status'];
    3262     $to_ping = isset( $postarr['to_ping'] ) ? sanitize_trackback_urls( $postarr['to_ping'] ) : '';
    3263     $pinged = isset( $postarr['pinged'] ) ? $postarr['pinged'] : '';
    3264     $import_id = isset( $postarr['import_id'] ) ? $postarr['import_id'] : 0;
     3404    $post_author           = isset( $postarr['post_author'] ) ? $postarr['post_author'] : $user_id;
     3405    $ping_status           = empty( $postarr['ping_status'] ) ? get_default_comment_status( $post_type, 'pingback' ) : $postarr['ping_status'];
     3406    $to_ping               = isset( $postarr['to_ping'] ) ? sanitize_trackback_urls( $postarr['to_ping'] ) : '';
     3407    $pinged                = isset( $postarr['pinged'] ) ? $postarr['pinged'] : '';
     3408    $import_id             = isset( $postarr['import_id'] ) ? $postarr['import_id'] : 0;
    32653409
    32663410    /*
     
    33593503        $data = apply_filters( 'wp_insert_post_data', $data, $postarr );
    33603504    }
    3361     $data = wp_unslash( $data );
     3505    $data  = wp_unslash( $data );
    33623506    $where = array( 'ID' => $post_ID );
    33633507
     
    33743518        if ( false === $wpdb->update( $wpdb->posts, $data, $where ) ) {
    33753519            if ( $wp_error ) {
    3376                 return new WP_Error('db_update_error', __('Could not update post in the database'), $wpdb->last_error);
     3520                return new WP_Error( 'db_update_error', __( 'Could not update post in the database' ), $wpdb->last_error );
    33773521            } else {
    33783522                return 0;
     
    33833527        if ( ! empty( $import_id ) ) {
    33843528            $import_id = (int) $import_id;
    3385             if ( ! $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE ID = %d", $import_id) ) ) {
     3529            if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE ID = %d", $import_id ) ) ) {
    33863530                $data['ID'] = $import_id;
    33873531            }
     
    33893533        if ( false === $wpdb->insert( $wpdb->posts, $data ) ) {
    33903534            if ( $wp_error ) {
    3391                 return new WP_Error('db_insert_error', __('Could not insert post into the database'), $wpdb->last_error);
     3535                return new WP_Error( 'db_insert_error', __( 'Could not insert post into the database' ), $wpdb->last_error );
    33923536            } else {
    33933537                return 0;
     
    34173561    if ( ! empty( $postarr['tax_input'] ) ) {
    34183562        foreach ( $postarr['tax_input'] as $taxonomy => $tags ) {
    3419             $taxonomy_obj = get_taxonomy($taxonomy);
     3563            $taxonomy_obj = get_taxonomy( $taxonomy );
    34203564            if ( ! $taxonomy_obj ) {
    34213565                /* translators: %s: taxonomy name */
     
    34263570            // array = hierarchical, string = non-hierarchical.
    34273571            if ( is_array( $tags ) ) {
    3428                 $tags = array_filter($tags);
     3572                $tags = array_filter( $tags );
    34293573            }
    34303574            if ( current_user_can( $taxonomy_obj->cap->assign_terms ) ) {
     
    34843628    if ( ! empty( $postarr['page_template'] ) ) {
    34853629        $post->page_template = $postarr['page_template'];
    3486         $page_templates = wp_get_theme()->get_page_templates( $post );
     3630        $page_templates      = wp_get_theme()->get_page_templates( $post );
    34873631        if ( 'default' != $postarr['page_template'] && ! isset( $page_templates[ $postarr['page_template'] ] ) ) {
    34883632            if ( $wp_error ) {
     
    35443688         */
    35453689        do_action( 'edit_post', $post_ID, $post );
    3546         $post_after = get_post($post_ID);
     3690        $post_after = get_post( $post_ID );
    35473691
    35483692        /**
     
    35553699         * @param WP_Post $post_before  Post object before the update.
    35563700         */
    3557         do_action( 'post_updated', $post_ID, $post_after, $post_before);
     3701        do_action( 'post_updated', $post_ID, $post_after, $post_before );
    35583702    }
    35593703
     
    36113755 */
    36123756function wp_update_post( $postarr = array(), $wp_error = false ) {
    3613     if ( is_object($postarr) ) {
     3757    if ( is_object( $postarr ) ) {
    36143758        // Non-escaped post was passed.
    3615         $postarr = get_object_vars($postarr);
    3616         $postarr = wp_slash($postarr);
     3759        $postarr = get_object_vars( $postarr );
     3760        $postarr = wp_slash( $postarr );
    36173761    }
    36183762
    36193763    // First, get all of the original fields.
    3620     $post = get_post($postarr['ID'], ARRAY_A);
     3764    $post = get_post( $postarr['ID'], ARRAY_A );
    36213765
    36223766    if ( is_null( $post ) ) {
    3623         if ( $wp_error )
     3767        if ( $wp_error ) {
    36243768            return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) );
     3769        }
    36253770        return 0;
    36263771    }
    36273772
    36283773    // Escape data pulled from DB.
    3629     $post = wp_slash($post);
     3774    $post = wp_slash( $post );
    36303775
    36313776    // Passed post category list overwrites existing category list if not empty.
    3632     if ( isset($postarr['post_category']) && is_array($postarr['post_category'])
    3633             && 0 != count($postarr['post_category']) )
     3777    if ( isset( $postarr['post_category'] ) && is_array( $postarr['post_category'] )
     3778            && 0 != count( $postarr['post_category'] ) ) {
    36343779        $post_cats = $postarr['post_category'];
    3635     else
     3780    } else {
    36363781        $post_cats = $post['post_category'];
     3782    }
    36373783
    36383784    // Drafts shouldn't be assigned a date unless explicitly done so by the user.
    3639     if ( isset( $post['post_status'] ) && in_array($post['post_status'], array('draft', 'pending', 'auto-draft')) && empty($postarr['edit_date']) &&
    3640             ('0000-00-00 00:00:00' == $post['post_date_gmt']) )
     3785    if ( isset( $post['post_status'] ) && in_array( $post['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) && empty( $postarr['edit_date'] ) &&
     3786            ( '0000-00-00 00:00:00' == $post['post_date_gmt'] ) ) {
    36413787        $clear_date = true;
    3642     else
     3788    } else {
    36433789        $clear_date = false;
     3790    }
    36443791
    36453792    // Merge old and new fields with new fields overwriting old ones.
    3646     $postarr = array_merge($post, $postarr);
     3793    $postarr                  = array_merge( $post, $postarr );
    36473794    $postarr['post_category'] = $post_cats;
    36483795    if ( $clear_date ) {
    3649         $postarr['post_date'] = current_time('mysql');
     3796        $postarr['post_date']     = current_time( 'mysql' );
    36503797        $postarr['post_date_gmt'] = '';
    36513798    }
    36523799
    3653     if ($postarr['post_type'] == 'attachment')
    3654         return wp_insert_attachment($postarr);
     3800    if ( $postarr['post_type'] == 'attachment' ) {
     3801        return wp_insert_attachment( $postarr );
     3802    }
    36553803
    36563804    return wp_insert_post( $postarr, $wp_error );
     
    36693817    global $wpdb;
    36703818
    3671     if ( ! $post = get_post( $post ) )
     3819    if ( ! $post = get_post( $post ) ) {
    36723820        return;
    3673 
    3674     if ( 'publish' == $post->post_status )
     3821    }
     3822
     3823    if ( 'publish' == $post->post_status ) {
    36753824        return;
     3825    }
    36763826
    36773827    $wpdb->update( $wpdb->posts, array( 'post_status' => 'publish' ), array( 'ID' => $post->ID ) );
     
    36793829    clean_post_cache( $post->ID );
    36803830
    3681     $old_status = $post->post_status;
     3831    $old_status        = $post->post_status;
    36823832    $post->post_status = 'publish';
    36833833    wp_transition_post_status( 'publish', $old_status, $post );
     
    37073857 */
    37083858function check_and_publish_future_post( $post_id ) {
    3709     $post = get_post($post_id);
    3710 
    3711     if ( empty($post) )
     3859    $post = get_post( $post_id );
     3860
     3861    if ( empty( $post ) ) {
    37123862        return;
    3713 
    3714     if ( 'future' != $post->post_status )
     3863    }
     3864
     3865    if ( 'future' != $post->post_status ) {
    37153866        return;
     3867    }
    37163868
    37173869    $time = strtotime( $post->post_date_gmt . ' GMT' );
     
    37443896 */
    37453897function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent ) {
    3746     if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) || ( 'inherit' == $post_status && 'revision' == $post_type ) )
     3898    if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) || ( 'inherit' == $post_status && 'revision' == $post_type ) ) {
    37473899        return $slug;
     3900    }
    37483901
    37493902    global $wpdb, $wp_rewrite;
     
    37523905
    37533906    $feeds = $wp_rewrite->feeds;
    3754     if ( ! is_array( $feeds ) )
     3907    if ( ! is_array( $feeds ) ) {
    37553908        $feeds = array();
     3909    }
    37563910
    37573911    if ( 'attachment' == $post_type ) {
    37583912        // Attachment slugs must be unique across all types.
    3759         $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1";
     3913        $check_sql       = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1";
    37603914        $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID ) );
    37613915
     
    37713925            $suffix = 2;
    37723926            do {
    3773                 $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
     3927                $alt_post_name   = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
    37743928                $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_ID ) );
    37753929                $suffix++;
     
    37783932        }
    37793933    } elseif ( is_post_type_hierarchical( $post_type ) ) {
    3780         if ( 'nav_menu_item' == $post_type )
     3934        if ( 'nav_menu_item' == $post_type ) {
    37813935            return $slug;
     3936        }
    37823937
    37833938        /*
     
    37853940         * namespace than posts so page slugs are allowed to overlap post slugs.
    37863941         */
    3787         $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( %s, 'attachment' ) AND ID != %d AND post_parent = %d LIMIT 1";
     3942        $check_sql       = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( %s, 'attachment' ) AND ID != %d AND post_parent = %d LIMIT 1";
    37883943        $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID, $post_parent ) );
    37893944
     
    37983953         * @param int    $post_parent Post parent ID.
    37993954         */
    3800         if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug )  || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent ) ) {
     3955        if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug ) || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent ) ) {
    38013956            $suffix = 2;
    38023957            do {
    3803                 $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
     3958                $alt_post_name   = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
    38043959                $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_ID, $post_parent ) );
    38053960                $suffix++;
     
    38093964    } else {
    38103965        // Post slugs must be unique across all posts.
    3811         $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1";
     3966        $check_sql       = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1";
    38123967        $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID ) );
    38133968
    38143969        // Prevent new post slugs that could result in URLs that conflict with date archives.
    3815         $post = get_post( $post_ID );
     3970        $post                        = get_post( $post_ID );
    38163971        $conflicts_with_date_archive = false;
    38173972        if ( 'post' === $post_type && ( ! $post || $post->post_name !== $slug ) && preg_match( '/^[0-9]+$/', $slug ) && $slug_num = intval( $slug ) ) {
     
    38464001            $suffix = 2;
    38474002            do {
    3848                 $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
     4003                $alt_post_name   = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
    38494004                $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_ID ) );
    38504005                $suffix++;
     
    38844039    if ( strlen( $slug ) > $length ) {
    38854040        $decoded_slug = urldecode( $slug );
    3886         if ( $decoded_slug === $slug )
     4041        if ( $decoded_slug === $slug ) {
    38874042            $slug = substr( $slug, 0, $length );
    3888         else
     4043        } else {
    38894044            $slug = utf8_uri_encode( $decoded_slug, $length );
     4045        }
    38904046    }
    38914047
     
    39064062 */
    39074063function wp_add_post_tags( $post_id = 0, $tags = '' ) {
    3908     return wp_set_post_tags($post_id, $tags, true);
     4064    return wp_set_post_tags( $post_id, $tags, true );
    39094065}
    39104066
     
    39244080 */
    39254081function wp_set_post_tags( $post_id = 0, $tags = '', $append = false ) {
    3926     return wp_set_post_terms( $post_id, $tags, 'post_tag', $append);
     4082    return wp_set_post_terms( $post_id, $tags, 'post_tag', $append );
    39274083}
    39284084
     
    39454101    $post_id = (int) $post_id;
    39464102
    3947     if ( !$post_id )
     4103    if ( ! $post_id ) {
    39484104        return false;
    3949 
    3950     if ( empty($tags) )
     4105    }
     4106
     4107    if ( empty( $tags ) ) {
    39514108        $tags = array();
     4109    }
    39524110
    39534111    if ( ! is_array( $tags ) ) {
    39544112        $comma = _x( ',', 'tag delimiter' );
    3955         if ( ',' !== $comma )
     4113        if ( ',' !== $comma ) {
    39564114            $tags = str_replace( $comma, ',', $tags );
     4115        }
    39574116        $tags = explode( ',', trim( $tags, " \n\t\r\0\x0B," ) );
    39584117    }
     
    39864145 */
    39874146function wp_set_post_categories( $post_ID = 0, $post_categories = array(), $append = false ) {
    3988     $post_ID = (int) $post_ID;
    3989     $post_type = get_post_type( $post_ID );
     4147    $post_ID     = (int) $post_ID;
     4148    $post_type   = get_post_type( $post_ID );
    39904149    $post_status = get_post_status( $post_ID );
    39914150    // If $post_categories isn't already an array, make it one:
     
    39934152    if ( empty( $post_categories ) ) {
    39944153        if ( 'post' == $post_type && 'auto-draft' != $post_status ) {
    3995             $post_categories = array( get_option('default_category') );
    3996             $append = false;
     4154            $post_categories = array( get_option( 'default_category' ) );
     4155            $append          = false;
    39974156        } else {
    39984157            $post_categories = array();
     
    41024261    if ( is_array( $uri ) ) {
    41034262        $pung = array_merge( $pung, $uri );
    4104     }
    4105     else {
     4263    } else {
    41064264        $pung[] = $uri;
    41074265    }
    4108     $new = implode("\n", $pung);
     4266    $new = implode( "\n", $pung );
    41094267
    41104268    /**
     
    41324290function get_enclosed( $post_id ) {
    41334291    $custom_fields = get_post_custom( $post_id );
    4134     $pung = array();
    4135     if ( !is_array( $custom_fields ) )
     4292    $pung          = array();
     4293    if ( ! is_array( $custom_fields ) ) {
    41364294        return $pung;
     4295    }
    41374296
    41384297    foreach ( $custom_fields as $key => $val ) {
    4139         if ( 'enclosure' != $key || !is_array( $val ) )
     4298        if ( 'enclosure' != $key || ! is_array( $val ) ) {
    41404299            continue;
     4300        }
    41414301        foreach ( $val as $enc ) {
    41424302            $enclosure = explode( "\n", $enc );
    4143             $pung[] = trim( $enclosure[ 0 ] );
     4303            $pung[]    = trim( $enclosure[0] );
    41444304        }
    41454305    }
     
    42024362
    42034363    $to_ping = sanitize_trackback_urls( $post->to_ping );
    4204     $to_ping = preg_split('/\s/', $to_ping, -1, PREG_SPLIT_NO_EMPTY);
     4364    $to_ping = preg_split( '/\s/', $to_ping, -1, PREG_SPLIT_NO_EMPTY );
    42054365
    42064366    /**
     
    42584418    global $wpdb;
    42594419
    4260     $page_ids = wp_cache_get('all_page_ids', 'posts');
     4420    $page_ids = wp_cache_get( 'all_page_ids', 'posts' );
    42614421    if ( ! is_array( $page_ids ) ) {
    4262         $page_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type = 'page'");
    4263         wp_cache_add('all_page_ids', $page_ids, 'posts');
     4422        $page_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type = 'page'" );
     4423        wp_cache_add( 'all_page_ids', $page_ids, 'posts' );
    42644424    }
    42654425
     
    42824442 * @return WP_Post|array|null WP_Post (or array) on success, or null on failure.
    42834443 */
    4284 function get_page( $page, $output = OBJECT, $filter = 'raw') {
     4444function get_page( $page, $output = OBJECT, $filter = 'raw' ) {
    42854445    return get_post( $page, $output, $filter );
    42864446}
     
    43044464    $last_changed = wp_cache_get_last_changed( 'posts' );
    43054465
    4306     $hash = md5( $page_path . serialize( $post_type ) );
     4466    $hash      = md5( $page_path . serialize( $post_type ) );
    43074467    $cache_key = "get_page_by_path:$hash:$last_changed";
    4308     $cached = wp_cache_get( $cache_key, 'posts' );
     4468    $cached    = wp_cache_get( $cache_key, 'posts' );
    43094469    if ( false !== $cached ) {
    43104470        // Special case: '0' is a bad `$page_path`.
     
    43164476    }
    43174477
    4318     $page_path = rawurlencode(urldecode($page_path));
    4319     $page_path = str_replace('%2F', '/', $page_path);
    4320     $page_path = str_replace('%20', ' ', $page_path);
    4321     $parts = explode( '/', trim( $page_path, '/' ) );
    4322     $parts = array_map( 'sanitize_title_for_query', $parts );
     4478    $page_path     = rawurlencode( urldecode( $page_path ) );
     4479    $page_path     = str_replace( '%2F', '/', $page_path );
     4480    $page_path     = str_replace( '%20', ' ', $page_path );
     4481    $parts         = explode( '/', trim( $page_path, '/' ) );
     4482    $parts         = array_map( 'sanitize_title_for_query', $parts );
    43234483    $escaped_parts = esc_sql( $parts );
    43244484
     
    43314491    }
    43324492
    4333     $post_types = esc_sql( $post_types );
     4493    $post_types          = esc_sql( $post_types );
    43344494    $post_type_in_string = "'" . implode( "','", $post_types ) . "'";
    4335     $sql = "
     4495    $sql                 = "
    43364496        SELECT ID, post_name, post_parent, post_type
    43374497        FROM $wpdb->posts
     
    43484508        if ( $page->post_name == $revparts[0] ) {
    43494509            $count = 0;
    4350             $p = $page;
     4510            $p     = $page;
    43514511
    43524512            /*
     
    43574517                $count++;
    43584518                $parent = $pages[ $p->post_parent ];
    4359                 if ( ! isset( $revparts[ $count ] ) || $parent->post_name != $revparts[ $count ] )
     4519                if ( ! isset( $revparts[ $count ] ) || $parent->post_name != $revparts[ $count ] ) {
    43604520                    break;
     4521                }
    43614522                $p = $parent;
    43624523            }
    43634524
    4364             if ( $p->post_parent == 0 && $count+1 == count( $revparts ) && $p->post_name == $revparts[ $count ] ) {
     4525            if ( $p->post_parent == 0 && $count + 1 == count( $revparts ) && $p->post_name == $revparts[ $count ] ) {
    43654526                $foundid = $page->ID;
    4366                 if ( $page->post_type == $post_type )
     4527                if ( $page->post_type == $post_type ) {
    43674528                    break;
     4529                }
    43684530            }
    43694531        }
     
    43954557
    43964558    if ( is_array( $post_type ) ) {
    4397         $post_type = esc_sql( $post_type );
     4559        $post_type           = esc_sql( $post_type );
    43984560        $post_type_in_string = "'" . implode( "','", $post_type ) . "'";
    4399         $sql = $wpdb->prepare( "
     4561        $sql                 = $wpdb->prepare(
     4562            "
    44004563            SELECT ID
    44014564            FROM $wpdb->posts
    44024565            WHERE post_title = %s
    44034566            AND post_type IN ($post_type_in_string)
    4404         ", $page_title );
     4567        ", $page_title
     4568        );
    44054569    } else {
    4406         $sql = $wpdb->prepare( "
     4570        $sql = $wpdb->prepare(
     4571            "
    44074572            SELECT ID
    44084573            FROM $wpdb->posts
    44094574            WHERE post_title = %s
    44104575            AND post_type = %s
    4411         ", $page_title, $post_type );
     4576        ", $page_title, $post_type
     4577        );
    44124578    }
    44134579
     
    44454611
    44464612        while ( $to_look ) {
    4447             $p = array_pop( $to_look );
     4613            $p           = array_pop( $to_look );
    44484614            $page_list[] = $p;
    44494615            if ( isset( $children[ $p->ID ] ) ) {
     
    44784644    $children = array();
    44794645    foreach ( (array) $pages as $p ) {
    4480         $parent_id = intval( $p->post_parent );
     4646        $parent_id                = intval( $p->post_parent );
    44814647        $children[ $parent_id ][] = $p;
    44824648    }
     
    45014667 * @param array $result    Result (passed by reference).
    45024668 */
    4503 function _page_traverse_name( $page_id, &$children, &$result ){
    4504     if ( isset( $children[ $page_id ] ) ){
    4505         foreach ( (array)$children[ $page_id ] as $child ) {
     4669function _page_traverse_name( $page_id, &$children, &$result ) {
     4670    if ( isset( $children[ $page_id ] ) ) {
     4671        foreach ( (array) $children[ $page_id ] as $child ) {
    45064672            $result[ $child->ID ] = $child->post_name;
    45074673            _page_traverse_name( $child->ID, $children, $result );
     
    45264692    }
    45274693
    4528     if ( ! $page )
     4694    if ( ! $page ) {
    45294695        return false;
     4696    }
    45304697
    45314698    $uri = $page->post_name;
     
    46144781    $r = wp_parse_args( $args, $defaults );
    46154782
    4616     $number = (int) $r['number'];
    4617     $offset = (int) $r['offset'];
    4618     $child_of = (int) $r['child_of'];
     4783    $number       = (int) $r['number'];
     4784    $offset       = (int) $r['offset'];
     4785    $child_of     = (int) $r['child_of'];
    46194786    $hierarchical = $r['hierarchical'];
    4620     $exclude = $r['exclude'];
    4621     $meta_key = $r['meta_key'];
    4622     $meta_value = $r['meta_value'];
    4623     $parent = $r['parent'];
    4624     $post_status = $r['post_status'];
     4787    $exclude      = $r['exclude'];
     4788    $meta_key     = $r['meta_key'];
     4789    $meta_value   = $r['meta_value'];
     4790    $parent       = $r['parent'];
     4791    $post_status  = $r['post_status'];
    46254792
    46264793    // Make sure the post type is hierarchical.
     
    46434810
    46444811    // $args can be whatever, only use the args defined in defaults to compute the key.
    4645     $key = md5( serialize( wp_array_slice_assoc( $r, array_keys( $defaults ) ) ) );
     4812    $key          = md5( serialize( wp_array_slice_assoc( $r, array_keys( $defaults ) ) ) );
    46464813    $last_changed = wp_cache_get_last_changed( 'posts' );
    46474814
     
    46574824    $inclusions = '';
    46584825    if ( ! empty( $r['include'] ) ) {
    4659         $child_of = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include
    4660         $parent = -1;
    4661         $exclude = '';
    4662         $meta_key = '';
    4663         $meta_value = '';
     4826        $child_of     = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include
     4827        $parent       = -1;
     4828        $exclude      = '';
     4829        $meta_key     = '';
     4830        $meta_value   = '';
    46644831        $hierarchical = false;
    4665         $incpages = wp_parse_id_list( $r['include'] );
     4832        $incpages     = wp_parse_id_list( $r['include'] );
    46664833        if ( ! empty( $incpages ) ) {
    4667             $inclusions = ' AND ID IN (' . implode( ',', $incpages ) .  ')';
     4834            $inclusions = ' AND ID IN (' . implode( ',', $incpages ) . ')';
    46684835        }
    46694836    }
     
    46734840        $expages = wp_parse_id_list( $exclude );
    46744841        if ( ! empty( $expages ) ) {
    4675             $exclusions = ' AND ID NOT IN (' . implode( ',', $expages ) .  ')';
     4842            $exclusions = ' AND ID NOT IN (' . implode( ',', $expages ) . ')';
    46764843        }
    46774844    }
     
    46844851            foreach ( $post_authors as $post_author ) {
    46854852                //Do we have an author id or an author login?
    4686                 if ( 0 == intval($post_author) ) {
    4687                     $post_author = get_user_by('login', $post_author);
     4853                if ( 0 == intval( $post_author ) ) {
     4854                    $post_author = get_user_by( 'login', $post_author );
    46884855                    if ( empty( $post_author ) ) {
    46894856                        continue;
     
    46964863
    46974864                if ( '' == $author_query ) {
    4698                     $author_query = $wpdb->prepare(' post_author = %d ', $post_author);
     4865                    $author_query = $wpdb->prepare( ' post_author = %d ', $post_author );
    46994866                } else {
    4700                     $author_query .= $wpdb->prepare(' OR post_author = %d ', $post_author);
     4867                    $author_query .= $wpdb->prepare( ' OR post_author = %d ', $post_author );
    47014868                }
    47024869            }
     
    47074874    }
    47084875
    4709     $join = '';
     4876    $join  = '';
    47104877    $where = "$exclusions $inclusions ";
    47114878    if ( '' !== $meta_key || '' !== $meta_value ) {
     
    47134880
    47144881        // meta_key and meta_value might be slashed
    4715         $meta_key = wp_unslash($meta_key);
    4716         $meta_value = wp_unslash($meta_value);
     4882        $meta_key   = wp_unslash( $meta_key );
     4883        $meta_value = wp_unslash( $meta_value );
    47174884        if ( '' !== $meta_key ) {
    4718             $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_key = %s", $meta_key);
     4885            $where .= $wpdb->prepare( " AND $wpdb->postmeta.meta_key = %s", $meta_key );
    47194886        }
    47204887        if ( '' !== $meta_value ) {
    4721             $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_value = %s", $meta_value);
    4722         }
    4723 
     4888            $where .= $wpdb->prepare( " AND $wpdb->postmeta.meta_value = %s", $meta_value );
     4889        }
    47244890    }
    47254891
     
    47304896        }
    47314897    } elseif ( $parent >= 0 ) {
    4732         $where .= $wpdb->prepare(' AND post_parent = %d ', $parent);
     4898        $where .= $wpdb->prepare( ' AND post_parent = %d ', $parent );
    47334899    }
    47344900
    47354901    if ( 1 == count( $post_status ) ) {
    4736         $where_post_type = $wpdb->prepare( "post_type = %s AND post_status = %s", $r['post_type'], reset( $post_status ) );
     4902        $where_post_type = $wpdb->prepare( 'post_type = %s AND post_status = %s', $r['post_type'], reset( $post_status ) );
    47374903    } else {
    4738         $post_status = implode( "', '", $post_status );
     4904        $post_status     = implode( "', '", $post_status );
    47394905        $where_post_type = $wpdb->prepare( "post_type = %s AND post_status IN ('$post_status')", $r['post_type'] );
    47404906    }
    47414907
    47424908    $orderby_array = array();
    4743     $allowed_keys = array( 'author', 'post_author', 'date', 'post_date', 'title', 'post_title', 'name', 'post_name', 'modified',
    4744         'post_modified', 'modified_gmt', 'post_modified_gmt', 'menu_order', 'parent', 'post_parent',
    4745         'ID', 'rand', 'comment_count' );
     4909    $allowed_keys  = array(
     4910        'author',
     4911        'post_author',
     4912        'date',
     4913        'post_date',
     4914        'title',
     4915        'post_title',
     4916        'name',
     4917        'post_name',
     4918        'modified',
     4919        'post_modified',
     4920        'modified_gmt',
     4921        'post_modified_gmt',
     4922        'menu_order',
     4923        'parent',
     4924        'post_parent',
     4925        'ID',
     4926        'rand',
     4927        'comment_count',
     4928    );
    47464929
    47474930    foreach ( explode( ',', $r['sort_column'] ) as $orderby ) {
     
    47814964    }
    47824965
    4783     $query = "SELECT * FROM $wpdb->posts $join WHERE ($where_post_type) $where ";
     4966    $query  = "SELECT * FROM $wpdb->posts $join WHERE ($where_post_type) $where ";
    47844967    $query .= $author_query;
    4785     $query .= " ORDER BY " . $sort_column . " " . $sort_order ;
     4968    $query .= ' ORDER BY ' . $sort_column . ' ' . $sort_order;
    47864969
    47874970    if ( ! empty( $number ) ) {
     
    47894972    }
    47904973
    4791     $pages = $wpdb->get_results($query);
    4792 
    4793     if ( empty($pages) ) {
     4974    $pages = $wpdb->get_results( $query );
     4975
     4976    if ( empty( $pages ) ) {
    47944977        /** This filter is documented in wp-includes/post.php */
    47954978        $pages = apply_filters( 'get_pages', array(), $r );
     
    47984981
    47994982    // Sanitize before caching so it'll only get done once.
    4800     $num_pages = count($pages);
    4801     for ($i = 0; $i < $num_pages; $i++) {
    4802         $pages[$i] = sanitize_post($pages[$i], 'raw');
     4983    $num_pages = count( $pages );
     4984    for ( $i = 0; $i < $num_pages; $i++ ) {
     4985        $pages[ $i ] = sanitize_post( $pages[ $i ], 'raw' );
    48034986    }
    48044987
     
    48074990
    48084991    if ( $child_of || $hierarchical ) {
    4809         $pages = get_page_children($child_of, $pages);
     4992        $pages = get_page_children( $child_of, $pages );
    48104993    }
    48114994
     
    48215004        $num_pages = count( $pages );
    48225005        for ( $i = 0; $i < $num_pages; $i++ ) {
    4823             if ( in_array( $pages[$i]->ID, $exclude ) ) {
    4824                 unset( $pages[$i] );
     5006            if ( in_array( $pages[ $i ]->ID, $exclude ) ) {
     5007                unset( $pages[ $i ] );
    48255008            }
    48265009        }
     
    48605043 * @return bool True on success, false on failure.
    48615044 */
    4862 function is_local_attachment($url) {
    4863     if (strpos($url, home_url()) === false)
     5045function is_local_attachment( $url ) {
     5046    if ( strpos( $url, home_url() ) === false ) {
    48645047        return false;
    4865     if (strpos($url, home_url('/?attachment_id=')) !== false)
     5048    }
     5049    if ( strpos( $url, home_url( '/?attachment_id=' ) ) !== false ) {
    48665050        return true;
    4867     if ( $id = url_to_postid($url) ) {
    4868         $post = get_post($id);
    4869         if ( 'attachment' == $post->post_type )
     5051    }
     5052    if ( $id = url_to_postid( $url ) ) {
     5053        $post = get_post( $id );
     5054        if ( 'attachment' == $post->post_type ) {
    48705055            return true;
     5056        }
    48715057    }
    48725058    return false;
     
    49015087    $defaults = array(
    49025088        'file'        => $file,
    4903         'post_parent' => 0
     5089        'post_parent' => 0,
    49045090    );
    49055091
     
    49535139    }
    49545140
    4955     delete_post_meta($post_id, '_wp_trash_meta_status');
    4956     delete_post_meta($post_id, '_wp_trash_meta_time');
    4957 
    4958     $meta = wp_get_attachment_metadata( $post_id );
     5141    delete_post_meta( $post_id, '_wp_trash_meta_status' );
     5142    delete_post_meta( $post_id, '_wp_trash_meta_time' );
     5143
     5144    $meta         = wp_get_attachment_metadata( $post_id );
    49595145    $backup_sizes = get_post_meta( $post->ID, '_wp_attachment_backup_sizes', true );
    4960     $file = get_attached_file( $post_id );
    4961 
    4962     if ( is_multisite() )
     5146    $file         = get_attached_file( $post_id );
     5147
     5148    if ( is_multisite() ) {
    49635149        delete_transient( 'dirsize_cache' );
     5150    }
    49645151
    49655152    /**
     
    49725159    do_action( 'delete_attachment', $post_id );
    49735160
    4974     wp_delete_object_term_relationships($post_id, array('category', 'post_tag'));
    4975     wp_delete_object_term_relationships($post_id, get_object_taxonomies($post->post_type));
     5161    wp_delete_object_term_relationships( $post_id, array( 'category', 'post_tag' ) );
     5162    wp_delete_object_term_relationships( $post_id, get_object_taxonomies( $post->post_type ) );
    49765163
    49775164    // Delete all for any posts.
     
    49805167    wp_defer_comment_counting( true );
    49815168
    4982     $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ));
     5169    $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ) );
    49835170    foreach ( $comment_ids as $comment_id ) {
    49845171        wp_delete_comment( $comment_id, true );
     
    49875174    wp_defer_comment_counting( false );
    49885175
    4989     $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id ));
    4990     foreach ( $post_meta_ids as $mid )
     5176    $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id ) );
     5177    foreach ( $post_meta_ids as $mid ) {
    49915178        delete_metadata_by_mid( 'post', $mid );
     5179    }
    49925180
    49935181    /** This action is documented in wp-includes/post.php */
     
    50025190    $uploadpath = wp_get_upload_dir();
    50035191
    5004     if ( ! empty($meta['thumb']) ) {
     5192    if ( ! empty( $meta['thumb'] ) ) {
    50055193        // Don't delete the thumb if another attachment uses it.
    5006         if (! $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s AND post_id <> %d", '%' . $wpdb->esc_like( $meta['thumb'] ) . '%', $post_id)) ) {
    5007             $thumbfile = str_replace(basename($file), $meta['thumb'], $file);
     5194        if ( ! $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s AND post_id <> %d", '%' . $wpdb->esc_like( $meta['thumb'] ) . '%', $post_id ) ) ) {
     5195            $thumbfile = str_replace( basename( $file ), $meta['thumb'], $file );
    50085196            /** This filter is documented in wp-includes/functions.php */
    50095197            $thumbfile = apply_filters( 'wp_delete_file', $thumbfile );
    5010             @ unlink( path_join($uploadpath['basedir'], $thumbfile) );
     5198            @ unlink( path_join( $uploadpath['basedir'], $thumbfile ) );
    50115199        }
    50125200    }
     
    50225210    }
    50235211
    5024     if ( is_array($backup_sizes) ) {
     5212    if ( is_array( $backup_sizes ) ) {
    50255213        foreach ( $backup_sizes as $size ) {
    5026             $del_file = path_join( dirname($meta['file']), $size['file'] );
     5214            $del_file = path_join( dirname( $meta['file'] ), $size['file'] );
    50275215            /** This filter is documented in wp-includes/functions.php */
    50285216            $del_file = apply_filters( 'wp_delete_file', $del_file );
    5029             @ unlink( path_join($uploadpath['basedir'], $del_file) );
     5217            @ unlink( path_join( $uploadpath['basedir'], $del_file ) );
    50305218        }
    50315219    }
     
    50555243    $data = get_post_meta( $post->ID, '_wp_attachment_metadata', true );
    50565244
    5057     if ( $unfiltered )
     5245    if ( $unfiltered ) {
    50585246        return $data;
     5247    }
    50595248
    50605249    /**
     
    50935282     * @param int   $attachment_id Attachment post ID.
    50945283     */
    5095     if ( $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ) )
     5284    if ( $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ) ) {
    50965285        return update_post_meta( $post->ID, '_wp_attachment_metadata', $data );
    5097     else
     5286    } else {
    50985287        return delete_post_meta( $post->ID, '_wp_attachment_metadata' );
     5288    }
    50995289}
    51005290
     
    51155305    }
    51165306
    5117     if ( 'attachment' != $post->post_type )
     5307    if ( 'attachment' != $post->post_type ) {
    51185308        return false;
     5309    }
    51195310
    51205311    $url = '';
     
    51265317            if ( 0 === strpos( $file, $uploads['basedir'] ) ) {
    51275318                // Replace file location with url location.
    5128                 $url = str_replace($uploads['basedir'], $uploads['baseurl'], $file);
    5129             } elseif ( false !== strpos($file, 'wp-content/uploads') ) {
     5319                $url = str_replace( $uploads['basedir'], $uploads['baseurl'], $file );
     5320            } elseif ( false !== strpos( $file, 'wp-content/uploads' ) ) {
    51305321                // Get the directory name relative to the basedir (back compat for pre-2.7 uploads)
    51315322                $url = trailingslashit( $uploads['baseurl'] . '/' . _wp_get_attachment_relative_path( $file ) ) . basename( $file );
     
    51415332     * not recommended to rely upon this.
    51425333     */
    5143     if ( empty($url) ) {
     5334    if ( empty( $url ) ) {
    51445335        $url = get_the_guid( $post->ID );
    51455336    }
     
    51605351    $url = apply_filters( 'wp_get_attachment_url', $url, $post->ID );
    51615352
    5162     if ( empty( $url ) )
     5353    if ( empty( $url ) ) {
    51635354        return false;
     5355    }
    51645356
    51655357    return $url;
     
    52075399function wp_get_attachment_thumb_file( $post_id = 0 ) {
    52085400    $post_id = (int) $post_id;
    5209     if ( !$post = get_post( $post_id ) )
     5401    if ( ! $post = get_post( $post_id ) ) {
    52105402        return false;
    5211     if ( !is_array( $imagedata = wp_get_attachment_metadata( $post->ID ) ) )
     5403    }
     5404    if ( ! is_array( $imagedata = wp_get_attachment_metadata( $post->ID ) ) ) {
    52125405        return false;
     5406    }
    52135407
    52145408    $file = get_attached_file( $post->ID );
    52155409
    5216     if ( !empty($imagedata['thumb']) && ($thumbfile = str_replace(basename($file), $imagedata['thumb'], $file)) && file_exists($thumbfile) ) {
     5410    if ( ! empty( $imagedata['thumb'] ) && ( $thumbfile = str_replace( basename( $file ), $imagedata['thumb'], $file ) ) && file_exists( $thumbfile ) ) {
    52175411        /**
    52185412         * Filters the attachment thumbnail file path.
     
    52385432function wp_get_attachment_thumb_url( $post_id = 0 ) {
    52395433    $post_id = (int) $post_id;
    5240     if ( !$post = get_post( $post_id ) )
     5434    if ( ! $post = get_post( $post_id ) ) {
    52415435        return false;
    5242     if ( !$url = wp_get_attachment_url( $post->ID ) )
     5436    }
     5437    if ( ! $url = wp_get_attachment_url( $post->ID ) ) {
    52435438        return false;
     5439    }
    52445440
    52455441    $sized = image_downsize( $post_id, 'thumbnail' );
    5246     if ( $sized )
     5442    if ( $sized ) {
    52475443        return $sized[0];
    5248 
    5249     if ( !$thumb = wp_get_attachment_thumb_file( $post->ID ) )
     5444    }
     5445
     5446    if ( ! $thumb = wp_get_attachment_thumb_file( $post->ID ) ) {
    52505447        return false;
    5251 
    5252     $url = str_replace(basename($url), basename($thumb), $url);
     5448    }
     5449
     5450    $url = str_replace( basename( $url ), basename( $thumb ), $url );
    52535451
    52545452    /**
     
    52975495
    52985496    switch ( $type ) {
    5299     case 'image':
    5300         $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' );
    5301         return in_array( $ext, $image_exts );
    5302 
    5303     case 'audio':
    5304         return in_array( $ext, wp_get_audio_extensions() );
    5305 
    5306     case 'video':
    5307         return in_array( $ext, wp_get_video_extensions() );
    5308 
    5309     default:
    5310         return $type === $ext;
     5497        case 'image':
     5498            $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' );
     5499            return in_array( $ext, $image_exts );
     5500
     5501        case 'audio':
     5502            return in_array( $ext, wp_get_audio_extensions() );
     5503
     5504        case 'video':
     5505            return in_array( $ext, wp_get_video_extensions() );
     5506
     5507        default:
     5508            return $type === $ext;
    53115509    }
    53125510}
     
    53355533 */
    53365534function wp_mime_type_icon( $mime = 0 ) {
    5337     if ( !is_numeric($mime) )
    5338         $icon = wp_cache_get("mime_type_icon_$mime");
     5535    if ( ! is_numeric( $mime ) ) {
     5536        $icon = wp_cache_get( "mime_type_icon_$mime" );
     5537    }
    53395538
    53405539    $post_id = 0;
    5341     if ( empty($icon) ) {
     5540    if ( empty( $icon ) ) {
    53425541        $post_mimes = array();
    5343         if ( is_numeric($mime) ) {
     5542        if ( is_numeric( $mime ) ) {
    53445543            $mime = (int) $mime;
    53455544            if ( $post = get_post( $mime ) ) {
    53465545                $post_id = (int) $post->ID;
    5347                 $file = get_attached_file( $post_id );
    5348                 $ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $file);
    5349                 if ( !empty($ext) ) {
     5546                $file    = get_attached_file( $post_id );
     5547                $ext     = preg_replace( '/^.+?\.([^.]+)$/', '$1', $file );
     5548                if ( ! empty( $ext ) ) {
    53505549                    $post_mimes[] = $ext;
    5351                     if ( $ext_type = wp_ext2type( $ext ) )
     5550                    if ( $ext_type = wp_ext2type( $ext ) ) {
    53525551                        $post_mimes[] = $ext_type;
     5552                    }
    53535553                }
    53545554                $mime = $post->post_mime_type;
     
    53605560        }
    53615561
    5362         $icon_files = wp_cache_get('icon_files');
    5363 
    5364         if ( !is_array($icon_files) ) {
     5562        $icon_files = wp_cache_get( 'icon_files' );
     5563
     5564        if ( ! is_array( $icon_files ) ) {
    53655565            /**
    53665566             * Filters the icon directory path.
     
    53885588             * @param array $uris List of icon directory URIs.
    53895589             */
    5390             $dirs = apply_filters( 'icon_dirs', array( $icon_dir => $icon_dir_uri ) );
     5590            $dirs       = apply_filters( 'icon_dirs', array( $icon_dir => $icon_dir_uri ) );
    53915591            $icon_files = array();
    53925592            while ( $dirs ) {
    53935593                $keys = array_keys( $dirs );
    5394                 $dir = array_shift( $keys );
    5395                 $uri = array_shift($dirs);
    5396                 if ( $dh = opendir($dir) ) {
    5397                     while ( false !== $file = readdir($dh) ) {
    5398                         $file = basename($file);
    5399                         if ( substr($file, 0, 1) == '.' )
    5400                             continue;
    5401                         if ( !in_array(strtolower(substr($file, -4)), array('.png', '.gif', '.jpg') ) ) {
    5402                             if ( is_dir("$dir/$file") )
    5403                                 $dirs["$dir/$file"] = "$uri/$file";
     5594                $dir  = array_shift( $keys );
     5595                $uri  = array_shift( $dirs );
     5596                if ( $dh = opendir( $dir ) ) {
     5597                    while ( false !== $file = readdir( $dh ) ) {
     5598                        $file = basename( $file );
     5599                        if ( substr( $file, 0, 1 ) == '.' ) {
    54045600                            continue;
    54055601                        }
    5406                         $icon_files["$dir/$file"] = "$uri/$file";
     5602                        if ( ! in_array( strtolower( substr( $file, -4 ) ), array( '.png', '.gif', '.jpg' ) ) ) {
     5603                            if ( is_dir( "$dir/$file" ) ) {
     5604                                $dirs[ "$dir/$file" ] = "$uri/$file";
     5605                            }
     5606                            continue;
     5607                        }
     5608                        $icon_files[ "$dir/$file" ] = "$uri/$file";
    54075609                    }
    5408                     closedir($dh);
     5610                    closedir( $dh );
    54095611                }
    54105612            }
     
    54145616        $types = array();
    54155617        // Icon basename - extension = MIME wildcard.
    5416         foreach ( $icon_files as $file => $uri )
    5417             $types[ preg_replace('/^([^.]*).*$/', '$1', basename($file)) ] =& $icon_files[$file];
    5418 
    5419         if ( ! empty($mime) ) {
    5420             $post_mimes[] = substr($mime, 0, strpos($mime, '/'));
    5421             $post_mimes[] = substr($mime, strpos($mime, '/') + 1);
    5422             $post_mimes[] = str_replace('/', '_', $mime);
    5423         }
    5424 
    5425         $matches = wp_match_mime_types(array_keys($types), $post_mimes);
    5426         $matches['default'] = array('default');
     5618        foreach ( $icon_files as $file => $uri ) {
     5619            $types[ preg_replace( '/^([^.]*).*$/', '$1', basename( $file ) ) ] =& $icon_files[ $file ];
     5620        }
     5621
     5622        if ( ! empty( $mime ) ) {
     5623            $post_mimes[] = substr( $mime, 0, strpos( $mime, '/' ) );
     5624            $post_mimes[] = substr( $mime, strpos( $mime, '/' ) + 1 );
     5625            $post_mimes[] = str_replace( '/', '_', $mime );
     5626        }
     5627
     5628        $matches            = wp_match_mime_types( array_keys( $types ), $post_mimes );
     5629        $matches['default'] = array( 'default' );
    54275630
    54285631        foreach ( $matches as $match => $wilds ) {
     
    55855788    }
    55865789
    5587     $sql = '( '. implode( ' OR ', $post_type_clauses ) . ' )';
     5790    $sql = '( ' . implode( ' OR ', $post_type_clauses ) . ' )';
    55885791
    55895792    if ( null !== $post_author ) {
     
    56645867    $lastpostmodified = _get_last_post_time( $timezone, 'modified', $post_type );
    56655868
    5666     $lastpostdate = get_lastpostdate($timezone);
     5869    $lastpostdate = get_lastpostdate( $timezone );
    56675870    if ( $lastpostdate > $lastpostmodified ) {
    56685871        $lastpostmodified = $lastpostdate;
     
    57255928    switch ( $timezone ) {
    57265929        case 'gmt':
    5727             $date = $wpdb->get_var("SELECT post_{$field}_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1");
     5930            $date = $wpdb->get_var( "SELECT post_{$field}_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1" );
    57285931            break;
    57295932        case 'blog':
    5730             $date = $wpdb->get_var("SELECT post_{$field} FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1");
     5933            $date = $wpdb->get_var( "SELECT post_{$field} FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1" );
    57315934            break;
    57325935        case 'server':
    57335936            $add_seconds_server = date( 'Z' );
    5734             $date = $wpdb->get_var("SELECT DATE_ADD(post_{$field}_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1");
     5937            $date               = $wpdb->get_var( "SELECT DATE_ADD(post_{$field}_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1" );
    57355938            break;
    57365939    }
     
    57535956 */
    57545957function update_post_cache( &$posts ) {
    5755     if ( ! $posts )
     5958    if ( ! $posts ) {
    57565959        return;
    5757 
    5758     foreach ( $posts as $post )
     5960    }
     5961
     5962    foreach ( $posts as $post ) {
    57595963        wp_cache_add( $post->ID, $post, 'posts' );
     5964    }
    57605965}
    57615966
     
    57785983    global $_wp_suspend_cache_invalidation;
    57795984
    5780     if ( ! empty( $_wp_suspend_cache_invalidation ) )
     5985    if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
    57815986        return;
     5987    }
    57825988
    57835989    $post = get_post( $post );
    5784     if ( empty( $post ) )
     5990    if ( empty( $post ) ) {
    57855991        return;
     5992    }
    57865993
    57875994    wp_cache_delete( $post->ID, 'posts' );
     
    58306037function update_post_caches( &$posts, $post_type = 'post', $update_term_cache = true, $update_meta_cache = true ) {
    58316038    // No point in doing all this work if we didn't match any posts.
    5832     if ( !$posts )
     6039    if ( ! $posts ) {
    58336040        return;
    5834 
    5835     update_post_cache($posts);
     6041    }
     6042
     6043    update_post_cache( $posts );
    58366044
    58376045    $post_ids = array();
    5838     foreach ( $posts as $post )
     6046    foreach ( $posts as $post ) {
    58396047        $post_ids[] = $post->ID;
    5840 
    5841     if ( ! $post_type )
     6048    }
     6049
     6050    if ( ! $post_type ) {
    58426051        $post_type = 'any';
     6052    }
    58436053
    58446054    if ( $update_term_cache ) {
    5845         if ( is_array($post_type) ) {
     6055        if ( is_array( $post_type ) ) {
    58466056            $ptypes = $post_type;
    58476057        } elseif ( 'any' == $post_type ) {
     
    58516061                $ptypes[] = $post->post_type;
    58526062            }
    5853             $ptypes = array_unique($ptypes);
     6063            $ptypes = array_unique( $ptypes );
    58546064        } else {
    5855             $ptypes = array($post_type);
    5856         }
    5857 
    5858         if ( ! empty($ptypes) )
    5859             update_object_term_cache($post_ids, $ptypes);
    5860     }
    5861 
    5862     if ( $update_meta_cache )
    5863         update_postmeta_cache($post_ids);
     6065            $ptypes = array( $post_type );
     6066        }
     6067
     6068        if ( ! empty( $ptypes ) ) {
     6069            update_object_term_cache( $post_ids, $ptypes );
     6070        }
     6071    }
     6072
     6073    if ( $update_meta_cache ) {
     6074        update_postmeta_cache( $post_ids );
     6075    }
    58646076}
    58656077
     
    58786090 */
    58796091function update_postmeta_cache( $post_ids ) {
    5880     return update_meta_cache('post', $post_ids);
     6092    return update_meta_cache( 'post', $post_ids );
    58816093}
    58826094
     
    58996111    global $_wp_suspend_cache_invalidation;
    59006112
    5901     if ( !empty($_wp_suspend_cache_invalidation) )
     6113    if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
    59026114        return;
     6115    }
    59036116
    59046117    $id = (int) $id;
    59056118
    5906     wp_cache_delete($id, 'posts');
    5907     wp_cache_delete($id, 'post_meta');
    5908 
    5909     if ( $clean_terms )
    5910         clean_object_term_cache($id, 'attachment');
     6119    wp_cache_delete( $id, 'posts' );
     6120    wp_cache_delete( $id, 'post_meta' );
     6121
     6122    if ( $clean_terms ) {
     6123        clean_object_term_cache( $id, 'attachment' );
     6124    }
    59116125
    59126126    /**
     
    59426156    if ( $old_status != 'publish' && $new_status == 'publish' ) {
    59436157        // Reset GUID if transitioning to publish and it is empty.
    5944         if ( '' == get_the_guid($post->ID) )
     6158        if ( '' == get_the_guid( $post->ID ) ) {
    59456159            $wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post->ID ) ), array( 'ID' => $post->ID ) );
     6160        }
    59466161
    59476162        /**
     
    59536168         * @param int $post_id Post ID.
    59546169         */
    5955         do_action('private_to_published', $post->ID);
     6170        do_action( 'private_to_published', $post->ID );
    59566171    }
    59576172
    59586173    // If published posts changed clear the lastpostmodified cache.
    5959     if ( 'publish' == $new_status || 'publish' == $old_status) {
     6174    if ( 'publish' == $new_status || 'publish' == $old_status ) {
    59606175        foreach ( array( 'server', 'gmt', 'blog' ) as $timezone ) {
    59616176            wp_cache_delete( "lastpostmodified:$timezone", 'timeinfo' );
     
    59716186
    59726187    // Always clears the hook in case the post status bounced from future to draft.
    5973     wp_clear_scheduled_hook('publish_future_post', array( $post->ID ) );
     6188    wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) );
    59746189}
    59756190
     
    59896204function _future_post_hook( $deprecated, $post ) {
    59906205    wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) );
    5991     wp_schedule_single_event( strtotime( get_gmt_from_date( $post->post_date ) . ' GMT') , 'publish_future_post', array( $post->ID ) );
     6206    wp_schedule_single_event( strtotime( get_gmt_from_date( $post->post_date ) . ' GMT' ), 'publish_future_post', array( $post->ID ) );
    59926207}
    59936208
     
    60146229    }
    60156230
    6016     if ( defined('WP_IMPORTING') )
     6231    if ( defined( 'WP_IMPORTING' ) ) {
    60176232        return;
    6018 
    6019     if ( get_option('default_pingback_flag') )
     6233    }
     6234
     6235    if ( get_option( 'default_pingback_flag' ) ) {
    60206236        add_post_meta( $post_id, '_pingme', '1' );
     6237    }
    60216238    add_post_meta( $post_id, '_encloseme', '1' );
    60226239
     
    60376254function wp_get_post_parent_id( $post_ID ) {
    60386255    $post = get_post( $post_ID );
    6039     if ( !$post || is_wp_error( $post ) )
     6256    if ( ! $post || is_wp_error( $post ) ) {
    60406257        return false;
     6258    }
    60416259    return (int) $post->post_parent;
    60426260}
     
    60586276function wp_check_post_hierarchy_for_loops( $post_parent, $post_ID ) {
    60596277    // Nothing fancy here - bail.
    6060     if ( !$post_parent )
     6278    if ( ! $post_parent ) {
    60616279        return 0;
     6280    }
    60626281
    60636282    // New post can't cause a loop.
    6064     if ( empty( $post_ID ) )
     6283    if ( empty( $post_ID ) ) {
    60656284        return $post_parent;
     6285    }
    60666286
    60676287    // Can't be its own parent.
    6068     if ( $post_parent == $post_ID )
     6288    if ( $post_parent == $post_ID ) {
    60696289        return 0;
     6290    }
    60706291
    60716292    // Now look for larger loops.
    6072     if ( !$loop = wp_find_hierarchy_loop( 'wp_get_post_parent_id', $post_ID, $post_parent ) )
     6293    if ( ! $loop = wp_find_hierarchy_loop( 'wp_get_post_parent_id', $post_ID, $post_parent ) ) {
    60736294        return $post_parent; // No loop
     6295    }
    60746296
    60756297    // Setting $post_parent to the given value causes a loop.
    6076     if ( isset( $loop[$post_ID] ) )
     6298    if ( isset( $loop[ $post_ID ] ) ) {
    60776299        return 0;
     6300    }
    60786301
    60796302    // There's a loop, but it doesn't contain $post_ID. Break the loop.
    6080     foreach ( array_keys( $loop ) as $loop_member )
    6081         wp_update_post( array( 'ID' => $loop_member, 'post_parent' => 0 ) );
     6303    foreach ( array_keys( $loop ) as $loop_member ) {
     6304        wp_update_post(
     6305            array(
     6306                'ID'          => $loop_member,
     6307                'post_parent' => 0,
     6308            )
     6309        );
     6310    }
    60826311
    60836312    return $post_parent;
     
    60946323 */
    60956324function set_post_thumbnail( $post, $thumbnail_id ) {
    6096     $post = get_post( $post );
     6325    $post         = get_post( $post );
    60976326    $thumbnail_id = absint( $thumbnail_id );
    60986327    if ( $post && $thumbnail_id && get_post( $thumbnail_id ) ) {
    6099         if ( wp_get_attachment_image( $thumbnail_id, 'thumbnail' ) )
     6328        if ( wp_get_attachment_image( $thumbnail_id, 'thumbnail' ) ) {
    61006329            return update_post_meta( $post->ID, '_thumbnail_id', $thumbnail_id );
    6101         else
     6330        } else {
    61026331            return delete_post_meta( $post->ID, '_thumbnail_id' );
     6332        }
    61036333    }
    61046334    return false;
     
    61156345function delete_post_thumbnail( $post ) {
    61166346    $post = get_post( $post );
    6117     if ( $post )
     6347    if ( $post ) {
    61186348        return delete_post_meta( $post->ID, '_thumbnail_id' );
     6349    }
    61196350    return false;
    61206351}
     
    62146445
    62156446    $non_cached_ids = _get_non_cached_ids( $ids, 'posts' );
    6216     if ( !empty( $non_cached_ids ) ) {
    6217         $fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE ID IN (%s)", join( ",", $non_cached_ids ) ) );
     6447    if ( ! empty( $non_cached_ids ) ) {
     6448        $fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE ID IN (%s)", join( ',', $non_cached_ids ) ) );
    62186449
    62196450        update_post_caches( $fresh_posts, 'any', $update_term_cache, $update_meta_cache );
     
    62366467 */
    62376468function wp_add_trashed_suffix_to_post_name_for_trashed_posts( $post_name, $post_ID = 0 ) {
    6238     $trashed_posts_with_desired_slug = get_posts( array(
    6239         'name' => $post_name,
    6240         'post_status' => 'trash',
    6241         'post_type' => 'any',
    6242         'nopaging' => true,
    6243         'post__not_in' => array( $post_ID )
    6244     ) );
     6469    $trashed_posts_with_desired_slug = get_posts(
     6470        array(
     6471            'name'         => $post_name,
     6472            'post_status'  => 'trash',
     6473            'post_type'    => 'any',
     6474            'nopaging'     => true,
     6475            'post__not_in' => array( $post_ID ),
     6476        )
     6477    );
    62456478
    62466479    if ( ! empty( $trashed_posts_with_desired_slug ) ) {
     
    63036536    $clauses['where'] = preg_replace(
    63046537        "/\({$wpdb->posts}.post_content (NOT LIKE|LIKE) (\'[^']+\')\)/",
    6305         "$0 OR ( sq1.meta_value $1 $2 )",
    6306         $clauses['where'] );
     6538        '$0 OR ( sq1.meta_value $1 $2 )',
     6539        $clauses['where']
     6540    );
    63076541
    63086542    return $clauses;
Note: See TracChangeset for help on using the changeset viewer.