236
236
wp_die( __('You are not allowed to edit posts.') );
239
if ( -1 == $post_data['_status'] ) {
240
$post_data['post_status'] = null;
241
unset($post_data['post_status']);
243
$post_data['post_status'] = $post_data['_status'];
245
unset($post_data['_status']);
239
247
$post_IDs = array_map( 'intval', (array) $post_data['post'] );
241
249
$reset = array( 'post_author', 'post_status', 'post_password', 'post_parent', 'page_template', 'comment_status', 'ping_status', 'keep_private', 'tags_input', 'post_category', 'sticky' );
318
326
* @return unknown
320
328
function get_default_post_to_edit() {
321
331
if ( !empty( $_REQUEST['post_title'] ) )
322
332
$post_title = esc_html( stripslashes( $_REQUEST['post_title'] ));
323
else if ( !empty( $_REQUEST['popuptitle'] ) ) {
324
$post_title = esc_html( stripslashes( $_REQUEST['popuptitle'] ));
325
$post_title = funky_javascript_fix( $post_title );
330
334
$post_content = '';
331
335
if ( !empty( $_REQUEST['content'] ) )
332
336
$post_content = esc_html( stripslashes( $_REQUEST['content'] ));
333
else if ( !empty( $post_title ) ) {
334
$text = esc_html( stripslashes( urldecode( $_REQUEST['text'] ) ) );
335
$text = funky_javascript_fix( $text);
336
$popupurl = esc_url($_REQUEST['popupurl']);
337
$post_content = '<a href="'.$popupurl.'">'.$post_title.'</a>'."\n$text";
340
339
if ( !empty( $_REQUEST['excerpt'] ) )
341
340
$post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] ));
346
343
$post->post_name = '';
563
560
$metakeyselect = isset($_POST['metakeyselect']) ? stripslashes( trim( $_POST['metakeyselect'] ) ) : '';
564
561
$metakeyinput = isset($_POST['metakeyinput']) ? stripslashes( trim( $_POST['metakeyinput'] ) ) : '';
565
$metavalue = isset($_POST['metavalue']) ? maybe_serialize( stripslashes( trim( $_POST['metavalue'] ) ) ) : '';
562
$metavalue = isset($_POST['metavalue']) ? maybe_serialize( stripslashes_deep( $_POST['metavalue'] ) ) : '';
563
if ( is_string($metavalue) )
564
$metavalue = trim( $metavalue );
567
566
if ( ('0' === $metavalue || !empty ( $metavalue ) ) && ((('#NONE#' != $metakeyselect) && !empty ( $metakeyselect) ) || !empty ( $metakeyinput) ) ) {
568
567
// We have a key/value pair. If both the select and the
580
579
wp_cache_delete($post_ID, 'post_meta');
582
581
$wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value ) VALUES (%s, %s, %s)", $post_ID, $metakey, $metavalue) );
582
do_action( 'added_postmeta', $wpdb->insert_id, $post_ID, $metakey, $metavalue );
583
584
return $wpdb->insert_id;
598
599
$mid = (int) $mid;
600
601
$post_id = $wpdb->get_var( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_id = %d", $mid) );
603
do_action( 'delete_postmeta', $mid );
601
604
wp_cache_delete($post_id, 'post_meta');
605
$rval = $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id = %d", $mid) );
606
do_action( 'deleted_postmeta', $mid );
603
return $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id = %d", $mid) );
683
688
$post_id = $wpdb->get_var( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_id = %d", $meta_id) );
684
wp_cache_delete($post_id, 'post_meta');
686
$meta_value = maybe_serialize( stripslashes( $meta_value ) );
690
$meta_value = maybe_serialize( stripslashes_deep( $meta_value ) );
687
691
$meta_id = (int) $meta_id;
689
693
$data = compact( 'meta_key', 'meta_value' );
690
694
$where = compact( 'meta_id' );
692
return $wpdb->update( $wpdb->postmeta, $data, $where );
696
do_action( 'update_postmeta', $meta_id, $post_id, $meta_key, $meta_value );
697
$rval = $wpdb->update( $wpdb->postmeta, $data, $where );
698
wp_cache_delete($post_id, 'post_meta');
699
do_action( 'updated_postmeta', $meta_id, $post_id, $meta_key, $meta_value );
735
745
$post_search[$i] = $anchor;
736
$post_replace[$i] = preg_replace( "#href=(\"|')[^'\"]*\\1#e", "stripslashes( 'href=\\1' ).get_attachment_link( $id ).stripslashes( '\\1' )", $anchor );
746
$_fix_attachment_link_id = $id;
747
$post_replace[$i] = preg_replace_callback( "#href=(\"|')[^'\"]*\\1#", '_fix_attachment_links_replace_cb', $anchor );
760
776
$old_ID = (int) $old_ID;
761
777
$new_ID = (int) $new_ID;
762
return $wpdb->update($wpdb->posts, array('post_parent' => $new_ID), array('post_parent' => $old_ID) );
779
$children = $wpdb->get_col( $wpdb->prepare("
782
WHERE meta_key = '_wp_attachment_temp_parent'
783
AND meta_value = %d", $old_ID) );
785
foreach ( $children as $child_id ) {
786
$wpdb->update($wpdb->posts, array('post_parent' => $new_ID), array('ID' => $child_id) );
787
delete_post_meta($child_id, '_wp_attachment_temp_parent');
795
821
'pending' => array(_x('Pending Review', 'post'), __('Pending posts'), _n_noop('Pending Review <span class="count">(%s)</span>', 'Pending Review <span class="count">(%s)</span>')),
796
822
'draft' => array(_x('Draft', 'post'), _x('Drafts', 'manage posts header'), _n_noop('Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>')),
797
823
'private' => array(_x('Private', 'post'), __('Private posts'), _n_noop('Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>')),
824
'trash' => array(_x('Trash', 'post'), __('Trash posts'), _n_noop('Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>')),
800
827
$post_stati = apply_filters('post_stati', $post_stati);
818
845
$orderby = 'date';
821
$posts_per_page = get_user_option('edit_per_page');
822
if ( empty($posts_per_page) )
848
$posts_per_page = (int) get_user_option( 'edit_per_page', 0, false );
849
if ( empty( $posts_per_page ) || $posts_per_page < 1 )
823
850
$posts_per_page = 15;
824
$posts_per_page = apply_filters('edit_posts_per_page', $posts_per_page);
851
$posts_per_page = apply_filters( 'edit_posts_per_page', $posts_per_page );
826
853
wp("post_type=post&$post_status_q&posts_per_page=$posts_per_page&order=$order&orderby=$orderby");
859
* Get default post mime types
865
function get_post_mime_types() {
866
$post_mime_types = array( // array( adj, noun )
867
'image' => array(__('Images'), __('Manage Images'), _n_noop('Image <span class="count">(%s)</span>', 'Images <span class="count">(%s)</span>')),
868
'audio' => array(__('Audio'), __('Manage Audio'), _n_noop('Audio <span class="count">(%s)</span>', 'Audio <span class="count">(%s)</span>')),
869
'video' => array(__('Video'), __('Manage Video'), _n_noop('Video <span class="count">(%s)</span>', 'Video <span class="count">(%s)</span>')),
872
return apply_filters('post_mime_types', $post_mime_types);
832
876
* {@internal Missing Short Description}}
858
902
$q['m'] = isset( $q['m'] ) ? (int) $q['m'] : 0;
859
903
$q['cat'] = isset( $q['cat'] ) ? (int) $q['cat'] : 0;
860
904
$q['post_type'] = 'attachment';
861
$q['post_status'] = 'any';
862
$media_per_page = get_user_option('upload_per_page');
863
if ( empty($media_per_page) )
905
$q['post_status'] = isset( $q['status'] ) && 'trash' == $q['status'] ? 'trash' : 'inherit';
906
$media_per_page = (int) get_user_option( 'upload_per_page', 0, false );
907
if ( empty( $media_per_page ) || $media_per_page < 1 )
864
908
$media_per_page = 20;
865
$q['posts_per_page'] = $media_per_page;
866
$post_mime_types = array( // array( adj, noun )
867
'image' => array(__('Images'), __('Manage Images'), _n_noop('Image <span class="count">(%s)</span>', 'Images <span class="count">(%s)</span>')),
868
'audio' => array(__('Audio'), __('Manage Audio'), _n_noop('Audio <span class="count">(%s)</span>', 'Audio <span class="count">(%s)</span>')),
869
'video' => array(__('Video'), __('Manage Video'), _n_noop('Video <span class="count">(%s)</span>', 'Video <span class="count">(%s)</span>')),
871
$post_mime_types = apply_filters('post_mime_types', $post_mime_types);
909
$q['posts_per_page'] = apply_filters( 'upload_per_page', $media_per_page );
911
$post_mime_types = get_post_mime_types();
873
912
$avail_post_mime_types = get_available_post_mime_types('attachment');
875
914
if ( isset($q['post_mime_type']) && !array_intersect( (array) $q['post_mime_type'], array_keys($post_mime_types) ) )
909
* @param unknown_type $id
910
* @param unknown_type $title
911
* @param unknown_type $name
948
* @param int|object $id Post ID or post object.
949
* @param string $title (optional) Title
950
* @param string $name (optional) Name
951
* @return array With two entries of type string
914
function get_sample_permalink($id, $title=null, $name = null) {
953
function get_sample_permalink($id, $title = null, $name = null) {
915
954
$post = &get_post($id);
916
955
if (!$post->ID) {
917
956
return array('', '');
924
963
// drafts, so we will fake, that our post is published
925
964
if (in_array($post->post_status, array('draft', 'pending'))) {
926
965
$post->post_status = 'publish';
927
$post->post_name = sanitize_title($post->post_name? $post->post_name : $post->post_title, $post->ID);
966
$post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID);
930
969
$post->post_name = wp_unique_post_slug($post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent);
932
971
// If the user wants to set a new name -- override the current one
933
972
// Note: if empty name is supplied -- use the title instead, see #6072
934
973
if (!is_null($name)) {
935
$post->post_name = sanitize_title($name? $name : $title, $post->ID);
974
$post->post_name = sanitize_title($name ? $name : $title, $post->ID);
938
977
$post->filter = 'sample';
963
* {@internal Missing Short Description}}
1002
* sample permalink html
1004
* intended to be used for the inplace editor of the permalink post slug on in the post (and page?) editor.
965
1006
* @since unknown
967
* @param unknown_type $id
968
* @param unknown_type $new_title
969
* @param unknown_type $new_slug
1008
* @param int|object $id Post ID or post object.
1009
* @param string $new_title (optional) New title
1010
* @param string $new_slug (optional) New slug
1011
* @return string intended to be used for the inplace editor of the permalink post slug on in the post (and page?) editor.
972
1013
function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
973
1014
$post = &get_post($id);
974
1015
list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
975
if ( 'publish' == $post->post_status )
1017
if ( 'publish' == $post->post_status ) {
976
1018
$view_post = 'post' == $post->post_type ? __('View Post') : __('View Page');
1019
$title = __('Click to edit this part of the permalink');
1021
$title = __('Temporary permalink. Click to edit this part.');
978
1024
if ( false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%') ) {
979
1025
$return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink">' . $permalink . "</span>\n";
980
if ( current_user_can( 'manage_options' ) )
1026
if ( current_user_can( 'manage_options' ) && !( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) )
981
1027
$return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button" target="_blank">' . __('Change Permalinks') . "</a></span>\n";
982
1028
if ( isset($view_post) )
983
1029
$return .= "<span id='view-post-btn'><a href='$permalink' class='button' target='_blank'>$view_post</a></span>\n";
1031
$return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug);
988
$title = __('Click to edit this part of the permalink');
989
if (function_exists('mb_strlen')) {
990
if (mb_strlen($post_name) > 30) {
1036
if ( function_exists('mb_strlen') ) {
1037
if ( mb_strlen($post_name) > 30 ) {
991
1038
$post_name_abridged = mb_substr($post_name, 0, 14). '…' . mb_substr($post_name, -14);
993
1040
$post_name_abridged = $post_name;
996
if (strlen($post_name) > 30) {
1043
if ( strlen($post_name) > 30 ) {
997
1044
$post_name_abridged = substr($post_name, 0, 14). '…' . substr($post_name, -14);
999
1046
$post_name_abridged = $post_name;
1004
1051
$display_link = str_replace(array('%pagename%','%postname%'), $post_name_html, $permalink);
1005
1052
$view_link = str_replace(array('%pagename%','%postname%'), $post_name, $permalink);
1006
1053
$return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink">' . $display_link . "</span>\n";
1007
$return .= '<span id="edit-slug-buttons"><a href="#post_name" class="edit-slug button hide-if-no-js" onclick="edit_permalink(' . $id . '); return false;">' . __('Edit') . "</a></span>\n";
1054
$return .= '<span id="edit-slug-buttons"><a href="#post_name" class="edit-slug button hide-if-no-js" onclick="editPermalink(' . $id . '); return false;">' . __('Edit') . "</a></span>\n";
1008
1055
$return .= '<span id="editable-post-name-full">' . $post_name . "</span>\n";
1009
1056
if ( isset($view_post) )
1010
1057
$return .= "<span id='view-post-btn'><a href='$view_link' class='button' target='_blank'>$view_post</a></span>\n";
1059
$return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug);
1012
1061
return $return;
1016
* {@internal Missing Short Description}}
1020
* @param unknown_type $post_id
1065
* Output HTML for the post thumbnail meta-box.
1069
* @param int $thumbnail_id ID of the attachment used for thumbnail
1070
* @return string html
1072
function _wp_post_thumbnail_html( $thumbnail_id = NULL ) {
1073
global $content_width, $_wp_additional_image_sizes;
1074
$content = '<p class="hide-if-no-js"><a href="#" id="set-post-thumbnail" onclick="jQuery(\'#add_image\').click();return false;">' . esc_html__( 'Set thumbnail' ) . '</a></p>';
1076
if ( $thumbnail_id && get_post( $thumbnail_id ) ) {
1077
$old_content_width = $content_width;
1078
$content_width = 266;
1079
if ( !isset( $_wp_additional_image_sizes['post-thumbnail'] ) )
1080
$thumbnail_html = wp_get_attachment_image( $thumbnail_id, array( $content_width, $content_width ) );
1082
$thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'post-thumbnail' );
1083
if ( !empty( $thumbnail_html ) ) {
1084
$content = '<a href="#" id="set-post-thumbnail" onclick="jQuery(\'#add_image\').click();return false;">' . $thumbnail_html . '</a>';
1085
$content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail" onclick="WPRemoveThumbnail();return false;">' . esc_html__( 'Remove thumbnail' ) . '</a></p>';
1087
$content_width = $old_content_width;
1090
return apply_filters( 'admin_post_thumbnail_html', $content );
1094
* Check to see if the post is currently being edited by another user.
1098
* @param int $post_id ID of the post to check for editing
1021
1099
* @return bool|int False: not locked or locked by current user. Int: user ID of user with lock.
1023
1101
function wp_check_post_lock( $post_id ) {
1040
* {@internal Missing Short Description}}
1044
* @param unknown_type $post_id
1118
* Mark the post as currently being edited by the current user
1122
* @param int $post_id ID of the post to being edited
1123
* @return bool Returns false if the post doesn't exist of there is no current user
1047
1125
function wp_set_post_lock( $post_id ) {
1048
1126
global $current_user;
1104
1182
if ( $old_autosave = wp_get_post_autosave( $post_id ) ) {
1105
1183
$new_autosave = _wp_post_revision_fields( $_POST, true );
1106
1184
$new_autosave['ID'] = $old_autosave->ID;
1185
$current_user = wp_get_current_user();
1186
$new_autosave['post_author'] = $current_user->ID;
1107
1187
return wp_update_post( $new_autosave );
1187
1267
* to the URL when queueing them with the mce_external_plugins filter.
1189
1269
* @param bool $teeny optional Output a trimmed down version used in Press This.
1270
* @param mixed $settings optional An array that can add to or overwrite the default TinyMCE settings.
1191
function wp_tiny_mce( $teeny = false ) {
1272
function wp_tiny_mce( $teeny = false, $settings = false ) {
1192
1273
global $concatenate_scripts, $compress_scripts, $tinymce_version;
1194
1275
if ( ! user_can_richedit() )
1207
1288
$mce_spellchecker_languages = apply_filters('mce_spellchecker_languages', '+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv');
1209
1290
if ( $teeny ) {
1210
$plugins = apply_filters( 'teeny_mce_plugins', array('safari', 'inlinepopups', 'media', 'autosave', 'fullscreen') );
1291
$plugins = apply_filters( 'teeny_mce_plugins', array('safari', 'inlinepopups', 'media', 'fullscreen', 'wordpress') );
1211
1292
$ext_plugins = '';
1213
1294
$plugins = array( 'safari', 'inlinepopups', 'spellchecker', 'paste', 'wordpress', 'media', 'fullscreen', 'wpeditimage', 'wpgallery', 'tabfocus' );
1341
1422
'accessibility_focus' => true,
1342
1423
'tabfocus_elements' => 'major-publishing-actions',
1343
1424
'media_strict' => false,
1344
'save_callback' => 'switchEditors.saveCallback',
1425
'paste_remove_styles' => true,
1426
'paste_remove_spans' => true,
1427
'paste_strip_class_attributes' => 'all',
1345
1428
'wpeditimage_disable_captions' => $no_captions,
1346
1429
'plugins' => "$plugins"
1351
1434
if ( ! empty($mce_css) )
1352
1435
$initArray['content_css'] = "$mce_css";
1437
if ( is_array($settings) )
1438
$initArray = array_merge($initArray, $settings);
1354
1440
// For people who really REALLY know what they're doing with TinyMCE
1355
1441
// You can modify initArray to add, remove, change elements of the config before tinyMCE.init
1356
1442
// Setting "valid_elements", "invalid_elements" and "extended_valid_elements" can be done through "tiny_mce_before_init".