From 385b81d4a3ffb65e1f872b8211aab1258a622a33 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Thu, 20 Nov 2014 10:35:53 -0500 Subject: [PATCH] Change to using function call and not widget --- controllers/Front.php | 10 +++--- index.php | 13 +++---- ...dget.php => Preston_Feather_Locations.php} | 35 +++++++------------ views/{vCard.php => locations.php} | 0 4 files changed, 26 insertions(+), 32 deletions(-) rename models/{PrestonInfoWidget.php => Preston_Feather_Locations.php} (57%) rename views/{vCard.php => locations.php} (100%) diff --git a/controllers/Front.php b/controllers/Front.php index 5882177..9692f09 100644 --- a/controllers/Front.php +++ b/controllers/Front.php @@ -45,16 +45,18 @@ class Preston_Info_Front_controller function __construct($path) { $this->path = $path; - add_action('widgets_init', array($this, 'prestonclientinfo_register_widget')); + } /** * Register the Client Info Widget with WordPress */ - function prestonclientinfo_register_widget() + function locations() { - include $this->path . 'models/PrestonInfoWidget.php'; - register_widget('PrestonInfoWidget'); + echo 'done'; + include $this->path . 'models/Preston_Feather_Locations.php'; + $locations = new Preston_Feather_Locations($this->path); + $locations->toHtml(); } } diff --git a/index.php b/index.php index 151b4c9..870f789 100644 --- a/index.php +++ b/index.php @@ -22,10 +22,11 @@ if (is_admin()) { $adminController = new Preston_Info_Admin_Controller( plugin_dir_path(__FILE__) ); +} else { + function preston_feather_get_locations() + { + include 'models/Preston_Feather_Locations.php'; + $locations = new Preston_Feather_Locations(plugin_dir_path(__FILE__)); + $locations->toHtml(); + } } - -// call the Front Controller to setup the widget -require_once 'controllers/Front.php'; -$frontController = new Preston_Info_Front_controller( - plugin_dir_path(__FILE__) -); diff --git a/models/PrestonInfoWidget.php b/models/Preston_Feather_Locations.php similarity index 57% rename from models/PrestonInfoWidget.php rename to models/Preston_Feather_Locations.php index 43b3bc8..b6a0a3e 100644 --- a/models/PrestonInfoWidget.php +++ b/models/Preston_Feather_Locations.php @@ -1,7 +1,7 @@ */ -class PrestonInfoWidget - extends WP_widget +class Preston_Feather_Locations { private $pluginDirPath; @@ -36,43 +35,35 @@ class PrestonInfoWidget /** * Class Initializer */ - public function __construct() + public function __construct($path) { - parent::__construct( - 'PrestonInfoWidget', - __('Locations Info Widget', 'text_domain'), - array('description' => __('Locations Widget', 'text_domain')) - ); + $this->pluginDirPath = $path; } /** - * Output widget + * Output Locations * * Includes the template file for the widget. * Template file is plain old php for your fastest template engine yet! * - * @param type $args Widget Args - * @param type $instance Widget Instance - * * @return string */ - public function widget($args, $instance) + public function toHtml() { - $path = plugin_dir_path(__FILE__); - include $path . '../views/vCard.php'; + include $this->pluginDirPath . 'views/locations.php'; } /** - * Return the quicksite option for the given key + * Return the locations option for the given key * - * @param type $name Name of the quicksite option to return + * @param string $name Name of the quicksite option to return + * @param string $key Sub key for the value * * @return string Option */ - function show_option($name, $key) + function show_option($name, $key = null) { $settings = get_option('prestonclientinfo_settings'); - $states = get_option('prestonclientinfo_states'); if ($key) { return ($settings[$name][$key]) ? $settings[$name][$key] diff --git a/views/vCard.php b/views/locations.php similarity index 100% rename from views/vCard.php rename to views/locations.php -- 2.17.1