Changes from branches/3.0/wp-admin/includes/post.php at r17401 to trunk/wp-admin/includes/post.php at r17457
- File:
-
- 1 edited
-
trunk/wp-admin/includes/post.php (modified) (45 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/post.php
r17401 r17457 16 16 * 17 17 * @param bool $update Are we updating a pre-existing post? 18 * @param post_data arrayArray of post data. Defaults to the contents of $_POST.18 * @param array $post_data Array of post data. Defaults to the contents of $_POST. 19 19 * @return object|bool WP_Error on failure, true on success. 20 20 */ … … 126 126 * Update an existing post with values provided in $_POST. 127 127 * 128 * @since unknown128 * @since 1.5.0 129 129 * 130 130 * @param array $post_data Optional. … … 137 137 138 138 $post_ID = (int) $post_data['post_ID']; 139 $post = get_post( $post_ID ); 140 $post_data['post_type'] = $post->post_type; 139 141 140 142 $ptype = get_post_type_object($post_data['post_type']); … … 157 159 158 160 $post_data = _wp_translate_postdata( true, $post_data ); 161 if ( is_wp_error($post_data) ) 162 wp_die( $post_data->get_error_message() ); 159 163 if ( 'autosave' != $post_data['action'] && 'auto-draft' == $post_data['post_status'] ) 160 164 $post_data['post_status'] = 'draft'; 161 if ( is_wp_error($post_data) )162 wp_die( $post_data->get_error_message() );163 165 164 166 if ( isset($post_data['visibility']) ) { … … 178 180 } 179 181 182 // Post Formats 183 if ( current_theme_supports( 'post-formats' ) && isset( $post_data['post_format'] ) ) { 184 $formats = get_theme_support( 'post-formats' ); 185 if ( is_array( $formats ) ) { 186 $formats = $formats[0]; 187 if ( in_array( $post_data['post_format'], $formats ) ) { 188 set_post_format( $post_ID, $post_data['post_format'] ); 189 } elseif ( '0' == $post_data['post_format'] ) { 190 set_post_format( $post_ID, false ); 191 } 192 } 193 } 194 180 195 // Meta Stuff 181 196 if ( isset($post_data['meta']) && $post_data['meta'] ) { 182 foreach ( $post_data['meta'] as $key => $value ) 197 foreach ( $post_data['meta'] as $key => $value ) { 198 if ( !$meta = get_post_meta_by_id( $key ) ) 199 continue; 200 if ( $meta->post_id != $post_ID ) 201 continue; 183 202 update_meta( $key, $value['key'], $value['value'] ); 203 } 184 204 } 185 205 186 206 if ( isset($post_data['deletemeta']) && $post_data['deletemeta'] ) { 187 foreach ( $post_data['deletemeta'] as $key => $value ) 207 foreach ( $post_data['deletemeta'] as $key => $value ) { 208 if ( !$meta = get_post_meta_by_id( $key ) ) 209 continue; 210 if ( $meta->post_id != $post_ID ) 211 continue; 188 212 delete_meta( $key ); 213 } 189 214 } 190 215 … … 206 231 wp_set_post_lock( $post_ID, $GLOBALS['current_user']->ID ); 207 232 208 if ( current_user_can( 'edit_others_posts') ) {209 if ( ! empty($post_data['sticky']) )210 stick_post( $post_ID);233 if ( current_user_can( $ptype->cap->edit_others_posts ) ) { 234 if ( ! empty( $post_data['sticky'] ) ) 235 stick_post( $post_ID ); 211 236 else 212 unstick_post( $post_ID);237 unstick_post( $post_ID ); 213 238 } 214 239 … … 337 362 $updated[] = wp_update_post( $post_data ); 338 363 339 if ( isset( $post_data['sticky'] ) && current_user_can( 'edit_others_posts') ) {364 if ( isset( $post_data['sticky'] ) && current_user_can( $ptype->cap->edit_others_posts ) ) { 340 365 if ( 'sticky' == $post_data['sticky'] ) 341 366 stick_post( $post_ID ); … … 352 377 * Default post information to use when populating the "Write Post" form. 353 378 * 354 * @since unknown355 * 356 * @param stringA post type string, defaults to 'post'.379 * @since 2.0.0 380 * 381 * @param string $post_type A post type string, defaults to 'post'. 357 382 * @return object stdClass object containing all the default post data as attributes 358 383 */ … … 379 404 $post_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) ); 380 405 $post = get_post( $post_id ); 406 if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) && get_option( 'default_post_format' ) ) 407 set_post_format( $post, get_option( 'default_post_format' ) ); 381 408 } else { 382 409 $post->ID = 0; … … 422 449 * Get an existing post and format it for editing. 423 450 * 424 * @since unknown451 * @since 2.0.0 425 452 * 426 453 * @param unknown_type $id … … 440 467 * Determine if a post exists based on title, content, and date 441 468 * 442 * @since unknown469 * @since 2.0.0 443 470 * 444 471 * @param string $title Post title … … 481 508 * Creates a new post from the "Write Post" form using $_POST information. 482 509 * 483 * @since unknown510 * @since 2.1.0 484 511 * 485 512 * @return unknown … … 578 605 * Calls wp_write_post() and handles the errors. 579 606 * 580 * @since unknown607 * @since 2.0.0 581 608 * 582 609 * @return unknown … … 597 624 * {@internal Missing Short Description}} 598 625 * 599 * @since unknown626 * @since 1.2.0 600 627 * 601 628 * @param unknown_type $post_ID … … 629 656 wp_cache_delete($post_ID, 'post_meta'); 630 657 $wpdb->insert( $wpdb->postmeta, array( 'post_id' => $post_ID, 'meta_key' => $metakey, 'meta_value' => $metavalue ) ); 631 do_action( 'added_postmeta', $wpdb->insert_id, $post_ID, $metakey, $metavalue ); 632 633 return $wpdb->insert_id; 658 $meta_id = $wpdb->insert_id; 659 do_action( 'added_postmeta', $meta_id, $post_ID, $metakey, $metavalue ); 660 661 return $meta_id; 634 662 } 635 663 return false; … … 639 667 * {@internal Missing Short Description}} 640 668 * 641 * @since unknown669 * @since 1.2.0 642 670 * 643 671 * @param unknown_type $mid … … 661 689 * Get a list of previously defined keys. 662 690 * 663 * @since unknown691 * @since 1.2.0 664 692 * 665 693 * @return unknown … … 680 708 * {@internal Missing Short Description}} 681 709 * 682 * @since unknown710 * @since 2.1.0 683 711 * 684 712 * @param unknown_type $mid … … 702 730 * Some postmeta stuff. 703 731 * 704 * @since unknown732 * @since 1.2.0 705 733 * 706 734 * @param unknown_type $postid … … 719 747 * {@internal Missing Short Description}} 720 748 * 721 * @since unknown749 * @since 1.2.0 722 750 * 723 751 * @param unknown_type $meta_id … … 762 790 * Replace hrefs of attachment anchors with up-to-date permalinks. 763 791 * 764 * @since unknown792 * @since 2.3.0 765 793 * @access private 766 794 * … … 818 846 * Move child posts to a new parent. 819 847 * 820 * @since unknown848 * @since 2.3.0 821 849 * @access private 822 850 * … … 883 911 } 884 912 885 if ( isset($q['post_status']) && 'pending' === $q['post_status'] ) { 913 if ( isset($q['orderby']) ) 914 $orderby = $q['orderby']; 915 elseif ( isset($q['post_status']) && in_array($q['post_status'], array('pending', 'draft')) ) 916 $orderby = 'modified'; 917 918 if ( isset($q['order']) ) 919 $order = $q['order']; 920 elseif ( isset($q['post_status']) && 'pending' == $q['post_status'] ) 886 921 $order = 'ASC'; 887 $orderby = 'modified';888 } elseif ( isset($q['post_status']) && 'draft' === $q['post_status'] ) {889 $order = 'DESC';890 $orderby = 'modified';891 } else {892 $order = 'DESC';893 $orderby = 'date';894 }895 922 896 923 $per_page = 'edit_' . $post_type . '_per_page'; … … 905 932 906 933 // Hierarchical types require special args. 907 if ( is_post_type_hierarchical( $post_type ) ) {934 if ( is_post_type_hierarchical( $post_type ) && !isset($orderby) ) { 908 935 $query['orderby'] = 'menu_order title'; 909 936 $query['order'] = 'asc'; … … 911 938 $query['posts_per_archive_page'] = -1; 912 939 } 940 941 if ( ! empty( $q['show_sticky'] ) ) 942 $query['post__in'] = (array) get_option( 'sticky_posts' ); 913 943 914 944 wp( $query ); … … 937 967 * {@internal Missing Short Description}} 938 968 * 939 * @since unknown969 * @since 2.5.0 940 970 * 941 971 * @param unknown_type $type … … 952 982 * {@internal Missing Short Description}} 953 983 * 954 * @since unknown984 * @since 2.5.0 955 985 * 956 986 * @param unknown_type $q … … 976 1006 unset($q['post_mime_type']); 977 1007 978 wp($q); 1008 if ( isset($q['detached']) ) 1009 add_filter('posts_where', '_edit_attachments_query_helper'); 1010 1011 wp( $q ); 1012 1013 if ( isset($q['detached']) ) 1014 remove_filter('posts_where', '_edit_attachments_query_helper'); 979 1015 980 1016 return array($post_mime_types, $avail_post_mime_types); 981 1017 } 982 1018 1019 function _edit_attachments_query_helper($where) { 1020 return $where .= ' AND post_parent < 1'; 1021 } 1022 983 1023 /** 984 1024 * {@internal Missing Short Description}} 985 1025 * 986 1026 * @uses get_user_option() 987 * @since unknown1027 * @since 2.5.0 988 1028 * 989 1029 * @param unknown_type $id … … 1008 1048 * {@internal Missing Short Description}} 1009 1049 * 1010 * @since unknown1050 * @since 2.5.0 1011 1051 * 1012 1052 * @param int|object $id Post ID or post object. … … 1055 1095 if ( !empty($uri) ) 1056 1096 $uri .= '/'; 1057 $permalink = str_replace('%pagename%', " ${uri}%pagename%", $permalink);1097 $permalink = str_replace('%pagename%', "{$uri}%pagename%", $permalink); 1058 1098 } 1059 1099 … … 1072 1112 * intended to be used for the inplace editor of the permalink post slug on in the post (and page?) editor. 1073 1113 * 1074 * @since unknown1114 * @since 2.5.0 1075 1115 * 1076 1116 * @param int|object $id Post ID or post object. … … 1095 1135 if ( false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%') ) { 1096 1136 $return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink">' . $permalink . "</span>\n"; 1097 if ( current_user_can( 'manage_options' ) && !( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) )1137 if ( '' == get_option( 'permalink_structure' ) && current_user_can( 'manage_options' ) && !( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) ) 1098 1138 $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button" target="_blank">' . __('Change Permalinks') . "</a></span>\n"; 1099 1139 if ( isset($view_post) ) … … 1178 1218 return false; 1179 1219 1180 $lock = get_post_meta( $post->ID, '_edit_lock', true ); 1181 $last = get_post_meta( $post->ID, '_edit_last', true ); 1220 if ( !$lock = get_post_meta( $post->ID, '_edit_lock', true ) ) 1221 return false; 1222 1223 $lock = explode( ':', $lock ); 1224 $time = $lock[0]; 1225 $user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true ); 1182 1226 1183 1227 $time_window = apply_filters( 'wp_check_post_lock_window', AUTOSAVE_INTERVAL * 2 ); 1184 1228 1185 if ( $ lock && $lock > time() - $time_window && $last!= get_current_user_id() )1186 return $ last;1229 if ( $time && $time > time() - $time_window && $user != get_current_user_id() ) 1230 return $user; 1187 1231 return false; 1188 1232 } … … 1199 1243 if ( !$post = get_post( $post_id ) ) 1200 1244 return false; 1201 if ( 0 == get_current_user_id() )1245 if ( 0 == ($user_id = get_current_user_id()) ) 1202 1246 return false; 1203 1247 1204 1248 $now = time(); 1205 1206 update_post_meta( $post->ID, '_edit_lock', $now ); 1249 $lock = "$now:$user_id"; 1250 1251 update_post_meta( $post->ID, '_edit_lock', $lock ); 1207 1252 } 1208 1253 … … 1215 1260 function _admin_notice_post_locked() { 1216 1261 global $post; 1217 $last_user = get_userdata( get_post_meta( $post->ID, '_edit_last', true ) ); 1262 1263 $lock = explode( ':', get_post_meta( $post->ID, '_edit_lock', true ) ); 1264 $user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true ); 1265 $last_user = get_userdata( $user ); 1218 1266 $last_user_name = $last_user ? $last_user->display_name : __('Somebody'); 1219 1267 … … 1360 1408 1361 1409 if ( $teeny ) { 1362 $plugins = apply_filters( 'teeny_mce_plugins', array(' safari', 'inlinepopups', 'media', 'fullscreen', 'wordpress') );1410 $plugins = apply_filters( 'teeny_mce_plugins', array('inlinepopups', 'fullscreen', 'wordpress', 'wplink', 'wpdialogs') ); 1363 1411 $ext_plugins = ''; 1364 1412 } else { 1365 $plugins = array( ' safari', 'inlinepopups', 'spellchecker', 'paste', 'wordpress', 'media', 'fullscreen', 'wpeditimage', 'wpgallery', 'tabfocus' );1413 $plugins = array( 'inlinepopups', 'spellchecker', 'paste', 'wordpress', 'fullscreen', 'wpeditimage', 'wpgallery', 'tabfocus', 'wplink', 'wpdialogs' ); 1366 1414 1367 1415 /* … … 1444 1492 } 1445 1493 1446 $plugins = implode($plugins, ',');1447 1448 1494 if ( $teeny ) { 1449 1495 $mce_buttons = apply_filters( 'teeny_mce_buttons', array('bold, italic, underline, blockquote, separator, strikethrough, bullist, numlist,justifyleft, justifycenter, justifyright, undo, redo, link, unlink, fullscreen') ); … … 1454 1500 $mce_buttons = implode($mce_buttons, ','); 1455 1501 1456 $mce_buttons_2 = array('formatselect', 'underline', 'justifyfull', 'forecolor', '|', 'pastetext', 'pasteword', 'removeformat', '|', 'media', 'charmap', '|', 'outdent', 'indent', '|', 'undo', 'redo', 'wp_help' ); 1457 if ( is_multisite() ) 1458 unset( $mce_buttons_2[ array_search( 'media', $mce_buttons_2 ) ] ); 1502 $mce_buttons_2 = array( 'formatselect', 'underline', 'justifyfull', 'forecolor', '|', 'pastetext', 'pasteword', 'removeformat', '|', 'charmap', '|', 'outdent', 'indent', '|', 'undo', 'redo', 'wp_help' ); 1459 1503 $mce_buttons_2 = apply_filters('mce_buttons_2', $mce_buttons_2); 1460 1504 $mce_buttons_2 = implode($mce_buttons_2, ','); … … 1487 1531 'theme_advanced_resize_horizontal' => false, 1488 1532 'dialog_type' => 'modal', 1533 'formats' => "{ 1534 alignleft : [ 1535 {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'left'}}, 1536 {selector : 'img,table', classes : 'alignleft'} 1537 ], 1538 aligncenter : [ 1539 {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'center'}}, 1540 {selector : 'img,table', classes : 'aligncenter'} 1541 ], 1542 alignright : [ 1543 {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'right'}}, 1544 {selector : 'img,table', classes : 'alignright'} 1545 ], 1546 strikethrough : {inline : 'del'} 1547 }", 1489 1548 'relative_urls' => false, 1490 1549 'remove_script_host' => false, … … 1500 1559 'paste_remove_spans' => true, 1501 1560 'paste_strip_class_attributes' => 'all', 1561 'paste_text_use_dialog' => true, 1502 1562 'wpeditimage_disable_captions' => $no_captions, 1503 'plugins' => $plugins1563 'plugins' => implode( ',', $plugins ), 1504 1564 ); 1505 1565 … … 1507 1567 $mce_css = array(); 1508 1568 $style_uri = get_stylesheet_directory_uri(); 1509 if ( TEMPLATEPATH == STYLESHEETPATH) {1569 if ( ! is_child_theme() ) { 1510 1570 foreach ( $editor_styles as $file ) 1511 1571 $mce_css[] = "$style_uri/$file"; … … 1515 1575 $template_dir = get_template_directory(); 1516 1576 foreach ( $editor_styles as $file ) { 1577 if ( file_exists( "$template_dir/$file" ) ) 1578 $mce_css[] = "$template_uri/$file"; 1517 1579 if ( file_exists( "$style_dir/$file" ) ) 1518 1580 $mce_css[] = "$style_uri/$file"; 1519 if ( file_exists( "$template_dir/$file" ) )1520 $mce_css[] = "$template_uri/$file";1521 1581 } 1522 1582 } … … 1571 1631 1572 1632 $mce_options = ''; 1573 foreach ( $initArray as $k => $v ) 1574 $mce_options .= $k . ':"' . $v . '", '; 1633 foreach ( $initArray as $k => $v ) { 1634 if ( is_bool($v) ) { 1635 $val = $v ? 'true' : 'false'; 1636 $mce_options .= $k . ':' . $val . ', '; 1637 continue; 1638 } elseif ( !empty($v) && is_string($v) && ( '{' == $v{0} || '[' == $v{0} ) ) { 1639 $mce_options .= $k . ':' . $v . ', '; 1640 continue; 1641 } 1642 1643 $mce_options .= $k . ':"' . $v . '", '; 1644 } 1575 1645 1576 1646 $mce_options = rtrim( trim($mce_options), '\n\r,' ); ?> … … 1602 1672 <script type="text/javascript"> 1603 1673 /* <![CDATA[ */ 1604 <?php if ( $ext_plugins ) echo "$ext_plugins\n"; ?> 1605 <?php if ( $compressed ) { ?> 1606 tinyMCEPreInit.go(); 1607 <?php } else { ?> 1674 <?php 1675 if ( $ext_plugins ) 1676 echo "$ext_plugins\n"; 1677 1678 if ( ! $compressed ) { 1679 ?> 1608 1680 (function(){var t=tinyMCEPreInit,sl=tinymce.ScriptLoader,ln=t.mceInit.language,th=t.mceInit.theme,pl=t.mceInit.plugins;sl.markDone(t.base+'/langs/'+ln+'.js');sl.markDone(t.base+'/themes/'+th+'/langs/'+ln+'.js');sl.markDone(t.base+'/themes/'+th+'/langs/'+ln+'_dlg.js');tinymce.each(pl.split(','),function(n){if(n&&n.charAt(0)!='-'){sl.markDone(t.base+'/plugins/'+n+'/langs/'+ln+'.js');sl.markDone(t.base+'/plugins/'+n+'/langs/'+ln+'_dlg.js');}});})(); 1609 1681 <?php } ?> … … 1612 1684 </script> 1613 1685 <?php 1614 } 1686 1687 // Load additional inline scripts based on active plugins. 1688 if ( in_array( 'wpdialogs', $plugins ) ) { 1689 wp_print_scripts( array( 'wpdialogs-popup' ) ); 1690 wp_print_styles('wp-jquery-ui-dialog'); 1691 } 1692 if ( in_array( 'wplink', $plugins ) ) { 1693 require_once ABSPATH . 'wp-admin/includes/internal-linking.php'; 1694 add_action('tiny_mce_preload_dialogs', 'wp_link_dialog'); 1695 wp_print_scripts('wplink'); 1696 wp_print_styles('wplink'); 1697 } 1698 } 1699 function wp_tiny_mce_preload_dialogs() { ?> 1700 <div id="preloaded-dialogs" style="display:none;"> 1701 <?php do_action('tiny_mce_preload_dialogs'); ?> 1702 </div> 1703 <?php }
Note: See TracChangeset
for help on using the changeset viewer.