wp_die( __('You are not allowed to edit posts.') );
}
+ if ( -1 == $post_data['_status'] ) {
+ $post_data['post_status'] = null;
+ unset($post_data['post_status']);
+ } else {
+ $post_data['post_status'] = $post_data['_status'];
+ }
+ unset($post_data['_status']);
+
$post_IDs = array_map( 'intval', (array) $post_data['post'] );
$reset = array( 'post_author', 'post_status', 'post_password', 'post_parent', 'page_template', 'comment_status', 'ping_status', 'keep_private', 'tags_input', 'post_category', 'sticky' );
if ( isset($post_data['post_category']) ) {
if ( is_array($post_data['post_category']) && ! empty($post_data['post_category']) )
- $new_cats = array_map( absint, $post_data['post_category'] );
+ $new_cats = array_map( 'absint', $post_data['post_category'] );
else
unset($post_data['post_category']);
}
$post_data['ID'] = $post_ID;
$updated[] = wp_update_post( $post_data );
- if ( current_user_can( 'edit_others_posts' ) && isset( $post_data['sticky'] ) ) {
+ if ( isset( $post_data['sticky'] ) && current_user_can( 'edit_others_posts' ) ) {
if ( 'sticky' == $post_data['sticky'] )
stick_post( $post_ID );
else
* @return unknown
*/
function get_default_post_to_edit() {
+
+ $post_title = '';
if ( !empty( $_REQUEST['post_title'] ) )
- $post_title = wp_specialchars( stripslashes( $_REQUEST['post_title'] ));
- else if ( !empty( $_REQUEST['popuptitle'] ) ) {
- $post_title = wp_specialchars( stripslashes( $_REQUEST['popuptitle'] ));
- $post_title = funky_javascript_fix( $post_title );
- } else {
- $post_title = '';
- }
+ $post_title = esc_html( stripslashes( $_REQUEST['post_title'] ));
$post_content = '';
if ( !empty( $_REQUEST['content'] ) )
- $post_content = wp_specialchars( stripslashes( $_REQUEST['content'] ));
- else if ( !empty( $post_title ) ) {
- $text = wp_specialchars( stripslashes( urldecode( $_REQUEST['text'] ) ) );
- $text = funky_javascript_fix( $text);
- $popupurl = clean_url($_REQUEST['popupurl']);
- $post_content = '<a href="'.$popupurl.'">'.$post_title.'</a>'."\n$text";
- }
+ $post_content = esc_html( stripslashes( $_REQUEST['content'] ));
+ $post_excerpt = '';
if ( !empty( $_REQUEST['excerpt'] ) )
- $post_excerpt = wp_specialchars( stripslashes( $_REQUEST['excerpt'] ));
- else
- $post_excerpt = '';
+ $post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] ));
$post->ID = 0;
$post->post_name = '';
$post->post_author = '';
$post->post_date = '';
+ $post->post_date_gmt = '';
$post->post_password = '';
$post->post_status = 'draft';
$post->post_type = 'post';
}
/**
- * {@internal Missing Short Description}}
+ * Determine if a post exists based on title, content, and date
*
* @since unknown
*
- * @param unknown_type $title
- * @param unknown_type $content
- * @param unknown_type $post_date
- * @return unknown
+ * @param string $title Post title
+ * @param string $content Optional post content
+ * @param string $date Optional post date
+ * @return int Post ID if post exists, 0 otherwise.
*/
-function post_exists($title, $content = '', $post_date = '') {
+function post_exists($title, $content = '', $date = '') {
global $wpdb;
- $title = stripslashes($title);
- $content = stripslashes($content);
- $post_date = stripslashes($post_date);
+ $post_title = stripslashes( sanitize_post_field( 'post_title', $title, 0, 'db' ) );
+ $post_content = stripslashes( sanitize_post_field( 'post_content', $content, 0, 'db' ) );
+ $post_date = stripslashes( sanitize_post_field( 'post_date', $date, 0, 'db' ) );
- if (!empty ($post_date))
- $post_date = $wpdb->prepare("AND post_date = %s", $post_date);
+ $query = "SELECT ID FROM $wpdb->posts WHERE 1=1";
+ $args = array();
- if (!empty ($title))
- return $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_title = %s $post_date", $title) );
- else
- if (!empty ($content))
- return $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_content = %s $post_date", $content) );
+ if ( !empty ( $date ) ) {
+ $query .= ' AND post_date = %s';
+ $args[] = $post_date;
+ }
+
+ if ( !empty ( $title ) ) {
+ $query .= ' AND post_title = %s';
+ $args[] = $post_title;
+ }
+
+ if ( !empty ( $content ) ) {
+ $query .= 'AND post_content = %s';
+ $args[] = $post_content;
+ }
+
+ if ( !empty ( $args ) )
+ return $wpdb->get_var( $wpdb->prepare($query, $args) );
return 0;
}
$metakeyselect = isset($_POST['metakeyselect']) ? stripslashes( trim( $_POST['metakeyselect'] ) ) : '';
$metakeyinput = isset($_POST['metakeyinput']) ? stripslashes( trim( $_POST['metakeyinput'] ) ) : '';
- $metavalue = isset($_POST['metavalue']) ? maybe_serialize( stripslashes( trim( $_POST['metavalue'] ) ) ) : '';
+ $metavalue = isset($_POST['metavalue']) ? maybe_serialize( stripslashes_deep( $_POST['metavalue'] ) ) : '';
+ if ( is_string($metavalue) )
+ $metavalue = trim( $metavalue );
if ( ('0' === $metavalue || !empty ( $metavalue ) ) && ((('#NONE#' != $metakeyselect) && !empty ( $metakeyselect) ) || !empty ( $metakeyinput) ) ) {
// We have a key/value pair. If both the select and the
wp_cache_delete($post_ID, 'post_meta');
$wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value ) VALUES (%s, %s, %s)", $post_ID, $metakey, $metavalue) );
+ do_action( 'added_postmeta', $wpdb->insert_id, $post_ID, $metakey, $metavalue );
+
return $wpdb->insert_id;
}
return false;
$mid = (int) $mid;
$post_id = $wpdb->get_var( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_id = %d", $mid) );
+
+ do_action( 'delete_postmeta', $mid );
wp_cache_delete($post_id, 'post_meta');
+ $rval = $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id = %d", $mid) );
+ do_action( 'deleted_postmeta', $mid );
- return $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id = %d", $mid) );
+ return $rval;
}
/**
if ( in_array($meta_key, $protected) )
return false;
+ if ( '' === trim( $meta_value ) )
+ return false;
+
$post_id = $wpdb->get_var( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_id = %d", $meta_id) );
- wp_cache_delete($post_id, 'post_meta');
- $meta_value = maybe_serialize( stripslashes( $meta_value ));
+ $meta_value = maybe_serialize( stripslashes_deep( $meta_value ) );
$meta_id = (int) $meta_id;
$data = compact( 'meta_key', 'meta_value' );
$where = compact( 'meta_id' );
- return $wpdb->update( $wpdb->postmeta, $data, $where );
+ do_action( 'update_postmeta', $meta_id, $post_id, $meta_key, $meta_value );
+ $rval = $wpdb->update( $wpdb->postmeta, $data, $where );
+ wp_cache_delete($post_id, 'post_meta');
+ do_action( 'updated_postmeta', $meta_id, $post_id, $meta_key, $meta_value );
+
+ return $rval;
}
//
* @return unknown
*/
function _fix_attachment_links( $post_ID ) {
+ global $_fix_attachment_link_id;
$post = & get_post( $post_ID, ARRAY_A );
}
$post_search[$i] = $anchor;
- $post_replace[$i] = preg_replace( "#href=(\"|')[^'\"]*\\1#e", "stripslashes( 'href=\\1' ).get_attachment_link( $id ).stripslashes( '\\1' )", $anchor );
+ $_fix_attachment_link_id = $id;
+ $post_replace[$i] = preg_replace_callback( "#href=(\"|')[^'\"]*\\1#", '_fix_attachment_links_replace_cb', $anchor );
++$i;
}
return wp_update_post( $post);
}
+function _fix_attachment_links_replace_cb($match) {
+ global $_fix_attachment_link_id;
+ return stripslashes( 'href='.$match[1] ).get_attachment_link( $_fix_attachment_link_id ).stripslashes( $match[1] );
+}
+
/**
* Move child posts to a new parent.
*
global $wpdb;
$old_ID = (int) $old_ID;
$new_ID = (int) $new_ID;
- return $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_parent = %d WHERE post_parent = %d", $new_ID, $old_ID) );
+
+ $children = $wpdb->get_col( $wpdb->prepare("
+ SELECT post_id
+ FROM $wpdb->postmeta
+ WHERE meta_key = '_wp_attachment_temp_parent'
+ AND meta_value = %d", $old_ID) );
+
+ foreach ( $children as $child_id ) {
+ $wpdb->update($wpdb->posts, array('post_parent' => $new_ID), array('ID' => $child_id) );
+ delete_post_meta($child_id, '_wp_attachment_temp_parent');
+ }
}
/**
$q['m'] = isset($q['m']) ? (int) $q['m'] : 0;
$q['cat'] = isset($q['cat']) ? (int) $q['cat'] : 0;
$post_stati = array( // array( adj, noun )
- 'publish' => array(__('Published'), __('Published posts'), __ngettext_noop('Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>')),
- 'future' => array(__('Scheduled'), __('Scheduled posts'), __ngettext_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>')),
- 'pending' => array(__('Pending Review'), __('Pending posts'), __ngettext_noop('Pending Review <span class="count">(%s)</span>', 'Pending Review <span class="count">(%s)</span>')),
- 'draft' => array(__('Draft'), _c('Drafts|manage posts header'), __ngettext_noop('Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>')),
- 'private' => array(__('Private'), __('Private posts'), __ngettext_noop('Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>')),
+ 'publish' => array(_x('Published', 'post'), __('Published posts'), _n_noop('Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>')),
+ 'future' => array(_x('Scheduled', 'post'), __('Scheduled posts'), _n_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>')),
+ 'pending' => array(_x('Pending Review', 'post'), __('Pending posts'), _n_noop('Pending Review <span class="count">(%s)</span>', 'Pending Review <span class="count">(%s)</span>')),
+ 'draft' => array(_x('Draft', 'post'), _x('Drafts', 'manage posts header'), _n_noop('Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>')),
+ 'private' => array(_x('Private', 'post'), __('Private posts'), _n_noop('Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>')),
+ 'trash' => array(_x('Trash', 'post'), __('Trash posts'), _n_noop('Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>')),
);
$post_stati = apply_filters('post_stati', $post_stati);
$orderby = 'date';
}
- wp("post_type=post&what_to_show=posts$post_status_q&posts_per_page=15&order=$order&orderby=$orderby");
+ $posts_per_page = (int) get_user_option( 'edit_per_page', 0, false );
+ if ( empty( $posts_per_page ) || $posts_per_page < 1 )
+ $posts_per_page = 15;
+ $posts_per_page = apply_filters( 'edit_posts_per_page', $posts_per_page );
+
+ wp("post_type=post&$post_status_q&posts_per_page=$posts_per_page&order=$order&orderby=$orderby");
return array($post_stati, $avail_post_stati);
}
+/**
+ * Get default post mime types
+ *
+ * @since 2.9.0
+ *
+ * @return array
+ */
+function get_post_mime_types() {
+ $post_mime_types = array( // array( adj, noun )
+ 'image' => array(__('Images'), __('Manage Images'), _n_noop('Image <span class="count">(%s)</span>', 'Images <span class="count">(%s)</span>')),
+ 'audio' => array(__('Audio'), __('Manage Audio'), _n_noop('Audio <span class="count">(%s)</span>', 'Audio <span class="count">(%s)</span>')),
+ 'video' => array(__('Video'), __('Manage Video'), _n_noop('Video <span class="count">(%s)</span>', 'Video <span class="count">(%s)</span>')),
+ );
+
+ return apply_filters('post_mime_types', $post_mime_types);
+}
+
/**
* {@internal Missing Short Description}}
*
$q['m'] = isset( $q['m'] ) ? (int) $q['m'] : 0;
$q['cat'] = isset( $q['cat'] ) ? (int) $q['cat'] : 0;
$q['post_type'] = 'attachment';
- $q['post_status'] = 'any';
- $q['posts_per_page'] = 15;
- $post_mime_types = array( // array( adj, noun )
- 'image' => array(__('Images'), __('Manage Images'), __ngettext_noop('Image <span class="count">(%s)</span>', 'Images <span class="count">(%s)</span>')),
- 'audio' => array(__('Audio'), __('Manage Audio'), __ngettext_noop('Audio <span class="count">(%s)</span>', 'Audio <span class="count">(%s)</span>')),
- 'video' => array(__('Video'), __('Manage Video'), __ngettext_noop('Video <span class="count">(%s)</span>', 'Video <span class="count">(%s)</span>')),
- );
- $post_mime_types = apply_filters('post_mime_types', $post_mime_types);
+ $q['post_status'] = isset( $q['status'] ) && 'trash' == $q['status'] ? 'trash' : 'inherit';
+ $media_per_page = (int) get_user_option( 'upload_per_page', 0, false );
+ if ( empty( $media_per_page ) || $media_per_page < 1 )
+ $media_per_page = 20;
+ $q['posts_per_page'] = apply_filters( 'upload_per_page', $media_per_page );
+ $post_mime_types = get_post_mime_types();
$avail_post_mime_types = get_available_post_mime_types('attachment');
if ( isset($q['post_mime_type']) && !array_intersect( (array) $q['post_mime_type'], array_keys($post_mime_types) ) )
$current_user = wp_get_current_user();
if ( $closed = get_user_option('closedpostboxes_'.$page, 0, false ) ) {
if ( !is_array( $closed ) ) return '';
- return in_array( $id, $closed )? 'if-js-closed' : '';
+ return in_array( $id, $closed )? 'closed' : '';
} else {
return '';
}
*
* @since unknown
*
- * @param unknown_type $id
- * @param unknown_type $title
- * @param unknown_type $name
- * @return unknown
+ * @param int|object $id Post ID or post object.
+ * @param string $title (optional) Title
+ * @param string $name (optional) Name
+ * @return array With two entries of type string
*/
-function get_sample_permalink($id, $title=null, $name = null) {
+function get_sample_permalink($id, $title = null, $name = null) {
$post = &get_post($id);
if (!$post->ID) {
return array('', '');
// drafts, so we will fake, that our post is published
if (in_array($post->post_status, array('draft', 'pending'))) {
$post->post_status = 'publish';
- $post->post_name = sanitize_title($post->post_name? $post->post_name : $post->post_title, $post->ID);
+ $post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID);
}
+ $post->post_name = wp_unique_post_slug($post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent);
+
// If the user wants to set a new name -- override the current one
// Note: if empty name is supplied -- use the title instead, see #6072
if (!is_null($name)) {
- $post->post_name = sanitize_title($name? $name : $title, $post->ID);
+ $post->post_name = sanitize_title($name ? $name : $title, $post->ID);
}
- $post->filter = 'sample';
+ $post->filter = 'sample';
$permalink = get_permalink($post, true);
}
/**
- * {@internal Missing Short Description}}
+ * sample permalink html
*
+ * intended to be used for the inplace editor of the permalink post slug on in the post (and page?) editor.
+ *
* @since unknown
*
- * @param unknown_type $id
- * @param unknown_type $new_title
- * @param unknown_type $new_slug
- * @return unknown
+ * @param int|object $id Post ID or post object.
+ * @param string $new_title (optional) New title
+ * @param string $new_slug (optional) New slug
+ * @return string intended to be used for the inplace editor of the permalink post slug on in the post (and page?) editor.
*/
-function get_sample_permalink_html($id, $new_title=null, $new_slug=null) {
+function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
$post = &get_post($id);
list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
- if (false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%')) {
- return '';
+
+ if ( 'publish' == $post->post_status ) {
+ $view_post = 'post' == $post->post_type ? __('View Post') : __('View Page');
+ $title = __('Click to edit this part of the permalink');
+ } else {
+ $title = __('Temporary permalink. Click to edit this part.');
+ }
+
+ if ( false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%') ) {
+ $return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink">' . $permalink . "</span>\n";
+ if ( current_user_can( 'manage_options' ) && !( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) )
+ $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button" target="_blank">' . __('Change Permalinks') . "</a></span>\n";
+ if ( isset($view_post) )
+ $return .= "<span id='view-post-btn'><a href='$permalink' class='button' target='_blank'>$view_post</a></span>\n";
+
+ $return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug);
+
+ return $return;
}
- $title = __('Click to edit this part of the permalink');
- if (function_exists('mb_strlen')) {
- if (mb_strlen($post_name) > 30) {
+
+ if ( function_exists('mb_strlen') ) {
+ if ( mb_strlen($post_name) > 30 ) {
$post_name_abridged = mb_substr($post_name, 0, 14). '…' . mb_substr($post_name, -14);
} else {
$post_name_abridged = $post_name;
}
} else {
- if (strlen($post_name) > 30) {
+ if ( strlen($post_name) > 30 ) {
$post_name_abridged = substr($post_name, 0, 14). '…' . substr($post_name, -14);
} else {
$post_name_abridged = $post_name;
}
}
- $post_name_html = '<span id="editable-post-name" title="'.$title.'">'.$post_name_abridged.'</span><span id="editable-post-name-full">'.$post_name.'</span>';
+
+ $post_name_html = '<span id="editable-post-name" title="' . $title . '">' . $post_name_abridged . '</span>';
$display_link = str_replace(array('%pagename%','%postname%'), $post_name_html, $permalink);
+ $view_link = str_replace(array('%pagename%','%postname%'), $post_name, $permalink);
$return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink">' . $display_link . "</span>\n";
- $return .= '<span id="edit-slug-buttons"><a href="#post_name" class="edit-slug button" onclick="edit_permalink(' . $id . '); return false;">' . __('Edit') . "</a></span>\n";
+ $return .= '<span id="edit-slug-buttons"><a href="#post_name" class="edit-slug button hide-if-no-js" onclick="editPermalink(' . $id . '); return false;">' . __('Edit') . "</a></span>\n";
+ $return .= '<span id="editable-post-name-full">' . $post_name . "</span>\n";
+ if ( isset($view_post) )
+ $return .= "<span id='view-post-btn'><a href='$view_link' class='button' target='_blank'>$view_post</a></span>\n";
+
+ $return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug);
+
return $return;
}
/**
- * {@internal Missing Short Description}}
+ * Output HTML for the post thumbnail meta-box.
*
- * @since unknown
+ * @since 2.9.0
+ *
+ * @param int $thumbnail_id ID of the attachment used for thumbnail
+ * @return string html
+ */
+function _wp_post_thumbnail_html( $thumbnail_id = NULL ) {
+ global $content_width, $_wp_additional_image_sizes;
+ $content = '<p class="hide-if-no-js"><a href="#" id="set-post-thumbnail" onclick="jQuery(\'#add_image\').click();return false;">' . esc_html__( 'Set thumbnail' ) . '</a></p>';
+
+ if ( $thumbnail_id && get_post( $thumbnail_id ) ) {
+ $old_content_width = $content_width;
+ $content_width = 266;
+ if ( !isset( $_wp_additional_image_sizes['post-thumbnail'] ) )
+ $thumbnail_html = wp_get_attachment_image( $thumbnail_id, array( $content_width, $content_width ) );
+ else
+ $thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'post-thumbnail' );
+ if ( !empty( $thumbnail_html ) ) {
+ $content = '<a href="#" id="set-post-thumbnail" onclick="jQuery(\'#add_image\').click();return false;">' . $thumbnail_html . '</a>';
+ $content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail" onclick="WPRemoveThumbnail();return false;">' . esc_html__( 'Remove thumbnail' ) . '</a></p>';
+ }
+ $content_width = $old_content_width;
+ }
+
+ return apply_filters( 'admin_post_thumbnail_html', $content );
+}
+
+/**
+ * Check to see if the post is currently being edited by another user.
+ *
+ * @since 2.5.0
*
- * @param unknown_type $post_id
+ * @param int $post_id ID of the post to check for editing
* @return bool|int False: not locked or locked by current user. Int: user ID of user with lock.
*/
function wp_check_post_lock( $post_id ) {
}
/**
- * {@internal Missing Short Description}}
+ * Mark the post as currently being edited by the current user
*
- * @since unknown
+ * @since 2.5.0
*
- * @param unknown_type $post_id
- * @return unknown
+ * @param int $post_id ID of the post to being edited
+ * @return bool Returns false if the post doesn't exist of there is no current user
*/
function wp_set_post_lock( $post_id ) {
global $current_user;
update_post_meta( $post->ID, '_edit_last', $current_user->ID );
}
+/**
+ * Outputs the notice message to say that someone else is editing this post at the moment.
+ *
+ * @since 2.8.5
+ * @return none
+ */
+function _admin_notice_post_locked() {
+ global $post;
+ $last_user = get_userdata( get_post_meta( $post->ID, '_edit_last', true ) );
+ $last_user_name = $last_user ? $last_user->display_name : __('Somebody');
+
+ switch ($post->post_type) {
+ case 'post':
+ $message = __( 'Warning: %s is currently editing this post' );
+ break;
+ case 'page':
+ $message = __( 'Warning: %s is currently editing this page' );
+ break;
+ default:
+ $message = __( 'Warning: %s is currently editing this.' );
+ }
+
+ $message = sprintf( $message, esc_html( $last_user_name ) );
+ echo "<div class='error'><p>$message</p></div>";
+}
+
/**
* Creates autosave data for the specified post from $_POST data.
*
if ( $old_autosave = wp_get_post_autosave( $post_id ) ) {
$new_autosave = _wp_post_revision_fields( $_POST, true );
$new_autosave['ID'] = $old_autosave->ID;
+ $current_user = wp_get_current_user();
+ $new_autosave['post_author'] = $current_user->ID;
return wp_update_post( $new_autosave );
}
+ // _wp_put_post_revision() expects unescaped.
+ $_POST = stripslashes_deep($_POST);
+
// Otherwise create the new autosave as a special post revision
return _wp_put_post_revision( $_POST, true );
}
/**
* Adds the TinyMCE editor used on the Write and Edit screens.
*
- * Has option to output a trimmed down version used in Press This.
- *
* @package WordPress
* @since 2.7
+ *
+ * TinyMCE is loaded separately from other Javascript by using wp-tinymce.php. It outputs concatenated
+ * and optionaly pre-compressed version of the core and all default plugins. Additional plugins are loaded
+ * directly by TinyMCE using non-blocking method. Custom plugins can be refreshed by adding a query string
+ * to the URL when queueing them with the mce_external_plugins filter.
+ *
+ * @param bool $teeny optional Output a trimmed down version used in Press This.
+ * @param mixed $settings optional An array that can add to or overwrite the default TinyMCE settings.
*/
-function wp_tiny_mce( $teeny = false ) {
+function wp_tiny_mce( $teeny = false, $settings = false ) {
+ global $concatenate_scripts, $compress_scripts, $tinymce_version;
+
if ( ! user_can_richedit() )
return;
$baseurl = includes_url('js/tinymce');
- $mce_css = $baseurl . '/wordpress.css';
- $mce_css = apply_filters('mce_css', $mce_css);
-
$mce_locale = ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) ); // only ISO 639-1
/*
$mce_spellchecker_languages = apply_filters('mce_spellchecker_languages', '+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv');
if ( $teeny ) {
- $plugins = apply_filters( 'teeny_mce_plugins', array('safari', 'inlinepopups', 'media', 'autosave', 'fullscreen') );
+ $plugins = apply_filters( 'teeny_mce_plugins', array('safari', 'inlinepopups', 'media', 'fullscreen', 'wordpress') );
$ext_plugins = '';
} else {
- $plugins = array( 'safari', 'inlinepopups', 'autosave', 'spellchecker', 'paste', 'wordpress', 'media', 'fullscreen', 'wpeditimage', 'wpgallery' );
+ $plugins = array( 'safari', 'inlinepopups', 'spellchecker', 'paste', 'wordpress', 'media', 'fullscreen', 'wpeditimage', 'wpgallery', 'tabfocus' );
/*
The following filter takes an associative array of external plugins for TinyMCE in the form 'plugin_name' => 'url'.
*/
$mce_external_plugins = apply_filters('mce_external_plugins', array());
- $ext_plugins = "\n";
+ $ext_plugins = '';
if ( ! empty($mce_external_plugins) ) {
/*
// TinyMCE init settings
$initArray = array (
- 'mode' => 'none',
- 'onpageload' => 'switchEditors.edInit',
+ 'mode' => 'specific_textareas',
+ 'editor_selector' => 'theEditor',
'width' => '100%',
'theme' => 'advanced',
'skin' => 'wp_theme',
'convert_urls' => false,
'apply_source_formatting' => false,
'remove_linebreaks' => true,
- 'paste_convert_middot_lists' => true,
- 'paste_remove_spans' => true,
- 'paste_remove_styles' => true,
'gecko_spellcheck' => true,
'entities' => '38,amp,60,lt,62,gt',
'accessibility_focus' => true,
- 'tab_focus' => ':prev,:next',
- 'content_css' => "$mce_css",
- 'save_callback' => 'switchEditors.saveCallback',
+ 'tabfocus_elements' => 'major-publishing-actions',
+ 'media_strict' => false,
+ 'paste_remove_styles' => true,
+ 'paste_remove_spans' => true,
+ 'paste_strip_class_attributes' => 'all',
'wpeditimage_disable_captions' => $no_captions,
'plugins' => "$plugins"
);
+ $mce_css = trim(apply_filters('mce_css', ''), ' ,');
+
+ if ( ! empty($mce_css) )
+ $initArray['content_css'] = "$mce_css";
+
+ if ( is_array($settings) )
+ $initArray = array_merge($initArray, $settings);
+
// For people who really REALLY know what they're doing with TinyMCE
// You can modify initArray to add, remove, change elements of the config before tinyMCE.init
// Setting "valid_elements", "invalid_elements" and "extended_valid_elements" can be done through "tiny_mce_before_init".
$initArray = apply_filters('tiny_mce_before_init', $initArray);
}
- $language = $initArray['language'];
+ if ( empty($initArray['theme_advanced_buttons3']) && !empty($initArray['theme_advanced_buttons4']) ) {
+ $initArray['theme_advanced_buttons3'] = $initArray['theme_advanced_buttons4'];
+ $initArray['theme_advanced_buttons4'] = '';
+ }
- $ver = apply_filters('tiny_mce_version', '3101');
+ if ( ! isset($concatenate_scripts) )
+ script_concat_settings();
+
+ $language = $initArray['language'];
+ $zip = $compress_scripts ? 1 : 0;
+
+ /**
+ * Deprecated
+ *
+ * The tiny_mce_version filter is not needed since external plugins are loaded directly by TinyMCE.
+ * These plugins can be refreshed by appending query string to the URL passed to mce_external_plugins filter.
+ * If the plugin has a popup dialog, a query string can be added to the button action that opens it (in the plugin's code).
+ */
+ $version = apply_filters('tiny_mce_version', '');
+ $version = 'ver=' . $tinymce_version . $version;
if ( 'en' != $language )
include_once(ABSPATH . WPINC . '/js/tinymce/langs/wp-langs.php');
tinyMCEPreInit = {
base : "<?php echo $baseurl; ?>",
suffix : "",
- query : "ver=<?php echo $ver; ?>",
+ query : "<?php echo $version; ?>",
mceInit : {<?php echo $mce_options; ?>},
-
- go : function() {
- var t = this, 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');
- }
- });
- },
-
- load_ext : function(url,lang) {
- var sl = tinymce.ScriptLoader;
-
- sl.markDone(url + '/langs/' + lang + '.js');
- sl.markDone(url + '/langs/' + lang + '_dlg.js');
- }
+ load_ext : function(url,lang){var sl=tinymce.ScriptLoader;sl.markDone(url+'/langs/'+lang+'.js');sl.markDone(url+'/langs/'+lang+'_dlg.js');}
};
/* ]]> */
</script>
-<script type="text/javascript" src="<?php echo $baseurl; ?>/tiny_mce.js?ver=<?php echo $ver; ?>"></script>
-<?php if ( 'en' != $language && isset($lang) ) { ?>
+
+<?php
+ if ( $concatenate_scripts )
+ echo "<script type='text/javascript' src='$baseurl/wp-tinymce.php?c=$zip&$version'></script>\n";
+ else
+ echo "<script type='text/javascript' src='$baseurl/tiny_mce.js?$version'></script>\n";
+
+ if ( 'en' != $language && isset($lang) )
+ echo "<script type='text/javascript'>\n$lang\n</script>\n";
+ else
+ echo "<script type='text/javascript' src='$baseurl/langs/wp-langs-en.js?$version'></script>\n";
+?>
+
<script type="text/javascript">
-<?php echo $lang; ?>
-</script>
+/* <![CDATA[ */
+<?php if ( $ext_plugins ) echo "$ext_plugins\n"; ?>
+<?php if ( $concatenate_scripts ) { ?>
+tinyMCEPreInit.go();
<?php } else { ?>
-<script type="text/javascript" src="<?php echo $baseurl; ?>/langs/wp-langs-en.js?ver=<?php echo $ver; ?>"></script>
+(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');}});})();
<?php } ?>
-<script type="text/javascript">
-<?php if ( $ext_plugins ) echo $ext_plugins; ?>
-
-// Mark translations as done
-tinyMCEPreInit.go();
-
-// Init
tinyMCE.init(tinyMCEPreInit.mceInit);
+/* ]]> */
</script>
-
<?php
}
-?>