|<': self::$custom_field_parameters['debug'] = 'console'; $start = 3; break; case '<|>': self::$custom_field_parameters['debug'] = 'log'; $start = 3; break; default: $start = 0; } if ( 'custom:' == substr( $_REQUEST['s'], $start, 7 ) ) { self::$custom_field_parameters['s'] = substr( $_REQUEST['s'], $start + 7 ); unset( $_REQUEST['s'] ); self::$custom_field_parameters['mla_search_connector'] = $_REQUEST['mla_search_connector']; unset( $_REQUEST['mla_search_connector'] ); self::$custom_field_parameters['mla_search_fields'] = $_REQUEST['mla_search_fields']; unset( $_REQUEST['mla_search_fields'] ); } else { self::$custom_field_parameters = array(); } } // isset s=custom: return $mla_list_table; } // mla_list_table_new_instance /** * Custom Field Search "parameters" * * @since 1.01 * * @var array */ public static $custom_field_parameters = array(); /** * Filter the WP_Query request parameters for the prepare_items query * * Gives you an opportunity to change the terms of the prepare_items query * after they are processed by the "Prepare List Table Query" handler. * * @since 1.01 * * @param array WP_Query request prepared by "Prepare List Table Query" * * @return array updated WP_Query request */ public static function mla_list_table_query_final_terms( $request ) { /* * If $request['offset'] and $request['posts_per_page'] are set, this is the "prepare_items" request. * If they are NOT set, this is a "view count" request, i.e., to get the count for a custom view. * * MLAData::$query_parameters and MLAData::$search_parameters contain * additional parameters used in some List Table queries. */ if ( ! ( isset( $request['offset'] ) && isset( $request['posts_per_page'] ) ) ) { return $request; } if ( empty( self::$custom_field_parameters ) ) { return $request; } if ( isset( self::$custom_field_parameters['debug'] ) ) { MLAData::$query_parameters['debug'] = self::$custom_field_parameters['debug']; MLAData::$search_parameters['debug'] = self::$custom_field_parameters['debug']; MLA::mla_debug_mode( self::$custom_field_parameters['debug'] ); } // Apply default field name? if ( '=' == substr( self::$custom_field_parameters['s'], 0, 1 ) ) { $tokens = array( 'Orientation', substr( self::$custom_field_parameters['s'], 1 ) ); } else { $tokens = explode( '=', self::$custom_field_parameters['s'] ) ; } // See if the custom field name is present, followed by "=" and a value if ( 1 < count( $tokens ) ) { $field = array_shift( $tokens ); $value = implode( '=', $tokens ); } else { // Supply a default custom field name $field = 'Orientation'; $value = $tokens[0]; } /* * Parse the query, remove MLA-specific elements, fix numeric and "commas" format fields */ $tokens = MLAMime::mla_prepare_view_query( 'custom_field_search', 'custom:' . $field . '=' . $value ); $tokens = $tokens['meta_query']; /* * Matching a meta_value to NULL requires a LEFT JOIN to a view and a special WHERE clause; * MLA filters will handle this case. */ if ( isset( $tokens['key'] ) ) { MLAData::$query_parameters['use_postmeta_view'] = true; MLAData::$query_parameters['postmeta_key'] = $tokens['key']; MLAData::$query_parameters['postmeta_value'] = NULL; return $request; } /* * Process "normal" meta_query */ $query = array( 'relation' => $tokens['relation'] ); $padded_values = array(); $patterns = array(); foreach ( $tokens as $key => $value ) { if ( ! is_numeric( $key ) ) { continue; } if ( in_array( $value['key'], array( 'File Size', 'pixels', 'width', 'height' ) ) ) { if ( '=' == $value['compare'] ) { $value['value'] = str_pad( $value['value'], 15, ' ', STR_PAD_LEFT ); $padded_values[ trim( $value['value'] ) ] = $value['value']; } else { $value['value'] = '%' . $value['value']; } } if ( 'LIKE' == $value['compare'] ) { $patterns[] = $value['value']; } $query[] = $value; } if ( ! empty( $padded_values ) ) { MLAData::$query_parameters['mla-metavalue'] = $padded_values; } if ( ! empty( $patterns ) ) { MLAData::$query_parameters['patterns'] = $patterns; } /* * Combine with an existing "custom view" meta_query, if present */ if ( isset( $request['meta_query'] ) ) { $request['meta_query'] = array( 'relation' => 'AND', $request['meta_query'], $query ); } else { $request['meta_query'] = $query; } return $request; } // mla_list_table_query_final_terms /** * MLA Edit Media "Query Attachments" initial terms Filter * * Gives you an opportunity to change the terms of the * Media Manager Modal Window "Query Attachments" query * before they are pre-processed by the MLA handler. * * @since 1.03 * * @param array WP_Query terms supported for "Query Attachments" * @param array All terms passed in the request */ public static function mla_media_modal_query_initial_terms( $query, $raw_query ) { /* * Look for the special "custom:" prefix in the Search Media text box, * after checking for the "debug" prefixes. */ if ( isset( $query['mla_search_value'] ) ) { switch ( substr( $query['mla_search_value'], 0, 3 ) ) { case '>|<': self::$custom_field_parameters['debug'] = 'console'; $start = 3; break; case '<|>': self::$custom_field_parameters['debug'] = 'log'; $start = 3; break; default: $start = 0; } if ( 'custom:' == substr( $query['mla_search_value'], $start, 7 ) ) { self::$custom_field_parameters['s'] = substr( $query['mla_search_value'], $start + 7 ); unset( $query['mla_search_value'] ); self::$custom_field_parameters['mla_search_connector'] = $query['mla_search_connector']; unset( $query['mla_search_connector'] ); self::$custom_field_parameters['mla_search_fields'] = $query['mla_search_fields']; unset( $query['mla_search_fields'] ); } else { self::$custom_field_parameters = array(); } } // isset mla_search_value=custom: return $query; } /** * MLA Edit Media "Query Attachments" final terms Filter * * Gives you an opportunity to change the terms of the * Media Manager Modal Window "Query Attachments" query * after they are processed by the "Prepare List Table Query" handler. * * @since 1.03 * * @param array WP_Query request prepared by "Prepare List Table Query" */ public static function mla_media_modal_query_final_terms( $request ) { /* * The logic used in the Media/Assistant Search Media box will work here as well */ return MLACustomFieldSearchExample::mla_list_table_query_final_terms( $request ); } } // Class MLACustomFieldSearchExample /* * Install the filters at an early opportunity */ add_action('init', 'MLACustomFieldSearchExample::initialize'); ?>