-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
pc-switcher-widget.php
118 lines (107 loc) · 2.96 KB
/
pc-switcher-widget.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/**
* Widget Name: PC Switcher Widget
* Plugin URI: https://github.com/thingsym/multi-device-switcher
* Description: PC Switcher Widget add-on for the Multi Device Switcher. Use this widget to add the PC Switcher to a widget.
* Version: 1.8.5
* Author: thingsym
* Author URI: https://www.thingslabo.com/
* License: GPLv2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: multi-device-switcher
* Domain Path: /languages/
*
* @package Multi_Device_Switcher
*/
/**
* PC Switcher Widget
*
* @since 1.2
*/
if ( class_exists( 'Multi_Device_Switcher' ) ) {
add_action( 'widgets_init', 'pc_switcher_load_widgets' );
}
/**
* Register PC_Switcher.
*
* @since 1.0.0
*/
function pc_switcher_load_widgets() {
register_widget( 'PC_Switcher' );
}
/**
* Core class PC_Switcher
*
* @since 1.0.0
*/
class PC_Switcher extends WP_Widget {
/**
* Sets up a new widget instance.
*
* @since 1.0.0
*
* @access public
*/
public function __construct() {
load_plugin_textdomain( 'multi-device-switcher', false, dirname( plugin_basename( __MULTI_DEVICE_SWITCHER_FILE__ ) ) . '/languages/' );
$widget_ops = array(
'classname' => 'widget_pc_switcher',
'description' => __( 'Add the PC Switcher to a widget.', 'multi-device-switcher' ),
'customize_selective_refresh' => true,
);
parent::__construct( 'pc-switcher', __( 'PC Switcher', 'multi-device-switcher' ), $widget_ops );
$this->alt_option_name = 'widget_pc_switcher';
}
/**
* Outputs the content for the widget instance.
*
* @since 1.0.0
*
* @access public
*
* @param array $args Display arguments including 'before_title', 'after_title',
* 'before_widget', and 'after_widget'.
* @param array $instance Settings for the current widget instance.
*/
public function widget( $args, $instance ) {
if ( ! function_exists( 'multi_device_switcher_add_pc_switcher' ) ) {
return;
}
global $multi_device_switcher;
$name = $multi_device_switcher->get_device_theme();
if ( $name && 'None' !== $name ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $args['before_widget'];
multi_device_switcher_add_pc_switcher();
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $args['after_widget'];
}
}
/**
* Handles updating settings for the current Archives widget instance.
*
* @since 1.0.0
*
* @access public
*
* @param array $new_instance New settings for this instance as input by the user via form() method.
* @param array $old_instance Old settings for this instance.
*
* @return array Updated settings to save.
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
return $instance;
}
/**
* Outputs the settings form for the widget.
*
* @since 1.0.0
*
* @access public
*
* @param array $instance Current settings.
*/
public function form( $instance ) {
}
}