Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2016
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.10 KB | None | 0 0
  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.  * The Shortcode: [table_filter id=123 /]
  12.  * will be filtered for http://example.com/?table_filter=myfilterword
  13.  */
  14. function tablepress_filter_shortcode( $attributes, $content ) {
  15.     if ( ! empty( $_GET['table_filter'] ) ) {
  16.         $filter_term = $_GET['table_filter'];
  17.         /*
  18.          * Only allow characters a-z, A-Z, 0-9, and spaces in the filter term.
  19.          * This regular expression needs to be extended if other characters shall be allowed.
  20.          */
  21.         $filter_term = preg_replace( '#[^a-z0-9 ]#i', '', $filter_term );
  22.         $attributes['filter'] = $filter_term;
  23.         return tablepress_get_table( $attributes );
  24.     } else {
  25.         return 'Please enter a Serial Number.';
  26.     }
  27. }
  28. if ( ! is_admin() ) {
  29.     add_shortcode( 'table_filter', 'tablepress_filter_shortcode' );
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement