[ 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  __DIR__ . '/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          // Used in the HTML title tag.
  49          $title = __( 'Edit Media' );
  50  
  51          if ( empty( $errors ) ) {
  52              $errors = null;
  53          }
  54  
  55          if ( empty( $_GET['attachment_id'] ) ) {
  56              wp_redirect( admin_url( 'upload.php' ) );
  57              exit;
  58          }
  59          $att_id = (int) $_GET['attachment_id'];
  60  
  61          if ( ! current_user_can( 'edit_post', $att_id ) ) {
  62              wp_die( __( 'Sorry, you are not allowed to edit this attachment.' ) );
  63          }
  64  
  65          $att = get_post( $att_id );
  66  
  67          if ( empty( $att->ID ) ) {
  68              wp_die( __( 'You attempted to edit an attachment that does not exist. Perhaps it was deleted?' ) );
  69          }
  70          if ( 'attachment' !== $att->post_type ) {
  71              wp_die( __( 'You attempted to edit an item that is not an attachment. Please go back and try again.' ) );
  72          }
  73          if ( 'trash' === $att->post_status ) {
  74              wp_die( __( 'You cannot edit this attachment because it is in the Trash. Please move it out of the Trash and try again.' ) );
  75          }
  76  
  77          add_filter( 'attachment_fields_to_edit', 'media_single_attachment_fields_to_edit', 10, 2 );
  78  
  79          wp_enqueue_script( 'wp-ajax-response' );
  80          wp_enqueue_script( 'image-edit' );
  81          wp_enqueue_style( 'imgareaselect' );
  82  
  83          get_current_screen()->add_help_tab(
  84              array(
  85                  'id'      => 'overview',
  86                  'title'   => __( 'Overview' ),
  87                  'content' =>
  88                      '<p>' . __( 'This screen allows you to edit fields for metadata in a file within the media library.' ) . '</p>' .
  89                      '<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>' .
  90                      '<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>' .
  91                      '<p>' . __( 'Remember to click Update Media to save metadata entered or changed.' ) . '</p>',
  92              )
  93          );
  94  
  95          get_current_screen()->set_help_sidebar(
  96              '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  97              '<p>' . __( '<a href="https://wordpress.org/support/article/edit-media/">Documentation on Edit Media</a>' ) . '</p>' .
  98              '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
  99          );
 100  
 101          require_once ABSPATH . 'wp-admin/admin-header.php';
 102  
 103          $parent_file = 'upload.php';
 104          $message     = '';
 105          $class       = '';
 106          if ( isset( $_GET['message'] ) ) {
 107              switch ( $_GET['message'] ) {
 108                  case 'updated':
 109                      $message = __( 'Media file updated.' );
 110                      $class   = 'updated';
 111                      break;
 112              }
 113          }
 114          if ( $message ) {
 115              echo "<div id='message' class='$class'><p>$message</p></div>\n";
 116          }
 117  
 118          ?>
 119  
 120      <div class="wrap">
 121      <h1 class="wp-heading-inline">
 122          <?php
 123          echo esc_html( $title );
 124          ?>
 125  </h1>
 126  
 127          <?php
 128          if ( current_user_can( 'upload_files' ) ) {
 129              ?>
 130      <a href="media-new.php" class="page-title-action"><?php echo esc_html_x( 'Add New', 'file' ); ?></a>
 131  <?php } ?>
 132  
 133      <hr class="wp-header-end">
 134  
 135      <form method="post" class="media-upload-form" id="media-single-form">
 136      <p class="submit" style="padding-bottom: 0;">
 137          <?php submit_button( __( 'Update Media' ), 'primary', 'save', false ); ?>
 138      </p>
 139  
 140      <div class="media-single">
 141      <div id="media-item-<?php echo $att_id; ?>" class="media-item">
 142          <?php
 143          echo get_media_item(
 144              $att_id,
 145              array(
 146                  'toggle'     => false,
 147                  'send'       => false,
 148                  'delete'     => false,
 149                  'show_title' => false,
 150                  'errors'     => ! empty( $errors[ $att_id ] ) ? $errors[ $att_id ] : null,
 151              )
 152          );
 153          ?>
 154      </div>
 155      </div>
 156  
 157          <?php submit_button( __( 'Update Media' ), 'primary', 'save' ); ?>
 158      <input type="hidden" name="post_id" id="post_id" value="<?php echo isset( $post_id ) ? esc_attr( $post_id ) : ''; ?>" />
 159      <input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo esc_attr( $att_id ); ?>" />
 160      <input type="hidden" name="action" value="editattachment" />
 161          <?php wp_original_referer_field( true, 'previous' ); ?>
 162          <?php wp_nonce_field( 'media-form' ); ?>
 163  
 164      </form>
 165  
 166      </div>
 167  
 168          <?php
 169  
 170          require_once ABSPATH . 'wp-admin/admin-footer.php';
 171  
 172          exit;
 173  
 174      default:
 175          wp_redirect( admin_url( 'upload.php' ) );
 176          exit;
 177  
 178  }


Generated: Wed Oct 16 01:00:02 2024 Cross-referenced by PHPXref 0.7.1