forked from ShenandoahU/bean-shortcodes
/
bean-shortcodes.php
executable file
·293 lines (229 loc) · 9.52 KB
/
bean-shortcodes.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
<?php
/**
* Plugin Name: Bean Shortcodes
* Plugin URI: http://themebeans.com/plugins/bean-shortcodes
* Description: Enables shortcodes to be used in your WordPress theme.
* Version: 2.2.1
* Author: ThemeBeans
* Author URI: http://themebeans.com
*
*
* @package Bean Plugins
* @subpackage BeanShortcodes
* @author ThemeBeans
* @since BeanShortcodes 1.0
*/
/*===================================================================*/
/* MAKE SURE WE DO NOT EXPOSE ANY INFO IF CALLED DIRECTLY
/*===================================================================*/
if ( !function_exists( 'add_action' ) )
{
echo 'Hi there! I\'m just a plugin, not much I can do when called directly.';
exit;
}
/*===================================================================*/
/*
/* PLUGIN FEATURES SETUP
/*
/*===================================================================*/
$bean_plugin_features[ plugin_basename( __FILE__ ) ] = array(
"updates" => false // Whether to utilize plugin updates feature or not
);
if ( ! function_exists( 'bean_plugin_supports' ) )
{
function bean_plugin_supports( $plugin_basename, $feature )
{
global $bean_plugin_features;
$setup = $bean_plugin_features;
if( isset( $setup[$plugin_basename][$feature] ) && $setup[$plugin_basename][$feature] )
return true;
else
return false;
}
}
/*===================================================================*/
/*
/* PLUGIN UPDATER FUNCTIONALITY
/*
/*===================================================================*/
define( 'EDD_BEANSHORTCODES_TB_URL', 'http://themebeans.com' );
define( 'EDD_BEANSHORTCODES_NAME', 'Bean Shortcodes' );
if ( bean_plugin_supports ( plugin_basename( __FILE__ ), 'updates' ) ) : // check to see if updates are allowed; only import if so
//LOAD UPDATER CLASS
if( !class_exists( 'EDD_SL_Plugin_Updater' ) )
{
include( dirname( __FILE__ ) . '/updates/EDD_SL_Plugin_Updater.php' );
}
//INCLUDE UPDATER SETUP
include( dirname( __FILE__ ) . '/updates/EDD_SL_Activation.php' );
endif; // END if ( bean_plugin_supports ( plugin_basename( __FILE__ ), 'updates' ) )
/*===================================================================*/
/* UPDATER SETUP
/*===================================================================*/
function beanshortcodes_license_setup()
{
add_option( 'edd_beanshortcodes_activate_license', 'BEANSHORTCODES' );
add_option( 'edd_beanshortcodes_license_status' );
}
add_action( 'init', 'beanshortcodes_license_setup' );
function edd_beanshortcodes_plugin_updater()
{
// check to see if updates are allowed; don't do anything if not
if ( ! bean_plugin_supports ( plugin_basename( __FILE__ ), 'updates' ) ) return;
//RETRIEVE LICENSE KEY
$license_key = trim( get_option( 'edd_beanshortcodes_activate_license' ) );
$edd_updater = new EDD_SL_Plugin_Updater( EDD_BEANSHORTCODES_TB_URL, __FILE__, array(
'version' => '2.2',
'license' => $license_key,
'item_name' => EDD_BEANSHORTCODES_NAME,
'author' => 'Rich Tabor / ThemeBeans'
)
);
}
add_action( 'admin_init', 'edd_beanshortcodes_plugin_updater' );
/*===================================================================*/
/* DEACTIVATION HOOK - REMOVE OPTION
/*===================================================================*/
function beanshortcodes_deactivate()
{
delete_option( 'edd_beanshortcodes_activate_license' );
delete_option( 'edd_beanshortcodes_license_status' );
}
register_deactivation_hook( __FILE__, 'beanshortcodes_deactivate' );
/*===================================================================*/
/*
/* BEGIN BEAN SHORTCODES PLUGIN
/*
/*===================================================================*/
/*===================================================================*/
/* BEGIN CLASS
/*===================================================================*/
if ( !class_exists( 'Bean_BeanShortcodes' ) ) {
class Bean_BeanShortcodes
{
private $all_shortcodes = array(
"toggle",
"tabs",
"tab",
"alert",
"highlight",
"tooltip",
"button",
"quote",
"note",
"list",
"one_third",
"one_third_last",
"two_third",
"two_third_last",
"one_half",
"one_half_last",
"one_fourth",
"one_fourth_last",
"three_fourth",
"three_fourth_last",
"one_fifth",
"one_fifth_last",
"two_fifth",
"two_fifth_last",
"three_fifth",
"three_fifth_last",
"four_fifth",
"four_fifth_last",
"one_sixth",
"one_sixth_last",
"five_sixth",
"five_sixth_last",
"clear",
"clearfix"
);
function __construct()
{
require_once( DIRNAME(__FILE__) . '/bean-theme-shortcodes.php' );
define('BEAN_SC_ADMIN_URI', plugin_dir_url(__FILE__) .'admin');
define('BEAN_TINYMCE_DIR', DIRNAME(__FILE__) .'/admin');
add_action('init', array(&$this, 'action_admin_init'));
add_action('admin_enqueue_scripts', array(&$this, 'action_admin_scripts_init'));
add_action('wp_enqueue_scripts', array(&$this, 'action_frontend_scripts'));
}
/*===================================================================*/
/* REGISTER SCRIPTS & STYLES
/*===================================================================*/
function action_frontend_scripts()
{
//VARIABLES
$js_url = plugin_dir_url(__FILE__) . 'assets/js/bean-shortcodes.min.js';
$css_url = plugin_dir_url(__FILE__) . 'assets/bean-shortcodes.css';
$font_awesome_css_url = plugin_dir_url(__FILE__) . 'assets/font-awesome.css';
global $post;
/*
* Conditionally check if the post content contains any of the shortcodes in which case load enqueue the scripts/styles
*
* A much much better way could have been to keep a flag that defaults to 0. Whenever any of the shortcode callback
* functions is called, it sets the flag to 1. Then, in the wp_footer, we can decide whether to load the scripts or not.
*
* The reason why that method is not used is to avoid loading css in body.
*
*/
wp_enqueue_script('bean-shortcodes', $js_url, 'jquery', '1.0', true);
wp_enqueue_style( 'bean-shortcodes', $css_url, false, '1.0', 'all' );
wp_enqueue_style( 'font-awesome', $font_awesome_css_url, false, '1.0', 'all' );
// foreach($this->all_shortcodes as $shortcode)
// {
// if (strpos($post->post_content, $shortcode) !== FALSE)
// {
// wp_enqueue_script('bean-shortcodes', $js_url, 'jquery', '1.0', true);
// wp_enqueue_style( 'bean-shortcodes', $css_url, false, '1.0', 'all' );
// break;
// }
// }
}
/*===================================================================*/
/* ENQUEUE SCRIPTS & STYLES
/*===================================================================*/
function action_admin_scripts_init()
{
//CSS
wp_enqueue_style( 'bean-shortcodes-admin', BEAN_SC_ADMIN_URI . '/css/bean-shortcodes-admin.css', false, '1.0', 'all' );
wp_enqueue_style( 'font-awesome', plugin_dir_url(__FILE__) . 'assets/font-awesome.css', false, '1.0', 'all' );
//JS
wp_enqueue_script( 'jquery-ui-sortable' );
wp_enqueue_script( 'bean-shortcodes-admin', BEAN_SC_ADMIN_URI . '/js/bean-shortcodes-admin.js', false, '1.0', false );
wp_enqueue_script( 'bean-shortcodes-popup', BEAN_SC_ADMIN_URI . '/js/bean-shortcodes-popup.js', false, '1.0', false );
wp_localize_script( 'jquery', 'BeanShortcodes', array('plugin_folder' => plugin_dir_url(__FILE__)) );
}
/*===================================================================*/
/* REGISTERS TINYMCE RICH EDITOR BUTTONS
/*===================================================================*/
function action_admin_init()
{
if ( !current_user_can('edit_posts') && !current_user_can('edit_pages') )
return;
if ( get_user_option('rich_editing') == 'true' && is_admin() ) {
add_filter( 'mce_external_plugins', array(&$this, 'add_rich_plugins') );
add_filter( 'mce_buttons', array(&$this, 'register_rich_buttons') );
}
}
/*===================================================================*/
/* DEFINES TINYNCE RICH EDITOR PLUGIN JS
/*===================================================================*/
function add_rich_plugins( $plugin_array )
{
if ( version_compare( get_bloginfo('version'), '3.9', '>=' ) ) {
$plugin_array['BeanShortcodes'] = BEAN_SC_ADMIN_URI . '/plugin.js';
} else {
$plugin_array['BeanShortcodes'] = BEAN_SC_ADMIN_URI . '/plugin-pre3.9.js';
}
return $plugin_array;
}
/*===================================================================*/
/* ADDS TINYMCE RICH EDITOR BUTTON
/*===================================================================*/
function register_rich_buttons( $buttons ) {
array_push( $buttons, "|", 'bean_shortcodes_button' );
return $buttons;
}
} //END class Bean_BeanShortcodes
new Bean_BeanShortcodes;
} //END if ( !class_exists( 'Bean_BeanShortcodes' ) )
?>