From 7b4f3d95ef4da72a50abe4133d648a9ebbea08e0 Mon Sep 17 00:00:00 2001 From: KOMATSU Shinichiro Date: Mon, 24 Aug 2020 23:00:23 +0900 Subject: [PATCH] Add shortcode [sm_list_popular_searches] and [sm_list_recent_searches]. These shortcodes make the functions of the same name to use in posts or pages. --- search-meter.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/search-meter.php b/search-meter.php index 8961631..66b5037 100644 --- a/search-meter.php +++ b/search-meter.php @@ -104,6 +104,21 @@ function sm_list_popular_searches($before = '', $after = '', $count = 5) { echo apply_filters('sm_list_popular_searches_display', $display, $searches); } +function sm_list_popular_searches_shortcode( $atts ) { + $atts_ = shortcode_atts( array( + 'before' => '', + 'after' => '', + 'count' => 5, + ), $atts ); + + ob_start(); + sm_list_popular_searches($atts_['before'], $atts_['after'], $atts_['count']); + $ret = ob_get_contents(); + ob_end_clean(); + + return $ret; +} + function sm_list_recent_searches($before = '', $after = '', $count = 5) { // List the most recent successful searches, ignoring duplicates global $wpdb; @@ -128,6 +143,27 @@ function sm_list_recent_searches($before = '', $after = '', $count = 5) { } } +function sm_list_recent_searches_shortcode( $atts ) { + $atts_ = shortcode_atts( array( + 'before' => '', + 'after' => '', + 'count' => 5, + ), $atts ); + + ob_start(); + sm_list_recent_searches($atts_['before'], $atts_['after'], $atts_['count']); + $ret = ob_get_contents(); + ob_end_clean(); + + return $ret; +} + +function sm_register_shortcodes(){ + add_shortcode('sm_list_popular_searches', 'sm_list_popular_searches_shortcode'); + add_shortcode('sm_list_recent_searches', 'sm_list_recent_searches_shortcode'); +} +add_action( 'init', 'sm_register_shortcodes'); + function sm_get_relative_search_url($term) { // Return the URL for a search term, relative to the home directory. global $wp_rewrite;