[ Index ]

PHP Cross Reference of Wordpress 2.9.1

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 ('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 ( __('You are not allowed to edit this attachment.') );
  24  
  25      $errors = media_upload_form_handler();
  26  
  27      if ( empty($errors) ) {
  28          $location = 'media.php';
  29          if ( $referer = wp_get_original_referer() ) {
  30              if ( false !== strpos($referer, 'upload.php') || ( url_to_postid($referer) == $attachment_id )  )
  31                  $location = $referer;
  32          }
  33          if ( false !== strpos($location, 'upload.php') ) {
  34              $location = remove_query_arg('message', $location);
  35              $location = add_query_arg('posted',    $attachment_id, $location);
  36          } elseif ( false !== strpos($location, 'media.php') ) {
  37              $location = add_query_arg('message', 'updated', $location);
  38          }
  39          wp_redirect($location);
  40          exit;
  41      }
  42  
  43      // no break
  44  case 'edit' :
  45      $title = __('Edit Media');
  46  
  47      if ( empty($errors) )
  48          $errors = null;
  49  
  50      if ( empty( $_GET['attachment_id'] ) ) {
  51          wp_redirect('upload.php');
  52          exit();
  53      }
  54      $att_id = (int) $_GET['attachment_id'];
  55  
  56      if ( !current_user_can('edit_post', $att_id) )
  57          wp_die ( __('You are not allowed to edit this attachment.') );
  58  
  59      $att = get_post($att_id);
  60  
  61      if ( empty($att->ID) ) wp_die( __('You attempted to edit an attachment that doesn&#8217;t exist. Perhaps it was deleted?') );
  62      if ( $att->post_status == 'trash' ) 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.') );
  63  
  64      add_filter('attachment_fields_to_edit', 'media_single_attachment_fields_to_edit', 10, 2);
  65  
  66      wp_enqueue_script( 'wp-ajax-response' );
  67      wp_enqueue_script('image-edit');
  68      wp_enqueue_style('imgareaselect');
  69  
  70      require ( 'admin-header.php' );
  71  
  72      $parent_file = 'upload.php';
  73      $message = '';
  74      $class = '';
  75      if ( isset($_GET['message']) ) {
  76          switch ( $_GET['message'] ) :
  77          case 'updated' :
  78              $message = __('Media attachment updated.');
  79              $class = 'updated fade';
  80              break;
  81          endswitch;
  82      }
  83      if ( $message )
  84          echo "<div id='message' class='$class'><p>$message</p></div>\n";
  85  
  86  ?>
  87  
  88  <div class="wrap">
  89  <?php screen_icon(); ?>
  90  <h2><?php _e( 'Edit Media' ); ?></h2>
  91  
  92  <form method="post" action="<?php echo esc_url( remove_query_arg( 'message' ) ); ?>" class="media-upload-form" id="media-single-form">
  93  <div class="media-single">
  94  <div id='media-item-<?php echo $att_id; ?>' class='media-item'>
  95  <?php echo get_media_item( $att_id, array( 'toggle' => false, 'send' => false, 'delete' => false, 'show_title' => false, 'errors' => $errors ) ); ?>
  96  </div>
  97  </div>
  98  
  99  <p class="submit">
 100  <input type="submit" class="button-primary" name="save" value="<?php esc_attr_e('Update Media'); ?>" />
 101  <input type="hidden" name="post_id" id="post_id" value="<?php echo isset($post_id) ? esc_attr($post_id) : ''; ?>" />
 102  <input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo esc_attr($att_id); ?>" />
 103  <input type="hidden" name="action" value="editattachment" />
 104  <?php wp_original_referer_field(true, 'previous'); ?>
 105  <?php wp_nonce_field('media-form'); ?>
 106  </p>
 107  </form>
 108  
 109  </div>
 110  
 111  <?php
 112  
 113      require ( 'admin-footer.php' );
 114  
 115      exit;
 116  
 117  default:
 118      wp_redirect( 'upload.php' );
 119      exit;
 120  
 121  endswitch;
 122  
 123  
 124  ?>


Generated: Fri Jan 8 00:19:48 2010 Cross-referenced by PHPXref 0.7