2003-10-26 21:34:24 +01:00
|
|
|
<?php
|
2008-08-16 09:27:34 +02:00
|
|
|
/**
|
|
|
|
* Edit post administration panel.
|
|
|
|
*
|
|
|
|
* Manage Post actions: post, edit, delete, etc.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Administration
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** WordPress Administration Bootstrap */
|
2020-02-06 07:33:11 +01:00
|
|
|
require_once __DIR__ . '/admin.php';
|
2003-10-26 21:34:24 +01:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
$parent_file = 'edit.php';
|
2006-05-18 08:49:22 +02:00
|
|
|
$submenu_file = 'edit.php';
|
2003-12-18 10:36:13 +01:00
|
|
|
|
2024-05-01 20:01:12 +02:00
|
|
|
$action = ! empty( $_REQUEST['action'] ) ? sanitize_text_field( $_REQUEST['action'] ) : '';
|
2006-04-19 10:02:16 +02:00
|
|
|
|
2019-02-07 05:12:51 +01:00
|
|
|
if ( isset( $_GET['post'] ) && isset( $_POST['post_ID'] ) && (int) $_GET['post'] !== (int) $_POST['post_ID'] ) {
|
|
|
|
wp_die( __( 'A post ID mismatch has been detected.' ), __( 'Sorry, you are not allowed to edit this item.' ), 400 );
|
|
|
|
} elseif ( isset( $_GET['post'] ) ) {
|
2019-07-01 14:52:01 +02:00
|
|
|
$post_id = (int) $_GET['post'];
|
2017-12-01 00:11:00 +01:00
|
|
|
} elseif ( isset( $_POST['post_ID'] ) ) {
|
2019-07-01 14:52:01 +02:00
|
|
|
$post_id = (int) $_POST['post_ID'];
|
2017-12-01 00:11:00 +01:00
|
|
|
} else {
|
2019-07-01 14:52:01 +02:00
|
|
|
$post_id = 0;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2019-07-01 14:52:01 +02:00
|
|
|
$post_ID = $post_id;
|
2011-10-24 20:34:08 +02:00
|
|
|
|
2015-05-28 23:41:30 +02:00
|
|
|
/**
|
Docs: Add missing description for a few globals in the admin.
This affects:
* `$post_type`
* `$post_type_object`
* `$taxonomy`
* `$title`
* `$wp_meta_boxes`
Follow-up to [31121], [32642], [32643], [37890], [43815], [44244], [45742], [53060], [53061], [54831].
Props shub07, 1naveengiri, sabernhardt, SergeyBiryukov.
Fixes #59561.
Built from https://develop.svn.wordpress.org/trunk@58419
git-svn-id: http://core.svn.wordpress.org/trunk@57868 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-06-15 14:34:13 +02:00
|
|
|
* @global string $post_type Global post type.
|
|
|
|
* @global WP_Post_Type $post_type_object Global post type object.
|
|
|
|
* @global WP_Post $post Global post object.
|
2015-05-28 23:41:30 +02:00
|
|
|
*/
|
2015-01-10 06:29:22 +01:00
|
|
|
global $post_type, $post_type_object, $post;
|
2011-10-24 20:34:08 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( $post_id ) {
|
2011-10-24 20:34:08 +02:00
|
|
|
$post = get_post( $post_id );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2011-10-24 20:34:08 +02:00
|
|
|
|
|
|
|
if ( $post ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
$post_type = $post->post_type;
|
2011-10-24 20:34:08 +02:00
|
|
|
$post_type_object = get_post_type_object( $post_type );
|
2010-01-12 17:50:37 +01:00
|
|
|
}
|
|
|
|
|
2019-02-07 05:12:51 +01:00
|
|
|
if ( isset( $_POST['post_type'] ) && $post && $post_type !== $_POST['post_type'] ) {
|
|
|
|
wp_die( __( 'A post type mismatch has been detected.' ), __( 'Sorry, you are not allowed to edit this item.' ), 400 );
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( isset( $_POST['deletepost'] ) ) {
|
2006-04-19 10:02:16 +02:00
|
|
|
$action = 'delete';
|
2020-05-16 20:42:12 +02:00
|
|
|
} elseif ( isset( $_POST['wp-preview'] ) && 'dopreview' === $_POST['wp-preview'] ) {
|
2008-10-31 23:47:07 +01:00
|
|
|
$action = 'preview';
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2005-04-16 18:31:38 +02:00
|
|
|
|
2009-12-02 00:28:20 +01:00
|
|
|
$sendback = wp_get_referer();
|
2011-11-14 17:59:45 +01:00
|
|
|
if ( ! $sendback ||
|
Code Modernization: Replace usage of `strpos()` with `str_contains()`.
`str_contains()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) contains the given substring (needle).
WordPress core includes a polyfill for `str_contains()` on PHP < 8.0 as of WordPress 5.9.
This commit replaces `false !== strpos( ... )` with `str_contains()` in core files, making the code more readable and consistent, as well as better aligned with modern development practices.
Follow-up to [52039], [52040], [52326], [55703], [55710], [55987].
Props Soean, spacedmonkey, costdev, dingo_d, azaozz, mikeschroder, flixos90, peterwilsoncc, SergeyBiryukov.
Fixes #58206.
Built from https://develop.svn.wordpress.org/trunk@55988
git-svn-id: http://core.svn.wordpress.org/trunk@55500 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-22 16:36:26 +02:00
|
|
|
str_contains( $sendback, 'post.php' ) ||
|
|
|
|
str_contains( $sendback, 'post-new.php' ) ) {
|
2020-05-16 20:42:12 +02:00
|
|
|
if ( 'attachment' === $post_type ) {
|
2012-09-22 00:52:54 +02:00
|
|
|
$sendback = admin_url( 'upload.php' );
|
|
|
|
} else {
|
|
|
|
$sendback = admin_url( 'edit.php' );
|
2015-03-05 23:31:24 +01:00
|
|
|
if ( ! empty( $post_type ) ) {
|
|
|
|
$sendback = add_query_arg( 'post_type', $post_type, $sendback );
|
|
|
|
}
|
2012-09-22 00:52:54 +02:00
|
|
|
}
|
2010-01-24 21:50:50 +01:00
|
|
|
} else {
|
2017-12-01 00:11:00 +01:00
|
|
|
$sendback = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'ids' ), $sendback );
|
2010-01-24 21:50:50 +01:00
|
|
|
}
|
2009-12-02 00:28:20 +01:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
switch ( $action ) {
|
|
|
|
case 'post-quickdraft-save':
|
2020-01-29 01:45:18 +01:00
|
|
|
// Check nonce and capabilities.
|
2017-12-01 00:11:00 +01:00
|
|
|
$nonce = $_REQUEST['_wpnonce'];
|
|
|
|
$error_msg = false;
|
2014-03-20 02:31:15 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// For output of the Quick Draft dashboard widget.
|
2017-12-01 00:11:00 +01:00
|
|
|
require_once ABSPATH . 'wp-admin/includes/dashboard.php';
|
2013-11-13 23:09:10 +01:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! wp_verify_nonce( $nonce, 'add-post' ) ) {
|
|
|
|
$error_msg = __( 'Unable to submit this form, please refresh and try again.' );
|
|
|
|
}
|
2013-11-13 23:09:10 +01:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) {
|
|
|
|
exit;
|
|
|
|
}
|
2014-01-16 21:24:13 +01:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( $error_msg ) {
|
|
|
|
return wp_dashboard_quick_press( $error_msg );
|
|
|
|
}
|
2014-01-16 21:24:13 +01:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
$post = get_post( $_REQUEST['post_ID'] );
|
|
|
|
check_admin_referer( 'add-' . $post->post_type );
|
2013-11-13 23:09:10 +01:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
$_POST['comment_status'] = get_default_comment_status( $post->post_type );
|
|
|
|
$_POST['ping_status'] = get_default_comment_status( $post->post_type, 'pingback' );
|
2003-10-26 21:34:24 +01:00
|
|
|
|
2020-02-05 09:10:05 +01:00
|
|
|
// Wrap Quick Draft content in the Paragraph block.
|
Code Modernization: Replace usage of `strpos()` with `str_contains()`.
`str_contains()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) contains the given substring (needle).
WordPress core includes a polyfill for `str_contains()` on PHP < 8.0 as of WordPress 5.9.
This commit replaces `false !== strpos( ... )` with `str_contains()` in core files, making the code more readable and consistent, as well as better aligned with modern development practices.
Follow-up to [52039], [52040], [52326], [55703], [55710], [55987].
Props Soean, spacedmonkey, costdev, dingo_d, azaozz, mikeschroder, flixos90, peterwilsoncc, SergeyBiryukov.
Fixes #58206.
Built from https://develop.svn.wordpress.org/trunk@55988
git-svn-id: http://core.svn.wordpress.org/trunk@55500 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-22 16:36:26 +02:00
|
|
|
if ( ! str_contains( $_POST['content'], '<!-- wp:paragraph -->' ) ) {
|
2020-02-05 09:10:05 +01:00
|
|
|
$_POST['content'] = sprintf(
|
|
|
|
'<!-- wp:paragraph -->%s<!-- /wp:paragraph -->',
|
|
|
|
str_replace( array( "\r\n", "\r", "\n" ), '<br />', $_POST['content'] )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
edit_post();
|
|
|
|
wp_dashboard_quick_press();
|
|
|
|
exit;
|
2008-02-06 22:40:52 +01:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
case 'postajaxpost':
|
|
|
|
case 'post':
|
|
|
|
check_admin_referer( 'add-' . $post_type );
|
2020-05-16 20:42:12 +02:00
|
|
|
$post_id = 'postajaxpost' === $action ? edit_post() : write_post();
|
2017-12-01 00:11:00 +01:00
|
|
|
redirect_post( $post_id );
|
2020-05-26 11:37:10 +02:00
|
|
|
exit;
|
2010-01-12 17:50:37 +01:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
case 'edit':
|
|
|
|
$editing = true;
|
2009-08-12 12:57:15 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( empty( $post_id ) ) {
|
|
|
|
wp_redirect( admin_url( 'post.php' ) );
|
2020-05-26 11:37:10 +02:00
|
|
|
exit;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2012-04-27 21:32:32 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! $post ) {
|
Administration: Replace contracted verb forms for better consistency.
This changeset replaces contracted verb forms like `doesn't`, `can't`, or `isn't` with non-contracted forms like `does not`, `cannot`, or `is not`, for better consistency across the WordPress administration. It also updates some corresponding unit tests strings.
Props Presskopp, socalchristina, aandrewdixon, francina, SergeyBiryukov, JeffPaul, audrasjb, hellofromTonya.
Fixes #38913.
See #39176.
Built from https://develop.svn.wordpress.org/trunk@52978
git-svn-id: http://core.svn.wordpress.org/trunk@52567 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-03-22 17:25:03 +01:00
|
|
|
wp_die( __( 'You attempted to edit an item that does not exist. Perhaps it was deleted?' ) );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2015-09-15 12:27:29 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! $post_type_object ) {
|
|
|
|
wp_die( __( 'Invalid post type.' ) );
|
|
|
|
}
|
2009-08-12 12:57:15 +02:00
|
|
|
|
2020-04-05 05:02:11 +02:00
|
|
|
if ( ! in_array( $typenow, get_post_types( array( 'show_ui' => true ) ), true ) ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
wp_die( __( 'Sorry, you are not allowed to edit posts in this post type.' ) );
|
|
|
|
}
|
2007-08-16 00:31:19 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! current_user_can( 'edit_post', $post_id ) ) {
|
|
|
|
wp_die( __( 'Sorry, you are not allowed to edit this item.' ) );
|
|
|
|
}
|
2013-03-12 04:22:30 +01:00
|
|
|
|
2020-05-16 20:42:12 +02:00
|
|
|
if ( 'trash' === $post->post_status ) {
|
Administration: Replace contracted verb forms for better consistency.
This changeset replaces contracted verb forms like `doesn't`, `can't`, or `isn't` with non-contracted forms like `does not`, `cannot`, or `is not`, for better consistency across the WordPress administration. It also updates some corresponding unit tests strings.
Props Presskopp, socalchristina, aandrewdixon, francina, SergeyBiryukov, JeffPaul, audrasjb, hellofromTonya.
Fixes #38913.
See #39176.
Built from https://develop.svn.wordpress.org/trunk@52978
git-svn-id: http://core.svn.wordpress.org/trunk@52567 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-03-22 17:25:03 +01:00
|
|
|
wp_die( __( 'You cannot edit this item because it is in the Trash. Please restore it and try again.' ) );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2010-01-04 17:58:43 +01:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! empty( $_GET['get-post-lock'] ) ) {
|
|
|
|
check_admin_referer( 'lock-post_' . $post_id );
|
|
|
|
wp_set_post_lock( $post_id );
|
|
|
|
wp_redirect( get_edit_post_link( $post_id, 'url' ) );
|
2020-05-26 11:37:10 +02:00
|
|
|
exit;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2017-10-11 14:06:48 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
$post_type = $post->post_type;
|
2020-05-16 20:42:12 +02:00
|
|
|
if ( 'post' === $post_type ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
$parent_file = 'edit.php';
|
|
|
|
$submenu_file = 'edit.php';
|
|
|
|
$post_new_file = 'post-new.php';
|
2020-05-16 20:42:12 +02:00
|
|
|
} elseif ( 'attachment' === $post_type ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
$parent_file = 'upload.php';
|
|
|
|
$submenu_file = 'upload.php';
|
|
|
|
$post_new_file = 'media-new.php';
|
|
|
|
} else {
|
2020-02-09 17:53:06 +01:00
|
|
|
if ( isset( $post_type_object ) && $post_type_object->show_in_menu && true !== $post_type_object->show_in_menu ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
$parent_file = $post_type_object->show_in_menu;
|
|
|
|
} else {
|
|
|
|
$parent_file = "edit.php?post_type=$post_type";
|
|
|
|
}
|
|
|
|
$submenu_file = "edit.php?post_type=$post_type";
|
|
|
|
$post_new_file = "post-new.php?post_type=$post_type";
|
|
|
|
}
|
2012-11-20 20:46:38 +01:00
|
|
|
|
2019-01-07 21:40:50 +01:00
|
|
|
$title = $post_type_object->labels->edit_item;
|
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
/**
|
|
|
|
* Allows replacement of the editor.
|
|
|
|
*
|
|
|
|
* @since 4.9.0
|
|
|
|
*
|
2019-10-27 20:11:02 +01:00
|
|
|
* @param bool $replace Whether to replace the editor. Default false.
|
|
|
|
* @param WP_Post $post Post object.
|
2017-12-01 00:11:00 +01:00
|
|
|
*/
|
2020-02-09 17:53:06 +01:00
|
|
|
if ( true === apply_filters( 'replace_editor', false, $post ) ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
break;
|
|
|
|
}
|
2008-01-03 02:34:11 +01:00
|
|
|
|
Editor: Merge some minor bug fixes.
There were some tweaks made to the post editor in WordPress 5.0 that hadn't been merged to `trunk`, this commit rectifies that.
Merges [43815,43816] from the 5.0 branch to trunk.
Props birgire, jorbin, abdullahramzan, adamsilverstein, mrahmadawais, airathalitov, ajitbohra, schlessera, albertomedina, aldavigdis, alexsanford1, xyfi, nitrajka, afercia, andreiglingeanu, euthelup, aduth, sumobi, anevins, azaozz, androb, andrewserong, kallehauge, nosolosw, apeatling, atimmer, arnaudban, asvinballoo, b-07, benlk, blowery, caxco93, benjamin_zekavica, kau-boy, bernhard-reiter, bcolumbia, bph, boblinthorst, bradyvercher, bpayton, brentswisher, bronsonquick, burhandodhy, icaleb, chouby, ehg, chrisvanpatten, butimnoexpert, christophherr, chriskmnds, claudiosanches, danielbachhuber, mrmadhat, danielhw, danieltj, goldsounds, dfangstrom, daniloercoli, dannycooper, nerrad, dsawardekar, davemoran118, davidherrera, dryanpress, davidsword, davisshaver, dmsnell, dlocc, diegoreymendez, dd32, dency, ocean90, donnapep, chopinbach, electricfeet, eliorivero, sewmyheadon, ericnmurphy, foobar4u, circlecube, fabs_pim, flixos90, floriansimeth, gma992, garrett-eclipse, garyj, pento, doomwaxer, revgeorge, gziolo, bordoni, hardeepasrani, helen, luehrsen, herbmiller, toro_unit, ianbelanger, iandunn, igorsch, ipstenu, ireneyoast, israelshmueli, sisanu, jd55, copons, jnylen0, jamestryon, ephoxjames, jamiehalvorson, jsnajdr, jagnew, dciso, octalmage, vengisss, jhoffm34, shenkj, audrasjb, jblz, jeremyfelt, motleydev, jipmoors, sephsekla, joemaller, joemcgill, joen, johndyer, johnjamesjacoby, joshuawold, johnny5, desrosj, jonsurrell, belcherj, sirjonathan, koke, jorgefilipecosta, shelob9, jvisick77, julienmelissas, kopepasah, kadamwhite, codebykat, ryelle, gwwar, kevinwhoffman, coderkevin, ixkaito, kjellr, obenland, lancewillett, postphotos, loicblascos, lucasstark, luigipulcini, lucaskowalski, lukepettway, mahdiyazdani, mahmoudsaeed, mkaz, tyxla, markjaquith, mapk, vindl, m-e-h, mboynes, mattheu, lonelyvegan, mtias, napy84, maurobringolf, maximebj, mayukojpn, woodent, michaelhull, mmtr86, stubgo, simison, mihai2u, mike-haydon-swo, mnelson4, mpheasant, mikeschroder, idpokute, mikeyarce, dimadin, gonzomir, milesdelliott, warmarks, munirkamal, nfmohit, nateconley, greatislander, njpanderson, notnownikki, nielslange, nikschavan, potbot, nshki, webmandesign, oskosk, pglewis, pareshradadiya-1, swissspidy, pbearne, pauldechov, psealock, paulstonier, paulwilde, pedromendonca, ptasker, peterwilsoncc, tyrannous, strategio, piersb, delawski, prtksxna, presskopp, rachelbaker, rachelmcr, rakshans1, rahmon, lamosty, youknowriad, riddhiehta02, noisysocks, deviodigital, sanchothefat, robertsky, _dorsvenabili, rohittm, magicroundabout, rmccue, welcher, ryo511, sagarprajapati, samikeijonen, scottmweaver, kluny, sharaz, giventofly76, designsimply, sstoqnov, hypest, netweb, stevehenty, stuartfeldt, sergioestevao, soean, tammie_l, karmatosed, thrijith, timgardner, timmydcrawford, tjnowell, mirucon, travislopes, truongwp, tjfunke001, vishalkakadiya, vtrpldn, walterebert, westonruter, skorasaurus, somtijds, earnjam, williampatton, willybahuaud, yoavf, zebulan, ziyaddin, abhijitrakas, andreamiddleton, csabotta, dixitadusara, etoledom, faishal, hideokamoto, imath, iseulde, j-falk, jaswrks, johnwatkins0, jomurgel, notlaura, leahkoerper, mcsf, meetjey, 0mirka00, mitogh, ephoxmogran, tacrapo, mzorz, nagayama, omarreiss, ramonopoly, rileybrook, tinkerbelly, shaileesheth, sikander, ssousa, tfrommen, yahil.
Fixes #45037.
Built from https://develop.svn.wordpress.org/trunk@44165
git-svn-id: http://core.svn.wordpress.org/trunk@43995 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-12-14 06:12:52 +01:00
|
|
|
if ( use_block_editor_for_post( $post ) ) {
|
2020-02-06 07:33:11 +01:00
|
|
|
require ABSPATH . 'wp-admin/edit-form-blocks.php';
|
Editor: Merge some minor bug fixes.
There were some tweaks made to the post editor in WordPress 5.0 that hadn't been merged to `trunk`, this commit rectifies that.
Merges [43815,43816] from the 5.0 branch to trunk.
Props birgire, jorbin, abdullahramzan, adamsilverstein, mrahmadawais, airathalitov, ajitbohra, schlessera, albertomedina, aldavigdis, alexsanford1, xyfi, nitrajka, afercia, andreiglingeanu, euthelup, aduth, sumobi, anevins, azaozz, androb, andrewserong, kallehauge, nosolosw, apeatling, atimmer, arnaudban, asvinballoo, b-07, benlk, blowery, caxco93, benjamin_zekavica, kau-boy, bernhard-reiter, bcolumbia, bph, boblinthorst, bradyvercher, bpayton, brentswisher, bronsonquick, burhandodhy, icaleb, chouby, ehg, chrisvanpatten, butimnoexpert, christophherr, chriskmnds, claudiosanches, danielbachhuber, mrmadhat, danielhw, danieltj, goldsounds, dfangstrom, daniloercoli, dannycooper, nerrad, dsawardekar, davemoran118, davidherrera, dryanpress, davidsword, davisshaver, dmsnell, dlocc, diegoreymendez, dd32, dency, ocean90, donnapep, chopinbach, electricfeet, eliorivero, sewmyheadon, ericnmurphy, foobar4u, circlecube, fabs_pim, flixos90, floriansimeth, gma992, garrett-eclipse, garyj, pento, doomwaxer, revgeorge, gziolo, bordoni, hardeepasrani, helen, luehrsen, herbmiller, toro_unit, ianbelanger, iandunn, igorsch, ipstenu, ireneyoast, israelshmueli, sisanu, jd55, copons, jnylen0, jamestryon, ephoxjames, jamiehalvorson, jsnajdr, jagnew, dciso, octalmage, vengisss, jhoffm34, shenkj, audrasjb, jblz, jeremyfelt, motleydev, jipmoors, sephsekla, joemaller, joemcgill, joen, johndyer, johnjamesjacoby, joshuawold, johnny5, desrosj, jonsurrell, belcherj, sirjonathan, koke, jorgefilipecosta, shelob9, jvisick77, julienmelissas, kopepasah, kadamwhite, codebykat, ryelle, gwwar, kevinwhoffman, coderkevin, ixkaito, kjellr, obenland, lancewillett, postphotos, loicblascos, lucasstark, luigipulcini, lucaskowalski, lukepettway, mahdiyazdani, mahmoudsaeed, mkaz, tyxla, markjaquith, mapk, vindl, m-e-h, mboynes, mattheu, lonelyvegan, mtias, napy84, maurobringolf, maximebj, mayukojpn, woodent, michaelhull, mmtr86, stubgo, simison, mihai2u, mike-haydon-swo, mnelson4, mpheasant, mikeschroder, idpokute, mikeyarce, dimadin, gonzomir, milesdelliott, warmarks, munirkamal, nfmohit, nateconley, greatislander, njpanderson, notnownikki, nielslange, nikschavan, potbot, nshki, webmandesign, oskosk, pglewis, pareshradadiya-1, swissspidy, pbearne, pauldechov, psealock, paulstonier, paulwilde, pedromendonca, ptasker, peterwilsoncc, tyrannous, strategio, piersb, delawski, prtksxna, presskopp, rachelbaker, rachelmcr, rakshans1, rahmon, lamosty, youknowriad, riddhiehta02, noisysocks, deviodigital, sanchothefat, robertsky, _dorsvenabili, rohittm, magicroundabout, rmccue, welcher, ryo511, sagarprajapati, samikeijonen, scottmweaver, kluny, sharaz, giventofly76, designsimply, sstoqnov, hypest, netweb, stevehenty, stuartfeldt, sergioestevao, soean, tammie_l, karmatosed, thrijith, timgardner, timmydcrawford, tjnowell, mirucon, travislopes, truongwp, tjfunke001, vishalkakadiya, vtrpldn, walterebert, westonruter, skorasaurus, somtijds, earnjam, williampatton, willybahuaud, yoavf, zebulan, ziyaddin, abhijitrakas, andreamiddleton, csabotta, dixitadusara, etoledom, faishal, hideokamoto, imath, iseulde, j-falk, jaswrks, johnwatkins0, jomurgel, notlaura, leahkoerper, mcsf, meetjey, 0mirka00, mitogh, ephoxmogran, tacrapo, mzorz, nagayama, omarreiss, ramonopoly, rileybrook, tinkerbelly, shaileesheth, sikander, ssousa, tfrommen, yahil.
Fixes #45037.
Built from https://develop.svn.wordpress.org/trunk@44165
git-svn-id: http://core.svn.wordpress.org/trunk@43995 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-12-14 06:12:52 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! wp_check_post_lock( $post->ID ) ) {
|
|
|
|
$active_post_lock = wp_set_post_lock( $post->ID );
|
2006-02-12 08:53:23 +01:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( 'attachment' !== $post_type ) {
|
|
|
|
wp_enqueue_script( 'autosave' );
|
|
|
|
}
|
|
|
|
}
|
2010-04-16 16:03:48 +02:00
|
|
|
|
2019-01-07 21:40:50 +01:00
|
|
|
$post = get_post( $post_id, OBJECT, 'edit' );
|
2004-10-22 16:41:01 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( post_type_supports( $post_type, 'comments' ) ) {
|
|
|
|
wp_enqueue_script( 'admin-comments' );
|
|
|
|
enqueue_comment_hotkeys_js();
|
|
|
|
}
|
2004-04-28 06:49:16 +02:00
|
|
|
|
2020-02-06 07:33:11 +01:00
|
|
|
require ABSPATH . 'wp-admin/edit-form-advanced.php';
|
2006-05-03 00:36:06 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
break;
|
2005-12-13 20:19:56 +01:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
case 'editattachment':
|
|
|
|
check_admin_referer( 'update-post_' . $post_id );
|
2005-12-13 20:19:56 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Don't let these be changed.
|
2017-12-01 00:11:00 +01:00
|
|
|
unset( $_POST['guid'] );
|
|
|
|
$_POST['post_type'] = 'attachment';
|
2005-12-13 20:19:56 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Update the thumbnail filename.
|
2017-12-01 00:11:00 +01:00
|
|
|
$newmeta = wp_get_attachment_metadata( $post_id, true );
|
2018-12-18 22:32:48 +01:00
|
|
|
$newmeta['thumb'] = wp_basename( $_POST['thumb'] );
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
wp_update_attachment_metadata( $post_id, $newmeta );
|
2006-06-24 09:34:35 +02:00
|
|
|
|
2019-01-11 07:26:50 +01:00
|
|
|
// Intentional fall-through to trigger the edit_post() call.
|
2017-12-01 00:11:00 +01:00
|
|
|
case 'editpost':
|
|
|
|
check_admin_referer( 'update-post_' . $post_id );
|
2013-03-14 04:06:07 +01:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
$post_id = edit_post();
|
2005-02-14 10:46:08 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Session cookie flag that the post was saved.
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( isset( $_COOKIE['wp-saving-post'] ) && $_COOKIE['wp-saving-post'] === $post_id . '-check' ) {
|
|
|
|
setcookie( 'wp-saving-post', $post_id . '-saved', time() + DAY_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN, is_ssl() );
|
|
|
|
}
|
2003-11-06 01:34:41 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
redirect_post( $post_id ); // Send user on their way while we keep working.
|
2009-07-30 15:39:34 +02:00
|
|
|
|
2020-05-26 11:37:10 +02:00
|
|
|
exit;
|
2013-05-08 20:56:54 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
case 'trash':
|
|
|
|
check_admin_referer( 'trash-post_' . $post_id );
|
2013-05-08 20:56:54 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! $post ) {
|
|
|
|
wp_die( __( 'The item you are trying to move to the Trash no longer exists.' ) );
|
|
|
|
}
|
2009-07-30 15:39:34 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! $post_type_object ) {
|
|
|
|
wp_die( __( 'Invalid post type.' ) );
|
|
|
|
}
|
2013-03-12 04:22:30 +01:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! current_user_can( 'delete_post', $post_id ) ) {
|
|
|
|
wp_die( __( 'Sorry, you are not allowed to move this item to the Trash.' ) );
|
|
|
|
}
|
2009-07-30 15:39:34 +02:00
|
|
|
|
2019-07-01 14:52:01 +02:00
|
|
|
$user_id = wp_check_post_lock( $post_id );
|
|
|
|
if ( $user_id ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
$user = get_userdata( $user_id );
|
2019-09-03 02:41:05 +02:00
|
|
|
/* translators: %s: User's display name. */
|
2017-12-01 00:11:00 +01:00
|
|
|
wp_die( sprintf( __( 'You cannot move this item to the Trash. %s is currently editing.' ), $user->display_name ) );
|
|
|
|
}
|
2009-07-30 15:39:34 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! wp_trash_post( $post_id ) ) {
|
2020-07-05 12:41:10 +02:00
|
|
|
wp_die( __( 'Error in moving the item to Trash.' ) );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2009-07-30 15:39:34 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
wp_redirect(
|
|
|
|
add_query_arg(
|
|
|
|
array(
|
|
|
|
'trashed' => 1,
|
|
|
|
'ids' => $post_id,
|
2018-08-17 03:51:36 +02:00
|
|
|
),
|
|
|
|
$sendback
|
2017-12-01 00:11:00 +01:00
|
|
|
)
|
|
|
|
);
|
2020-05-26 11:37:10 +02:00
|
|
|
exit;
|
2013-05-08 20:56:54 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
case 'untrash':
|
|
|
|
check_admin_referer( 'untrash-post_' . $post_id );
|
2009-07-30 15:39:34 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! $post ) {
|
|
|
|
wp_die( __( 'The item you are trying to restore from the Trash no longer exists.' ) );
|
|
|
|
}
|
2013-05-08 20:56:54 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! $post_type_object ) {
|
|
|
|
wp_die( __( 'Invalid post type.' ) );
|
|
|
|
}
|
2009-07-30 15:39:34 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! current_user_can( 'delete_post', $post_id ) ) {
|
|
|
|
wp_die( __( 'Sorry, you are not allowed to restore this item from the Trash.' ) );
|
|
|
|
}
|
2009-07-30 15:39:34 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! wp_untrash_post( $post_id ) ) {
|
2020-07-05 12:41:10 +02:00
|
|
|
wp_die( __( 'Error in restoring the item from Trash.' ) );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2005-12-13 20:19:56 +01:00
|
|
|
|
2020-10-11 15:39:07 +02:00
|
|
|
$sendback = add_query_arg(
|
|
|
|
array(
|
|
|
|
'untrashed' => 1,
|
|
|
|
'ids' => $post_id,
|
|
|
|
),
|
|
|
|
$sendback
|
|
|
|
);
|
|
|
|
wp_redirect( $sendback );
|
2020-05-26 11:37:10 +02:00
|
|
|
exit;
|
2013-05-08 20:56:54 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
case 'delete':
|
|
|
|
check_admin_referer( 'delete-post_' . $post_id );
|
2013-05-08 20:56:54 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! $post ) {
|
|
|
|
wp_die( __( 'This item has already been deleted.' ) );
|
|
|
|
}
|
2004-04-28 06:49:16 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! $post_type_object ) {
|
|
|
|
wp_die( __( 'Invalid post type.' ) );
|
|
|
|
}
|
2003-11-12 16:22:47 +01:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! current_user_can( 'delete_post', $post_id ) ) {
|
|
|
|
wp_die( __( 'Sorry, you are not allowed to delete this item.' ) );
|
|
|
|
}
|
2004-04-28 06:49:16 +02:00
|
|
|
|
2020-02-09 17:53:06 +01:00
|
|
|
if ( 'attachment' === $post->post_type ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
$force = ( ! MEDIA_TRASH );
|
|
|
|
if ( ! wp_delete_attachment( $post_id, $force ) ) {
|
2020-07-05 12:41:10 +02:00
|
|
|
wp_die( __( 'Error in deleting the attachment.' ) );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ( ! wp_delete_post( $post_id, true ) ) {
|
2020-07-05 12:41:10 +02:00
|
|
|
wp_die( __( 'Error in deleting the item.' ) );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
|
|
|
}
|
2008-10-31 23:47:07 +01:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
wp_redirect( add_query_arg( 'deleted', 1, $sendback ) );
|
2020-05-26 11:37:10 +02:00
|
|
|
exit;
|
2008-10-31 23:47:07 +01:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
case 'preview':
|
|
|
|
check_admin_referer( 'update-post_' . $post_id );
|
2008-10-31 23:47:07 +01:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
$url = post_preview();
|
2016-05-12 17:44:28 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
wp_redirect( $url );
|
2020-05-26 11:37:10 +02:00
|
|
|
exit;
|
2017-12-01 00:11:00 +01:00
|
|
|
|
2018-12-17 04:52:51 +01:00
|
|
|
case 'toggle-custom-fields':
|
2021-02-08 22:39:16 +01:00
|
|
|
check_admin_referer( 'toggle-custom-fields', 'toggle-custom-fields-nonce' );
|
2018-12-17 04:52:51 +01:00
|
|
|
|
|
|
|
$current_user_id = get_current_user_id();
|
|
|
|
if ( $current_user_id ) {
|
|
|
|
$enable_custom_fields = (bool) get_user_meta( $current_user_id, 'enable_custom_fields', true );
|
|
|
|
update_user_meta( $current_user_id, 'enable_custom_fields', ! $enable_custom_fields );
|
|
|
|
}
|
|
|
|
|
|
|
|
wp_safe_redirect( wp_get_referer() );
|
2020-05-26 11:37:10 +02:00
|
|
|
exit;
|
2018-12-17 04:52:51 +01:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
default:
|
|
|
|
/**
|
|
|
|
* Fires for a given custom post action request.
|
|
|
|
*
|
|
|
|
* The dynamic portion of the hook name, `$action`, refers to the custom post action.
|
|
|
|
*
|
|
|
|
* @since 4.6.0
|
|
|
|
*
|
|
|
|
* @param int $post_id Post ID sent with the request.
|
|
|
|
*/
|
|
|
|
do_action( "post_action_{$action}", $post_id );
|
|
|
|
|
|
|
|
wp_redirect( admin_url( 'edit.php' ) );
|
2020-05-26 11:37:10 +02:00
|
|
|
exit;
|
2020-01-29 01:45:18 +01:00
|
|
|
} // End switch.
|
2020-02-06 07:33:11 +01:00
|
|
|
|
|
|
|
require_once ABSPATH . 'wp-admin/admin-footer.php';
|