View difference between Paste ID: DbAGhM5U and 6A62suWA
SHOW: | | - or go back to the newest paste.
1
<?php
2
/*
3
Plugin Name: TablePress Extension: Shortcode Filter from GET parameter
4
Plugin URI: https://tablepress.org/extensions/shortcode-filter-get-parameter/
5
Description: Custom Extension for TablePress to use the Row Filter extension with a filter term from a $_GET parameter
6
Version: 1.0
7
Author: Tobias Bäthge
8
Author URI: https://tobias.baethge.com/
9
*/
10
11
/*
12
 * The Shortcode: [table_filter id=123 /]
13
 * will be filtered for http://example.com/?table_filter=myfilterword
14
 */
15
16
function tablepress_filter_shortcode( $attributes, $content ) {
17
	if ( ! empty( $_GET['table_filter'] ) ) {
18
		$filter_term = $_GET['table_filter'];
19
		/*
20
		 * Only allow characters a-z, A-Z, 0-9, and spaces in the filter term.
21
		 * This regular expression needs to be extended if other characters shall be allowed.
22
		 */
23
		$filter_term = preg_replace( '#[^a-z0-9 ]#i', '', $filter_term );
24
		$attributes['filter'] = $filter_term;
25
	} else {
26
		$attributes['filter'] = '';
27-
} else {
27+
28-
  $attributes['filter'] = '';
28+
29
}
30
31
if ( ! is_admin() ) {
32
	add_shortcode( 'table_filter', 'tablepress_filter_shortcode' );
33
}