The Media Library Assistant cannot activate multi-language support. Another plugin or theme has declared conflicting class, function or constant names:
'."\r\n";
echo "\r\n";
echo 'You must resolve these conflicts before multi-language support can be activated.
'."\r\n";
}
/**
* Initialization function, similar to __construct()
*
* This function contains add_action and add_filter calls
* to set up the Ajax handlers, enqueue JavaScript and CSS files, and
* set up the Assistant submenu.
*
* @since 0.1
*
* @return void
*/
public static function initialize( ) {
global $sitepress, $polylang;
if ( 'checked' == MLACore::mla_get_option( 'enable_featured_image_generation' ) ) {
if ( class_exists( 'MLA_Thumbnail' ) ) {
self::$mla_language_support_error_messages .= "class MLA_Thumbnail";
} else {
require_once( MLA_PLUGIN_PATH . 'includes/class-mla-thumbnail-generation.php' );
MLA_Thumbnail::initialize();
}
}
/*
* Check for WPML/Polylang presence before loading language support class,
* then immediately initialize it since we're already in the "init" action.
*/
if ( is_object( $sitepress ) ) {
if ( class_exists( 'MLA_WPML' ) ) {
self::$mla_language_support_error_messages .= "class MLA_WPML";
}
if ( class_exists( 'MLA_WPML_List_Table' ) ) {
self::$mla_language_support_error_messages .= "class MLA_WPML_List_Table";
}
if ( class_exists( 'MLA_WPML_Table' ) ) {
self::$mla_language_support_error_messages .= "class MLA_WPML_Table";
}
if ( empty( self::$mla_language_support_error_messages ) ) {
require_once( MLA_PLUGIN_PATH . 'includes/class-mla-wpml-support.php' );
MLA_WPML::initialize();
}
} elseif ( is_object( $polylang ) ) {
if ( class_exists( 'MLA_Polylang' ) ) {
self::$mla_language_support_error_messages .= "class MLA_Polylang";
}
if ( empty( self::$mla_language_support_error_messages ) ) {
require_once( MLA_PLUGIN_PATH . 'includes/class-mla-polylang-support.php' );
MLA_Polylang::initialize();
}
}
if ( ! empty( self::$mla_language_support_error_messages ) ) {
add_action( 'admin_notices', 'MLA::mla_name_conflict_reporting_action' );
}
add_action( 'admin_init', 'MLA::mla_admin_init_action' );
add_action( 'admin_enqueue_scripts', 'MLA::mla_admin_enqueue_scripts_action' );
add_action( 'admin_menu', 'MLA::mla_admin_menu_action' );
add_filter( 'set-screen-option', 'MLA::mla_set_screen_option_filter', 10, 3 ); // $status, $option, $value
add_filter( 'screen_options_show_screen', 'MLA::mla_screen_options_show_screen_filter', 10, 2 ); // $show_screen, $this
}
/**
* Load the plugin's Ajax handler or process Edit Media update actions
*
* @since 0.20
*
* @return void
*/
public static function mla_admin_init_action() {
//static $count = 0;
//error_log( __LINE__ . ' MLA::mla_admin_init_action $count = ' . var_export( $count++, true ), 0 );
//error_log( __LINE__ . ' MLA::mla_admin_init_action referer = ' . var_export( wp_get_referer(), true ), 0 );
//error_log( __LINE__ . ' MLA::mla_admin_init_action $_REQUEST = ' . var_export( $_REQUEST, true ), 0 );
//error_log( __LINE__ . ' MLA::mla_admin_init_action $_POST = ' . var_export( $_POST, true ), 0 );
//error_log( __LINE__ . ' MLA::mla_admin_init_action $_GET = ' . var_export( $_GET, true ), 0 );
// Process secure file download requests
if ( isset( $_REQUEST['mla_download_file'] ) && isset( $_REQUEST['mla_download_type'] ) ) {
check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
self::_process_mla_download_file( $_REQUEST, true );
exit();
}
// Process example plugin download requests from the Documentation tab
if ( isset( $_REQUEST['mla_download_example_plugin'] ) ) {
check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
$request = array (
'mla_download_file' => str_replace( '\\', '/', MLA_PLUGIN_PATH . 'examples/plugins/' . stripslashes( $_REQUEST['mla_download_example_plugin'] ) ),
'mla_download_type' => 'text/plain',
);
self::_process_mla_download_file( $request, false );
exit();
}
// Process error log download requests from the Debug tab
if ( isset( $_REQUEST['mla_download_error_log'] ) ) {
check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
// Find the appropriate error log file
$error_log_name = MLACore::mla_get_option( MLACoreOptions::MLA_DEBUG_FILE );
if ( empty( $error_log_name ) ) {
$error_log_name = ini_get( 'error_log' );
} else {
$first = substr( $error_log_name, 0, 1 );
if ( ( '/' != $first ) && ( '\\' != $first ) ) {
$error_log_name = '/' . $error_log_name;
}
$error_log_name = WP_CONTENT_DIR . $error_log_name;
}
if ( file_exists ( $error_log_name ) ) {
$request = array (
'mla_download_file' => addslashes( $error_log_name ),
'mla_download_type' => 'text/plain',
);
self::_process_mla_download_file( $request, false );
}
exit();
}
$bulk_action = '';
if ( isset( $_REQUEST['action'] ) && 'download-zip' == $_REQUEST['action']) {
$bulk_action = 'download-zip';
} elseif ( isset( $_REQUEST['action2'] ) && 'download-zip' == $_REQUEST['action2']) {
$bulk_action = 'download-zip';
}
if ( 'download-zip' == $bulk_action ) {
// Exits after redirect unless it returns an error
$_REQUEST['mla_zip_archive_error_message'] = self::_process_zip_archive_download( $_REQUEST );
MLACore::mla_debug_add( __LINE__ . " MLA::_process_zip_archive_download message = " . var_export( $_REQUEST['mla_zip_archive_error_message'], true ), MLACore::MLA_DEBUG_CATEGORY_ANY );
return;
}
// Process row-level actions from the Edit Media screen
if ( !empty( $_REQUEST['mla_admin_action'] ) ) {
if ( isset( $_REQUEST['mla-set-parent-ajax-nonce'] ) ) {
check_admin_referer( 'mla_find_posts', 'mla-set-parent-ajax-nonce' );
} else {
check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
}
if ( apply_filters( 'mla_list_table_admin_action', true, $_REQUEST['mla_admin_action'], ( isset( $_REQUEST['mla_item_ID'] ) ? $_REQUEST['mla_item_ID'] : 0 ) ) ) {
switch ( $_REQUEST['mla_admin_action'] ) {
case MLACore::MLA_ADMIN_SINGLE_CUSTOM_FIELD_MAP:
if ( 'checked' == MLACore::mla_get_option( MLACoreOptions::MLA_ALLOW_CUSTOM_FIELD_MAPPING ) ) {
do_action( 'mla_begin_mapping', 'single_custom', $_REQUEST['mla_item_ID'] );
$updates = MLAOptions::mla_evaluate_custom_field_mapping( $_REQUEST['mla_item_ID'], 'single_attachment_mapping' );
do_action( 'mla_end_mapping' );
if ( !empty( $updates ) ) {
$item_content = MLAData::mla_update_single_item( $_REQUEST['mla_item_ID'], $updates );
}
$message = '101';
} else {
$message = '103';
}
$view_args = isset( $_REQUEST['mla_source'] ) ? array( 'mla_source' => $_REQUEST['mla_source']) : array();
wp_redirect( add_query_arg( $view_args, admin_url( 'post.php' ) . '?post=' . $_REQUEST['mla_item_ID'] . '&action=edit&message=' . $message ), 302 );
exit;
case MLACore::MLA_ADMIN_SINGLE_MAP:
if ( 'checked' == MLACore::mla_get_option( MLACoreOptions::MLA_ALLOW_IPTC_EXIF_MAPPING ) ) {
$item = get_post( $_REQUEST['mla_item_ID'] );
do_action( 'mla_begin_mapping', 'single_iptc_exif', $_REQUEST['mla_item_ID'] );
$updates = MLAOptions::mla_evaluate_iptc_exif_mapping( $item, 'iptc_exif_mapping' );
do_action( 'mla_end_mapping' );
$page_content = MLAData::mla_update_single_item( $_REQUEST['mla_item_ID'], $updates );
$message = '102';
} else {
$message = '104';
}
$view_args = isset( $_REQUEST['mla_source'] ) ? array( 'mla_source' => $_REQUEST['mla_source']) : array();
wp_redirect( add_query_arg( $view_args, admin_url( 'post.php' ) . '?post=' . $_REQUEST['mla_item_ID'] . '&action=edit&message=' . $message ), 302 );
exit;
default:
do_action( 'mla_list_table_custom_admin_action', $_REQUEST['mla_admin_action'], ( isset( $_REQUEST['mla_item_ID'] ) ? $_REQUEST['mla_item_ID'] : 0 ) );
// ignore the rest
} // switch ($_REQUEST['mla_admin_action'])
} // apply_filters mla_list_table_admin_action
} // (!empty($_REQUEST['mla_admin_action'])
if ( is_admin() ) {
if ( defined('DOING_AJAX') && DOING_AJAX ) {
add_action( 'wp_ajax_' . MLACore::JAVASCRIPT_INLINE_EDIT_SLUG, 'MLA::mla_inline_edit_ajax_action' );
}
}
}
/**
* Print optional in-lne styles for Media/Assistant submenu table
*
* @since 2.13
*/
public static function mla_admin_print_styles_action() {
echo "\n";
}
/**
* Load the plugin's Style Sheet and Javascript files
*
* @since 0.1
*
* @param string Name of the page being loaded
*
* @return void
*/
public static function mla_admin_enqueue_scripts_action( $page_hook ) {
global $wp_locale;
$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
if ( 'checked' != MLACore::mla_get_option( MLACoreOptions::MLA_SCREEN_DISPLAY_LIBRARY ) ) {
wp_register_style( MLACore::STYLESHEET_SLUG . '-nolibrary', MLA_PLUGIN_URL . 'css/mla-nolibrary.css', false, MLACore::CURRENT_MLA_VERSION );
wp_enqueue_style( MLACore::STYLESHEET_SLUG . '-nolibrary' );
}
if ( 'edit-tags.php' == $page_hook ) {
wp_register_style( MLACore::STYLESHEET_SLUG, MLA_PLUGIN_URL . 'css/mla-edit-tags-style.css', false, MLACore::CURRENT_MLA_VERSION );
wp_enqueue_style( MLACore::STYLESHEET_SLUG );
return;
}
if ( 'media_page_' . MLACore::ADMIN_PAGE_SLUG != $page_hook ) {
return;
}
// Add the styles for variable-size icon and WP 4.3 primary column display
add_action( 'admin_print_styles', 'MLA::mla_admin_print_styles_action' );
if ( $wp_locale->is_rtl() ) {
wp_register_style( MLACore::STYLESHEET_SLUG, MLA_PLUGIN_URL . 'css/mla-style-rtl.css', false, MLACore::CURRENT_MLA_VERSION );
} else {
wp_register_style( MLACore::STYLESHEET_SLUG, MLA_PLUGIN_URL . 'css/mla-style.css', false, MLACore::CURRENT_MLA_VERSION );
}
wp_enqueue_style( MLACore::STYLESHEET_SLUG );
wp_register_style( MLACore::STYLESHEET_SLUG . '-set-parent', MLA_PLUGIN_URL . 'css/mla-style-set-parent.css', false, MLACore::CURRENT_MLA_VERSION );
wp_enqueue_style( MLACore::STYLESHEET_SLUG . '-set-parent' );
wp_enqueue_script( MLACore::JAVASCRIPT_INLINE_EDIT_SLUG, MLA_PLUGIN_URL . "js/mla-inline-edit-scripts{$suffix}.js",
array( 'wp-lists', 'suggest', 'jquery' ), MLACore::CURRENT_MLA_VERSION, false );
if ( MLACore::mla_supported_taxonomies( 'checklist-add-term' ) ) {
wp_enqueue_script( MLACore::JAVASCRIPT_INLINE_EDIT_SLUG . '-add-term', MLA_PLUGIN_URL . "js/mla-add-term-scripts{$suffix}.js",
array( 'wp-ajax-response', 'jquery', MLACore::JAVASCRIPT_INLINE_EDIT_SLUG ), MLACore::CURRENT_MLA_VERSION, false );
}
wp_enqueue_script( MLACore::JAVASCRIPT_INLINE_EDIT_SLUG . '-set-parent', MLA_PLUGIN_URL . "js/mla-set-parent-scripts{$suffix}.js",
array( 'wp-lists', 'suggest', 'jquery', MLACore::JAVASCRIPT_INLINE_EDIT_SLUG ), MLACore::CURRENT_MLA_VERSION, false );
MLAModal::mla_add_terms_search_scripts();
$fields = array( 'post_title', 'post_name', 'post_excerpt', 'post_content', 'image_alt', 'jj', 'mm', 'aa', 'hh', 'mn', 'ss', 'post_parent', 'post_parent_title', 'menu_order', 'post_author' );
$custom_fields = MLACore::mla_custom_field_support( 'quick_edit' );
$custom_fields = array_merge( $custom_fields, MLACore::mla_custom_field_support( 'bulk_edit' ) );
foreach ( $custom_fields as $slug => $details ) {
$fields[] = $slug;
}
$fields = apply_filters( 'mla_list_table_inline_fields', $fields );
$script_variables = array(
'fields' => $fields,
'ajaxFailError' => __( 'An ajax.fail error has occurred. Please reload the page and try again.', 'media-library-assistant' ),
'ajaxDoneError' => __( 'An ajax.done error has occurred. Please reload the page and try again.', 'media-library-assistant' ),
'error' => __( 'Error while saving the changes.', 'media-library-assistant' ),
'ntdelTitle' => __( 'Remove From Bulk Edit', 'media-library-assistant' ),
'noTitle' => __( '(no title)', 'media-library-assistant' ),
'bulkTitle' => __( 'Bulk Edit items', 'media-library-assistant' ),
'bulkWaiting' => __( 'Waiting', 'media-library-assistant' ),
'bulkComplete' => __( 'Complete', 'media-library-assistant' ),
'bulkUnchanged' => __( 'Unchanged', 'media-library-assistant' ),
'bulkSuccess' => __( 'Succeeded', 'media-library-assistant' ),
'bulkFailure' => __( 'Failed', 'media-library-assistant' ),
'bulkCanceled' => __( 'CANCELED', 'media-library-assistant' ),
'bulkChunkSize' => MLACore::mla_get_option( MLACoreOptions::MLA_BULK_CHUNK_SIZE ),
'comma' => _x( ',', 'tag_delimiter', 'media-library-assistant' ),
'useSpinnerClass' => false,
'ajax_action' => MLACore::JAVASCRIPT_INLINE_EDIT_SLUG,
'ajax_nonce' => wp_create_nonce( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ),
'deleteAcpBulkEdit' => false,
);
if ( version_compare( get_bloginfo( 'version' ), '4.2', '>=' ) ) {
$script_variables['useSpinnerClass'] = true;
}
if ( 'checked' == MLACore::mla_get_option( MLACoreOptions::MLA_BULK_EDITOR ) ) {
$script_variables['quickTagsInit'] = array( 'post_content' => array( 'id' => 'post_content', 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close', 'active' => true, ) );
}
if ( function_exists( 'ACP' ) && ( version_compare( ACP()->get_version(), '4.5', '>=' ) ) ) {
if ( version_compare( ACP()->get_version(), '4.5.4', '<' ) ) {
$script_variables['deleteAcpBulkEdit'] = true;
}
}
wp_localize_script( MLACore::JAVASCRIPT_INLINE_EDIT_SLUG, self::JAVASCRIPT_INLINE_EDIT_OBJECT, $script_variables );
}
/**
* Add the submenu pages
*
* Add a submenu page in the "Media" section,
* add settings page in the "Settings" section.
* add settings link in the Plugins section entry for MLA.
*
* @since 0.1
*
* @return void
*/
public static function mla_admin_menu_action( ) {
global $submenu;
add_action( 'load-upload.php', 'MLA::mla_load_media_action' );
// Disable the MLA Download ZIP Example plugin, if necessary
if ( isset( $_REQUEST['page'] ) && 'mla-menu' === $_REQUEST['page'] ) {
$bulk_action = '';
if ( isset( $_REQUEST['action'] ) && 'download-zip' === $_REQUEST['action']) {
$bulk_action = 'download-zip';
} elseif ( isset( $_REQUEST['action2'] ) && 'download-zip' === $_REQUEST['action2']) {
$bulk_action = 'download-zip';
}
if ( 'download-zip' === $bulk_action ) {
if ( is_plugin_active( 'mla-zip-archive-example/mla-zip-archive-example.php' ) ) {
deactivate_plugins( 'mla-zip-archive-example/mla-zip-archive-example.php', true );
}
if ( is_plugin_active( 'mla-zip-archive-example.php' ) ) {
deactivate_plugins( 'mla-zip-archive-example.php', true );
}
}
}
$page_title = MLACore::mla_get_option( MLACoreOptions::MLA_SCREEN_PAGE_TITLE );
if ( empty( $page_title ) ) {
$page_title = MLACore::mla_get_option( MLACoreOptions::MLA_SCREEN_PAGE_TITLE, true );
}
$menu_title = MLACore::mla_get_option( MLACoreOptions::MLA_SCREEN_MENU_TITLE );
if ( empty( $menu_title ) ) {
$menu_title = MLACore::mla_get_option( MLACoreOptions::MLA_SCREEN_MENU_TITLE, true );
}
$hook = add_submenu_page( 'upload.php', $page_title, $menu_title, 'upload_files', MLACore::ADMIN_PAGE_SLUG, 'MLA::mla_render_admin_page' );
add_action( 'load-' . $hook, 'MLA::mla_add_menu_options' );
add_action( 'load-' . $hook, 'MLA::mla_add_help_tab' );
self::$page_hooks[ $hook ] = $hook;
$taxonomies = get_object_taxonomies( 'attachment', 'objects' );
if ( !empty( $taxonomies ) ) {
foreach ( $taxonomies as $tax_name => $tax_object ) {
/*
* The page_hook we need for taxonomy edits is slightly different
*/
$hook = 'edit-' . $tax_name;
self::$page_hooks[ $hook ] = 't_' . $tax_name;
} // foreach $taxonomies
/*
* Load here, not 'load-edit-tags.php', to put our tab after the defaults
*/
add_action( 'admin_head-edit-tags.php', 'MLA::mla_add_help_tab' );
}
/*
* If we are suppressing the Media/Library submenu, force Media/Assistant to come first
*/
if ( 'checked' != MLACore::mla_get_option( MLACoreOptions::MLA_SCREEN_DISPLAY_LIBRARY ) ) {
$menu_position = 4;
} else {
$menu_position = (integer) MLACore::mla_get_option( MLACoreOptions::MLA_SCREEN_ORDER );
}
if ( $menu_position && !empty( $submenu['upload.php'] ) ) {
foreach ( $submenu['upload.php'] as $menu_order => $menu_item ) {
if ( MLACore::ADMIN_PAGE_SLUG == $menu_item[2] ) {
$menu_item[2] = 'upload.php?page=' . MLACore::ADMIN_PAGE_SLUG;
$submenu['upload.php'][$menu_position] = $menu_item;
unset( $submenu['upload.php'][$menu_order] );
ksort( $submenu['upload.php'] );
break;
}
}
}
add_filter( 'parent_file', 'MLA::mla_parent_file_filter', 10, 1 );
}
/**
* Redirect to Media/Assistant if Media/Library is hidden or a trash/delete
* returns from Media/Edit Media initiated from Media/Assistant
*
* @since 1.60
*
* @return void
*/
public static function mla_load_media_action( ) {
$mla_source = isset( $_REQUEST['mla_source'] ) && in_array( $_REQUEST['mla_source'], array ( 'trash', 'delete' ) );
if ( $mla_source || ( 'checked' != MLACore::mla_get_option( MLACoreOptions::MLA_SCREEN_DISPLAY_LIBRARY ) ) ) {
// Allow "grid" view even if the list view is suppressed
if ( isset( $_REQUEST['mode'] ) && 'grid' === $_REQUEST['mode'] ) {
return;
}
$query_args = '?page=' . MLACore::ADMIN_PAGE_SLUG;
// Compose a message if returning from the Edit Media screen
if ( ! empty( $_GET['deleted'] ) && $deleted = absint( $_GET['deleted'] ) ) {
$query_args .= '&mla_admin_message=' . urlencode( sprintf( _n( 'Item permanently deleted.', '%d items permanently deleted.', $deleted, 'media-library-assistant' ), number_format_i18n( $_GET['deleted'] ) ) );
}
if ( ! empty( $_GET['trashed'] ) && $trashed = absint( $_GET['trashed'] ) ) {
/* translators: 1: post ID */
$query_args .= '&mla_admin_message=' . urlencode( sprintf( __( 'Item %1$d moved to Trash.', 'media-library-assistant' ), $_GET['ids'] ) );
}
wp_redirect( admin_url( 'upload.php' ) . $query_args, 302 );
exit;
}
}
/**
* Add the "XX Entries per page" filter to the Screen Options tab
*
* @since 0.1
*
* @return void
*/
public static function mla_add_menu_options( ) {
$option = 'per_page';
$args = array(
'label' => __( 'Entries per page', 'media-library-assistant' ),
'default' => 10,
'option' => MLA_OPTION_PREFIX . 'entries_per_page'
);
add_screen_option( $option, $args );
}
/**
* Add contextual help tabs to all the MLA pages
*
* @since 0.1
*
* @return void
*/
public static function mla_add_help_tab( ) {
$screen = get_current_screen();
// Is this one of our pages?
if ( !array_key_exists( $screen->id, self::$page_hooks ) ) {
return;
}
if ( 'edit-tags' == $screen->base && 'attachment' != $screen->post_type ) {
return;
}
$file_suffix = $screen->id;
// Use a generic page for edit taxonomy screens
if ( 't_' == substr( self::$page_hooks[ $file_suffix ], 0, 2 ) ) {
$taxonomy = substr( self::$page_hooks[ $file_suffix ], 2 );
switch ( $taxonomy ) {
case 'attachment_category':
case 'attachment_tag':
break;
default:
$tax_object = get_taxonomy( $taxonomy );
if ( $tax_object->hierarchical ) {
$file_suffix = 'edit-hierarchical-taxonomy';
} else {
$file_suffix = 'edit-flat-taxonomy';
}
} // $taxonomy switch
} // is taxonomy
$template_array = apply_filters( 'mla_list_table_help_template', NULL, 'help-for-' . $file_suffix . '.tpl', $file_suffix );
if ( is_null( $template_array ) ) {
$template_array = MLACore::mla_load_template( 'help-for-' . $file_suffix . '.tpl' );
}
if ( empty( $template_array ) ) {
return;
}
// Don't add sidebar to the WordPress category and post_tag screens
if ( ! ( 'edit-tags' == $screen->base && in_array( $screen->taxonomy, array( 'post_tag', 'category' ) ) ) ) {
if ( !empty( $template_array['sidebar'] ) ) {
$page_values = array( 'settingsURL' => admin_url('options-general.php') );
$content = MLAData::mla_parse_template( $template_array['sidebar'], $page_values );
$screen->set_help_sidebar( $content );
}
}
unset( $template_array['sidebar'] );
// Provide explicit control over tab order
$tab_array = array();
foreach ( $template_array as $id => $content ) {
$match_count = preg_match( '#\\n";
/*
* Insert the hidden form and table for inline edits (quick & bulk)
*/
echo self::_build_inline_edit_form( $MLAListTable );
echo "\n";
echo "
\n";
echo "\n";
} // display attachments list
}
/**
* Ajax handler for bulk editing and mapping
*
* @since 2.00
*
* @return void echo json results or error message, then die()
*/
private static function _bulk_edit_ajax_handler() {
/*
* The category taxonomy (edit screens) 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'] );
}
/*
* Convert bulk_action to the old button name/value variables
*/
switch ( $_REQUEST['bulk_action'] ) {
case 'bulk_custom_field_map':
$_REQUEST['bulk_custom_field_map'] = __( 'Map Custom Field metadata', 'media-library-assistant' );
break;
case 'bulk_map':
$_REQUEST['bulk_map'] = __( 'Map IPTC/EXIF metadata', 'media-library-assistant' );
break;
case 'bulk_edit':
$_REQUEST['bulk_edit'] = __( 'Update', 'media-library-assistant' );
}
$item_content = (object) self::mla_process_bulk_action( 'edit' );
wp_send_json_success( $item_content );
}
/**
* 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 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( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::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 ( MLACore::mla_custom_field_support( 'quick_edit' ) as $slug => $details ) {
if ( isset( $_REQUEST[ $slug ] ) ) {
$value = trim( $_REQUEST[ $slug ] );
unset ( $_REQUEST[ $slug ] );
// '(Array)' indicates an existing array value in the field, which we preserve
if ( 'array' == $details['option'] ) {
$value = explode( ',', $value );
} elseif ( '(Array)' == $value ) {
continue;
}
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 ) ) {
// Make sure term_id values are integers, not strings, for flat-checklist
$tax_value = array_map( 'absint', $tax_value );
} else {
$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 ) {
MLACore::mla_debug_add( __LINE__ . " MLA::mla_inline_edit_ajax_action( {$post_id} ) \$_REQUEST = " . var_export( $_REQUEST, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
$new_date = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $_REQUEST['aa'], $_REQUEST['mm'], $_REQUEST['jj'], $_REQUEST['hh'], $_REQUEST['mn'], $_REQUEST['ss'] );
if ( wp_checkdate( $_REQUEST['mm'], $_REQUEST['jj'], $_REQUEST['aa'], $new_date ) ) {
$_REQUEST['post_date'] = $new_date;
$_REQUEST['post_date_gmt'] = get_gmt_from_date( $new_date );
}
$results = MLAData::mla_update_single_item( $post_id, $_REQUEST, $_REQUEST['tax_input'] );
MLACore::mla_debug_add( __LINE__ . " MLA::mla_inline_edit_ajax_action( {$post_id} ) results = " . var_export( $results, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
}
$new_item = (object) MLAData::mla_get_attachment_by_id( $post_id );
MLACore::mla_debug_add( __LINE__ . " MLA::mla_inline_edit_ajax_action( {$post_id} ) new_item = " . var_export( $new_item, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
// 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
}
/**
* Compose a Post Type Options list with current selection
*
* @since 1.90
*
* @param array template parts
* @param string current selection or 'all' (default)
*
* @return string HTML markup with select field options
*/
private static function _compose_post_type_select( &$templates, $selection = 'all' ) {
$option_template = $templates['post-type-select-option'];
$option_values = array (
'selected' => ( 'all' == $selection ) ? 'selected="selected"' : '',
'value' => 'all',
'text' => '— ' . __( 'All Post Types', 'media-library-assistant' ) . ' —'
);
$options = MLAData::mla_parse_template( $option_template, $option_values );
$post_types = get_post_types( array( 'public' => true ), 'objects' );
unset( $post_types['attachment'] );
foreach ( $post_types as $key => $value ) {
$option_values = array (
'selected' => ( $key == $selection ) ? 'selected="selected"' : '',
'value' => $key,
'text' => $value->labels->name
);
$options .= MLAData::mla_parse_template( $option_template, $option_values );
} // foreach post_type
$select_template = $templates['post-type-select'];
$select_values = array (
'options' => $options,
);
$select = MLAData::mla_parse_template( $select_template, $select_values );
return $select;
} // _compose_post_type_select
/**
* Build the hidden form for the "Set Parent" popup modal window
*
* @since 1.90
*
* @param boolean true to return complete form, false to return mla-set-parent-div
*
* @return string HTML