Skip to content

Commit

Permalink
Refactor - get_product_search_form().
Browse files Browse the repository at this point in the history
Also removed < 2.1 deprecated filter mapping.

Closes woocommerce#4444
  • Loading branch information
mikejolley committed Oct 10, 2014
1 parent 9836180 commit bf885f8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 35 deletions.
18 changes: 6 additions & 12 deletions includes/wc-deprecated-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,30 +509,24 @@ function woocommerce_list_pages( $pages ) {
global $wc_map_deprecated_filters;

$wc_map_deprecated_filters = array(
'woocommerce_cart_item_class' => 'woocommerce_cart_table_item_class',
'woocommerce_cart_item_product_id' => 'hook_woocommerce_in_cart_product_id',
'woocommerce_cart_item_thumbnail' => 'hook_woocommerce_in_cart_product_thumbnail',
'woocommerce_cart_item_price' => 'woocommerce_cart_item_price_html',
'woocommerce_cart_item_name' => 'woocommerce_in_cart_product_title',
'woocommerce_order_item_class' => 'woocommerce_order_table_item_class',
'woocommerce_order_item_name' => 'woocommerce_order_table_product_title',
'woocommerce_order_amount_shipping' => 'woocommerce_order_amount_total_shipping',
'woocommerce_package_rates' => 'woocommerce_available_shipping_methods'
'pre_get_product_search_form' => 'get_product_search_form'
);

foreach ( $wc_map_deprecated_filters as $new => $old )
foreach ( $wc_map_deprecated_filters as $new => $old ) {
add_filter( $new, 'woocommerce_deprecated_filter_mapping' );
}

function woocommerce_deprecated_filter_mapping( $data, $arg_1 = '', $arg_2 = '', $arg_3 = '' ) {
global $wc_map_deprecated_filters;

$filter = current_filter();

if ( isset( $wc_map_deprecated_filters[ $filter ] ) )
if ( isset( $wc_map_deprecated_filters[ $filter ] ) ) {
if ( has_filter( $wc_map_deprecated_filters[ $filter ] ) ) {
$data = apply_filters( $wc_map_deprecated_filters[ $filter ], $data, $arg_1, $arg_2, $arg_3 );
_deprecated_function( 'The ' . $wc_map_deprecated_filters[ $filter ] . ' filter', '2.1', $filter );
_deprecated_function( 'The ' . $wc_map_deprecated_filters[ $filter ] . ' filter', '', $filter );
}
}

return $data;
}
Expand Down
40 changes: 18 additions & 22 deletions includes/wc-template-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1876,35 +1876,31 @@ function woocommerce_form_field( $key, $args, $value = null ) {
if ( ! function_exists( 'get_product_search_form' ) ) {

/**
* Output Product search forms.
* Display prdouct search form.
*
* Will first attempt to locate the product-searchform.php file in either the child or
* the parent, then load it. If it doesn't exist, then the default search form
* will be displayed.
*
* The default searchform uses html5.
*
* @access public
* @subpackage Forms
* @param bool $echo (default: true)
* @return string
* @todo This function needs to be broken up in smaller pieces
*/
function get_product_search_form( $echo = true ) {
do_action( 'get_product_search_form' );
ob_start();

$search_form_template = locate_template( 'product-searchform.php' );
if ( '' != $search_form_template ) {
require $search_form_template;
return;
}
do_action( 'pre_get_product_search_form' );

$form = '<form role="search" method="get" id="searchform" action="' . esc_url( home_url( '/' ) ) . '">
<div>
<label class="screen-reader-text" for="s">' . __( 'Search for:', 'woocommerce' ) . '</label>
<input type="text" value="' . get_search_query() . '" name="s" id="s" placeholder="' . __( 'Search for products', 'woocommerce' ) . '" />
<input type="submit" id="searchsubmit" value="'. esc_attr__( 'Search', 'woocommerce' ) .'" />
<input type="hidden" name="post_type" value="product" />
</div>
</form>';

if ( $echo )
echo apply_filters( 'get_product_search_form', $form );
else
return apply_filters( 'get_product_search_form', $form );
wc_get_template( 'product-searchform.php' );

$form = apply_filters( 'get_product_search_form', ob_get_clean() );

if ( $echo ) {
echo $form;
} else {
return $form;
}
}
}
3 changes: 2 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
= 2.3.0 =
* Refactor - Removed deprecated methods from WC_Frontend_Scripts and rewrote script registration and localization to run once.
* Refactor - Routing all email functionality through one send() method.
* Refactor - Replaced existing email css inliner with Emogrifier
* Refactor - Replaced existing email css inliner with Emogrifier.
* Refactor - get_product_search_form().
* Fix - When 'hide out of stock products' is disabled, out of stock variations / attributes are now visible.
* Tweak - Double the default product image dimensions.
* Tweak - Added refunds to Sales by Date report.
Expand Down
6 changes: 6 additions & 0 deletions templates/product-searchform.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<form role="search" method="get" class="woocommerce-product-search" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<label class="screen-reader-text" for="s"><?php _e( 'Search for:', 'woocommerce' ); ?></label>
<input type="search" class="search-field" placeholder="<?php echo esc_attr_x( 'Search Products&hellip;', 'placeholder', 'woocommerce' ); ?>" value="<?php echo get_search_query(); ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label' ); ?>" />
<input type="submit" value="<?php echo esc_attr_x( 'Search', 'submit button', 'woocommerce' ); ?>" />
<input type="hidden" name="post_type" value="product" />
</form>

0 comments on commit bf885f8

Please sign in to comment.