Make WordPress Core

Ticket #39625: 39625.diff

File 39625.diff, 2.8 KB (added by worldweb, 6 years ago)

Issue resolved. Now, it if file is not image then it will give error in featured image popup.

  • wp-admin/includes/ajax-actions.php

     
    24162416                wp_die();
    24172417        }
    24182418
    2419         echo wp_json_encode(
    2420                 array(
    2421                         'success' => true,
    2422                         'data'    => $attachment,
    2423                 )
    2424         );
     2419  /**
     2420   * Ajax handler check set as featured image or not
     2421   * if set as featured image and set as doc. file then it's return error.
     2422   *
     2423   * @since 5.3.0
     2424   */
     2425  $success = true;
    24252426
     2427  if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'upload-attachment' && isset($_REQUEST['is_featured']) && $_REQUEST['is_featured'] == 'true' && isset($attachment['type']) && $attachment['type'] != 'image'){
     2428   
     2429    $success = false;
     2430    $attachment = array(
     2431          'message'  => __( 'The uploaded file is not a valid image. Please select valid file format.' ),
     2432          'filename' => $_FILES['async-upload']['name'],
     2433        );
     2434
     2435  }
     2436
     2437  echo wp_json_encode(
     2438    array(
     2439      'success' => $success,
     2440      'data'    => $attachment,
     2441    )
     2442  );
     2443 
    24262444        wp_die();
    24272445}
    24282446
  • wp-includes/js/media-editor.js

     
    693693
    694694                        wp.media.featuredImage.set( selection ? selection.id : -1 );
    695695                },
     696
    696697                /**
    697698                 * Open the content media manager to the 'featured image' tab when
    698699                 * the post thumbnail is clicked.
     
    700701                 * Update the featured image id when the 'remove' link is clicked.
    701702                 */
    702703                init: function() {
    703                         $('#postimagediv').on( 'click', '#set-post-thumbnail', function( event ) {
     704
     705      $(document).on('click', '.editor-post-featured-image__toggle', function(){
     706         _wpPluploadSettings.defaults.multipart_params['is_featured'] = true;
     707      });
     708
     709      $(document).on('click', '.editor-media-placeholder__button', function(){
     710         _wpPluploadSettings.defaults.multipart_params['is_featured'] = false;
     711      });
     712
     713                        $('#postimagediv').on( 'click', '#set-post-thumbnail, .editor-post-featured-image__toggle', function( event ) {
     714        _wpPluploadSettings.defaults.multipart_params['is_featured'] = true;
    704715                                event.preventDefault();
    705716                                // Stop propagation to prevent thickbox from activating.
    706717                                event.stopPropagation();
     
    778789                 * @returns {wp.media.view.MediaFrame.Select} A media workflow.
    779790                 */
    780791                add: function( id, options ) {
     792       
     793      /**
     794       * Check upload media is not a featured image
     795       *
     796       **/
     797         
     798       _wpPluploadSettings.defaults.multipart_params['is_featured'] = false;
     799
    781800                        var workflow = this.get( id );
    782801
    783802                        // only add once: if exists return existing