/** * Build the hidden row templates for inline editing (quick and bulk edit) * * inspired by inline_edit() in wp-admin\includes\class-wp-posts-list-table.php. * * @since 0.20 * * @param object MLA List Table object * * @return string HTML <form> markup for hidden rows */ private static function _build_inline_edit_form($MLAListTable) { $taxonomies = get_object_taxonomies('attachment', 'objects'); $hierarchical_taxonomies = array(); $flat_taxonomies = array(); foreach ($taxonomies as $tax_name => $tax_object) { if ($tax_object->hierarchical && $tax_object->show_ui && MLAOptions::mla_taxonomy_support($tax_name, 'quick-edit')) { $hierarchical_taxonomies[$tax_name] = $tax_object; } elseif ($tax_object->show_ui && MLAOptions::mla_taxonomy_support($tax_name, 'quick-edit')) { $flat_taxonomies[$tax_name] = $tax_object; } } $page_template_array = MLAData::mla_load_template('admin-inline-edit-form.tpl'); if (!is_array($page_template_array)) { /* translators: 1: ERROR tag 2: function name 3: non-array value */ error_log(sprintf(_x('%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), 'MLA::_build_inline_edit_form', var_export($page_template_array, true)), 0); return ''; } if ($authors = self::mla_authors_dropdown()) { $authors_dropdown = ' <label class="inline-edit-author">' . "\n"; $authors_dropdown .= ' <span class="title">' . __('Author', 'media-library-assistant') . '</span>' . "\n"; $authors_dropdown .= $authors . "\n"; $authors_dropdown .= ' </label>' . "\n"; } else { $authors_dropdown = ''; } $custom_fields = ''; foreach (MLAOptions::mla_custom_field_support('quick_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); } /* * The middle column contains the hierarchical taxonomies, e.g., Attachment Category */ $quick_middle_column = ''; $bulk_middle_column = ''; if (count($hierarchical_taxonomies)) { $quick_category_blocks = ''; $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)); $tax_checklist = ob_get_contents(); ob_end_clean(); $page_values = array('tax_html' => esc_html($tax_object->labels->name), 'more' => __('more', 'media-library-assistant'), 'less' => __('less', 'media-library-assistant'), 'tax_attr' => esc_attr($tax_name), 'tax_checklist' => $tax_checklist, '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); $quick_category_blocks .= $category_block; $bulk_category_blocks .= $category_block . $taxonomy_options; } // current_user_can } // foreach $hierarchical_taxonomies $page_values = array('category_blocks' => $quick_category_blocks); $quick_middle_column = MLAData::mla_parse_template($page_template_array['category_fieldset'], $page_values); $page_values = array('category_blocks' => $bulk_category_blocks); $bulk_middle_column = MLAData::mla_parse_template($page_template_array['category_fieldset'], $page_values); } // count( $hierarchical_taxonomies ) /* * The right-hand column contains the flat taxonomies, e.g., Attachment Tag */ $quick_right_column = ''; $bulk_right_column = ''; if (count($flat_taxonomies)) { $quick_tag_blocks = ''; $bulk_tag_blocks = ''; foreach ($flat_taxonomies as $tax_name => $tax_object) { if (current_user_can($tax_object->cap->assign_terms)) { $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); $quick_tag_blocks .= $tag_block; $bulk_tag_blocks .= $tag_block . $taxonomy_options; } // current_user_can } // foreach $flat_taxonomies $page_values = array('tag_blocks' => $quick_tag_blocks); $quick_right_column = MLAData::mla_parse_template($page_template_array['tag_fieldset'], $page_values); $page_values = array('tag_blocks' => $bulk_tag_blocks); $bulk_right_column = MLAData::mla_parse_template($page_template_array['tag_fieldset'], $page_values); } // count( $flat_taxonomies ) if ($authors = self::mla_authors_dropdown(-1)) { $bulk_authors_dropdown = ' <label class="inline-edit-author alignright">' . "\n"; $bulk_authors_dropdown .= ' <span class="title">' . __('Author', 'media-library-assistant') . '</span>' . "\n"; $bulk_authors_dropdown .= $authors . "\n"; $bulk_authors_dropdown .= ' </label>' . "\n"; } else { $bulk_authors_dropdown = ''; } $bulk_custom_fields = ''; foreach (MLAOptions::mla_custom_field_support('bulk_edit') as $slug => $details) { $page_values = array('slug' => $slug, 'label' => esc_attr($details['name'])); $bulk_custom_fields .= MLAData::mla_parse_template($page_template_array['custom_field'], $page_values); } $set_parent_form = MLA::mla_set_parent_form(); $page_values = array('colspan' => $MLAListTable->get_column_count(), 'Quick Edit' => __('Quick Edit', 'media-library-assistant'), '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'), 'Parent ID' => __('Parent ID', 'media-library-assistant'), 'Select' => __('Select', 'media-library-assistant'), 'Menu Order' => __('Menu Order', 'media-library-assistant'), 'authors' => $authors_dropdown, 'custom_fields' => $custom_fields, 'quick_middle_column' => $quick_middle_column, 'quick_right_column' => $quick_right_column, 'Cancel' => __('Cancel', 'media-library-assistant'), 'Reset' => __('Reset', 'media-library-assistant'), 'Update' => __('Update', 'media-library-assistant'), 'Bulk Edit' => __('Bulk Edit', 'media-library-assistant'), 'bulk_middle_column' => $bulk_middle_column, 'bulk_right_column' => $bulk_right_column, 'bulk_authors' => $bulk_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'), 'bulk_custom_fields' => $bulk_custom_fields, 'Map IPTC/EXIF metadata' => __('Map IPTC/EXIF metadata', 'media-library-assistant'), 'Map Custom Field metadata' => __('Map Custom Field metadata', 'media-library-assistant'), 'Bulk Waiting' => __('Waiting', 'media-library-assistant'), 'Bulk Running' => __('In-process', 'media-library-assistant'), 'Bulk Complete' => __('Complete', 'media-library-assistant'), 'Refresh' => __('Refresh', 'media-library-assistant'), 'set_parent_form' => $set_parent_form); $page_values = apply_filters('mla_list_table_inline_values', $page_values); $page_template = apply_filters('mla_list_table_inline_template', $page_template_array['page']); $parse_value = MLAData::mla_parse_template($page_template, $page_values); return apply_filters('mla_list_table_inline_parse', $parse_value, $page_template, $page_values); }
/** * 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->hierarchical && $tax_object->show_ui && MLAOptions::mla_taxonomy_support($tax_name, 'quick-edit')) { $hierarchical_taxonomies[$tax_name] = $tax_object; } elseif ($tax_object->show_ui && MLAOptions::mla_taxonomy_support($tax_name, 'quick-edit')) { $flat_taxonomies[$tax_name] = $tax_object; } } $page_template_array = MLAData::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 */ error_log(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)), 0); return; } /* * The left-hand column contains the hierarchical taxonomies, * e.g., Attachment 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)); $tax_checklist = ob_get_contents(); ob_end_clean(); $page_values = array('tax_html' => esc_html($tax_object->labels->name), 'more' => __('more', 'media-library-assistant'), 'less' => __('less', 'media-library-assistant'), 'tax_attr' => esc_attr($tax_name), 'tax_checklist' => $tax_checklist, '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., Attachment 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)) { $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 = ' <label class="inline-edit-author alignright">' . "\n"; $authors_dropdown .= ' <span class="title">' . __('Author', 'media-library-assistant') . '</span>' . "\n"; $authors_dropdown .= $authors . "\n"; $authors_dropdown .= ' </label>' . "\n"; } else { $authors_dropdown = ''; } $custom_fields = ''; foreach (MLAOptions::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'), 'Parent ID' => __('Parent ID', 'media-library-assistant'), 'Select' => __('Select', 'media-library-assistant'), 'set_parent_form' => $set_parent_form); echo MLAData::mla_parse_template($page_template_array['page'], $page_values); }
/** * Add hidden fields with the data for use in the inline editor * * @since 0.20 * * @param object A singular attachment (post) object * * @return string HTML <div> with row data */ private function _build_inline_data($item) { $inline_data = "\r\n" . '<div class="hidden" id="inline_' . $item->ID . "\">\r\n"; $inline_data .= ' <div class="post_title">' . esc_attr($item->post_title) . "</div>\r\n"; $inline_data .= ' <div class="post_name">' . esc_attr($item->post_name) . "</div>\r\n"; $inline_data .= ' <div class="post_excerpt">' . esc_attr($item->post_excerpt) . "</div>\r\n"; $inline_data .= ' <div class="post_content">' . esc_attr($item->post_content) . "</div>\r\n"; if (!empty($item->mla_wp_attachment_metadata)) { if (isset($item->mla_wp_attachment_image_alt)) { $inline_data .= ' <div class="image_alt">' . esc_attr($item->mla_wp_attachment_image_alt) . "</div>\r\n"; } else { $inline_data .= ' <div class="image_alt">' . "</div>\r\n"; } } $inline_data .= ' <div class="post_parent">' . $item->post_parent . "</div>\r\n"; $inline_data .= ' <div class="menu_order">' . $item->menu_order . "</div>\r\n"; $inline_data .= ' <div class="post_author">' . $item->post_author . "</div>\r\n"; $custom_fields = MLAOptions::mla_custom_field_support('quick_edit'); $custom_fields = array_merge($custom_fields, MLAOptions::mla_custom_field_support('bulk_edit')); foreach ($custom_fields as $slug => $label) { $value = get_metadata('post', $item->ID, $label, true); $inline_data .= ' <div class="' . $slug . '">' . esc_html($value) . "</div>\r\n"; } $taxonomies = get_object_taxonomies('attachment', 'objects'); foreach ($taxonomies as $tax_name => $tax_object) { if ($tax_object->hierarchical && $tax_object->show_ui && MLAOptions::mla_taxonomy_support($tax_name, 'quick-edit')) { $inline_data .= ' <div class="mla_category" id="' . $tax_name . '_' . $item->ID . '">' . implode(',', wp_get_object_terms($item->ID, $tax_name, array('fields' => 'ids'))) . "</div>\r\n"; } elseif ($tax_object->show_ui && MLAOptions::mla_taxonomy_support($tax_name, 'quick-edit')) { $inline_data .= ' <div class="mla_tags" id="' . $tax_name . '_' . $item->ID . '">' . esc_html(str_replace(',', ', ', get_terms_to_edit($item->ID, $tax_name))) . "</div>\r\n"; } } $inline_data .= "</div>\r\n"; return $inline_data; }
/** * Add hidden fields with the data for use in the inline editor * * @since 0.20 * * @param object A singular attachment (post) object * * @return string HTML <div> with row data */ protected function _build_inline_data($item) { $inline_data = "\r\n" . '<div class="hidden" id="inline_' . $item->ID . "\">\r\n"; $inline_data .= ' <div class="item_thumbnail">' . self::_build_item_thumbnail($item) . "</div>\r\n"; $inline_data .= ' <div class="post_title">' . esc_attr($item->post_title) . "</div>\r\n"; $inline_data .= ' <div class="post_name">' . esc_attr($item->post_name) . "</div>\r\n"; $inline_data .= ' <div class="post_excerpt">' . esc_attr($item->post_excerpt) . "</div>\r\n"; $inline_data .= ' <div class="post_content">' . esc_attr($item->post_content) . "</div>\r\n"; if (!empty($item->mla_wp_attachment_metadata)) { $inline_data .= ' <div class="image_alt">'; if (isset($item->mla_wp_attachment_image_alt)) { if (is_array($item->mla_wp_attachment_image_alt)) { $inline_data .= esc_attr($item->mla_wp_attachment_image_alt[0]); } else { $inline_data .= esc_attr($item->mla_wp_attachment_image_alt); } } $inline_data .= "</div>\r\n"; } $inline_data .= ' <div class="post_parent">' . $item->post_parent . "</div>\r\n"; if ($item->post_parent) { if (isset($item->parent_title)) { $parent_title = $item->parent_title; } else { $parent_title = __('(no title)', 'media-library-assistant'); } } else { $parent_title = ''; } $inline_data .= ' <div class="post_parent_title">' . $parent_title . "</div>\r\n"; $inline_data .= ' <div class="menu_order">' . $item->menu_order . "</div>\r\n"; $inline_data .= ' <div class="post_author">' . $item->post_author . "</div>\r\n"; $custom_fields = MLAOptions::mla_custom_field_support('quick_edit'); $custom_fields = array_merge($custom_fields, MLAOptions::mla_custom_field_support('bulk_edit')); foreach ($custom_fields as $slug => $details) { $value = get_metadata('post', $item->ID, $details['name'], true); $inline_data .= ' <div class="' . $slug . '">' . esc_html($value) . "</div>\r\n"; } $taxonomies = get_object_taxonomies('attachment', 'objects'); foreach ($taxonomies as $tax_name => $tax_object) { if ($tax_object->show_ui && MLAOptions::mla_taxonomy_support($tax_name, 'quick-edit')) { $terms = get_object_term_cache($item->ID, $tax_name); if (false === $terms) { $terms = wp_get_object_terms($item->ID, $tax_name); wp_cache_add($item->ID, $terms, $tax_name . '_relationships'); } if (is_wp_error($terms) || empty($terms)) { $terms = array(); } $ids = array(); if ($tax_object->hierarchical) { foreach ($terms as $term) { $ids[] = $term->term_id; } $inline_data .= ' <div class="mla_category" id="' . $tax_name . '_' . $item->ID . '">' . implode(',', $ids) . "</div>\r\n"; } else { foreach ($terms as $term) { $ids[] = $term->name; } $inline_data .= ' <div class="mla_tags" id="' . $tax_name . '_' . $item->ID . '">' . esc_attr(implode(', ', $ids)) . "</div>\r\n"; } } } $inline_data = apply_filters('mla_list_table_build_inline_data', $inline_data, $item); $inline_data .= "</div>\r\n"; return $inline_data; }
/** * Build the hidden row templates for inline editing (quick and bulk edit) * * inspired by inline_edit() in wp-admin\includes\class-wp-posts-list-table.php. * * @since 0.20 * * @param object MLA List Table object * * @return string HTML <form> markup for hidden rows */ private static function _build_inline_edit_form($MLAListTable) { $taxonomies = get_object_taxonomies('attachment', 'objects'); $hierarchical_taxonomies = array(); $flat_taxonomies = array(); foreach ($taxonomies as $tax_name => $tax_object) { if ($tax_object->hierarchical && $tax_object->show_ui && MLAOptions::mla_taxonomy_support($tax_name, 'quick-edit')) { $hierarchical_taxonomies[$tax_name] = $tax_object; } elseif ($tax_object->show_ui && MLAOptions::mla_taxonomy_support($tax_name, 'quick-edit')) { $flat_taxonomies[$tax_name] = $tax_object; } } $page_template_array = MLAData::mla_load_template(MLA_PLUGIN_PATH . 'tpls/admin-inline-edit-form.tpl'); if (!array($page_template_array)) { error_log("ERROR: MLA::_build_inline_edit_form \$page_template_array = " . var_export($page_template_array, true), 0); return ''; } if ($authors = self::_authors_dropdown()) { $authors_dropdown = ' <label class="inline-edit-author">' . "\r\n"; $authors_dropdown .= ' <span class="title">' . __('Author') . '</span>' . "\r\n"; $authors_dropdown .= $authors . "\r\n"; $authors_dropdown .= ' </label>' . "\r\n"; } else { $authors_dropdown = ''; } $custom_fields = ''; foreach (MLAOptions::mla_custom_field_support('quick_edit') as $slug => $label) { $page_values = array('slug' => $slug, 'label' => esc_attr($label)); $custom_fields .= MLAData::mla_parse_template($page_template_array['custom_field'], $page_values); } /* * The middle column contains the hierarchical taxonomies, e.g., Attachment Category */ $quick_middle_column = ''; $bulk_middle_column = ''; if (count($hierarchical_taxonomies)) { $quick_category_blocks = ''; $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)); $tax_checklist = ob_get_contents(); ob_end_clean(); $page_values = array('tax_html' => esc_html($tax_object->labels->name), 'tax_attr' => esc_attr($tax_name), 'tax_checklist' => $tax_checklist); $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); $quick_category_blocks .= $category_block; $bulk_category_blocks .= $category_block . $taxonomy_options; } // current_user_can } // foreach $hierarchical_taxonomies $page_values = array('category_blocks' => $quick_category_blocks); $quick_middle_column = MLAData::mla_parse_template($page_template_array['category_fieldset'], $page_values); $page_values = array('category_blocks' => $bulk_category_blocks); $bulk_middle_column = MLAData::mla_parse_template($page_template_array['category_fieldset'], $page_values); } // count( $hierarchical_taxonomies ) /* * The right-hand column contains the flat taxonomies, e.g., Attachment Tag */ $quick_right_column = ''; $bulk_right_column = ''; if (count($flat_taxonomies)) { $quick_tag_blocks = ''; $bulk_tag_blocks = ''; foreach ($flat_taxonomies as $tax_name => $tax_object) { if (current_user_can($tax_object->cap->assign_terms)) { $page_values = array('tax_html' => esc_html($tax_object->labels->name), 'tax_attr' => esc_attr($tax_name)); $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); $quick_tag_blocks .= $tag_block; $bulk_tag_blocks .= $tag_block . $taxonomy_options; } // current_user_can } // foreach $flat_taxonomies $page_values = array('tag_blocks' => $quick_tag_blocks); $quick_right_column = MLAData::mla_parse_template($page_template_array['tag_fieldset'], $page_values); $page_values = array('tag_blocks' => $bulk_tag_blocks); $bulk_right_column = MLAData::mla_parse_template($page_template_array['tag_fieldset'], $page_values); } // count( $flat_taxonomies ) if ($authors = self::_authors_dropdown(-1)) { $bulk_authors_dropdown = ' <label class="inline-edit-author">' . "\r\n"; $bulk_authors_dropdown .= ' <span class="title">' . __('Author') . '</span>' . "\r\n"; $bulk_authors_dropdown .= $authors . "\r\n"; $bulk_authors_dropdown .= ' </label>' . "\r\n"; } else { $bulk_authors_dropdown = ''; } $bulk_custom_fields = ''; foreach (MLAOptions::mla_custom_field_support('bulk_edit') as $slug => $label) { $page_values = array('slug' => $slug, 'label' => esc_attr($label)); $bulk_custom_fields .= MLAData::mla_parse_template($page_template_array['custom_field'], $page_values); } $page_values = array('colspan' => count($MLAListTable->get_columns()), 'authors' => $authors_dropdown, 'custom_fields' => $custom_fields, 'quick_middle_column' => $quick_middle_column, 'quick_right_column' => $quick_right_column, 'bulk_middle_column' => $bulk_middle_column, 'bulk_right_column' => $bulk_right_column, 'bulk_authors' => $bulk_authors_dropdown, 'bulk_custom_fields' => $bulk_custom_fields); $page_template = MLAData::mla_parse_template($page_template_array['page'], $page_values); return $page_template; }
/** * Sanitize and expand query arguments from request variables * * Prepare the arguments for WP_Query. * Modeled after wp_edit_attachments_query in wp-admin/post.php * * @since 0.1 * * @param array query parameters from web page, usually found in $_REQUEST * @param int Optional number of rows (default 0) to skip over to reach desired page * @param int Optional number of rows on each page (0 = all rows, default) * * @return array revised arguments suitable for WP_Query */ private static function _prepare_list_table_query($raw_request, $offset = 0, $count = 0) { /* * Go through the $raw_request, take only the arguments that are used in the query and * sanitize or validate them. */ if (!is_array($raw_request)) { /* translators: 1: ERROR tag 2: function name 3: non-array value */ error_log(sprintf(_x('%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), 'MLAData::_prepare_list_table_query', var_export($raw_request, true)), 0); return null; } /* * Make sure the current orderby choice still exists or revert to default. */ $default_orderby = array_merge(array('none' => array('none', false)), MLA_List_Table::mla_get_sortable_columns()); $current_orderby = MLAOptions::mla_get_option(MLAOptions::MLA_DEFAULT_ORDERBY); $found_current = false; foreach ($default_orderby as $key => $value) { if ($current_orderby == $value[0]) { $found_current = true; break; } } if ($found_current) { /* * Custom fields can have HTML reserved characters, which are encoded by * mla_get_sortable_columns, so a separate, unencoded list is required. */ $default_orderby = MLAOptions::mla_custom_field_support('custom_sortable_columns'); foreach ($default_orderby as $sort_key => $sort_value) { if ($current_orderby == $sort_key) { $current_orderby = 'c_' . $sort_value[0]; break; } } // foreach } else { MLAOptions::mla_delete_option(MLAOptions::MLA_DEFAULT_ORDERBY); $current_orderby = MLAOptions::mla_get_option(MLAOptions::MLA_DEFAULT_ORDERBY); } $clean_request = array('m' => 0, 'orderby' => $current_orderby, 'order' => MLAOptions::mla_get_option(MLAOptions::MLA_DEFAULT_ORDER), 'post_type' => 'attachment', 'post_status' => 'inherit', 'mla_search_connector' => 'AND', 'mla_search_fields' => array()); foreach ($raw_request as $key => $value) { switch ($key) { /* * 'sentence' and 'exact' modify the keyword search ('s') * Their value is not important, only their presence. */ case 'sentence': case 'exact': case 'mla-tax': case 'mla-term': $clean_request[$key] = sanitize_key($value); break; case 'orderby': if (in_array($value, array('none', 'post__in'))) { $clean_request[$key] = $value; } else { $orderby = NULL; /* * Custom fields can have HTML reserved characters, which are encoded by * mla_get_sortable_columns, so a separate, unencoded list is required. */ $sortable_columns = MLAOptions::mla_custom_field_support('custom_sortable_columns'); foreach ($sortable_columns as $sort_key => $sort_value) { if ($value == $sort_key) { $orderby = 'c_' . $sort_value[0]; break; } } // foreach if (NULL === $orderby) { $sortable_columns = MLA_List_Table::mla_get_sortable_columns(); foreach ($sortable_columns as $sort_key => $sort_value) { if ($value == $sort_value[0]) { $orderby = $value; break; } } // foreach } if (NULL !== $orderby) { $clean_request[$key] = $orderby; } } break; /* * ids allows hooks to supply a persistent list of items */ /* * ids allows hooks to supply a persistent list of items */ case 'ids': if (is_array($value)) { $clean_request['post__in'] = $value; } else { $clean_request['post__in'] = array_map('absint', explode(',', $value)); } break; /* * post__in and post__not_in are used in the Media Modal Ajax queries */ /* * post__in and post__not_in are used in the Media Modal Ajax queries */ case 'post__in': case 'post__not_in': case 'post_mime_type': $clean_request[$key] = $value; break; case 'parent': case 'post_parent': $clean_request['post_parent'] = absint($value); break; /* * ['m'] - filter by year and month of post, e.g., 201204 */ /* * ['m'] - filter by year and month of post, e.g., 201204 */ case 'author': case 'm': $clean_request[$key] = absint($value); break; /* * ['mla_filter_term'] - filter by category or tag ID; -1 allowed */ /* * ['mla_filter_term'] - filter by category or tag ID; -1 allowed */ case 'mla_filter_term': $clean_request[$key] = intval($value); break; case 'order': switch ($value = strtoupper($value)) { case 'ASC': case 'DESC': $clean_request[$key] = $value; break; default: $clean_request[$key] = 'ASC'; } break; case 'detached': if ('0' == $value || '1' == $value) { $clean_request['detached'] = $value; } break; case 'status': if ('trash' == $value) { $clean_request['post_status'] = 'trash'; } break; /* * ['s'] - Search Media by one or more keywords * ['mla_search_connector'], ['mla_search_fields'] - Search Media options */ /* * ['s'] - Search Media by one or more keywords * ['mla_search_connector'], ['mla_search_fields'] - Search Media options */ case 's': switch (substr($value, 0, 3)) { case '>|<': $clean_request['debug'] = 'console'; break; case '<|>': $clean_request['debug'] = 'log'; break; } if (isset($clean_request['debug'])) { $value = substr($value, 3); } $value = stripslashes(trim($value)); if (!empty($value)) { $clean_request[$key] = $value; } break; case 'mla_terms_search': if (!empty($value['phrases']) && !empty($value['taxonomies'])) { $value['phrases'] = stripslashes(trim($value['phrases'])); if (!empty($value['phrases'])) { $clean_request[$key] = $value; } } break; case 'mla_search_connector': case 'mla_search_fields': $clean_request[$key] = $value; break; case 'mla-metakey': case 'mla-metavalue': $clean_request[$key] = stripslashes($value); break; case 'meta_query': if (!empty($value)) { if (is_array($value)) { $clean_request[$key] = $value; } else { $clean_request[$key] = unserialize(stripslashes($value)); unset($clean_request[$key]['slug']); } // not array } break; default: // ignore anything else in $_REQUEST } // switch $key } // foreach $raw_request /* * Pass query and search parameters to the filters for _execute_list_table_query */ self::$query_parameters = array('use_postmeta_view' => false, 'orderby' => $clean_request['orderby'], 'order' => $clean_request['order']); self::$query_parameters['detached'] = isset($clean_request['detached']) ? $clean_request['detached'] : NULL; self::$search_parameters = array('debug' => 'none'); /* * Matching a meta_value to NULL requires a LEFT JOIN to a view and a special WHERE clause * Matching a wildcard pattern requires mainpulating the WHERE clause, too */ if (isset($clean_request['meta_query']['key'])) { self::$query_parameters['use_postmeta_view'] = true; self::$query_parameters['postmeta_key'] = $clean_request['meta_query']['key']; self::$query_parameters['postmeta_value'] = NULL; unset($clean_request['meta_query']); } elseif (isset($clean_request['meta_query']['patterns'])) { self::$query_parameters['patterns'] = $clean_request['meta_query']['patterns']; unset($clean_request['meta_query']['patterns']); } if (isset($clean_request['debug'])) { self::$query_parameters['debug'] = $clean_request['debug']; self::$search_parameters['debug'] = $clean_request['debug']; MLA::mla_debug_mode($clean_request['debug']); unset($clean_request['debug']); } /* * We must patch the WHERE clause if there are leading spaces in the meta_value */ if (isset($clean_request['mla-metavalue']) && 0 < strlen($clean_request['mla-metavalue']) && ' ' == $clean_request['mla-metavalue'][0]) { self::$query_parameters['mla-metavalue'] = $clean_request['mla-metavalue']; } /* * We will handle "Terms Search" in the mla_query_posts_search_filter. */ if (isset($clean_request['mla_terms_search'])) { self::$search_parameters['mla_terms_search'] = $clean_request['mla_terms_search']; /* * The Terms Search overrides any terms-based keyword search for now; too complicated. */ if (isset($clean_request['mla_search_fields'])) { foreach ($clean_request['mla_search_fields'] as $index => $field) { if ('terms' == $field) { unset($clean_request['mla_search_fields'][$index]); } } } } /* * We will handle keyword search in the mla_query_posts_search_filter. */ if (isset($clean_request['s'])) { self::$search_parameters['s'] = $clean_request['s']; self::$search_parameters['mla_search_fields'] = apply_filters('mla_list_table_search_filter_fields', $clean_request['mla_search_fields'], array('content', 'title', 'excerpt', 'alt-text', 'name', 'terms')); self::$search_parameters['mla_search_connector'] = $clean_request['mla_search_connector']; self::$search_parameters['sentence'] = isset($clean_request['sentence']); self::$search_parameters['exact'] = isset($clean_request['exact']); if (in_array('alt-text', self::$search_parameters['mla_search_fields'])) { self::$query_parameters['use_postmeta_view'] = true; self::$query_parameters['postmeta_key'] = '_wp_attachment_image_alt'; } if (in_array('terms', self::$search_parameters['mla_search_fields'])) { self::$search_parameters['mla_search_taxonomies'] = MLAOptions::mla_supported_taxonomies('term-search'); } unset($clean_request['s']); unset($clean_request['mla_search_connector']); unset($clean_request['mla_search_fields']); unset($clean_request['sentence']); unset($clean_request['exact']); } /* * We have to handle custom field/post_meta values here * because they need a JOIN clause supplied by WP_Query */ if ('c_' == substr($clean_request['orderby'], 0, 2)) { $option_value = MLAOptions::mla_custom_field_option_value($clean_request['orderby']); if (isset($option_value['name'])) { self::$query_parameters['use_postmeta_view'] = true; self::$query_parameters['postmeta_key'] = $option_value['name']; if (isset($clean_request['orderby'])) { unset($clean_request['orderby']); } if (isset($clean_request['order'])) { unset($clean_request['order']); } } } else { // custom field switch (self::$query_parameters['orderby']) { /* * '_wp_attachment_image_alt' is special; we'll handle it in the JOIN and ORDERBY filters */ case '_wp_attachment_image_alt': self::$query_parameters['use_postmeta_view'] = true; self::$query_parameters['postmeta_key'] = '_wp_attachment_image_alt'; if (isset($clean_request['orderby'])) { unset($clean_request['orderby']); } if (isset($clean_request['order'])) { unset($clean_request['order']); } break; case '_wp_attached_file': $clean_request['meta_key'] = '_wp_attached_file'; $clean_request['orderby'] = 'meta_value'; $clean_request['order'] = self::$query_parameters['order']; break; } // switch $orderby } /* * Ignore incoming paged value; use offset and count instead */ if ((int) $count > 0) { $clean_request['offset'] = $offset; $clean_request['posts_per_page'] = $count; } elseif ((int) $count == -1) { $clean_request['posts_per_page'] = $count; } /* * ['mla_filter_term'] - filter by taxonomy * * cat = 0 is "All Categories", i.e., no filtering * cat = -1 is "No Categories" */ if (isset($clean_request['mla_filter_term'])) { if ($clean_request['mla_filter_term'] != 0) { $tax_filter = MLAOptions::mla_taxonomy_support('', 'filter'); if ($clean_request['mla_filter_term'] == -1) { $term_list = get_terms($tax_filter, array('fields' => 'ids', 'hide_empty' => false)); $clean_request['tax_query'] = array(array('taxonomy' => $tax_filter, 'field' => 'id', 'terms' => $term_list, 'operator' => 'NOT IN')); } else { // mla_filter_term == -1 $clean_request['tax_query'] = array(array('taxonomy' => $tax_filter, 'field' => 'id', 'terms' => array((int) $clean_request['mla_filter_term']), 'include_children' => 'checked' == MLAOptions::mla_get_option(MLAOptions::MLA_TAXONOMY_FILTER_INCLUDE_CHILDREN))); } // mla_filter_term != -1 } // mla_filter_term != 0 unset($clean_request['mla_filter_term']); } // isset mla_filter_term if (isset($clean_request['mla-tax']) && isset($clean_request['mla-term'])) { $clean_request['tax_query'] = array(array('taxonomy' => $clean_request['mla-tax'], 'field' => 'slug', 'terms' => $clean_request['mla-term'], 'include_children' => false)); unset($clean_request['mla-tax']); unset($clean_request['mla-term']); } // isset mla_tax if (isset($clean_request['mla-metakey']) && isset($clean_request['mla-metavalue'])) { $clean_request['meta_key'] = $clean_request['mla-metakey']; $clean_request['meta_value'] = $clean_request['mla-metavalue']; unset($clean_request['mla-metakey']); unset($clean_request['mla-metavalue']); } // isset mla_tax return $clean_request; }