Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r17401 r17457  
    1616 *
    1717 * @param bool $update Are we updating a pre-existing post?
    18  * @param post_data array Array of post data. Defaults to the contents of $_POST.
     18 * @param array $post_data 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 unknown
     128 * @since 1.5.0
    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;
    139141
    140142    $ptype = get_post_type_object($post_data['post_type']);
     
    157159
    158160    $post_data = _wp_translate_postdata( true, $post_data );
     161    if ( is_wp_error($post_data) )
     162        wp_die( $post_data->get_error_message() );
    159163    if ( 'autosave' != $post_data['action']  && 'auto-draft' == $post_data['post_status'] )
    160164        $post_data['post_status'] = 'draft';
    161     if ( is_wp_error($post_data) )
    162         wp_die( $post_data->get_error_message() );
    163165
    164166    if ( isset($post_data['visibility']) ) {
     
    178180    }
    179181
     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
    180195    // Meta Stuff
    181196    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;
    183202            update_meta( $key, $value['key'], $value['value'] );
     203        }
    184204    }
    185205
    186206    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;
    188212            delete_meta( $key );
     213        }
    189214    }
    190215
     
    206231    wp_set_post_lock( $post_ID, $GLOBALS['current_user']->ID );
    207232
    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 );
    211236        else
    212             unstick_post($post_ID);
     237            unstick_post( $post_ID );
    213238    }
    214239
     
    337362        $updated[] = wp_update_post( $post_data );
    338363
    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 ) ) {
    340365            if ( 'sticky' == $post_data['sticky'] )
    341366                stick_post( $post_ID );
     
    352377 * Default post information to use when populating the "Write Post" form.
    353378 *
    354  * @since unknown
    355  *
    356  *@param string A post type string, defaults to 'post'.
     379 * @since 2.0.0
     380 *
     381 * @param string $post_type A post type string, defaults to 'post'.
    357382 * @return object stdClass object containing all the default post data as attributes
    358383 */
     
    379404        $post_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) );
    380405        $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' ) );
    381408    } else {
    382409        $post->ID = 0;
     
    422449 * Get an existing post and format it for editing.
    423450 *
    424  * @since unknown
     451 * @since 2.0.0
    425452 *
    426453 * @param unknown_type $id
     
    440467 * Determine if a post exists based on title, content, and date
    441468 *
    442  * @since unknown
     469 * @since 2.0.0
    443470 *
    444471 * @param string $title Post title
     
    481508 * Creates a new post from the "Write Post" form using $_POST information.
    482509 *
    483  * @since unknown
     510 * @since 2.1.0
    484511 *
    485512 * @return unknown
     
    578605 * Calls wp_write_post() and handles the errors.
    579606 *
    580  * @since unknown
     607 * @since 2.0.0
    581608 *
    582609 * @return unknown
     
    597624 * {@internal Missing Short Description}}
    598625 *
    599  * @since unknown
     626 * @since 1.2.0
    600627 *
    601628 * @param unknown_type $post_ID
     
    629656        wp_cache_delete($post_ID, 'post_meta');
    630657        $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;
    634662    }
    635663    return false;
     
    639667 * {@internal Missing Short Description}}
    640668 *
    641  * @since unknown
     669 * @since 1.2.0
    642670 *
    643671 * @param unknown_type $mid
     
    661689 * Get a list of previously defined keys.
    662690 *
    663  * @since unknown
     691 * @since 1.2.0
    664692 *
    665693 * @return unknown
     
    680708 * {@internal Missing Short Description}}
    681709 *
    682  * @since unknown
     710 * @since 2.1.0
    683711 *
    684712 * @param unknown_type $mid
     
    702730 * Some postmeta stuff.
    703731 *
    704  * @since unknown
     732 * @since 1.2.0
    705733 *
    706734 * @param unknown_type $postid
     
    719747 * {@internal Missing Short Description}}
    720748 *
    721  * @since unknown
     749 * @since 1.2.0
    722750 *
    723751 * @param unknown_type $meta_id
     
    762790 * Replace hrefs of attachment anchors with up-to-date permalinks.
    763791 *
    764  * @since unknown
     792 * @since 2.3.0
    765793 * @access private
    766794 *
     
    818846 * Move child posts to a new parent.
    819847 *
    820  * @since unknown
     848 * @since 2.3.0
    821849 * @access private
    822850 *
     
    883911    }
    884912
    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'] )
    886921        $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     }
    895922
    896923    $per_page = 'edit_' . $post_type . '_per_page';
     
    905932
    906933    // Hierarchical types require special args.
    907     if ( is_post_type_hierarchical( $post_type ) ) {
     934    if ( is_post_type_hierarchical( $post_type ) && !isset($orderby) ) {
    908935        $query['orderby'] = 'menu_order title';
    909936        $query['order'] = 'asc';
     
    911938        $query['posts_per_archive_page'] = -1;
    912939    }
     940
     941    if ( ! empty( $q['show_sticky'] ) )
     942        $query['post__in'] = (array) get_option( 'sticky_posts' );
    913943
    914944    wp( $query );
     
    937967 * {@internal Missing Short Description}}
    938968 *
    939  * @since unknown
     969 * @since 2.5.0
    940970 *
    941971 * @param unknown_type $type
     
    952982 * {@internal Missing Short Description}}
    953983 *
    954  * @since unknown
     984 * @since 2.5.0
    955985 *
    956986 * @param unknown_type $q
     
    9761006        unset($q['post_mime_type']);
    9771007
    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');
    9791015
    9801016    return array($post_mime_types, $avail_post_mime_types);
    9811017}
    9821018
     1019function _edit_attachments_query_helper($where) {
     1020    return $where .= ' AND post_parent < 1';
     1021}
     1022
    9831023/**
    9841024 * {@internal Missing Short Description}}
    9851025 *
    9861026 * @uses get_user_option()
    987  * @since unknown
     1027 * @since 2.5.0
    9881028 *
    9891029 * @param unknown_type $id
     
    10081048 * {@internal Missing Short Description}}
    10091049 *
    1010  * @since unknown
     1050 * @since 2.5.0
    10111051 *
    10121052 * @param int|object $id    Post ID or post object.
     
    10551095        if ( !empty($uri) )
    10561096            $uri .= '/';
    1057         $permalink = str_replace('%pagename%', "${uri}%pagename%", $permalink);
     1097        $permalink = str_replace('%pagename%', "{$uri}%pagename%", $permalink);
    10581098    }
    10591099
     
    10721112 * intended to be used for the inplace editor of the permalink post slug on in the post (and page?) editor.
    10731113 *
    1074  * @since unknown
     1114 * @since 2.5.0
    10751115 *
    10761116 * @param int|object $id Post ID or post object.
     
    10951135    if ( false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%') ) {
    10961136        $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') ) )
    10981138            $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button" target="_blank">' . __('Change Permalinks') . "</a></span>\n";
    10991139        if ( isset($view_post) )
     
    11781218        return false;
    11791219
    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 );
    11821226
    11831227    $time_window = apply_filters( 'wp_check_post_lock_window', AUTOSAVE_INTERVAL * 2 );
    11841228
    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;
    11871231    return false;
    11881232}
     
    11991243    if ( !$post = get_post( $post_id ) )
    12001244        return false;
    1201     if ( 0 == get_current_user_id() )
     1245    if ( 0 == ($user_id = get_current_user_id()) )
    12021246        return false;
    12031247
    12041248    $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 );
    12071252}
    12081253
     
    12151260function _admin_notice_post_locked() {
    12161261    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 );
    12181266    $last_user_name = $last_user ? $last_user->display_name : __('Somebody');
    12191267
     
    13601408
    13611409    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') );
    13631411        $ext_plugins = '';
    13641412    } 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' );
    13661414
    13671415        /*
     
    14441492    }
    14451493
    1446     $plugins = implode($plugins, ',');
    1447 
    14481494    if ( $teeny ) {
    14491495        $mce_buttons = apply_filters( 'teeny_mce_buttons', array('bold, italic, underline, blockquote, separator, strikethrough, bullist, numlist,justifyleft, justifycenter, justifyright, undo, redo, link, unlink, fullscreen') );
     
    14541500        $mce_buttons = implode($mce_buttons, ',');
    14551501
    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' );
    14591503        $mce_buttons_2 = apply_filters('mce_buttons_2', $mce_buttons_2);
    14601504        $mce_buttons_2 = implode($mce_buttons_2, ',');
     
    14871531        'theme_advanced_resize_horizontal' => false,
    14881532        '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        }",
    14891548        'relative_urls' => false,
    14901549        'remove_script_host' => false,
     
    15001559        'paste_remove_spans' => true,
    15011560        'paste_strip_class_attributes' => 'all',
     1561        'paste_text_use_dialog' => true,
    15021562        'wpeditimage_disable_captions' => $no_captions,
    1503         'plugins' => $plugins
     1563        'plugins' => implode( ',', $plugins ),
    15041564    );
    15051565
     
    15071567        $mce_css = array();
    15081568        $style_uri = get_stylesheet_directory_uri();
    1509         if ( TEMPLATEPATH == STYLESHEETPATH ) {
     1569        if ( ! is_child_theme() ) {
    15101570            foreach ( $editor_styles as $file )
    15111571                $mce_css[] = "$style_uri/$file";
     
    15151575            $template_dir = get_template_directory();
    15161576            foreach ( $editor_styles as $file ) {
     1577                if ( file_exists( "$template_dir/$file" ) )
     1578                    $mce_css[] = "$template_uri/$file";
    15171579                if ( file_exists( "$style_dir/$file" ) )
    15181580                    $mce_css[] = "$style_uri/$file";
    1519                 if ( file_exists( "$template_dir/$file" ) )
    1520                     $mce_css[] = "$template_uri/$file";
    15211581            }
    15221582        }
     
    15711631
    15721632    $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    }
    15751645
    15761646    $mce_options = rtrim( trim($mce_options), '\n\r,' ); ?>
     
    16021672<script type="text/javascript">
    16031673/* <![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?>
    16081680(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');}});})();
    16091681<?php } ?>
     
    16121684</script>
    16131685<?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}
     1699function 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.