Exemplo n.º 1
0
 /**
  * Ajax handler to set post_parent for a single attachment
  *
  * Adapted from wp_ajax_inline_save in /wp-admin/includes/ajax-actions.php
  *
  * @since 0.20
  *
  * @return	void	echo HTML <td> innerHTML for updated call or error message, then die()
  */
 public static function mla_set_parent_ajax_action()
 {
     check_ajax_referer(MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME);
     if (empty($_REQUEST['post_ID'])) {
         echo __('ERROR', 'media-library-assistant') . ': ' . __('No post ID found', 'media-library-assistant');
         die;
     } else {
         $post_id = $_REQUEST['post_ID'];
     }
     if (!current_user_can('edit_post', $post_id)) {
         wp_die(__('ERROR', 'media-library-assistant') . ': ' . __('You are not allowed to edit this Attachment.', 'media-library-assistant'));
     }
     if (!class_exists('MLAData')) {
         require_once MLA_PLUGIN_PATH . 'includes/class-mla-data.php';
         MLAData::initialize();
     }
     $results = MLAData::mla_update_single_item($post_id, $_REQUEST);
     if (false !== strpos($results['message'], __('ERROR', 'media-library-assistant'))) {
         wp_die($results['message']);
     }
     $new_item = (object) MLAData::mla_get_attachment_by_id($post_id);
     if (!class_exists('MLA_List_Table')) {
         require_once MLA_PLUGIN_PATH . 'includes/class-mla-list-table.php';
         MLA_List_Table::mla_admin_init_action();
     }
     //	Create an instance of our package class and echo the new HTML
     $MLAListTable = apply_filters('mla_list_table_new_instance', NULL);
     if (is_null($MLAListTable)) {
         $MLAListTable = new MLA_List_Table();
     }
     $MLAListTable->single_row($new_item);
     die;
     // this is required to return a proper result
 }