| 1 |
<?php |
| 2 |
/* |
| 3 |
Widget Name: PC Switcher Widget |
| 4 |
Plugin URI: https://github.com/thingsym/multi-device-switcher |
| 5 |
Description: PC Switcher Widget add-on for the Multi Device Switcher. Use this widget to add the PC Switcher to a widget. |
| 6 |
Version: 1.3.0 |
| 7 |
Author: thingsym |
| 8 |
Author URI: http://www.thingslabo.com/ |
| 9 |
License: GPL2 |
| 10 |
Text Domain: multi-device-switcher |
| 11 |
Domain Path: /languages/ |
| 12 |
*/ |
| 13 |
|
| 14 |
/* |
| 15 |
Copyright 2013 thingsym (http://www.thingslabo.com/) |
| 16 |
|
| 17 |
This program is free software; you can redistribute it and/or modify |
| 18 |
it under the terms of the GNU General Public License as published by |
| 19 |
the Free Software Foundation; either version 2 of the License, or |
| 20 |
(at your option) any later version. |
| 21 |
|
| 22 |
This program is distributed in the hope that it will be useful, |
| 23 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 24 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 25 |
GNU General Public License for more details. |
| 26 |
|
| 27 |
You should have received a copy of the GNU General Public License |
| 28 |
along with this program; if not, write to the Free Software |
| 29 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA |
| 30 |
*/ |
| 31 |
|
| 32 |
/** |
| 33 |
* PC Switcher Widget |
| 34 |
* |
| 35 |
* @since 1.2 |
| 36 |
*/ |
| 37 |
if ( class_exists('Multi_Device_Switcher') ) |
| 38 |
add_action('widgets_init', 'PC_Switcher_load_widgets'); |
| 39 |
|
| 40 |
function PC_Switcher_load_widgets() { |
| 41 |
register_widget('PC_Switcher'); |
| 42 |
} |
| 43 |
|
| 44 |
class PC_Switcher extends WP_Widget { |
| 45 |
|
| 46 |
function __construct() { |
| 47 |
load_plugin_textdomain('multi-device-switcher', false, 'multi-device-switcher/languages'); |
| 48 |
$widget_ops = array('classname' => 'widget_pc_switcher', 'description' => __( "Add the PC Switcher to a widget.", 'multi-device-switcher') ); |
| 49 |
parent::__construct('pc-switcher', __('PC Switcher', 'multi-device-switcher'), $widget_ops); |
| 50 |
$this->alt_option_name = 'widget_pc_switcher'; |
| 51 |
|
| 52 |
add_action( 'save_post', array(&$this, 'flush_widget_cache') ); |
| 53 |
add_action( 'deleted_post', array(&$this, 'flush_widget_cache') ); |
| 54 |
add_action( 'switch_theme', array(&$this, 'flush_widget_cache') ); |
| 55 |
} |
| 56 |
|
| 57 |
function widget($args, $instance) { |
| 58 |
if ( !function_exists( 'multi_device_switcher_add_pc_switcher' ) ) |
| 59 |
return; |
| 60 |
|
| 61 |
global $multi_device_switcher; |
| 62 |
$name = $multi_device_switcher->get_device_theme(); |
| 63 |
|
| 64 |
if ( $name && $name != 'None' ) { |
| 65 |
|
| 66 |
$cache = wp_cache_get('widget_pc_switcher', 'widget'); |
| 67 |
|
| 68 |
if ( !is_array($cache) ) |
| 69 |
$cache = array(); |
| 70 |
|
| 71 |
if ( isset($cache[ $args['widget_id'] ]) ) { |
| 72 |
echo $cache[ $args['widget_id'] ]; |
| 73 |
return; |
| 74 |
} |
| 75 |
|
| 76 |
ob_start(); |
| 77 |
extract($args); |
| 78 |
|
| 79 |
echo $before_widget; |
| 80 |
multi_device_switcher_add_pc_switcher(); |
| 81 |
echo $after_widget; |
| 82 |
|
| 83 |
$cache[ $args['widget_id'] ] = ob_get_flush(); |
| 84 |
wp_cache_set('widget_pc_switcher', $cache, 'widget'); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
function update( $new_instance, $old_instance ) { |
| 89 |
$instance = $old_instance; |
| 90 |
|
| 91 |
$this->flush_widget_cache(); |
| 92 |
|
| 93 |
$alloptions = wp_cache_get( 'alloptions', 'options' ); |
| 94 |
if ( isset($alloptions['widget_pc_switcher']) ) |
| 95 |
delete_option('widget_pc_switcher'); |
| 96 |
|
| 97 |
return $instance; |
| 98 |
} |
| 99 |
|
| 100 |
function flush_widget_cache() { |
| 101 |
wp_cache_delete('widget_pc_switcher', 'widget'); |
| 102 |
} |
| 103 |
|
| 104 |
function form( $instance ) { |
| 105 |
} |
| 106 |
} |
| 107 |
?> |
| 108 |
|