Advertisement
daymobrew

WP Store Locator shortcode

Jan 12th, 2015
796
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: WP Store Locator shortcodes
  4. Plugin URI: http://www.damiencarbery.com
  5. Description: Shortcodes for use with WP Store Locator plugin.
  6. Author: Damien Carbery
  7. Version: 0.1
  8.  
  9. $Id: $
  10. */
  11.  
  12. add_shortcode('wpsl_list', 'wpsl_shortcodes');
  13.  
  14. function wpsl_shortcodes($atts, $content, $code) {
  15.     include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
  16.     if (is_plugin_active( 'wp-store-locator.php' )) {
  17.         return 'WPSL Plugin Not Active';  // Or return nothing.
  18.     }
  19.  
  20.     global $wpdb;
  21.     $wpdb->wpsl_stores = $wpdb->prefix . 'wpsl_stores';
  22.  
  23.     $all_stores = $wpdb->get_results( "SELECT * FROM $wpdb->wpsl_stores WHERE `active` ='1' ORDER BY `country`,`store` ASC", ARRAY_A );
  24.     $stores_list = '<table><tr><td>Store Name</td><td>address</td><td>URL</td></tr>';
  25.     foreach ($all_stores as $store_info) {
  26.         $stores_list .= sprintf('<tr><td>%s</td><td>%s</td><td>%s</td></tr>%s', $store_info['store'], $store_info['address'], $store_info['url'], "\n");
  27.     }
  28.     $stores_list .= '</table>';
  29.  
  30.     return $stores_list;
  31. }
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement