Changeset 31654
- Timestamp:
- 03/07/2015 01:16:05 AM (10 years ago)
- Location:
- trunk/src/wp-admin
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/css/press-this.css
r31651 r31654 350 350 outline: 0; 351 351 text-decoration: underline; 352 } 353 354 .preview-button { 355 margin-right: 1em; 352 356 } 353 357 -
trunk/src/wp-admin/includes/class-wp-press-this.php
r31651 r31654 134 134 */ 135 135 public function save_post() { 136 if ( empty( $_POST['pressthis-nonce'] ) || ! wp_verify_nonce( $_POST['pressthis-nonce'], 'press-this' ) ) {137 wp_send_json_error( array( 'errorMessage' => __( 'Cheatin’ uh?' ) ) );138 }139 140 136 if ( empty( $_POST['post_ID'] ) || ! $post_id = (int) $_POST['post_ID'] ) { 141 137 wp_send_json_error( array( 'errorMessage' => __( 'Missing post ID.' ) ) ); 142 138 } 143 139 144 if ( ! current_user_can( 'edit_post', $post_id ) ) { 145 wp_send_json_error( array( 'errorMessage' => __( 'Cheatin’ uh?' ) ) ); 140 if ( empty( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], 'update-post_' . $post_id ) || 141 ! current_user_can( 'edit_post', $post_id ) ) { 142 143 wp_send_json_error( array( 'errorMessage' => __( 'Invalid post.' ) ) ); 146 144 } 147 145 148 146 $post = array( 149 147 'ID' => $post_id, 150 'post_title' => ( ! empty( $_POST[' title'] ) ) ? sanitize_text_field( trim( $_POST['title'] ) ) : '',151 'post_content' => ( ! empty( $_POST['p ressthis'] ) ) ? trim( $_POST['pressthis'] ) : '',148 'post_title' => ( ! empty( $_POST['post_title'] ) ) ? sanitize_text_field( trim( $_POST['post_title'] ) ) : '', 149 'post_content' => ( ! empty( $_POST['post_content'] ) ) ? trim( $_POST['post_content'] ) : '', 152 150 'post_type' => 'post', 153 151 'post_status' => 'draft', … … 888 886 <!--[if gt IE 8]><!--> <html <?php language_attributes(); ?>> <!--<![endif]--> 889 887 <head> 890 <meta http-equiv="Content-Type" content="<?php e sc_attr(bloginfo( 'html_type' ) ); ?>; charset=<?php echo esc_attr( get_option( 'blog_charset' ) ); ?>" />888 <meta http-equiv="Content-Type" content="<?php echo esc_attr( get_bloginfo( 'html_type' ) ); ?>; charset=<?php echo esc_attr( get_option( 'blog_charset' ) ); ?>" /> 891 889 <meta name="viewport" content="width=device-width"> 892 890 <title><?php esc_html_e( 'Press This!' ) ?></title> … … 955 953 </head> 956 954 <?php 957 $admin_body_class = 'press-this'; 958 $admin_body_class .= ( is_rtl() ) ? ' rtl' : ''; 959 $admin_body_class .= ' branch-' . str_replace( array( '.', ',' ), '-', floatval( $wp_version ) ); 960 $admin_body_class .= ' version-' . str_replace( '.', '-', preg_replace( '/^([.0-9]+).*/', '$1', $wp_version ) ); 961 $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' ); 962 $admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) ); 963 964 /** This filter is documented in wp-admin/admin-header.php */ 965 $admin_body_classes = apply_filters( 'admin_body_class', '' ); 955 956 $admin_body_class = 'press-this'; 957 $admin_body_class .= ( is_rtl() ) ? ' rtl' : ''; 958 $admin_body_class .= ' branch-' . str_replace( array( '.', ',' ), '-', floatval( $wp_version ) ); 959 $admin_body_class .= ' version-' . str_replace( '.', '-', preg_replace( '/^([.0-9]+).*/', '$1', $wp_version ) ); 960 $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' ); 961 $admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) ); 962 963 /** This filter is documented in wp-admin/admin-header.php */ 964 $admin_body_classes = apply_filters( 'admin_body_class', '' ); 965 966 966 ?> 967 967 <body class="wp-admin wp-core-ui <?php echo $admin_body_classes . ' ' . $admin_body_class; ?>"> … … 985 985 </div> 986 986 987 <form id="pressthis-form" name="pressthis-form" method="POST" autocomplete="off">987 <form id="pressthis-form" method="post" action="post.php" autocomplete="off"> 988 988 <input type="hidden" name="post_ID" id="post_ID" value="<?php echo $post_ID; ?>" /> 989 989 <input type="hidden" name="action" value="press-this-save-post" /> 990 990 <input type="hidden" name="post_status" id="post_status" value="draft" /> 991 <input type="hidden" name="wp-preview" id="wp-preview" value="" /> 992 <input type="hidden" name="post_title" id="post_title" value="" /> 991 993 <?php 992 wp_nonce_field( 'press-this', 'pressthis-nonce', false ); 994 995 wp_nonce_field( 'update-post_' . $post_ID, '_wpnonce', false ); 993 996 wp_nonce_field( 'add-category', '_ajax_nonce-add-category', false ); 997 994 998 ?> 995 <input type="hidden" name="title" id="title-field" value="" />996 999 997 1000 <div class="wrapper"> … … 1017 1020 'editor_height' => 600, 1018 1021 'media_buttons' => false, 1022 'textarea_name' => 'post_content', 1019 1023 'teeny' => true, 1020 1024 'tinymce' => array( … … 1029 1033 'toolbar2' => 'undo,redo', 1030 1034 ), 1031 'quicktags' 1035 'quicktags' => false, 1032 1036 ) ); 1033 1037 … … 1052 1056 <span class="dashicons dashicons-category"></span> 1053 1057 <span class="post-option-title"><?php _e( 'Categories' ); ?></span> 1054 <span class="post-option-contents" id="post-option-category"></span>1055 1058 <span class="dashicons post-option-forward"></span> 1056 1059 </button> … … 1059 1062 <span class="dashicons dashicons-tag"></span> 1060 1063 <span class="post-option-title"><?php _e( 'Tags' ); ?></span> 1061 <span class="post-option-contents" id="post-option-tags"></span>1062 1064 <span class="dashicons post-option-forward"></span> 1063 1065 </button> … … 1103 1105 </div> 1104 1106 <div class="post-actions"> 1105 <button type="button" class="button-subtle" id="draft-field"><?php _e( 'Save Draft' ); ?></button> 1106 <button type="button" class="button-primary" id="publish-field"><?php _e( 'Publish' ); ?></button> 1107 <button type="button" class="button-subtle draft-button"><?php _e( 'Save Draft' ); ?></button> 1108 <button type="button" class="button preview-button"><?php _e( 'Preview' ); ?></button> 1109 <button type="button" class="button-primary publish-button"><?php _e( 'Publish' ); ?></button> 1107 1110 </div> 1108 1111 </div> -
trunk/src/wp-admin/js/press-this.js
r31651 r31654 304 304 305 305 /** 306 * Submit the post form via AJAX, and redirect to the proper screen if published vs saved as a draft. 307 * 308 * @param action string publish|draft 309 */ 310 function submitPost( action ) { 311 saveAlert = false; 312 showSpinner(); 313 314 var $form = $( '#pressthis-form' ); 315 316 if ( 'publish' === action ) { 317 $( '#post_status' ).val( 'publish' ); 318 } 319 306 * Prepare the form data for saving. 307 */ 308 function prepareFormData() { 320 309 editor && editor.save(); 321 310 322 $( '# title-field' ).val( sanitizeText( $( '#title-container' ).text() ) );311 $( '#post_title' ).val( sanitizeText( $( '#title-container' ).text() ) ); 323 312 324 313 // Make sure to flush out the tags with tagBox before saving … … 328 317 } ); 329 318 } 330 331 var data = $form.serialize(); 319 } 320 321 /** 322 * Submit the post form via AJAX, and redirect to the proper screen if published vs saved as a draft. 323 * 324 * @param action string publish|draft 325 */ 326 function submitPost( action ) { 327 var data; 328 329 saveAlert = false; 330 showSpinner(); 331 332 if ( 'publish' === action ) { 333 $( '#post_status' ).val( 'publish' ); 334 } 335 336 prepareFormData(); 337 data = $( '#pressthis-form' ).serialize(); 332 338 333 339 $.ajax( { … … 503 509 504 510 if ( ! hasEmptyTitleStr ) { 505 $( '# title-field' ).val( suggestedTitle );511 $( '#post_title' ).val( suggestedTitle ); 506 512 $title.text( suggestedTitle ); 507 513 $( '.post-title-placeholder' ).addClass( 'is-hidden' ); … … 757 763 758 764 // Publish and Draft buttons and submit 759 760 $( '#draft-field' ).on( 'click', function() { 761 submitPost( 'draft' ); 762 } ); 763 764 $( '#publish-field' ).on( 'click', function() { 765 submitPost( 'publish' ); 766 } ); 765 766 767 $( '.post-actions' ).on( 'click.press-this', function( event ) { 768 var $target = $( event.target ); 769 770 if ( $target.hasClass( 'draft-button' ) ) { 771 submitPost( 'draft' ); 772 } else if ( $target.hasClass( 'publish-button' ) ) { 773 submitPost( 'publish' ); 774 } else if ( $target.hasClass( 'preview-button' ) ) { 775 prepareFormData(); 776 window.opener && window.opener.focus(); 777 778 $( '#wp-preview' ).val( 'dopreview' ); 779 $( '#pressthis-form' ).attr( 'target', '_blank' ).submit().attr( 'target', '' ); 780 $( '#wp-preview' ).val( '' ); 781 } 782 }); 767 783 768 784 monitorOptionsModal();
Note: See TracChangeset
for help on using the changeset viewer.