This repository has been archived by the owner on Dec 31, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.php
197 lines (149 loc) · 6.13 KB
/
plugin.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
/*
Plugin Name: SWDC Event Sponsors Widget
Description: Extends the Event Organiser plugin with a sponsor widget
Version: 1.0
Author: Fredrik Broman
Author URI: http://synack.se
Author Email: [email protected]
Text Domain: eosw
Domain Path: /lang/
Network: false
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Copyright 2013 [email protected]
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class SWDC_Event_Sponsors_Widget extends WP_Widget {
/*--------------------------------------------------*/
/* Constructor
/*--------------------------------------------------*/
/**
* Specifies the classname and description, instantiates the widget,
* loads localization files, and includes necessary stylesheets and JavaScript.
*/
public function __construct() {
// load plugin text domain
add_action( 'init', array( $this, 'widget_textdomain' ) );
// Hooks fired when the Widget is activated and deactivated
register_activation_hook( __FILE__, array( $this, 'activate' ) );
register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
parent::__construct(
'swdc-event-sponsors-widget',
__( 'SWDC Event Sponsors Widget', 'eosw' ),
array(
'classname' => 'swdc-event-sponsors-widget',
'description' => __( 'Extends the Event Organiser plugin with a sponsor widget', 'eosw' )
)
);
// Register admin styles and scripts
// add_action( 'admin_print_styles', array( $this, 'register_admin_styles' ) );
// add_action( 'admin_enqueue_scripts', array( $this, 'register_admin_scripts' ) );
// Register site styles and scripts
// add_action( 'wp_enqueue_scripts', array( $this, 'register_widget_styles' ) );
// add_action( 'wp_enqueue_scripts', array( $this, 'register_widget_scripts' ) );
} // end constructor
/*--------------------------------------------------*/
/* Widget API Functions
/*--------------------------------------------------*/
/**
* Outputs the content of the widget.
*
* @param array args The array of form elements
* @param array instance The current instance of the widget
*/
public function widget( $args, $instance ) {
extract( $args, EXTR_SKIP );
echo $before_widget;
// TODO: Here is where you manipulate your widget's values based on their input fields
$eventid = $instance['eventid'];
$html = $instance['html'];
include( plugin_dir_path( __FILE__ ) . '/views/widget.php' );
echo $after_widget;
} // end widget
/**
* Processes the widget's options to be saved.
*
* @param array $new_instance Values just sent to be saved.
* @param array $old_instance Previously saved values from database.
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['eventid'] = ( !empty( $new_instance['eventid'] ) ) ? strip_tags( $new_instance['eventid'] ) : '';
$instance['html'] = ( !empty( $new_instance['html'] ) ) ? $new_instance['html'] : '';
return $instance;
} // end widget
/**
* Generates the administration form for the widget.
*
* @param array instance The array of keys and values for the widget.
*/
public function form( $instance ) {
$instance = wp_parse_args(
(array) $instance
);
$eventid = isset($instance['eventid']) ? $instance['eventid'] : '-1';
$html = isset($instance['html']) ? $instance['html'] : '';
// Display the admin form
include( plugin_dir_path(__FILE__) . '/views/admin.php' );
} // end form
/*--------------------------------------------------*/
/* Public Functions
/*--------------------------------------------------*/
/**
* Loads the Widget's text domain for localization and translation.
*/
public function widget_textdomain() {
load_plugin_textdomain( 'eosw', false, plugin_dir_path( __FILE__ ) . '/lang/' );
} // end widget_textdomain
/**
* Fired when the plugin is activated.
*
* @param boolean $network_wide True if WPMU superadmin uses "Network Activate" action, false if WPMU is disabled or plugin is activated on an individual blog.
*/
public function activate( $network_wide ) {
// TODO define activation functionality here
} // end activate
/**
* Fired when the plugin is deactivated.
*
* @param boolean $network_wide True if WPMU superadmin uses "Network Activate" action, false if WPMU is disabled or plugin is activated on an individual blog
*/
public function deactivate( $network_wide ) {
// TODO define deactivation functionality here
} // end deactivate
/**
* Registers and enqueues admin-specific styles.
*/
public function register_admin_styles() {
wp_enqueue_style( 'swdc-event-sponsors-widget-admin-styles', plugins_url( 'swdc-event-sponsors-widget/css/admin.css' ) );
} // end register_admin_styles
/**
* Registers and enqueues admin-specific JavaScript.
*/
public function register_admin_scripts() {
wp_enqueue_script( 'swdc-event-sponsors-widget-admin-script', plugins_url( 'swdc-event-sponsors-widget/js/admin.js' ), array('jquery') );
} // end register_admin_scripts
/**
* Registers and enqueues widget-specific styles.
*/
public function register_widget_styles() {
wp_enqueue_style( 'swdc-event-sponsors-widget-widget-styles', plugins_url( 'swdc-event-sponsors-widget/css/widget.css' ) );
} // end register_widget_styles
/**
* Registers and enqueues widget-specific scripts.
*/
public function register_widget_scripts() {
wp_enqueue_script( 'swdc-event-sponsors-widget-script', plugins_url( 'swdc-event-sponsors-widget/js/widget.js' ), array('jquery') );
} // end register_widget_scripts
} // end class
add_action( 'widgets_init', create_function( '', 'register_widget("SWDC_Event_Sponsors_Widget");' ) );