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.

git-svn-id: https://develop.svn.wordpress.org/trunk@15688 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2010-10-03 02:58:59 +00:00
parent 3791a39615
commit ea2f90c70e
6 changed files with 162 additions and 147 deletions

View File

@ -345,55 +345,6 @@ if ( is_string($content_func) )
<?php
}
/**
* {@internal Missing Short Description}}
*
* @since unknown
*/
function media_buttons() {
$do_image = $do_audio = $do_video = true;
if ( is_multisite() ) {
$media_buttons = get_site_option( 'mu_media_buttons' );
if ( empty($media_buttons['image']) )
$do_image = false;
if ( empty($media_buttons['audio']) )
$do_audio = false;
if ( empty($media_buttons['video']) )
$do_video = false;
}
$out = '';
if ( $do_image )
$out .= _media_button(__('Add an Image'), 'images/media-button-image.gif?ver=20100531', 'image');
if ( $do_video )
$out .= _media_button(__('Add Video'), 'images/media-button-video.gif?ver=20100531', 'video');
if ( $do_audio )
$out .= _media_button(__('Add Audio'), 'images/media-button-music.gif?ver=20100531', 'audio');
$out .= _media_button(__('Add Media'), 'images/media-button-other.gif?ver=20100531', 'media');
$context = apply_filters('media_buttons_context', __('Upload/Insert %s'));
printf($context, $out);
}
add_action( 'media_buttons', 'media_buttons' );
function _media_button($title, $icon, $type) {
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>";
}
function get_upload_iframe_src($type) {
global $post_ID, $temp_ID;
$uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID);
$upload_iframe_src = add_query_arg('post_id', $uploading_iframe_ID, 'media-upload.php');
if ( 'media' != $type )
$upload_iframe_src = add_query_arg('type', $type, $upload_iframe_src);
$upload_iframe_src = apply_filters($type . '_upload_iframe_src', $upload_iframe_src);
return add_query_arg('TB_iframe', true, $upload_iframe_src);
}
/**
* {@internal Missing Short Description}}
*

View File

@ -348,62 +348,7 @@ function bulk_edit_posts( $post_data = null ) {
return array( 'updated' => $updated, 'skipped' => $skipped, 'locked' => $locked );
}
/**
* Default post information to use when populating the "Write Post" form.
*
* @since unknown
*
* @param string $post_type A post type string, defaults to 'post'.
* @return object stdClass object containing all the default post data as attributes
*/
function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) {
global $wpdb;
$post_title = '';
if ( !empty( $_REQUEST['post_title'] ) )
$post_title = esc_html( stripslashes( $_REQUEST['post_title'] ));
$post_content = '';
if ( !empty( $_REQUEST['content'] ) )
$post_content = esc_html( stripslashes( $_REQUEST['content'] ));
$post_excerpt = '';
if ( !empty( $_REQUEST['excerpt'] ) )
$post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] ));
if ( $create_in_db ) {
// Cleanup old auto-drafts more than 7 days old
$old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" );
foreach ( (array) $old_posts as $delete )
wp_delete_post( $delete, true ); // Force delete
$post_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) );
$post = get_post( $post_id );
} else {
$post->ID = 0;
$post->post_author = '';
$post->post_date = '';
$post->post_date_gmt = '';
$post->post_password = '';
$post->post_type = $post_type;
$post->post_status = 'draft';
$post->to_ping = '';
$post->pinged = '';
$post->comment_status = get_option( 'default_comment_status' );
$post->ping_status = get_option( 'default_ping_status' );
$post->post_pingback = get_option( 'default_pingback_flag' );
$post->post_category = get_option( 'default_category' );
$post->page_template = 'default';
$post->post_parent = 0;
$post->menu_order = 0;
}
$post->post_content = apply_filters( 'default_content', $post_content, $post );
$post->post_title = apply_filters( 'default_title', $post_title, $post );
$post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt, $post );
$post->post_name = '';
return $post;
}
/**
* Get the default page information to use.

View File

@ -189,48 +189,6 @@ function wp_update_category($catarr) {
// Tags
//
/**
* {@internal Missing Short Description}}
*
* @since unknown
*
* @param unknown_type $post_id
* @return unknown
*/
function get_tags_to_edit( $post_id, $taxonomy = 'post_tag' ) {
return get_terms_to_edit( $post_id, $taxonomy);
}
/**
* {@internal Missing Short Description}}
*
* @since unknown
*
* @param unknown_type $post_id
* @return unknown
*/
function get_terms_to_edit( $post_id, $taxonomy = 'post_tag' ) {
$post_id = (int) $post_id;
if ( !$post_id )
return false;
$tags = wp_get_post_terms($post_id, $taxonomy, array());
if ( !$tags )
return false;
if ( is_wp_error($tags) )
return $tags;
foreach ( $tags as $tag )
$tag_names[] = $tag->name;
$tags_to_edit = join( ',', $tag_names );
$tags_to_edit = esc_attr( $tags_to_edit );
$tags_to_edit = apply_filters( 'terms_to_edit', $tags_to_edit, $taxonomy );
return $tags_to_edit;
}
/**
* {@internal Missing Short Description}}
*

View File

@ -1395,3 +1395,63 @@ function wp_oembed_add_provider( $format, $provider, $regex = false ) {
$oembed = _wp_oembed_get_object();
$oembed->providers[$format] = array( $provider, $regex );
}
/**
*
*
*
*/
function get_media_buttons(){
$do_image = $do_audio = $do_video = true;
if ( is_multisite() ) {
$media_buttons = get_site_option( 'mu_media_buttons' );
if ( empty($media_buttons['image']) )
$do_image = false;
if ( empty($media_buttons['audio']) )
$do_audio = false;
if ( empty($media_buttons['video']) )
$do_video = false;
}
$out = '';
if ( $do_image )
$out .= _media_button(__('Add an Image'), 'images/media-button-image.gif?ver=20100531', 'image');
if ( $do_video )
$out .= _media_button(__('Add Video'), 'images/media-button-video.gif?ver=20100531', 'video');
if ( $do_audio )
$out .= _media_button(__('Add Audio'), 'images/media-button-music.gif?ver=20100531', 'audio');
$out .= _media_button(__('Add Media'), 'images/media-button-other.gif?ver=20100531', 'media');
$context = apply_filters('media_buttons_context', __('Upload/Insert %s'));
return sprintf($context, $out);
}
/**
* {@internal Missing Short Description}}
*
* @since unknown
*/
function media_buttons() {
echo get_media_buttons();
}
add_action( 'media_buttons', 'media_buttons' );
function _media_button($title, $icon, $type) {
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>";
}
function get_upload_iframe_src($type) {
global $post_ID, $temp_ID;
$uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID);
$upload_iframe_src = add_query_arg('post_id', $uploading_iframe_ID, 'media-upload.php');
if ( 'media' != $type )
$upload_iframe_src = add_query_arg('type', $type, $upload_iframe_src);
$upload_iframe_src = apply_filters($type . '_upload_iframe_src', $upload_iframe_src);
return add_query_arg('TB_iframe', true, $upload_iframe_src);
}

View File

@ -2074,7 +2074,7 @@ function wp_get_single_post($postid = 0, $mode = OBJECT) {
$post = get_post($postid, $mode);
if (
if (
( OBJECT == $mode && empty( $post->ID ) ) ||
( OBJECT != $mode && empty( $post['ID'] ) )
)
@ -4713,3 +4713,61 @@ function _show_post_preview() {
add_filter('the_preview', '_set_preview');
}
}
/**
* Default post information to use when populating the "Write Post" form.
*
* @since unknown
*
*@param string A post type string, defaults to 'post'.
* @return object stdClass object containing all the default post data as attributes
*/
function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) {
global $wpdb;
$post_title = '';
if ( !empty( $_REQUEST['post_title'] ) )
$post_title = esc_html( stripslashes( $_REQUEST['post_title'] ));
$post_content = '';
if ( !empty( $_REQUEST['content'] ) )
$post_content = esc_html( stripslashes( $_REQUEST['content'] ));
$post_excerpt = '';
if ( !empty( $_REQUEST['excerpt'] ) )
$post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] ));
if ( $create_in_db ) {
// Cleanup old auto-drafts more than 7 days old
$old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" );
foreach ( (array) $old_posts as $delete )
wp_delete_post( $delete, true ); // Force delete
$post_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) );
$post = get_post( $post_id );
} else {
$post->ID = 0;
$post->post_author = '';
$post->post_date = '';
$post->post_date_gmt = '';
$post->post_password = '';
$post->post_type = $post_type;
$post->post_status = 'draft';
$post->to_ping = '';
$post->pinged = '';
$post->comment_status = get_option( 'default_comment_status' );
$post->ping_status = get_option( 'default_ping_status' );
$post->post_pingback = get_option( 'default_pingback_flag' );
$post->post_category = get_option( 'default_category' );
$post->page_template = 'default';
$post->post_parent = 0;
$post->menu_order = 0;
}
$post->post_content = apply_filters( 'default_content', $post_content, $post );
$post->post_title = apply_filters( 'default_title', $post_title, $post );
$post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt, $post );
$post->post_name = '';
return $post;
}

View File

@ -2821,3 +2821,46 @@ function get_ancestors($object_id = 0, $object_type = '') {
return apply_filters('get_ancestors', $ancestors, $object_id, $object_type);
}
/**
* {@internal Missing Short Description}}
*
* @since unknown
*
* @param unknown_type $post_id
* @return unknown
*/
function get_tags_to_edit( $post_id, $taxonomy = 'post_tag' ) {
return get_terms_to_edit( $post_id, $taxonomy);
}
/**
* {@internal Missing Short Description}}
*
* @since unknown
*
* @param unknown_type $post_id
* @return unknown
*/
function get_terms_to_edit( $post_id, $taxonomy = 'post_tag' ) {
$post_id = (int) $post_id;
if ( !$post_id )
return false;
$tags = wp_get_post_terms($post_id, $taxonomy, array());
if ( !$tags )
return false;
if ( is_wp_error($tags) )
return $tags;
foreach ( $tags as $tag )
$tag_names[] = $tag->name;
$tags_to_edit = join( ',', $tag_names );
$tags_to_edit = esc_attr( $tags_to_edit );
$tags_to_edit = apply_filters( 'terms_to_edit', $tags_to_edit, $taxonomy );
return $tags_to_edit;
}