~canonical-sysadmins/wordpress/4.8.1

« back to all changes in this revision

Viewing changes to wp-admin/includes/post.php

  • Committer: Barry Price
  • Date: 2016-08-17 04:50:12 UTC
  • mfrom: (1.1.18 upstream)
  • Revision ID: barry.price@canonical.com-20160817045012-qfui81zhqnqv2ba9
Merge WP4.6 from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
        if ( $update && ! current_user_can( 'edit_post', $post_data['ID'] ) ) {
32
32
                if ( 'page' == $post_data['post_type'] )
33
 
                        return new WP_Error( 'edit_others_pages', __( 'You are not allowed to edit pages as this user.' ) );
 
33
                        return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to edit pages as this user.' ) );
34
34
                else
35
 
                        return new WP_Error( 'edit_others_posts', __( 'You are not allowed to edit posts as this user.' ) );
 
35
                        return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to edit posts as this user.' ) );
36
36
        } elseif ( ! $update && ! current_user_can( $ptype->cap->create_posts ) ) {
37
37
                if ( 'page' == $post_data['post_type'] )
38
 
                        return new WP_Error( 'edit_others_pages', __( 'You are not allowed to create pages as this user.' ) );
 
38
                        return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to create pages as this user.' ) );
39
39
                else
40
 
                        return new WP_Error( 'edit_others_posts', __( 'You are not allowed to create posts as this user.' ) );
 
40
                        return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to create posts as this user.' ) );
41
41
        }
42
42
 
43
43
        if ( isset( $post_data['content'] ) )
68
68
                 && ! current_user_can( $ptype->cap->edit_others_posts ) ) {
69
69
                if ( $update ) {
70
70
                        if ( 'page' == $post_data['post_type'] )
71
 
                                return new WP_Error( 'edit_others_pages', __( 'You are not allowed to edit pages as this user.' ) );
 
71
                                return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to edit pages as this user.' ) );
72
72
                        else
73
 
                                return new WP_Error( 'edit_others_posts', __( 'You are not allowed to edit posts as this user.' ) );
 
73
                                return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to edit posts as this user.' ) );
74
74
                } else {
75
75
                        if ( 'page' == $post_data['post_type'] )
76
 
                                return new WP_Error( 'edit_others_pages', __( 'You are not allowed to create pages as this user.' ) );
 
76
                                return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to create pages as this user.' ) );
77
77
                        else
78
 
                                return new WP_Error( 'edit_others_posts', __( 'You are not allowed to create posts as this user.' ) );
 
78
                                return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to create posts as this user.' ) );
79
79
                }
80
80
        }
81
81
 
210
210
        $ptype = get_post_type_object($post_data['post_type']);
211
211
        if ( !current_user_can( 'edit_post', $post_ID ) ) {
212
212
                if ( 'page' == $post_data['post_type'] )
213
 
                        wp_die( __('You are not allowed to edit this page.' ));
 
213
                        wp_die( __('Sorry, you are not allowed to edit this page.' ));
214
214
                else
215
 
                        wp_die( __('You are not allowed to edit this post.' ));
 
215
                        wp_die( __('Sorry, you are not allowed to edit this post.' ));
216
216
        }
217
217
 
218
218
        if ( post_type_supports( $ptype->name, 'revisions' ) ) {
428
428
 
429
429
        if ( !current_user_can( $ptype->cap->edit_posts ) ) {
430
430
                if ( 'page' == $ptype->name )
431
 
                        wp_die( __('You are not allowed to edit pages.'));
 
431
                        wp_die( __('Sorry, you are not allowed to edit pages.'));
432
432
                else
433
 
                        wp_die( __('You are not allowed to edit posts.'));
 
433
                        wp_die( __('Sorry, you are not allowed to edit posts.'));
434
434
        }
435
435
 
436
436
        if ( -1 == $post_data['_status'] ) {
629
629
        }
630
630
 
631
631
        /**
632
 
         * Filter the default post content initially used in the "Write Post" form.
 
632
         * Filters the default post content initially used in the "Write Post" form.
633
633
         *
634
634
         * @since 1.5.0
635
635
         *
639
639
        $post->post_content = apply_filters( 'default_content', $post_content, $post );
640
640
 
641
641
        /**
642
 
         * Filter the default post title initially used in the "Write Post" form.
 
642
         * Filters the default post title initially used in the "Write Post" form.
643
643
         *
644
644
         * @since 1.5.0
645
645
         *
649
649
        $post->post_title = apply_filters( 'default_title', $post_title, $post );
650
650
 
651
651
        /**
652
 
         * Filter the default post excerpt initially used in the "Write Post" form.
 
652
         * Filters the default post excerpt initially used in the "Write Post" form.
653
653
         *
654
654
         * @since 1.5.0
655
655
         *
721
721
 
722
722
        if ( !current_user_can( $ptype->cap->edit_posts ) ) {
723
723
                if ( 'page' == $ptype->name )
724
 
                        return new WP_Error( 'edit_pages', __( 'You are not allowed to create pages on this site.' ) );
 
724
                        return new WP_Error( 'edit_pages', __( 'Sorry, you are not allowed to create pages on this site.' ) );
725
725
                else
726
 
                        return new WP_Error( 'edit_posts', __( 'You are not allowed to create posts or drafts on this site.' ) );
 
726
                        return new WP_Error( 'edit_posts', __( 'Sorry, you are not allowed to create posts or drafts on this site.' ) );
727
727
        }
728
728
 
729
729
        $_POST['post_mime_type'] = '';
1029
1029
                $posts_per_page = 20;
1030
1030
 
1031
1031
        /**
1032
 
         * Filter the number of items per page to show for a specific 'per_page' type.
 
1032
         * Filters the number of items per page to show for a specific 'per_page' type.
1033
1033
         *
1034
1034
         * The dynamic portion of the hook name, `$post_type`, refers to the post type.
1035
1035
         *
1044
1044
        $posts_per_page = apply_filters( "edit_{$post_type}_per_page", $posts_per_page );
1045
1045
 
1046
1046
        /**
1047
 
         * Filter the number of posts displayed per page when specifically listing "posts".
 
1047
         * Filters the number of posts displayed per page when specifically listing "posts".
1048
1048
         *
1049
1049
         * @since 2.8.0
1050
1050
         *
1120
1120
        }
1121
1121
 
1122
1122
        /**
1123
 
         * Filter the number of items to list per page when listing media items.
 
1123
         * Filters the number of items to list per page when listing media items.
1124
1124
         *
1125
1125
         * @since 2.9.0
1126
1126
         *
1166
1166
}
1167
1167
 
1168
1168
/**
1169
 
 * Returns the list of classes to be used by a metabox
 
1169
 * Returns the list of classes to be used by a meta box.
1170
1170
 *
1171
1171
 * @since 2.5.0
1172
1172
 *
1188
1188
        }
1189
1189
 
1190
1190
        /**
1191
 
         * Filter the postbox classes for a specific screen and screen ID combo.
 
1191
         * Filters the postbox classes for a specific screen and screen ID combo.
1192
1192
         *
1193
1193
         * The dynamic portions of the hook name, `$page` and `$id`, refer to
1194
1194
         * the screen and screen ID, respectively.
1266
1266
        unset($post->filter);
1267
1267
 
1268
1268
        /**
1269
 
         * Filter the sample permalink.
 
1269
         * Filters the sample permalink.
1270
1270
         *
1271
1271
         * @since 4.4.0
1272
1272
         *
1329
1329
                        $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small" target="_blank">' . __('Change Permalinks') . "</a></span>\n";
1330
1330
                }
1331
1331
        } else {
1332
 
                if ( function_exists( 'mb_strlen' ) ) {
1333
 
                        if ( mb_strlen( $post_name ) > 34 ) {
1334
 
                                $post_name_abridged = mb_substr( $post_name, 0, 16 ) . '&hellip;' . mb_substr( $post_name, -16 );
1335
 
                        } else {
1336
 
                                $post_name_abridged = $post_name;
1337
 
                        }
 
1332
                if ( mb_strlen( $post_name ) > 34 ) {
 
1333
                        $post_name_abridged = mb_substr( $post_name, 0, 16 ) . '&hellip;' . mb_substr( $post_name, -16 );
1338
1334
                } else {
1339
 
                        if ( strlen( $post_name ) > 34 ) {
1340
 
                                $post_name_abridged = substr( $post_name, 0, 16 ) . '&hellip;' . substr( $post_name, -16 );
1341
 
                        } else {
1342
 
                                $post_name_abridged = $post_name;
1343
 
                        }
 
1335
                        $post_name_abridged = $post_name;
1344
1336
                }
1345
1337
 
1346
1338
                $post_name_html = '<span id="editable-post-name">' . esc_html( $post_name_abridged ) . '</span>';
1354
1346
        }
1355
1347
 
1356
1348
        /**
1357
 
         * Filter the sample permalink HTML markup.
 
1349
         * Filters the sample permalink HTML markup.
1358
1350
         *
1359
1351
         * @since 2.9.0
1360
1352
         * @since 4.4.0 Added `$post` parameter.
1375
1367
 *
1376
1368
 * @since 2.9.0
1377
1369
 *
1378
 
 * @global int   $content_width
1379
1370
 * @global array $_wp_additional_image_sizes
1380
1371
 *
1381
1372
 * @param int $thumbnail_id ID of the attachment used for thumbnail
1383
1374
 * @return string html
1384
1375
 */
1385
1376
function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) {
1386
 
        global $content_width, $_wp_additional_image_sizes;
 
1377
        global $_wp_additional_image_sizes;
1387
1378
 
1388
1379
        $post               = get_post( $post );
1389
1380
        $post_type_object   = get_post_type_object( $post->post_type );
1400
1391
                $size = isset( $_wp_additional_image_sizes['post-thumbnail'] ) ? 'post-thumbnail' : array( 266, 266 );
1401
1392
 
1402
1393
                /**
1403
 
                 * Filter the size used to display the post thumbnail image in the 'Featured Image' meta box.
 
1394
                 * Filters the size used to display the post thumbnail image in the 'Featured Image' meta box.
1404
1395
                 *
1405
1396
                 * Note: When a theme adds 'post-thumbnail' support, a special 'post-thumbnail'
1406
1397
                 * image size is registered, which differs from the 'thumbnail' image size
1420
1411
 
1421
1412
                $thumbnail_html = wp_get_attachment_image( $thumbnail_id, $size );
1422
1413
 
1423
 
                if ( !empty( $thumbnail_html ) ) {
1424
 
                        $ajax_nonce = wp_create_nonce( 'set_post_thumbnail-' . $post->ID );
 
1414
                if ( ! empty( $thumbnail_html ) ) {
1425
1415
                        $content = sprintf( $set_thumbnail_link,
1426
1416
                                esc_url( $upload_iframe_src ),
1427
1417
                                ' aria-describedby="set-post-thumbnail-desc"',
1428
1418
                                $thumbnail_html
1429
1419
                        );
1430
1420
                        $content .= '<p class="hide-if-no-js howto" id="set-post-thumbnail-desc">' . __( 'Click the image to edit or update' ) . '</p>';
1431
 
                        $content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail" onclick="WPRemoveThumbnail(\'' . $ajax_nonce . '\');return false;">' . esc_html( $post_type_object->labels->remove_featured_image ) . '</a></p>';
 
1421
                        $content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail">' . esc_html( $post_type_object->labels->remove_featured_image ) . '</a></p>';
1432
1422
                }
1433
1423
        }
1434
1424
 
 
1425
        $content .= '<input type="hidden" id="_thumbnail_id" name="_thumbnail_id" value="' . esc_attr( $thumbnail_id ? $thumbnail_id : '-1' ) . '" />';
 
1426
 
1435
1427
        /**
1436
 
         * Filter the admin post thumbnail HTML markup to return.
 
1428
         * Filters the admin post thumbnail HTML markup to return.
1437
1429
         *
1438
1430
         * @since 2.9.0
 
1431
         * @since 3.5.0 Added the `$post_id` parameter.
 
1432
         * @since 4.6.0 Added the `$thumbnail_id` parameter.
1439
1433
         *
1440
 
         * @param string $content Admin post thumbnail HTML markup.
1441
 
         * @param int    $post_id Post ID.
 
1434
         * @param string $content      Admin post thumbnail HTML markup.
 
1435
         * @param int    $post_id      Post ID.
 
1436
         * @param int    $thumbnail_id Thumbnail ID.
1442
1437
         */
1443
 
        return apply_filters( 'admin_post_thumbnail_html', $content, $post->ID );
 
1438
        return apply_filters( 'admin_post_thumbnail_html', $content, $post->ID, $thumbnail_id );
1444
1439
}
1445
1440
 
1446
1441
/**
1509
1504
        if ( $user ) {
1510
1505
 
1511
1506
                /**
1512
 
                 * Filter whether to show the post locked dialog.
 
1507
                 * Filters whether to show the post locked dialog.
1513
1508
                 *
1514
1509
                 * Returning a falsey value to the filter will short-circuit displaying the dialog.
1515
1510
                 *
1561
1556
                $preview_link = get_preview_post_link( $post->ID, $query_args );
1562
1557
 
1563
1558
                /**
1564
 
                 * Filter whether to allow the post lock to be overridden.
 
1559
                 * Filters whether to allow the post lock to be overridden.
1565
1560
                 *
1566
1561
                 * Returning a falsey value to the filter will disable the ability
1567
1562
                 * to override the post lock.
1721
1716
        $_POST['ID'] = $post_ID;
1722
1717
 
1723
1718
        if ( ! $post = get_post( $post_ID ) ) {
1724
 
                wp_die( __( 'You are not allowed to edit this post.' ) );
 
1719
                wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
1725
1720
        }
1726
1721
 
1727
1722
        if ( ! current_user_can( 'edit_post', $post->ID ) ) {
1728
 
                wp_die( __( 'You are not allowed to edit this post.' ) );
 
1723
                wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
1729
1724
        }
1730
1725
 
1731
1726
        $is_autosave = false;
1750
1745
                $query_args['preview_id'] = $post->ID;
1751
1746
                $query_args['preview_nonce'] = wp_create_nonce( 'post_preview_' . $post->ID );
1752
1747
 
1753
 
                if ( isset( $_POST['post_format'] ) )
 
1748
                if ( isset( $_POST['post_format'] ) ) {
1754
1749
                        $query_args['post_format'] = empty( $_POST['post_format'] ) ? 'standard' : sanitize_key( $_POST['post_format'] );
 
1750
                }
 
1751
 
 
1752
                if ( isset( $_POST['_thumbnail_id'] ) ) {
 
1753
                        $query_args['_thumbnail_id'] = ( intval( $_POST['_thumbnail_id'] ) <= 0 ) ? '-1' : intval( $_POST['_thumbnail_id'] );
 
1754
                }
1755
1755
        }
1756
1756
 
1757
1757
        return get_preview_post_link( $post, $query_args );
1783
1783
        $post = get_post( $post_id );
1784
1784
 
1785
1785
        if ( ! current_user_can( 'edit_post', $post->ID ) ) {
1786
 
                return new WP_Error( 'edit_posts', __( 'You are not allowed to edit this item.' ) );
 
1786
                return new WP_Error( 'edit_posts', __( 'Sorry, you are not allowed to edit this item.' ) );
1787
1787
        }
1788
1788
 
1789
1789
        if ( 'auto-draft' == $post->post_status )
1839
1839
        }
1840
1840
 
1841
1841
        /**
1842
 
         * Filter the post redirect destination URL.
 
1842
         * Filters the post redirect destination URL.
1843
1843
         *
1844
1844
         * @since 2.9.0
1845
1845
         *