Make WordPress Core

Ticket #14966: quickpress.part1.patch

File quickpress.part1.patch, 11.5 KB (added by jorbin, 15 years ago)

Moves some functions from the admin to the universal api

  • wp-includes/taxonomy.php

     
    26932693
    26942694        return false;
    26952695}
     2696
     2697
     2698/**
     2699 * {@internal Missing Short Description}}
     2700 *
     2701 * @since unknown
     2702 *
     2703 * @param unknown_type $post_id
     2704 * @return unknown
     2705 */
     2706function get_tags_to_edit( $post_id, $taxonomy = 'post_tag' ) {
     2707        return get_terms_to_edit( $post_id, $taxonomy);
     2708}
     2709
     2710/**
     2711 * {@internal Missing Short Description}}
     2712 *
     2713 * @since unknown
     2714 *
     2715 * @param unknown_type $post_id
     2716 * @return unknown
     2717 */
     2718function get_terms_to_edit( $post_id, $taxonomy = 'post_tag' ) {
     2719        $post_id = (int) $post_id;
     2720        if ( !$post_id )
     2721                return false;
     2722
     2723        $tags = wp_get_post_terms($post_id, $taxonomy, array());
     2724
     2725        if ( !$tags )
     2726                return false;
     2727
     2728        if ( is_wp_error($tags) )
     2729                return $tags;
     2730
     2731        foreach ( $tags as $tag )
     2732                $tag_names[] = $tag->name;
     2733        $tags_to_edit = join( ',', $tag_names );
     2734        $tags_to_edit = esc_attr( $tags_to_edit );
     2735        $tags_to_edit = apply_filters( 'terms_to_edit', $tags_to_edit, $taxonomy );
     2736
     2737        return $tags_to_edit;
     2738}
  • wp-includes/post.php

     
    20742074
    20752075        $post = get_post($postid, $mode);
    20762076
    2077         if ( 
     2077        if (
    20782078                ( OBJECT == $mode && empty( $post->ID ) ) ||
    20792079                ( OBJECT != $mode && empty( $post['ID'] ) )
    20802080        )
     
    47134713                add_filter('the_preview', '_set_preview');
    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}
  • wp-includes/media.php

     
    13951395        $oembed = _wp_oembed_get_object();
    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}
  • wp-admin/includes/taxonomy.php

     
    194194 *
    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
    241199 */
  • wp-admin/includes/post.php

     
    348348        return array( 'updated' => $updated, 'skipped' => $skipped, 'locked' => $locked );
    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;
    361351
    362         $post_title = '';
    363         if ( !empty( $_REQUEST['post_title'] ) )
    364                 $post_title = esc_html( stripslashes( $_REQUEST['post_title'] ));
    365352
    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 }
    407 
    408353/**
    409354 * Get the default page information to use.
    410355 *
  • wp-admin/includes/media.php

     
    349349 * {@internal Missing Short Description}}
    350350 *
    351351 * @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);
    395 }
    396 
    397 /**
    398  * {@internal Missing Short Description}}
    399352 *
    400  * @since unknown
    401  *
    402353 * @return unknown
    403354 */
    404355function media_upload_form_handler() {