Make WordPress Core

Changeset 15688


Ignore:
Timestamp:
10/03/2010 02:58:59 AM (14 years ago)
Author:
nacin
Message:

Move some post and taxonomy functions from admin/includes to wp-includes in preparation for QuickPress template tag. Moves get_tags_to_edit, get_terms_to_edit, get_default_post_to_edit, media_buttons, _media_button, get_upload_iframe_src. Also introduce get_media_buttons as a wrapper for media_buttons. props jorbin, see #14966.

Location:
trunk
Files:
6 edited

Legend:

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

    r15590 r15688  
    344344</html>
    345345<?php
    346 }
    347 
    348 /**
    349  * {@internal Missing Short Description}}
    350  *
    351  * @since unknown
    352  */
    353 function media_buttons() {
    354     $do_image = $do_audio = $do_video = true;
    355     if ( is_multisite() ) {
    356         $media_buttons = get_site_option( 'mu_media_buttons' );
    357         if ( empty($media_buttons['image']) )
    358             $do_image = false;
    359         if ( empty($media_buttons['audio']) )
    360             $do_audio = false;
    361         if ( empty($media_buttons['video']) )
    362             $do_video = false;
    363     }
    364     $out = '';
    365 
    366     if ( $do_image )
    367         $out .= _media_button(__('Add an Image'), 'images/media-button-image.gif?ver=20100531', 'image');
    368     if ( $do_video )
    369         $out .= _media_button(__('Add Video'), 'images/media-button-video.gif?ver=20100531', 'video');
    370     if ( $do_audio )
    371         $out .= _media_button(__('Add Audio'), 'images/media-button-music.gif?ver=20100531', 'audio');
    372 
    373     $out .= _media_button(__('Add Media'), 'images/media-button-other.gif?ver=20100531', 'media');
    374 
    375     $context = apply_filters('media_buttons_context', __('Upload/Insert %s'));
    376 
    377     printf($context, $out);
    378 }
    379 add_action( 'media_buttons', 'media_buttons' );
    380 
    381 function _media_button($title, $icon, $type) {
    382     return "<a href='" . esc_url( get_upload_iframe_src($type) ) . "' id='add_$type' class='thickbox' title='$title'><img src='" . esc_url( admin_url( $icon ) ) . "' alt='$title' /></a>";
    383 }
    384 
    385 function get_upload_iframe_src($type) {
    386     global $post_ID, $temp_ID;
    387     $uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID);
    388     $upload_iframe_src = add_query_arg('post_id', $uploading_iframe_ID, 'media-upload.php');
    389 
    390     if ( 'media' != $type )
    391         $upload_iframe_src = add_query_arg('type', $type, $upload_iframe_src);
    392     $upload_iframe_src = apply_filters($type . '_upload_iframe_src', $upload_iframe_src);
    393 
    394     return add_query_arg('TB_iframe', true, $upload_iframe_src);
    395346}
    396347
  • trunk/wp-admin/includes/post.php

    r15683 r15688  
    349349}
    350350
    351 /**
    352  * Default post information to use when populating the "Write Post" form.
    353  *
    354  * @since unknown
    355  *
    356  * @param string $post_type A post type string, defaults to 'post'.
    357  * @return object stdClass object containing all the default post data as attributes
    358  */
    359 function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) {
    360     global $wpdb;
    361 
    362     $post_title = '';
    363     if ( !empty( $_REQUEST['post_title'] ) )
    364         $post_title = esc_html( stripslashes( $_REQUEST['post_title'] ));
    365 
    366     $post_content = '';
    367     if ( !empty( $_REQUEST['content'] ) )
    368         $post_content = esc_html( stripslashes( $_REQUEST['content'] ));
    369 
    370     $post_excerpt = '';
    371     if ( !empty( $_REQUEST['excerpt'] ) )
    372         $post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] ));
    373 
    374     if ( $create_in_db ) {
    375         // Cleanup old auto-drafts more than 7 days old
    376         $old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" );
    377         foreach ( (array) $old_posts as $delete )
    378             wp_delete_post( $delete, true ); // Force delete
    379         $post_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) );
    380         $post = get_post( $post_id );
    381     } else {
    382         $post->ID = 0;
    383         $post->post_author = '';
    384         $post->post_date = '';
    385         $post->post_date_gmt = '';
    386         $post->post_password = '';
    387         $post->post_type = $post_type;
    388         $post->post_status = 'draft';
    389         $post->to_ping = '';
    390         $post->pinged = '';
    391         $post->comment_status = get_option( 'default_comment_status' );
    392         $post->ping_status = get_option( 'default_ping_status' );
    393         $post->post_pingback = get_option( 'default_pingback_flag' );
    394         $post->post_category = get_option( 'default_category' );
    395         $post->page_template = 'default';
    396         $post->post_parent = 0;
    397         $post->menu_order = 0;
    398     }
    399 
    400     $post->post_content = apply_filters( 'default_content', $post_content, $post );
    401     $post->post_title   = apply_filters( 'default_title',   $post_title, $post   );
    402     $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt, $post );
    403     $post->post_name = '';
    404 
    405     return $post;
    406 }
     351
    407352
    408353/**
  • trunk/wp-admin/includes/taxonomy.php

    r15220 r15688  
    195195 * @since unknown
    196196 *
    197  * @param unknown_type $post_id
    198  * @return unknown
    199  */
    200 function get_tags_to_edit( $post_id, $taxonomy = 'post_tag' ) {
    201     return get_terms_to_edit( $post_id, $taxonomy);
    202 }
    203 
    204 /**
    205  * {@internal Missing Short Description}}
    206  *
    207  * @since unknown
    208  *
    209  * @param unknown_type $post_id
    210  * @return unknown
    211  */
    212 function get_terms_to_edit( $post_id, $taxonomy = 'post_tag' ) {
    213     $post_id = (int) $post_id;
    214     if ( !$post_id )
    215         return false;
    216 
    217     $tags = wp_get_post_terms($post_id, $taxonomy, array());
    218 
    219     if ( !$tags )
    220         return false;
    221 
    222     if ( is_wp_error($tags) )
    223         return $tags;
    224 
    225     foreach ( $tags as $tag )
    226         $tag_names[] = $tag->name;
    227     $tags_to_edit = join( ',', $tag_names );
    228     $tags_to_edit = esc_attr( $tags_to_edit );
    229     $tags_to_edit = apply_filters( 'terms_to_edit', $tags_to_edit, $taxonomy );
    230 
    231     return $tags_to_edit;
    232 }
    233 
    234 /**
    235  * {@internal Missing Short Description}}
    236  *
    237  * @since unknown
    238  *
    239197 * @param unknown_type $tag_name
    240198 * @return unknown
  • trunk/wp-includes/media.php

    r15590 r15688  
    13961396    $oembed->providers[$format] = array( $provider, $regex );
    13971397}
     1398
     1399/**
     1400 *
     1401 *
     1402 *
     1403 */
     1404function get_media_buttons(){
     1405    $do_image = $do_audio = $do_video = true;
     1406    if ( is_multisite() ) {
     1407        $media_buttons = get_site_option( 'mu_media_buttons' );
     1408        if ( empty($media_buttons['image']) )
     1409            $do_image = false;
     1410        if ( empty($media_buttons['audio']) )
     1411            $do_audio = false;
     1412        if ( empty($media_buttons['video']) )
     1413            $do_video = false;
     1414    }
     1415    $out = '';
     1416
     1417    if ( $do_image )
     1418        $out .= _media_button(__('Add an Image'), 'images/media-button-image.gif?ver=20100531', 'image');
     1419    if ( $do_video )
     1420        $out .= _media_button(__('Add Video'), 'images/media-button-video.gif?ver=20100531', 'video');
     1421    if ( $do_audio )
     1422        $out .= _media_button(__('Add Audio'), 'images/media-button-music.gif?ver=20100531', 'audio');
     1423
     1424    $out .= _media_button(__('Add Media'), 'images/media-button-other.gif?ver=20100531', 'media');
     1425
     1426    $context = apply_filters('media_buttons_context', __('Upload/Insert %s'));
     1427
     1428    return sprintf($context, $out);
     1429
     1430
     1431}
     1432
     1433/**
     1434 * {@internal Missing Short Description}}
     1435 *
     1436 * @since unknown
     1437 */
     1438function media_buttons() {
     1439    echo get_media_buttons();
     1440}
     1441add_action( 'media_buttons', 'media_buttons' );
     1442
     1443function _media_button($title, $icon, $type) {
     1444    return "<a href='" . esc_url( get_upload_iframe_src($type) ) . "' id='add_$type' class='thickbox' title='$title'><img src='" . esc_url( admin_url( $icon ) ) . "' alt='$title' /></a>";
     1445}
     1446
     1447function get_upload_iframe_src($type) {
     1448    global $post_ID, $temp_ID;
     1449    $uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID);
     1450    $upload_iframe_src = add_query_arg('post_id', $uploading_iframe_ID, 'media-upload.php');
     1451
     1452    if ( 'media' != $type )
     1453        $upload_iframe_src = add_query_arg('type', $type, $upload_iframe_src);
     1454    $upload_iframe_src = apply_filters($type . '_upload_iframe_src', $upload_iframe_src);
     1455
     1456    return add_query_arg('TB_iframe', true, $upload_iframe_src);
     1457}
  • trunk/wp-includes/post.php

    r15635 r15688  
    20752075    $post = get_post($postid, $mode);
    20762076
    2077     if ( 
     2077    if (
    20782078        ( OBJECT == $mode && empty( $post->ID ) ) ||
    20792079        ( OBJECT != $mode && empty( $post['ID'] ) )
     
    47144714    }
    47154715}
     4716
     4717
     4718/**
     4719 * Default post information to use when populating the "Write Post" form.
     4720 *
     4721 * @since unknown
     4722 *
     4723 *@param string A post type string, defaults to 'post'.
     4724 * @return object stdClass object containing all the default post data as attributes
     4725 */
     4726function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) {
     4727    global $wpdb;
     4728
     4729    $post_title = '';
     4730    if ( !empty( $_REQUEST['post_title'] ) )
     4731        $post_title = esc_html( stripslashes( $_REQUEST['post_title'] ));
     4732
     4733    $post_content = '';
     4734    if ( !empty( $_REQUEST['content'] ) )
     4735        $post_content = esc_html( stripslashes( $_REQUEST['content'] ));
     4736
     4737    $post_excerpt = '';
     4738    if ( !empty( $_REQUEST['excerpt'] ) )
     4739        $post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] ));
     4740
     4741    if ( $create_in_db ) {
     4742        // Cleanup old auto-drafts more than 7 days old
     4743        $old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" );
     4744        foreach ( (array) $old_posts as $delete )
     4745            wp_delete_post( $delete, true ); // Force delete
     4746        $post_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) );
     4747        $post = get_post( $post_id );
     4748    } else {
     4749        $post->ID = 0;
     4750        $post->post_author = '';
     4751        $post->post_date = '';
     4752        $post->post_date_gmt = '';
     4753        $post->post_password = '';
     4754        $post->post_type = $post_type;
     4755        $post->post_status = 'draft';
     4756        $post->to_ping = '';
     4757        $post->pinged = '';
     4758        $post->comment_status = get_option( 'default_comment_status' );
     4759        $post->ping_status = get_option( 'default_ping_status' );
     4760        $post->post_pingback = get_option( 'default_pingback_flag' );
     4761        $post->post_category = get_option( 'default_category' );
     4762        $post->page_template = 'default';
     4763        $post->post_parent = 0;
     4764        $post->menu_order = 0;
     4765    }
     4766
     4767    $post->post_content = apply_filters( 'default_content', $post_content, $post );
     4768    $post->post_title   = apply_filters( 'default_title',   $post_title, $post   );
     4769    $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt, $post );
     4770    $post->post_name = '';
     4771
     4772    return $post;
     4773}
  • trunk/wp-includes/taxonomy.php

    r15654 r15688  
    28222822    return apply_filters('get_ancestors', $ancestors, $object_id, $object_type);
    28232823}
     2824
     2825
     2826/**
     2827 * {@internal Missing Short Description}}
     2828 *
     2829 * @since unknown
     2830 *
     2831 * @param unknown_type $post_id
     2832 * @return unknown
     2833 */
     2834function get_tags_to_edit( $post_id, $taxonomy = 'post_tag' ) {
     2835    return get_terms_to_edit( $post_id, $taxonomy);
     2836}
     2837
     2838/**
     2839 * {@internal Missing Short Description}}
     2840 *
     2841 * @since unknown
     2842 *
     2843 * @param unknown_type $post_id
     2844 * @return unknown
     2845 */
     2846function get_terms_to_edit( $post_id, $taxonomy = 'post_tag' ) {
     2847    $post_id = (int) $post_id;
     2848    if ( !$post_id )
     2849        return false;
     2850
     2851    $tags = wp_get_post_terms($post_id, $taxonomy, array());
     2852
     2853    if ( !$tags )
     2854        return false;
     2855
     2856    if ( is_wp_error($tags) )
     2857        return $tags;
     2858
     2859    foreach ( $tags as $tag )
     2860        $tag_names[] = $tag->name;
     2861    $tags_to_edit = join( ',', $tag_names );
     2862    $tags_to_edit = esc_attr( $tags_to_edit );
     2863    $tags_to_edit = apply_filters( 'terms_to_edit', $tags_to_edit, $taxonomy );
     2864
     2865    return $tags_to_edit;
     2866}
Note: See TracChangeset for help on using the changeset viewer.