$value ) { if ( is_array( $value ) ) { $tax = get_taxonomy( $key ); if ( $tax->hierarchical ) { continue; } if ( false !== ( $bad_term = array_search( '0', $value ) ) ) { unset( $value[ $bad_term ] ); } $comma = _x( ',', 'tag_delimiter', 'media-library-assistant' ); $_POST['tax_input'][ $key ] = implode( $comma, $value ); $_REQUEST['tax_input'][ $key ] = implode( $comma, $value ); } // array value } // foreach tax_input } // array tax_input } // action editpost } /** * Load the plugin's Style Sheet and Javascript files * * @since 1.71 * * @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'; // Add New Bulk Edit Area if ( 'media-new.php' == $page_hook && ( 'checked' == MLACore::mla_get_option( MLACoreOptions::MLA_ADD_NEW_BULK_EDIT ) ) ) { if ( $wp_locale->is_rtl() ) { wp_register_style( 'mla-add-new-bulk-edit', MLA_PLUGIN_URL . 'css/mla-add-new-bulk-edit-rtl.css', false, MLACore::CURRENT_MLA_VERSION ); wp_register_style( 'mla-add-new-bulk-edit' . '-set-parent', MLA_PLUGIN_URL . 'css/mla-style-set-parent-rtl.css', false, MLACore::CURRENT_MLA_VERSION ); } else { wp_register_style( 'mla-add-new-bulk-edit', MLA_PLUGIN_URL . 'css/mla-add-new-bulk-edit.css', false, MLACore::CURRENT_MLA_VERSION ); wp_register_style( 'mla-add-new-bulk-edit' . '-set-parent', MLA_PLUGIN_URL . 'css/mla-style-set-parent.css', false, MLACore::CURRENT_MLA_VERSION ); } wp_enqueue_style( 'mla-add-new-bulk-edit' ); wp_enqueue_style( 'mla-add-new-bulk-edit' . '-set-parent' ); // 'suggest' loads the script for flat taxonomy auto-complete/suggested matches wp_enqueue_script( 'mla-add-new-bulk-edit-scripts', MLA_PLUGIN_URL . "js/mla-add-new-bulk-edit-scripts{$suffix}.js", array( 'suggest', 'jquery' ), MLACore::CURRENT_MLA_VERSION, false ); if ( MLACore::mla_supported_taxonomies( 'checklist-add-term' ) ) { wp_enqueue_script( 'mla-add-new-bulk-edit-scripts' . '-add-term', MLA_PLUGIN_URL . "js/mla-add-term-scripts{$suffix}.js", array( 'wp-ajax-response', 'jquery', 'mla-add-new-bulk-edit-scripts' ), MLACore::CURRENT_MLA_VERSION, false ); } wp_enqueue_script( 'mla-add-new-bulk-edit-scripts' . '-set-parent', MLA_PLUGIN_URL . "js/mla-set-parent-scripts{$suffix}.js", array( 'mla-add-new-bulk-edit-scripts', 'jquery' ), MLACore::CURRENT_MLA_VERSION, false ); $script_variables = array( 'uploadTitle' => __( 'Upload New Media items', 'media-library-assistant' ), 'toggleOpen' => __( 'Open Bulk Edit area', 'media-library-assistant' ), 'toggleClose' => __( 'Close Bulk Edit area', 'media-library-assistant' ), 'areaOnTop' => ( 'checked' == MLACore::mla_get_option( MLACoreOptions::MLA_ADD_NEW_BULK_EDIT_ON_TOP ) ), 'areaOpen' => ( 'checked' == MLACore::mla_get_option( MLACoreOptions::MLA_ADD_NEW_BULK_EDIT_AUTO_OPEN ) ), 'comma' => _x( ',', 'tag_delimiter', 'media-library-assistant' ), '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' ), 'useDashicons' => false, 'useSpinnerClass' => false, ); if ( version_compare( get_bloginfo( 'version' ), '3.8', '>=' ) ) { $script_variables['useDashicons'] = true; } if ( version_compare( get_bloginfo( 'version' ), '4.2', '>=' ) ) { $script_variables['useSpinnerClass'] = true; } wp_localize_script( 'mla-add-new-bulk-edit-scripts', 'mla_add_new_bulk_edit_vars', $script_variables ); // Filter the media upload post parameters. // @param array $post_params An array of media upload parameters used by Plupload. add_filter( 'upload_post_params', 'MLAEdit::mla_upload_post_params', 10, 1 ); // Fires on the post upload UI screen; legacy (pre-3.5.0) upload interface. add_action( 'post-upload-ui', 'MLAEdit::mla_post_upload_ui' ); return; } // media-new.php if ( ( 'post.php' != $page_hook ) || ( ! isset( $_REQUEST['post'] ) ) || ( ! isset( $_REQUEST['action'] ) ) || ( 'edit' != $_REQUEST['action'] ) ) { return; } $post = get_post( $_REQUEST['post'] ); if ( 'attachment' != $post->post_type ) { return; } /* * Media/Edit Media submenu * Register and queue the style sheet, if needed */ wp_register_style( self::JAVASCRIPT_EDIT_MEDIA_STYLES, MLA_PLUGIN_URL . 'css/mla-edit-media-style.css', false, MLACore::CURRENT_MLA_VERSION ); wp_enqueue_style( self::JAVASCRIPT_EDIT_MEDIA_STYLES ); wp_register_style( self::JAVASCRIPT_EDIT_MEDIA_STYLES . '-set-parent', MLA_PLUGIN_URL . 'css/mla-style-set-parent.css', false, MLACore::CURRENT_MLA_VERSION ); wp_enqueue_style( self::JAVASCRIPT_EDIT_MEDIA_STYLES . '-set-parent' ); wp_enqueue_script( self::JAVASCRIPT_EDIT_MEDIA_SLUG, MLA_PLUGIN_URL . "js/mla-edit-media-scripts{$suffix}.js", array( 'post', 'wp-lists', 'suggest', 'jquery' ), MLACore::CURRENT_MLA_VERSION, false ); wp_enqueue_script( self::JAVASCRIPT_EDIT_MEDIA_SLUG . '-set-parent', MLA_PLUGIN_URL . "js/mla-set-parent-scripts{$suffix}.js", array( 'post', 'wp-lists', 'suggest', 'jquery', self::JAVASCRIPT_EDIT_MEDIA_SLUG ), MLACore::CURRENT_MLA_VERSION, false ); $script_variables = array( 'comma' => _x( ',', 'tag_delimiter', 'media-library-assistant' ), 'Ajax_Url' => admin_url( 'admin-ajax.php' ), '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' ), 'uploadLabel' => sprintf( __( 'Uploaded on: %s' ), '' ), 'modifyLabel' => __( 'Last modified', 'media-library-assistant' ) . ': ', 'useDashicons' => false, 'useSpinnerClass' => false, ); if ( version_compare( get_bloginfo( 'version' ), '3.8', '>=' ) ) { $script_variables['useDashicons'] = true; } if ( version_compare( get_bloginfo( 'version' ), '4.2', '>=' ) ) { $script_variables['useSpinnerClass'] = true; } wp_localize_script( self::JAVASCRIPT_EDIT_MEDIA_SLUG, self::JAVASCRIPT_EDIT_MEDIA_OBJECT, $script_variables ); } /** * Filter the Media/Add New post parameters. * * @since 2.02 * * @param array $post_parms An array of media upload parameters used by Plupload. */ public static function mla_upload_post_params( $post_parms ) { /* * You can add elements to the array. It will end up in the client global * variable: wpUploaderInit.multipart_params and is then copied to * uploader.settings.multipart_params * * The elements of this array come back as $_REQUEST elements when the * upload is submitted. */ //$post_parms['mlaAddNewBulkEdit'] = array ( 'formData' => array() ); return $post_parms; } /** * Echoes bulk edit area HTML to the Media/Add New screen * * Fires on the post upload UI screen; legacy (pre-3.5.0) upload interface. * Anything echoed here goes below the "Maximum upload file size" message * and above the id="media-items" div. * * @since 2.02 * */ public static function mla_post_upload_ui() { /* * Only add our form to the Media/Add New screen. In particular, * do NOT add it to the Media Manager Modal Window */ if ( function_exists( 'get_current_screen' ) ) { $screen = get_current_screen(); } else { $screen = NULL; } if ( is_object( $screen ) && ( 'add' != $screen->action || 'media' != $screen->base ) ) { return; } $taxonomies = get_object_taxonomies( 'attachment', 'objects' ); $hierarchical_taxonomies = array(); $flat_taxonomies = array(); foreach ( $taxonomies as $tax_name => $tax_object ) { if ( $tax_object->show_ui && MLACore::mla_taxonomy_support($tax_name, 'quick-edit') ) { if ( $tax_object->hierarchical ) { $hierarchical_taxonomies[$tax_name] = $tax_object; } else { $flat_taxonomies[$tax_name] = $tax_object; } } } $page_template_array = MLACore::mla_load_template( 'mla-add-new-bulk-edit.tpl' ); if ( ! is_array( $page_template_array ) ) { /* translators: 1: ERROR tag 2: function name 3: non-array value */ MLACore::mla_debug_add( sprintf( _x( '%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'MLAEdit::mla_post_upload_ui', var_export( $page_template_array, true ) ), MLACore::MLA_DEBUG_CATEGORY_ANY ); return; } // The left-hand column contains the hierarchical taxonomies,e.g., Att. Category $category_fieldset = ''; if ( count( $hierarchical_taxonomies ) ) { $bulk_category_blocks = ''; foreach ( $hierarchical_taxonomies as $tax_name => $tax_object ) { if ( current_user_can( $tax_object->cap->assign_terms ) ) { ob_start(); wp_terms_checklist( NULL, array( 'taxonomy' => $tax_name, 'popular_cats' => array(), ) ); $tax_checklist = ob_get_contents(); ob_end_clean(); if ( MLACore::mla_taxonomy_support( $tax_name, 'checklist-add-term' ) ) { $page_values = array( 'tax_attr' => esc_attr( $tax_name ), 'Add New Term' => __( '+ Add New Term', 'media-library-assistant' ), 'Add Reader' => __( 'Add New', 'media-library-assistant' ) . ' ' . esc_html( $tax_object->labels->singular_name ), 'tax_parents' => wp_dropdown_categories( array( 'taxonomy' => $tax_name, 'hide_empty' => 0, 'name' => "new{$tax_name}_parent", 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => '— ' . $tax_object->labels->parent_item . ' —', 'echo' => 0 ) ), 'Add Button' => esc_html( $tax_object->labels->add_new_item ), 'ajax_nonce_field' => wp_nonce_field( 'add-'.$tax_name, '_ajax_nonce-add-'.$tax_name, false ), ); $category_add_link = MLAData::mla_parse_template( $page_template_array['category_add_link'], $page_values ); $category_adder = MLAData::mla_parse_template( $page_template_array['category_adder'], $page_values ); } else { $category_add_link = ''; $category_adder = ''; } $page_values = array( 'tax_html' => esc_html( $tax_object->labels->name ), 'tax_attr' => esc_attr( $tax_name ), 'tax_checklist' => $tax_checklist, 'category_add_link' => $category_add_link, 'Search' => __( '? Search', 'media-library-assistant' ), 'category_adder' => $category_adder, 'Search Reader' => __( 'Search', 'media-library-assistant' ) . ' ' . esc_html( $tax_object->labels->name ), 'Add' => __( 'Add', 'media-library-assistant' ), 'Remove' => __( 'Remove', 'media-library-assistant' ), 'Replace' => __( 'Replace', 'media-library-assistant' ), ); $category_block = MLAData::mla_parse_template( $page_template_array['category_block'], $page_values ); $taxonomy_options = MLAData::mla_parse_template( $page_template_array['taxonomy_options'], $page_values ); $bulk_category_blocks .= $category_block . $taxonomy_options; } // current_user_can } // foreach $hierarchical_taxonomies $page_values = array( 'category_blocks' => $bulk_category_blocks ); $category_fieldset = MLAData::mla_parse_template( $page_template_array['category_fieldset'], $page_values ); } // count( $hierarchical_taxonomies ) // The middle column contains the flat taxonomies, e.g., Att. Tag $tag_fieldset = ''; if ( count( $flat_taxonomies ) ) { $bulk_tag_blocks = ''; foreach ( $flat_taxonomies as $tax_name => $tax_object ) { if ( current_user_can( $tax_object->cap->assign_terms ) ) { if ( MLACore::mla_taxonomy_support( $tax_name, 'flat-checklist' ) ) { ob_start(); wp_terms_checklist( NULL, array( 'taxonomy' => $tax_name, 'popular_cats' => array(), ) ); $tax_checklist = ob_get_contents(); ob_end_clean(); if ( MLACore::mla_taxonomy_support( $tax_name, 'checklist-add-term' ) ) { $page_values = array( 'tax_attr' => esc_attr( $tax_name ), 'Add New Term' => __( '+ Add New Term', 'media-library-assistant' ), 'Add Reader' => __( 'Add New', 'media-library-assistant' ) . ' ' . esc_html( $tax_object->labels->singular_name ), 'tax_parents' => "", 'Add Button' => esc_html( $tax_object->labels->add_new_item ), 'ajax_nonce_field' => wp_nonce_field( 'add-'.$tax_name, '_ajax_nonce-add-'.$tax_name, false ), ); $category_add_link = MLAData::mla_parse_template( $page_template_array['category_add_link'], $page_values ); $category_adder = MLAData::mla_parse_template( $page_template_array['category_adder'], $page_values ); } else { $category_add_link = ''; $category_adder = ''; } $page_values = array( 'tax_html' => esc_html( $tax_object->labels->name ), 'tax_attr' => esc_attr( $tax_name ), 'tax_checklist' => $tax_checklist, 'category_add_link' => $category_add_link, 'Search' => __( '? Search', 'media-library-assistant' ), 'category_adder' => $category_adder, 'Search Reader' => __( 'Search', 'media-library-assistant' ) . ' ' . esc_html( $tax_object->labels->name ), 'Add' => __( 'Add', 'media-library-assistant' ), 'Remove' => __( 'Remove', 'media-library-assistant' ), 'Replace' => __( 'Replace', 'media-library-assistant' ), ); $tag_block = MLAData::mla_parse_template( $page_template_array['category_block'], $page_values ); } else { $page_values = array( 'tax_html' => esc_html( $tax_object->labels->name ), 'tax_attr' => esc_attr( $tax_name ), 'Add' => __( 'Add', 'media-library-assistant' ), 'Remove' => __( 'Remove', 'media-library-assistant' ), 'Replace' => __( 'Replace', 'media-library-assistant' ), ); $tag_block = MLAData::mla_parse_template( $page_template_array['tag_block'], $page_values ); } $taxonomy_options = MLAData::mla_parse_template( $page_template_array['taxonomy_options'], $page_values ); $bulk_tag_blocks .= $tag_block . $taxonomy_options; } // current_user_can } // foreach $flat_taxonomies $page_values = array( 'tag_blocks' => $bulk_tag_blocks ); $tag_fieldset = MLAData::mla_parse_template( $page_template_array['tag_fieldset'], $page_values ); } // count( $flat_taxonomies ) // The right-hand column contains the standard and custom fields if ( $authors = MLA::mla_authors_dropdown( -1 ) ) { $authors_dropdown = ' ' . "\n"; } else { $authors_dropdown = ''; } $custom_fields = ''; foreach (MLACore::mla_custom_field_support( 'bulk_edit' ) as $slug => $details ) { $page_values = array( 'slug' => $slug, 'label' => esc_attr( $details['name'] ), ); $custom_fields .= MLAData::mla_parse_template( $page_template_array['custom_field'], $page_values ); } $set_parent_form = MLA::mla_set_parent_form( false ); $page_values = array( 'NOTE' => __( 'IMPORTANT: Make your entries BEFORE uploading new items. Pull down the Help menu for more information.', 'media-library-assistant' ), 'Toggle' => __( 'Open Bulk Edit area', 'media-library-assistant' ), 'Reset' => __( 'Reset', 'media-library-assistant' ), 'category_fieldset' => $category_fieldset, 'tag_fieldset' => $tag_fieldset, 'authors' => $authors_dropdown, 'Comments' => __( 'Comments', 'media-library-assistant' ), 'Pings' => __( 'Pings', 'media-library-assistant' ), 'No Change' => __( 'No Change', 'media-library-assistant' ), 'Allow' => __( 'Allow', 'media-library-assistant' ), 'Do not allow' => __( 'Do not allow', 'media-library-assistant' ), 'custom_fields' => $custom_fields, 'Title' => __( 'Title', 'media-library-assistant' ), 'Name/Slug' => __( 'Name/Slug', 'media-library-assistant' ), 'Caption' => __( 'Caption', 'media-library-assistant' ), 'Description' => __( 'Description', 'media-library-assistant' ), 'ALT Text' => __( 'ALT Text', 'media-library-assistant' ), 'Uploaded on' => __( 'Uploaded on', 'media-library-assistant' ), 'Parent ID' => __( 'Parent ID', 'media-library-assistant' ), 'Select' => __( 'Select', 'media-library-assistant' ), 'set_parent_form' => $set_parent_form, ); $page_values = apply_filters( 'mla_upload_bulk_edit_form_values', $page_values ); $page_template = apply_filters( 'mla_upload_bulk_edit_form_template', $page_template_array['page'] ); $parse_value = MLAData::mla_parse_template( $page_template, $page_values ); echo apply_filters( 'mla_upload_bulk_edit_form_parse', $parse_value, $page_template, $page_values ); } /** * Apply Media/Add New bulk edit area updates, if any * * This filter is called AFTER MLA mapping rules are applied during * wp_update_attachment_metadata() processing. If none of the mapping rules * is enabled it is called from the 'wp_update_attachment_metadata' filter * with just two arguments. * * @since 2.02 * * @param array attachment metadata * @param integer The Post ID of the new/updated attachment * @param array Processing options, e.g., 'is_upload' * * @return array updated attachment metadata */ public static function mla_update_attachment_metadata_postfilter( $data, $post_id, $options = array( 'is_upload' => true ) ) { // Check for active debug setting if ( ( MLACore::$mla_debug_level & 1 ) && ( MLACore::$mla_debug_level & MLACore::MLA_DEBUG_CATEGORY_THUMBNAIL ) ) { $post = get_post( $post_id ); MLACore::mla_debug_add( __LINE__ . " MLAEdit::mla_update_attachment_metadata_postfilter( $post_id ) post = " . var_export( $post, true ), MLACore::MLA_DEBUG_CATEGORY_THUMBNAIL ); MLACore::mla_debug_add( __LINE__ . " MLAEdit::mla_update_attachment_metadata_postfilter( $post_id ) data = " . var_export( $data, true ), MLACore::MLA_DEBUG_CATEGORY_THUMBNAIL ); } if ( ( true == $options['is_upload'] ) && ! empty( $_REQUEST['mlaAddNewBulkEditFormString'] ) ) { /* * Clean up the inputs, which have everything from the enclosing