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
 }
Exemplo n.º 2
0
 /**
  * Ajax handler for inline editing
  *
  * Adapted for Quick Edit from wp_ajax_inline_save in /wp-admin/includes/ajax-actions.php
  *
  * @since 0.20
  *
  * @return	void	echo HTML <tr> markup for updated row or error message, then die()
  */
 public static function mla_inline_edit_ajax_action()
 {
     set_current_screen($_REQUEST['screen']);
     check_ajax_referer(self::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME);
     if (!empty($_REQUEST['bulk_action'])) {
         self::_bulk_edit_ajax_handler();
         // calls wp_send_json_success and die()
     }
     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'));
     }
     /*
      * Custom field support
      */
     $custom_fields = array();
     foreach (MLAOptions::mla_custom_field_support('quick_edit') as $slug => $details) {
         if (isset($_REQUEST[$slug])) {
             $value = trim($_REQUEST[$slug]);
             unset($_REQUEST[$slug]);
             if ($details['no_null'] && empty($value)) {
                 $custom_fields[$details['name']] = NULL;
             } else {
                 $custom_fields[$details['name']] = $value;
             }
         }
     }
     if (!empty($custom_fields)) {
         $_REQUEST['custom_updates'] = $custom_fields;
     }
     /*
      * The category taxonomy is a special case because post_categories_meta_box() changes the input name
      */
     if (!isset($_REQUEST['tax_input'])) {
         $_REQUEST['tax_input'] = array();
     }
     if (isset($_REQUEST['post_category'])) {
         $_REQUEST['tax_input']['category'] = $_REQUEST['post_category'];
         unset($_REQUEST['post_category']);
     }
     if (!empty($_REQUEST['tax_input'])) {
         /*
          * Flat taxonomy strings must be cleaned up and duplicates removed
          */
         $tax_output = array();
         foreach ($_REQUEST['tax_input'] as $tax_name => $tax_value) {
             if (!is_array($tax_value)) {
                 $comma = _x(',', 'tag_delimiter', 'media-library-assistant');
                 if (',' != $comma) {
                     $tax_value = str_replace($comma, ',', $tax_value);
                 }
                 $tax_value = preg_replace('#\\s*,\\s*#', ',', $tax_value);
                 $tax_value = preg_replace('#,+#', ',', $tax_value);
                 $tax_value = preg_replace('#[,\\s]+$#', '', $tax_value);
                 $tax_value = preg_replace('#^[,\\s]+#', '', $tax_value);
                 if (',' != $comma) {
                     $tax_value = str_replace(',', $comma, $tax_value);
                 }
                 $tax_array = array();
                 $dedup_array = explode($comma, $tax_value);
                 foreach ($dedup_array as $tax_value) {
                     $tax_array[$tax_value] = $tax_value;
                 }
                 $tax_value = implode($comma, $tax_array);
             }
             // ! array( $tax_value )
             $tax_output[$tax_name] = $tax_value;
         }
         // foreach tax_input
         $_REQUEST['tax_input'] = $tax_output;
     }
     // ! empty( $_REQUEST['tax_input'] )
     $item_content = apply_filters('mla_list_table_inline_action', NULL, $post_id);
     if (is_null($item_content)) {
         $prevent_default = false;
         $custom_message = '';
     } else {
         $prevent_default = isset($item_content['prevent_default']) ? $item_content['prevent_default'] : false;
         $custom_message = isset($item_content['message']) ? $page_content['message'] : '';
     }
     if (!$prevent_default) {
         $results = MLAData::mla_update_single_item($post_id, $_REQUEST, $_REQUEST['tax_input']);
     }
     $new_item = (object) MLAData::mla_get_attachment_by_id($post_id);
     //	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
 }
 /**
  * Ajax handler to Quick Translate a single attachment
  *
  * @since 2.11
  *
  * @return	void	echo HTML <td> innerHTML for updated call or error message, then die()
  */
 public static function quick_translate()
 {
     global $polylang;
     check_ajax_referer(MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME);
     if (empty($_REQUEST['post_ID'])) {
         echo __('ERROR: No post ID found', 'media-library-assistant');
         die;
     } else {
         $post_id = (int) $_REQUEST['post_ID'];
     }
     if (!current_user_can('edit_post', $post_id)) {
         wp_die(__('You are not allowed to edit this Attachment.', 'media-library-assistant'));
     }
     self::_build_existing_terms($post_id);
     /*
      * pll_quick_language is used by the translation status links; edit or add the selected translation
      * inline_lang_choice is the value of the Language dropdown control; change the value of the current item
      */
     if (!empty($_REQUEST['pll_quick_language'])) {
         $new_id = MLA_Polylang::_get_translation($post_id, $_REQUEST['pll_quick_language']);
     } else {
         $new_id = $post_id;
         // Language dropdown in Quick Edit area
         if (isset($_REQUEST['inline_lang_choice'])) {
             $translations = $polylang->model->get_translations('post', $post_id);
             if (!array_key_exists($_REQUEST['inline_lang_choice'], $translations)) {
                 $post = get_post($post_id);
                 // save_post() does a check_admin_referer() security test
                 $_REQUEST['_inline_edit'] = wp_create_nonce('inlineeditnonce');
                 $polylang->filters_post->save_post($post_id, $post, true);
                 if ('checked' == MLAOptions::mla_get_option('term_assignment', false, false, MLA_Polylang::$mla_language_option_definitions)) {
                     // Record new language for Term Assignment and Synchronization
                     if (!empty($_REQUEST['tax_input'])) {
                         // Discard the old translation, which is gone
                         unset(self::$existing_terms[self::$existing_terms['slug']]);
                         self::$existing_terms['slug'] = $_REQUEST['inline_lang_choice'];
                     }
                     self::_build_existing_terms($post_id);
                     self::_build_tax_input($post_id);
                     $tax_inputs = self::_apply_tax_input(0, $_REQUEST['inline_lang_choice']);
                 } else {
                     $tax_inputs = NULL;
                 }
                 if (!empty($tax_inputs)) {
                     MLAData::mla_update_single_item($post_id, array(), $tax_inputs);
                 }
             }
             // change language
         }
     }
     //	Create an instance of our package class and echo the new HTML for all translations
     $translations = $polylang->model->get_translations('post', $post_id);
     $MLAListTable = new MLA_List_Table();
     $new_item = (object) MLAData::mla_get_attachment_by_id($new_id);
     $MLAListTable->single_row($new_item);
     foreach ($translations as $language => $post_id) {
         if ($new_id == $post_id) {
             continue;
         }
         $new_item = (object) MLAData::mla_get_attachment_by_id($post_id);
         $MLAListTable->single_row($new_item);
         echo "\n";
     }
     die;
     // this is required to return a proper result
 }
Exemplo n.º 4
0
 /**
  * Ajax handler for inline editing (quick and bulk edit)
  *
  * Adapted from wp_ajax_inline_save in /wp-admin/includes/ajax-actions.php
  *
  * @since 0.20
  *
  * @return	void	echo HTML <tr> markup for updated row or error message, then die()
  */
 public static function mla_inline_edit_action()
 {
     set_current_screen($_REQUEST['screen']);
     check_ajax_referer(self::MLA_ADMIN_NONCE, 'nonce');
     if (empty($_REQUEST['post_ID'])) {
         echo 'Error: no post ID found';
         die;
     } else {
         $post_id = $_REQUEST['post_ID'];
     }
     if (!current_user_can('edit_post', $post_id)) {
         wp_die(__('You are not allowed to edit this Attachment.'));
     }
     /*
      * Custom field support
      */
     $custom_fields = array();
     foreach (MLAOptions::mla_custom_field_support('quick_edit') as $slug => $label) {
         if (isset($_REQUEST[$slug])) {
             $custom_fields[$label] = $_REQUEST[$slug];
             unset($_REQUEST[$slug]);
         }
     }
     if (!empty($custom_fields)) {
         $_REQUEST['custom_updates'] = $custom_fields;
     }
     /*
      * The category taxonomy is a special case because post_categories_meta_box() changes the input name
      */
     if (!isset($_REQUEST['tax_input'])) {
         $_REQUEST['tax_input'] = array();
     }
     if (isset($_REQUEST['post_category'])) {
         $_REQUEST['tax_input']['category'] = $_REQUEST['post_category'];
         unset($_REQUEST['post_category']);
     }
     if (!empty($_REQUEST['tax_input'])) {
         /*
          * Flat taxonomy strings must be cleaned up and duplicates removed
          */
         $tax_output = array();
         $tax_input = $_REQUEST['tax_input'];
         foreach ($tax_input as $tax_name => $tax_value) {
             if (!is_array($tax_value)) {
                 $comma = _x(',', 'tag delimiter');
                 if (',' != $comma) {
                     $tax_value = str_replace($comma, ',', $tax_value);
                 }
                 $tax_value = preg_replace('#\\s*,\\s*#', ',', $tax_value);
                 $tax_value = preg_replace('#,+#', ',', $tax_value);
                 $tax_value = preg_replace('#[,\\s]+$#', '', $tax_value);
                 $tax_value = preg_replace('#^[,\\s]+#', '', $tax_value);
                 if (',' != $comma) {
                     $tax_value = str_replace(',', $comma, $tax_value);
                 }
                 $tax_array = array();
                 $dedup_array = explode($comma, $tax_value);
                 foreach ($dedup_array as $tax_value) {
                     $tax_array[$tax_value] = $tax_value;
                 }
                 $tax_value = implode($comma, $tax_array);
             }
             // ! array( $tax_value )
             $tax_output[$tax_name] = $tax_value;
         }
         // foreach $tax_input
     } else {
         $tax_output = NULL;
     }
     $results = MLAData::mla_update_single_item($post_id, $_REQUEST, $tax_output);
     $new_item = (object) MLAData::mla_get_attachment_by_id($post_id);
     //	Create an instance of our package class and echo the new HTML
     $MLAListTable = new MLA_List_Table();
     $MLAListTable->single_row($new_item);
     die;
     // this is required to return a proper result
 }