bad_property; //trigger_error( 'mla_print_media_templates_action', E_USER_WARNING ); //error_log( 'DEBUG: xdebug_get_function_stack = ' . var_export( xdebug_get_function_stack(), true), 0 ); // If there's no action variable, we have nothing to do if ( ! isset( $_REQUEST['action'] ) ) { return; } /* * Build a list of enhanced taxonomies for later $_REQUEST/$_POST cleansing. * Remove "Media Categories" instances, if present. */ $enhanced_taxonomies = array(); foreach ( get_taxonomies( array ( 'show_ui' => true ), 'objects' ) as $key => $value ) { if ( MLACore::mla_taxonomy_support( $key ) ) { if ( ! $use_checklist = $value->hierarchical ) { $use_checklist = MLACore::mla_taxonomy_support( $key, 'flat-checklist' ); } if ( $use_checklist ) { if ( 'checked' == MLACore::mla_get_option( MLACoreOptions::MLA_MEDIA_MODAL_DETAILS_CATEGORY_METABOX ) ) { $enhanced_taxonomies[] = $key; if ( class_exists( 'Media_Categories' ) && is_array( Media_Categories::$instances ) ) { foreach( Media_Categories::$instances as $index => $instance ) { if ( $instance->taxonomy == $key ) { // unset( Media_Categories::$instances[ $index ] ); Media_Categories::$instances[ $index ]->taxonomy = 'MLA-has-disabled-this-instance'; } } } // class_exists } // checked } // use_checklist } // supported } // foreach taxonomy /* * The 'query-attachments' action fills the Modal Window thumbnail pane with media items. * If the 's' value is an array, the MLA Enhanced elements are present; unpack the arguments * and substitute our handler for the WordPress default handler. */ if ( ( $_REQUEST['action'] == 'query-attachments' ) && isset( $_POST['query']['s'] ) && is_array( $_POST['query']['s'] ) ){ foreach ( $_POST['query']['s'] as $key => $value ) { $_POST['query'][ $key ] = $value; $_REQUEST['query'][ $key ] = $value; } unset( $_POST['query']['s'] ); unset( $_REQUEST['query']['s'] ); $_POST['action'] = MLACore::JAVASCRIPT_QUERY_ATTACHMENTS_ACTION; $_REQUEST['action'] = MLACore::JAVASCRIPT_QUERY_ATTACHMENTS_ACTION; return; } // query-attachments /* * The 'save-attachment-compat' action updates taxonomy and custom field * values for an item. Remove any MLA-enhanced taxonomy data from the * incoming data. The other taxonomies will be processed by * /wp-admin/includes/ajax-actions.php, function wp_ajax_save_attachment_compat(). */ if ( ( $_REQUEST['action'] == 'save-attachment-compat' ) ){ if ( empty( $_REQUEST['id'] ) || ! $id = absint( $_REQUEST['id'] ) ) { wp_send_json_error(); } if ( empty( $_REQUEST['attachments'] ) || empty( $_REQUEST['attachments'][ $id ] ) ) { wp_send_json_error(); } // Media Categories uses this if ( isset( $_REQUEST['category-filter'] ) ) { unset( $_REQUEST['category-filter'] ); unset( $_POST['category-filter'] ); } if ( isset( $_REQUEST['mla_attachments'] ) ) { unset( $_REQUEST['mla_attachments'] ); unset( $_POST['mla_attachments'] ); } if ( isset( $_REQUEST['tax_input'] ) ) { unset( $_REQUEST['tax_input'] ); unset( $_POST['tax_input'] ); } foreach( $enhanced_taxonomies as $taxonomy ) { if ( isset( $_REQUEST['attachments'][ $id ][ $taxonomy ] ) ) { unset( $_REQUEST['attachments'][ $id ][ $taxonomy ] ); unset( $_POST['attachments'][ $id ][ $taxonomy ] ); } if ( isset( $_REQUEST[ $taxonomy ] ) ) { unset( $_REQUEST[ $taxonomy ] ); unset( $_POST[ $taxonomy ] ); } if ( ( 'category' == $taxonomy ) && isset( $_REQUEST['post_category'] ) ) { unset( $_REQUEST['post_category'] ); unset( $_POST['post_category'] ); } if ( isset( $_REQUEST[ 'new' . $taxonomy ] ) ) { unset( $_REQUEST[ 'new' . $taxonomy ] ); unset( $_POST[ 'new' . $taxonomy ] ); unset( $_REQUEST[ 'new' . $taxonomy . '_parent' ] ); unset( $_POST[ 'new' . $taxonomy . '_parent' ] ); unset( $_REQUEST[ '_ajax_nonce-add-' . $taxonomy ] ); unset( $_POST[ '_ajax_nonce-add-' . $taxonomy ] ); } if ( isset( $_REQUEST[ 'search-' . $taxonomy ] ) ) { unset( $_REQUEST[ 'search-' . $taxonomy ] ); unset( $_POST[ 'search-' . $taxonomy ] ); unset( $_REQUEST[ '_ajax_nonce-search-' . $taxonomy ] ); unset( $_POST[ '_ajax_nonce-search-' . $taxonomy ] ); } } // foreach taxonomy } // save-attachment-compat } // mla_admin_init_action /** * Saves the get_media_item_args array for the attachment_fields_to_edit filter * * Declared public because it is a filter. * * @since 1.71 * * @param array arguments for the get_media_item function in /wp-admin/includes/media.php * * @return array arguments for the get_media_item function (unchanged) */ public static function mla_get_media_item_args_filter( $args ) { self::$media_item_args = $args; return $args; } // mla_get_media_item_args_filter /** * The get_media_item_args array * * @since 1.71 * * @var array ( 'errors' => array of strings, 'in_modal => boolean ) */ private static $media_item_args = array( 'errors' => NULL, 'in_modal' => false ); /** * Add/change custom fields to the Edit Media screen and Modal Window * * Called from /wp-admin/includes/media.php, function get_compat_media_markup(); * If "get_media_item_args"['in_modal'] => false ) its the Edit Media screen. * If "get_media_item_args"['in_modal'] => true ) its the Media Manager Modal Window. * For the Modal Window, $form_fields contains all the "compat-attachment-fields" * including the taxonomies, which we want to enhance. * Declared public because it is a filter. * * @since 1.71 * * @param array descriptors for the "compat-attachment-fields" * @param object the post to be edited * * @return array updated descriptors for the "compat-attachment-fields" */ public static function mla_attachment_fields_to_edit_filter( $form_fields, $post ) { $id = $post->ID; /* * This logic is only required for the MLA-enhanced Media Manager Modal Window. * For the non-Modal Media/Edit Media screen, the MLAEdit::mla_add_meta_boxes_action * function changes the default meta box to the MLA searchable meta box. */ if ( isset( self::$media_item_args['in_modal'] ) && self::$media_item_args['in_modal'] ) { foreach ( get_taxonomies( array ( 'show_ui' => true ), 'objects' ) as $key => $value ) { if ( MLACore::mla_taxonomy_support( $key ) ) { if ( isset( $form_fields[ $key ] ) ) { $field = $form_fields[ $key ]; } else { continue; } if ( ! $use_checklist = $value->hierarchical ) { $use_checklist = MLACore::mla_taxonomy_support( $key, 'flat-checklist' ); } // Make sure the appropriate MMMW Enhancement option has been checked if ( $use_checklist ) { if ( 'checked' !== MLACore::mla_get_option( MLACoreOptions::MLA_MEDIA_MODAL_DETAILS_CATEGORY_METABOX ) ) { continue; } } else { if ( 'checked' !== MLACore::mla_get_option( MLACoreOptions::MLA_MEDIA_MODAL_DETAILS_TAG_METABOX ) ) { continue; } } // Remove "Media Categories" meta box, if present. if ( isset( $form_fields[ $key . '_metabox' ] ) ) { unset( $form_fields[ $key . '_metabox' ] ); } /* * Simulate the default MMMW text box with a hidden field; * use term names for flat taxonomies and term_ids for hierarchical. */ $post_id = $post->ID; $label = $field['labels']->name; $terms = get_object_term_cache( $post_id, $key ); if ( false === $terms ) { $terms = wp_get_object_terms( $post_id, $key ); wp_cache_add( $post_id, $terms, $key . '_relationships' ); } if ( is_wp_error( $terms ) || empty( $terms ) ) { $terms = array(); } $list = array(); foreach ( $terms as $term ) { if ( $value->hierarchical ) { $list[] = $term->term_id; } else { $list[] = $term->name; } } // foreach $term sort( $list ); $list = join( ',', $list ); $class = ( $value->hierarchical ) ? 'categorydiv' : 'tagsdiv'; $row = "\t\t
\n"; //$form_fields[ $key ] = array( 'tr' => $row ); $form_fields[ 'mla-' . $key ] = array( 'tr' => $row ); } // is supported } // foreach $form_fields = apply_filters( 'mla_media_modal_form_fields', $form_fields, $post ); } // in_modal self::$media_item_args = array( 'errors' => NULL, 'in_modal' => false ); return $form_fields; } // mla_attachment_fields_to_edit_filter /** * Ajax handler for Media Manager "fill compat-attachment-fields" queries * * Prepares an array of (HTML) taxonomy meta boxes with attachment-specific values. * * @since 2.20 * * @return void passes array of results to wp_send_json_success() for JSON encoding and transmission */ public static function mla_fill_compat_fields_action() { if ( empty( $_REQUEST['query'] ) || ! $requested = $_REQUEST['query'] ) { wp_send_json_error(); } if ( empty( $_REQUEST['id'] ) || ! $post_id = absint( $_REQUEST['id'] ) ) { wp_send_json_error(); } if ( NULL == ( $post = get_post( $post_id ) ) ) { wp_send_json_error(); } $results = apply_filters( 'mla_media_modal_begin_fill_compat_fields', array(), $requested, $post ); if ( ! empty( $results ) ) { wp_send_json_success( $results ); } // Flat taxonomy handling is WP version-specific $wp_version = get_bloginfo('version'); $generate_tag_buttons = version_compare( $wp_version, '4.6.99', '>' ); $generate_tag_ul = version_compare( $wp_version, '4.8.99', '>' ); // Match all supported taxonomies against the requested list foreach ( get_taxonomies( array ( 'show_ui' => true ), 'objects' ) as $key => $value ) { if ( MLACore::mla_taxonomy_support( $key ) ) { if ( is_integer( $index = array_search( $key, $requested ) ) ) { $request = $requested[ $index ]; } else { continue; } if ( ! $use_checklist = $value->hierarchical ) { $use_checklist = MLACore::mla_taxonomy_support( $key, 'flat-checklist' ); } if ( $use_checklist ) { if ( 'checked' == MLACore::mla_get_option( MLACoreOptions::MLA_MEDIA_MODAL_DETAILS_CATEGORY_METABOX ) ) { unset( $requested[ $index ] ); $label = $value->label; $terms = get_object_term_cache( $post_id, $key ); if ( false === $terms ) { $terms = wp_get_object_terms( $post_id, $key ); wp_cache_add( $post_id, $terms, $key . '_relationships' ); } if ( is_wp_error( $terms ) || empty( $terms ) ) { $terms = array(); } $list = array(); foreach ( $terms as $term ) { $list[] = $term->term_id; } // foreach $term sort( $list ); $list = join( ',', $list ); // Simulate the 'add_meta_boxes' callback $box = array ( 'id' => $key . 'div', 'title' => $label, 'callback' => 'MLACore::mla_checklist_meta_box', 'args' => array ( 'taxonomy' => $key, 'in_modal' => true ), ); ob_start(); MLACore::mla_checklist_meta_box( $post, $box ); $row_content = ob_get_clean(); $row = "\t\t