Ad Widget Version: 2.1.0 Author: Broadstreet Ads Author URI: http://broadstreetads.com */ add_action('admin_init', array('AdWidget_Core', 'registerScripts')); add_action('widgets_init', array('AdWidget_Core', 'registerWidgets')); add_action('admin_menu', array('AdWidget_Core', 'registerAdmin')); /** * This class is the core of Ad Widget */ class AdWidget_Core { /** * The callback used to register the scripts */ static function registerScripts() { # Include thickbox on widgets page if($GLOBALS['pagenow'] == 'widgets.php') { wp_enqueue_script('thickbox'); wp_enqueue_style('thickbox'); wp_enqueue_script('adwidget-main', self::getBaseURL().'assets/widgets.js'); } } /** * The callback used to register the widget */ static function registerWidgets() { register_widget('AdWidget_HTMLWidget'); register_widget('AdWidget_ImageWidget'); } /** * Get the base URL of the plugin installation * @return string the base URL */ public static function getBaseURL() { return (get_bloginfo('url') . '/wp-content/plugins/adwidget/'); } /** * Register the admin settings page */ static function registerAdmin() { add_options_page('Ad Widget', 'Ad Widget', 'edit_pages', 'adwidget.php', array(__CLASS__, 'adminMenuCallback')); } /** * The function used by WP to print the admin settings page */ static function adminMenuCallback() { include dirname(__FILE__) . '/views/admin.php'; } } /** * The HTML Widget */ class AdWidget_HTMLWidget extends WP_Widget { /** * Set the widget options */ function AdWidget_HTMLWidget() { $widget_ops = array('classname' => 'AdWidget_HTMLWidget', 'description' => 'Place an ad code like Google ads or other ad provider'); $this->WP_Widget('AdWidget_HTMLWidget', 'Ad: HTML/Javascript Ad', $widget_ops); } /** * Display the widget on the sidebar * @param array $args * @param array $instance */ function widget($args, $instance) { extract($args); echo $before_widget; $instance['w_adcode']; echo $after_widget; } /** * Update the widget info from the admin panel * @param array $new_instance * @param array $old_instance * @return array */ function update($new_instance, $old_instance) { $instance = $old_instance; $instance['w_adcode'] = $new_instance['w_adcode']; return $instance; } /** * Display the widget update form * @param array $instance */ function form($instance) { $defaults = array('w_adcode' => ''); $instance = wp_parse_args((array) $instance, $defaults); ?>
'AdWidget_ImageWidget', 'description' => 'Place an image ad with a link'); $this->WP_Widget('AdWidget_ImageWidget', 'Ad: Image/Banner Ad', $widget_ops); } /** * Display the widget on the sidebar * @param array $args * @param array $instance */ function widget($args, $instance) { extract($args); $link = $instance['w_link']; $img = $instance['w_img']; echo $before_widget; echo "