[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-admin/ -> media.php (source)

   1  <?php
   2  /**
   3   * Media management action handler.
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   */
   8  
   9  /** Load WordPress Administration Bootstrap */
  10  require_once( dirname( __FILE__ ) . '/admin.php' );
  11  
  12  $parent_file  = 'upload.php';
  13  $submenu_file = 'upload.php';
  14  
  15  wp_reset_vars( array( 'action' ) );
  16  
  17  switch ( $action ) {
  18      case 'editattachment':
  19          $attachment_id = (int) $_POST['attachment_id'];
  20          check_admin_referer( 'media-form' );
  21  
  22          if ( ! current_user_can( 'edit_post', $attachment_id ) ) {
  23              wp_die( __( 'Sorry, you are not allowed to edit this attachment.' ) );
  24          }
  25  
  26          $errors = media_upload_form_handler();
  27  
  28          if ( empty( $errors ) ) {
  29              $location = 'media.php';
  30              $referer  = wp_get_original_referer();
  31              if ( $referer ) {
  32                  if ( false !== strpos( $referer, 'upload.php' ) || ( url_to_postid( $referer ) == $attachment_id ) ) {
  33                      $location = $referer;
  34                  }
  35              }
  36              if ( false !== strpos( $location, 'upload.php' ) ) {
  37                  $location = remove_query_arg( 'message', $location );
  38                  $location = add_query_arg( 'posted', $attachment_id, $location );
  39              } elseif ( false !== strpos( $location, 'media.php' ) ) {
  40                  $location = add_query_arg( 'message', 'updated', $location );
  41              }
  42              wp_redirect( $location );
  43              exit;
  44          }
  45  
  46          // No break.
  47      case 'edit':
  48          $title = __( 'Edit Media' );
  49  
  50          if ( empty( $errors ) ) {
  51              $errors = null;
  52          }
  53  
  54          if ( empty( $_GET['attachment_id'] ) ) {
  55              wp_redirect( admin_url( 'upload.php' ) );
  56              exit();
  57          }
  58          $att_id = (int) $_GET['attachment_id'];
  59  
  60          if ( ! current_user_can( 'edit_post', $att_id ) ) {
  61              wp_die( __( 'Sorry, you are not allowed to edit this attachment.' ) );
  62          }
  63  
  64          $att = get_post( $att_id );
  65  
  66          if ( empty( $att->ID ) ) {
  67              wp_die( __( 'You attempted to edit an attachment that doesn&#8217;t exist. Perhaps it was deleted?' ) );
  68          }
  69          if ( 'attachment' !== $att->post_type ) {
  70              wp_die( __( 'You attempted to edit an item that isn&#8217;t an attachment. Please go back and try again.' ) );
  71          }
  72          if ( $att->post_status == 'trash' ) {
  73              wp_die( __( 'You can&#8217;t edit this attachment because it is in the Trash. Please move it out of the Trash and try again.' ) );
  74          }
  75  
  76          add_filter( 'attachment_fields_to_edit', 'media_single_attachment_fields_to_edit', 10, 2 );
  77  
  78          wp_enqueue_script( 'wp-ajax-response' );
  79          wp_enqueue_script( 'image-edit' );
  80          wp_enqueue_style( 'imgareaselect' );
  81  
  82          get_current_screen()->add_help_tab(
  83              array(
  84                  'id'      => 'overview',
  85                  'title'   => __( 'Overview' ),
  86                  'content' =>
  87                      '<p>' . __( 'This screen allows you to edit fields for metadata in a file within the media library.' ) . '</p>' .
  88                      '<p>' . __( 'For images only, you can click on Edit Image under the thumbnail to expand out an inline image editor with icons for cropping, rotating, or flipping the image as well as for undoing and redoing. The boxes on the right give you more options for scaling the image, for cropping it, and for cropping the thumbnail in a different way than you crop the original image. You can click on Help in those boxes to get more information.' ) . '</p>' .
  89                      '<p>' . __( 'Note that you crop the image by clicking on it (the Crop icon is already selected) and dragging the cropping frame to select the desired part. Then click Save to retain the cropping.' ) . '</p>' .
  90                      '<p>' . __( 'Remember to click Update Media to save metadata entered or changed.' ) . '</p>',
  91              )
  92          );
  93  
  94          get_current_screen()->set_help_sidebar(
  95              '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  96              '<p>' . __( '<a href="https://wordpress.org/support/article/edit-media/">Documentation on Edit Media</a>' ) . '</p>' .
  97              '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
  98          );
  99  
 100          require( ABSPATH . 'wp-admin/admin-header.php' );
 101  
 102          $parent_file = 'upload.php';
 103          $message     = '';
 104          $class       = '';
 105          if ( isset( $_GET['message'] ) ) {
 106              switch ( $_GET['message'] ) {
 107                  case 'updated':
 108                      $message = __( 'Media file updated.' );
 109                      $class   = 'updated';
 110                      break;
 111              }
 112          }
 113          if ( $message ) {
 114              echo "<div id='message' class='$class'><p>$message</p></div>\n";
 115          }
 116  
 117          ?>
 118  
 119      <div class="wrap">
 120      <h1 class="wp-heading-inline">
 121          <?php
 122          echo esc_html( $title );
 123          ?>
 124  </h1>
 125  
 126          <?php
 127          if ( current_user_can( 'upload_files' ) ) {
 128              ?>
 129      <a href="media-new.php" class="page-title-action"><?php echo esc_html_x( 'Add New', 'file' ); ?></a>
 130  <?php } ?>
 131  
 132      <hr class="wp-header-end">
 133  
 134      <form method="post" class="media-upload-form" id="media-single-form">
 135      <p class="submit" style="padding-bottom: 0;">
 136          <?php submit_button( __( 'Update Media' ), 'primary', 'save', false ); ?>
 137      </p>
 138  
 139      <div class="media-single">
 140      <div id="media-item-<?php echo $att_id; ?>" class="media-item">
 141          <?php
 142          echo get_media_item(
 143              $att_id,
 144              array(
 145                  'toggle'     => false,
 146                  'send'       => false,
 147                  'delete'     => false,
 148                  'show_title' => false,
 149                  'errors'     => ! empty( $errors[ $att_id ] ) ? $errors[ $att_id ] : null,
 150              )
 151          );
 152          ?>
 153      </div>
 154      </div>
 155  
 156          <?php submit_button( __( 'Update Media' ), 'primary', 'save' ); ?>
 157      <input type="hidden" name="post_id" id="post_id" value="<?php echo isset( $post_id ) ? esc_attr( $post_id ) : ''; ?>" />
 158      <input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo esc_attr( $att_id ); ?>" />
 159      <input type="hidden" name="action" value="editattachment" />
 160          <?php wp_original_referer_field( true, 'previous' ); ?>
 161          <?php wp_nonce_field( 'media-form' ); ?>
 162  
 163      </form>
 164  
 165      </div>
 166  
 167          <?php
 168  
 169          require( ABSPATH . 'wp-admin/admin-footer.php' );
 170  
 171          exit;
 172  
 173      default:
 174          wp_redirect( admin_url( 'upload.php' ) );
 175          exit;
 176  
 177  }


Generated: Wed Dec 11 01:00:03 2019 Cross-referenced by PHPXref 0.7.1