Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.0/wp-admin/includes/post.php

    r17457 r17401  
    1616 *
    1717 * @param bool $update Are we updating a pre-existing post?
    18  * @param array $post_data Array of post data. Defaults to the contents of $_POST.
     18 * @param post_data array Array of post data. Defaults to the contents of $_POST.
    1919 * @return object|bool WP_Error on failure, true on success.
    2020 */
     
    126126 * Update an existing post with values provided in $_POST.
    127127 *
    128  * @since 1.5.0
     128 * @since unknown
    129129 *
    130130 * @param array $post_data Optional.
     
    137137
    138138    $post_ID = (int) $post_data['post_ID'];
    139     $post = get_post( $post_ID );
    140     $post_data['post_type'] = $post->post_type;
    141139
    142140    $ptype = get_post_type_object($post_data['post_type']);
     
    159157
    160158    $post_data = _wp_translate_postdata( true, $post_data );
     159    if ( 'autosave' != $post_data['action']  && 'auto-draft' == $post_data['post_status'] )
     160        $post_data['post_status'] = 'draft';
    161161    if ( is_wp_error($post_data) )
    162162        wp_die( $post_data->get_error_message() );
    163     if ( 'autosave' != $post_data['action']  && 'auto-draft' == $post_data['post_status'] )
    164         $post_data['post_status'] = 'draft';
    165163
    166164    if ( isset($post_data['visibility']) ) {
     
    180178    }
    181179
    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 
    195180    // Meta Stuff
    196181    if ( isset($post_data['meta']) && $post_data['meta'] ) {
    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;
     182        foreach ( $post_data['meta'] as $key => $value )
    202183            update_meta( $key, $value['key'], $value['value'] );
    203         }
    204184    }
    205185
    206186    if ( isset($post_data['deletemeta']) && $post_data['deletemeta'] ) {
    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;
     187        foreach ( $post_data['deletemeta'] as $key => $value )
    212188            delete_meta( $key );
    213         }
    214189    }
    215190
     
    231206    wp_set_post_lock( $post_ID, $GLOBALS['current_user']->ID );
    232207
    233     if ( current_user_can( $ptype->cap->edit_others_posts ) ) {
    234         if ( ! empty( $post_data['sticky'] ) )
    235             stick_post( $post_ID );
     208    if ( current_user_can( 'edit_others_posts' ) ) {
     209        if ( !empty($post_data['sticky']) )
     210            stick_post($post_ID);
    236211        else
    237             unstick_post( $post_ID );
     212            unstick_post($post_ID);
    238213    }
    239214
     
    362337        $updated[] = wp_update_post( $post_data );
    363338
    364         if ( isset( $post_data['sticky'] ) && current_user_can( $ptype->cap->edit_others_posts ) ) {
     339        if ( isset( $post_data['sticky'] ) && current_user_can( 'edit_others_posts' ) ) {
    365340            if ( 'sticky' == $post_data['sticky'] )
    366341                stick_post( $post_ID );
     
    377352 * Default post information to use when populating the "Write Post" form.
    378353 *
    379  * @since 2.0.0
    380  *
    381  * @param string $post_type A post type string, defaults to 'post'.
     354 * @since unknown
     355 *
     356 *@param string A post type string, defaults to 'post'.
    382357 * @return object stdClass object containing all the default post data as attributes
    383358 */
     
    404379        $post_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) );
    405380        $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' ) );
    408381    } else {
    409382        $post->ID = 0;
     
    449422 * Get an existing post and format it for editing.
    450423 *
    451  * @since 2.0.0
     424 * @since unknown
    452425 *
    453426 * @param unknown_type $id
     
    467440 * Determine if a post exists based on title, content, and date
    468441 *
    469  * @since 2.0.0
     442 * @since unknown
    470443 *
    471444 * @param string $title Post title
     
    508481 * Creates a new post from the "Write Post" form using $_POST information.
    509482 *
    510  * @since 2.1.0
     483 * @since unknown
    511484 *
    512485 * @return unknown
     
    605578 * Calls wp_write_post() and handles the errors.
    606579 *
    607  * @since 2.0.0
     580 * @since unknown
    608581 *
    609582 * @return unknown
     
    624597 * {@internal Missing Short Description}}
    625598 *
    626  * @since 1.2.0
     599 * @since unknown
    627600 *
    628601 * @param unknown_type $post_ID
     
    656629        wp_cache_delete($post_ID, 'post_meta');
    657630        $wpdb->insert( $wpdb->postmeta, array( 'post_id' => $post_ID, 'meta_key' => $metakey, 'meta_value' => $metavalue ) );
    658         $meta_id = $wpdb->insert_id;
    659         do_action( 'added_postmeta', $meta_id, $post_ID, $metakey, $metavalue );
    660 
    661         return $meta_id;
     631        do_action( 'added_postmeta', $wpdb->insert_id, $post_ID, $metakey, $metavalue );
     632
     633        return $wpdb->insert_id;
    662634    }
    663635    return false;
     
    667639 * {@internal Missing Short Description}}
    668640 *
    669  * @since 1.2.0
     641 * @since unknown
    670642 *
    671643 * @param unknown_type $mid
     
    689661 * Get a list of previously defined keys.
    690662 *
    691  * @since 1.2.0
     663 * @since unknown
    692664 *
    693665 * @return unknown
     
    708680 * {@internal Missing Short Description}}
    709681 *
    710  * @since 2.1.0
     682 * @since unknown
    711683 *
    712684 * @param unknown_type $mid
     
    730702 * Some postmeta stuff.
    731703 *
    732  * @since 1.2.0
     704 * @since unknown
    733705 *
    734706 * @param unknown_type $postid
     
    747719 * {@internal Missing Short Description}}
    748720 *
    749  * @since 1.2.0
     721 * @since unknown
    750722 *
    751723 * @param unknown_type $meta_id
     
    790762 * Replace hrefs of attachment anchors with up-to-date permalinks.
    791763 *
    792  * @since 2.3.0
     764 * @since unknown
    793765 * @access private
    794766 *
     
    846818 * Move child posts to a new parent.
    847819 *
    848  * @since 2.3.0
     820 * @since unknown
    849821 * @access private
    850822 *
     
    911883    }
    912884
    913     if ( isset($q['orderby']) )
    914         $orderby = $q['orderby'];
    915     elseif ( isset($q['post_status']) && in_array($q['post_status'], array('pending', 'draft')) )
     885    if ( isset($q['post_status']) && 'pending' === $q['post_status'] ) {
     886        $order = 'ASC';
    916887        $orderby = 'modified';
    917 
    918     if ( isset($q['order']) )
    919         $order = $q['order'];
    920     elseif ( isset($q['post_status']) && 'pending' == $q['post_status'] )
    921         $order = 'ASC';
     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    }
    922895
    923896    $per_page = 'edit_' . $post_type . '_per_page';
     
    932905
    933906    // Hierarchical types require special args.
    934     if ( is_post_type_hierarchical( $post_type ) && !isset($orderby) ) {
     907    if ( is_post_type_hierarchical( $post_type ) ) {
    935908        $query['orderby'] = 'menu_order title';
    936909        $query['order'] = 'asc';
     
    938911        $query['posts_per_archive_page'] = -1;
    939912    }
    940 
    941     if ( ! empty( $q['show_sticky'] ) )
    942         $query['post__in'] = (array) get_option( 'sticky_posts' );
    943913
    944914    wp( $query );
     
    967937 * {@internal Missing Short Description}}
    968938 *
    969  * @since 2.5.0
     939 * @since unknown
    970940 *
    971941 * @param unknown_type $type
     
    982952 * {@internal Missing Short Description}}
    983953 *
    984  * @since 2.5.0
     954 * @since unknown
    985955 *
    986956 * @param unknown_type $q
     
    1006976        unset($q['post_mime_type']);
    1007977
    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');
     978    wp($q);
    1015979
    1016980    return array($post_mime_types, $avail_post_mime_types);
    1017981}
    1018982
    1019 function _edit_attachments_query_helper($where) {
    1020     return $where .= ' AND post_parent < 1';
    1021 }
    1022 
    1023983/**
    1024984 * {@internal Missing Short Description}}
    1025985 *
    1026986 * @uses get_user_option()
    1027  * @since 2.5.0
     987 * @since unknown
    1028988 *
    1029989 * @param unknown_type $id
     
    10481008 * {@internal Missing Short Description}}
    10491009 *
    1050  * @since 2.5.0
     1010 * @since unknown
    10511011 *
    10521012 * @param int|object $id    Post ID or post object.
     
    10951055        if ( !empty($uri) )
    10961056            $uri .= '/';
    1097         $permalink = str_replace('%pagename%', "{$uri}%pagename%", $permalink);
     1057        $permalink = str_replace('%pagename%', "${uri}%pagename%", $permalink);
    10981058    }
    10991059
     
    11121072 * intended to be used for the inplace editor of the permalink post slug on in the post (and page?) editor.
    11131073 *
    1114  * @since 2.5.0
     1074 * @since unknown
    11151075 *
    11161076 * @param int|object $id Post ID or post object.
     
    11351095    if ( false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%') ) {
    11361096        $return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink">' . $permalink . "</span>\n";
    1137         if ( '' == get_option( 'permalink_structure' ) && current_user_can( 'manage_options' ) && !( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) )
     1097        if ( current_user_can( 'manage_options' ) && !( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) )
    11381098            $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button" target="_blank">' . __('Change Permalinks') . "</a></span>\n";
    11391099        if ( isset($view_post) )
     
    12181178        return false;
    12191179
    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 );
     1180    $lock = get_post_meta( $post->ID, '_edit_lock', true );
     1181    $last = get_post_meta( $post->ID, '_edit_last', true );
    12261182
    12271183    $time_window = apply_filters( 'wp_check_post_lock_window', AUTOSAVE_INTERVAL * 2 );
    12281184
    1229     if ( $time && $time > time() - $time_window && $user != get_current_user_id() )
    1230         return $user;
     1185    if ( $lock && $lock > time() - $time_window && $last != get_current_user_id() )
     1186        return $last;
    12311187    return false;
    12321188}
     
    12431199    if ( !$post = get_post( $post_id ) )
    12441200        return false;
    1245     if ( 0 == ($user_id = get_current_user_id()) )
     1201    if ( 0 == get_current_user_id() )
    12461202        return false;
    12471203
    12481204    $now = time();
    1249     $lock = "$now:$user_id";
    1250 
    1251     update_post_meta( $post->ID, '_edit_lock', $lock );
     1205
     1206    update_post_meta( $post->ID, '_edit_lock', $now );
    12521207}
    12531208
     
    12601215function _admin_notice_post_locked() {
    12611216    global $post;
    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 );
     1217    $last_user = get_userdata( get_post_meta( $post->ID, '_edit_last', true ) );
    12661218    $last_user_name = $last_user ? $last_user->display_name : __('Somebody');
    12671219
     
    14081360
    14091361    if ( $teeny ) {
    1410         $plugins = apply_filters( 'teeny_mce_plugins', array('inlinepopups', 'fullscreen', 'wordpress', 'wplink', 'wpdialogs') );
     1362        $plugins = apply_filters( 'teeny_mce_plugins', array('safari', 'inlinepopups', 'media', 'fullscreen', 'wordpress') );
    14111363        $ext_plugins = '';
    14121364    } else {
    1413         $plugins = array( 'inlinepopups', 'spellchecker', 'paste', 'wordpress', 'fullscreen', 'wpeditimage', 'wpgallery', 'tabfocus', 'wplink', 'wpdialogs' );
     1365        $plugins = array( 'safari', 'inlinepopups', 'spellchecker', 'paste', 'wordpress', 'media', 'fullscreen', 'wpeditimage', 'wpgallery', 'tabfocus' );
    14141366
    14151367        /*
     
    14921444    }
    14931445
     1446    $plugins = implode($plugins, ',');
     1447
    14941448    if ( $teeny ) {
    14951449        $mce_buttons = apply_filters( 'teeny_mce_buttons', array('bold, italic, underline, blockquote, separator, strikethrough, bullist, numlist,justifyleft, justifycenter, justifyright, undo, redo, link, unlink, fullscreen') );
     
    15001454        $mce_buttons = implode($mce_buttons, ',');
    15011455
    1502         $mce_buttons_2 = array( 'formatselect', 'underline', 'justifyfull', 'forecolor', '|', 'pastetext', 'pasteword', 'removeformat', '|', 'charmap', '|', 'outdent', 'indent', '|', 'undo', 'redo', 'wp_help' );
     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 ) ] );
    15031459        $mce_buttons_2 = apply_filters('mce_buttons_2', $mce_buttons_2);
    15041460        $mce_buttons_2 = implode($mce_buttons_2, ',');
     
    15311487        'theme_advanced_resize_horizontal' => false,
    15321488        '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         }",
    15481489        'relative_urls' => false,
    15491490        'remove_script_host' => false,
     
    15591500        'paste_remove_spans' => true,
    15601501        'paste_strip_class_attributes' => 'all',
    1561         'paste_text_use_dialog' => true,
    15621502        'wpeditimage_disable_captions' => $no_captions,
    1563         'plugins' => implode( ',', $plugins ),
     1503        'plugins' => $plugins
    15641504    );
    15651505
     
    15671507        $mce_css = array();
    15681508        $style_uri = get_stylesheet_directory_uri();
    1569         if ( ! is_child_theme() ) {
     1509        if ( TEMPLATEPATH == STYLESHEETPATH ) {
    15701510            foreach ( $editor_styles as $file )
    15711511                $mce_css[] = "$style_uri/$file";
     
    15751515            $template_dir = get_template_directory();
    15761516            foreach ( $editor_styles as $file ) {
     1517                if ( file_exists( "$style_dir/$file" ) )
     1518                    $mce_css[] = "$style_uri/$file";
    15771519                if ( file_exists( "$template_dir/$file" ) )
    15781520                    $mce_css[] = "$template_uri/$file";
    1579                 if ( file_exists( "$style_dir/$file" ) )
    1580                     $mce_css[] = "$style_uri/$file";
    15811521            }
    15821522        }
     
    16311571
    16321572    $mce_options = '';
    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     }
     1573    foreach ( $initArray as $k => $v )
     1574        $mce_options .= $k . ':"' . $v . '", ';
    16451575
    16461576    $mce_options = rtrim( trim($mce_options), '\n\r,' ); ?>
     
    16721602<script type="text/javascript">
    16731603/* <![CDATA[ */
    1674 <?php
    1675     if ( $ext_plugins )
    1676         echo "$ext_plugins\n";
    1677 
    1678     if ( ! $compressed ) {
    1679 ?>
     1604<?php if ( $ext_plugins ) echo "$ext_plugins\n"; ?>
     1605<?php if ( $compressed ) { ?>
     1606tinyMCEPreInit.go();
     1607<?php } else { ?>
    16801608(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');}});})();
    16811609<?php } ?>
     
    16841612</script>
    16851613<?php
    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 }
     1614}
Note: See TracChangeset for help on using the changeset viewer.