-
Notifications
You must be signed in to change notification settings - Fork 11
/
stagtools.php
516 lines (450 loc) · 15.5 KB
/
stagtools.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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
<?php
/**
* Plugin Name: StagTools
* Plugin URI: https://wordpress.org/plugins/stagtools/
* Description: A powerful plugin to extend functionality to your WordPress themes offering shortcodes, font icons, and useful widgets.
* Version: 2.3.8
* Author: <a href="https://twitter.com/mauryaratan/">Ram Ratan Maurya</a>, <a href="https://codestag.com/">Codestag</a>
* Author URI: https://codestag.com
* License: GPL2
* Requires at least: 5.0
* Tested up to: 6.2.2
*
* Text Domain: stag
* Domain Path: /languages/
*
* @package StagTools
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if ( ! class_exists( 'StagTools' ) ) :
/**
* Main StagTools Class
*
* @package StagTools
* @version 2.3.6
* @author Ram Ratan Maurya (Codestag)
* @link https://mauryaratan.me
* @link https://codestag.com
*/
class StagTools {
/**
* Plugin version.
*
* @var string
*/
public $version = '2.3.8';
/**
* The single instance of the class.
*
* @var StagTools
* @since 2.1
*/
protected static $_instance = null;
/**
* Plugin URL.
*
* @var string
*/
public $plugin_url;
/**
* Plugin path.
*
* @var string
*/
public $plugin_path;
/**
* Template URL.
*
* @var string
*/
public $template_url;
/**
* Main StagTools Instance
*
* Ensures only one instance of StagTools is loaded or can be loaded.
*
* @since 2.0.1
* @static
* @see StagTools()
* @return StagTools - Main instance
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* StagTools Constructor.
*
* @access public
* @return void
*/
public function __construct() {
// Define version constant.
define( 'STAGTOOLS_VERSION', $this->version );
if ( ( defined( 'SCRIPT_DEBUG' ) && true === SCRIPT_DEBUG ) ) {
define( 'SCRIPT_SUFFIX', '' );
} else {
define( 'SCRIPT_SUFFIX', '.min' );
}
// Hooks.
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'action_links' ) );
add_action( 'init', array( &$this, 'init' ) );
add_action( 'admin_menu', array( &$this, 'stag_add_options_page' ) );
add_action( 'admin_head', array( &$this, 'widget_styles' ) );
add_action( 'after_setup_theme', array( &$this, 'editor_styles' ) );
// Include required files.
$this->includes();
}
/**
* Editor styles to hook in WordPress editor.
*
* @return void
*/
public function editor_styles() {
$shortcode_styles = $this->plugin_url() . '/assets/css/stag-shortcodes.css';
add_editor_style( $shortcode_styles );
}
/**
* Add custom links on plugins page.
*
* @access public
* @param mixed $links Add link to Stagtools' settings page on Plugins screen.
* @return mixed|void
*/
public function action_links( $links ) {
$plugin_links = array(
'<a href="' . admin_url( 'options-general.php?page=stagtools' ) . '">' . __( 'Settings', 'stag' ) . '</a>',
);
return array_merge( $plugin_links, $links );
}
/**
* Initiate all the stuff.
*
* @return void
*/
public function init() {
$this->stag_load_textdomain();
add_action( 'wp_enqueue_scripts', array( &$this, 'frontend_style' ), 0 );
add_filter( 'body_class', array( &$this, 'body_class' ) );
add_action( 'current_screen', array( &$this, 'stag_contextual_help' ), 10, 3 );
add_filter( 'script_loader_tag', array( &$this, 'add_defer_attribute' ), 10, 2 );
/**
* Deprecataed lines.
*
* @deprecated 1.2
*/
if ( current_theme_supports( 'stag-portfolio' ) ) {
include_once 'includes/post-type/portfolio.php';
}
if ( current_theme_supports( 'stag-slides' ) ) {
include_once 'includes/post-type/slides.php';
}
if ( current_theme_supports( 'stag-team' ) ) {
include_once 'includes/post-type/team.php';
}
if ( current_theme_supports( 'stag-testimonials' ) ) {
include_once 'includes/post-type/testimonials.php';
}
/**
* Include custom post type files, depending on which are supported.
*
* @since 1.2
*/
if ( current_theme_supports( 'post-type' ) ) {
$theme_supports = get_theme_support( 'post-type' );
foreach ( $theme_supports[0] as $support ) {
include_once "includes/post-type/{$support}.php";
}
}
}
/**
* Add StagTools admin options.
*
* @global string $stag_options One true options page
* @return void
*/
public function stag_add_options_page() {
add_options_page( __( 'StagTools Options', 'stag' ), __( 'StagTools', 'stag' ), 'manage_options', 'stagtools', 'stagtools_options_page' );
}
/**
* Setup localisation.
*
* @return void
*/
public function stag_load_textdomain() {
// Set filter for plugin's languages directory.
$stagtools_lang_dir = dirname( plugin_basename( __FILE__ ) ) . '/languages/';
$stagtools_lang_dir = apply_filters( 'stagtools_languages_directory', $stagtools_lang_dir );
// Traditional WordPress plugin locale filter.
$locale = apply_filters( 'plugin_locale', get_locale(), 'stag' );
$mofile = sprintf( '%1$s-%2$s.mo', 'stag', $locale );
// Setup paths to current locale file.
$mofile_local = $stagtools_lang_dir . $mofile;
$mofile_global = WP_LANG_DIR . '/stagtools/' . $mofile;
if ( file_exists( $mofile_global ) ) {
// Look in global /wp-content/languages/stagtools folder.
load_textdomain( 'stag', $mofile_global );
} elseif ( file_exists( $mofile_local ) ) {
// Look in local /wp-content/plugins/stagtools/languages/ folder.
load_textdomain( 'stag', $mofile_local );
} else {
// Load the default language files.
load_plugin_textdomain( 'stag', false, $stagtools_lang_dir );
}
}
/**
* Include admin and frontend files.
*
* @uses StagTools::admin_includes() Includes admin files
* @uses StagTools::frontend_includes() Includes frontend files
* @return void
*/
public function includes() {
global $stag_options;
require_once 'includes/settings/settings.php';
$stag_options = stagtools_get_settings();
if ( is_admin() ) {
$this->admin_includes();
}
if ( ! is_admin() ) {
$this->frontend_includes();
}
// Widgets.
include_once 'includes/widgets/stagtools-widget.php';
include_once 'includes/widgets/widget-dribbble.php';
include_once 'includes/widgets/widget-flickr.php';
include_once 'includes/widgets/widget-instagram.php';
include_once 'includes/widgets/widget-twitter.php';
}
/**
* Include admin files.
*
* @return void
*/
public function admin_includes() {
include_once 'shortcodes/stag-shortcodes.php';
include_once 'includes/settings/settings.php';
include_once 'includes/tinymce.php';
include_once 'includes/class-stagtools-themes.php';
}
/**
* Include frontend files.
*
* @return void
*/
public function frontend_includes() {
include_once plugin_dir_path( __FILE__ ) . 'shortcodes/shortcodes.php';
}
/**
* Add frontend scripts and styles.
*
* @return void
*/
public function frontend_style() {
wp_enqueue_style( 'font-awesome', $this->plugin_url() . '/assets/css/fontawesome-all' . SCRIPT_SUFFIX . '.css', '', '5.15.3', 'all' );
wp_register_style( 'stag-shortcode-styles', $this->plugin_url() . '/assets/css/stag-shortcodes.css', array(), $this->version, 'all' );
wp_enqueue_style( 'stag-shortcode-styles' );
wp_register_script( 'stag-shortcode-scripts', $this->plugin_url() . '/assets/js/stag-shortcode-scripts.js', array( 'jquery', 'jquery-ui-accordion', 'jquery-ui-tabs' ), $this->version, true );
wp_enqueue_script( 'font-awesome-v5-svg', $this->plugin_url() . '/assets/js/fontawesome-all.min.js', array(), '5.15.3', true );
wp_enqueue_script( 'font-awesome-v4-shim', $this->plugin_url() . '/assets/js/fa-v4-shims.min.js', array( 'font-awesome-v5-svg' ), '5.15.3', true );
}
/**
* Add defer attribute to selected scripts.
*
* @since 2.2.3.
*
* @param string $tag Script tag.
* @param string $handle Script handle.
* @return mixed|void
*/
public function add_defer_attribute( $tag, $handle ) {
$scripts_to_defer = array( 'font-awesome-v5-svg', 'font-awesome-v4-shim' );
foreach ( $scripts_to_defer as $defer_script ) {
if ( $defer_script === $handle ) {
return str_replace( ' src', ' defer src', $tag );
}
}
return $tag;
}
/**
* Plugin path.
*
* @return string Plugin path
*/
public function plugin_path() {
if ( $this->plugin_path ) {
return $this->plugin_path;
}
$this->plugin_path = untrailingslashit( plugin_dir_path( __FILE__ ) );
return $this->plugin_path;
}
/**
* Plugin url.
*
* @return string Plugin url
*/
public function plugin_url() {
if ( $this->plugin_url ) {
return $this->plugin_url;
}
$this->plugin_url = untrailingslashit( plugins_url( '/', __FILE__ ) );
return $this->plugin_url;
}
/**
* Add stagtools to body class for use on frontend.
*
* @since 1.0.0
* @param var $classes List of existing classes.
* @return array $classes List of new classes
*/
public function body_class( $classes ) {
$classes[] = 'stagtools';
return $classes;
}
/**
* Widget styles.
*
* @return void
*/
public function widget_styles() {
global $pagenow;
if ( 'widgets.php' !== $pagenow ) {
return;
}
?>
<style type="text/css">
div[id*="_stag"] .widget-top {
background: #C8E5F3 !important;
border-color: #B4D0DD !important;
box-shadow: inset 0 1px 0 white !important;
-webkit-box-shadow: inset 0 1px 0 white !important;
-moz-box-shadow: inset 0 1px 0 white !important;
-ms-box-shadow: inset 0 1px 0 white !important;
-o-box-shadow: inset 0 1px 0 white !important;
background: -moz-linear-gradient(top, #EAF8FF 0%, #C8E5F3 100%) !important;
background: -webkit-linear-gradient(top, #EAF8FF 0%,#C8E5F3 100%) !important;
background: linear-gradient(to bottom, #EAF8FF 0%,#C8E5F3 100%) !important;
border-bottom: 1px solid #98B3C0 !important;
margin-top: 0px;
}
div[id*="_stag"] .description {
padding-bottom: 0;
padding-left: 0 !important;
font-style: italic;
}
</style>
<?php
}
/**
* Check if the plugin Stag Custom Sidebars is active.
*
* @since 1.1
* @link https://wordpress.org/plugins/stag-custom-sidebars
* @return boolean True if plugin is active or false.
*/
public function is_scs_active() {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
$is_scs_active = ( is_plugin_active( 'stag-custom-sidebars/stag-custom-sidebars.php' ) ) ? true : false;
if ( $is_scs_active ) {
$custom_sidebars = get_option( 'stag_custom_sidebars' );
if ( $custom_sidebars && count( $custom_sidebars ) ) {
return true;
}
}
return false;
}
/**
* Add help screen for StagTools settings page.
*
* @since 1.1
* @return void
*/
public function stag_contextual_help() {
$currentScreen = get_current_screen();
if ( 'settings_page_stagtools' !== $currentScreen->id ) {
return;
}
$currentScreen->set_help_sidebar(
'<p><strong>' . sprintf(
__( 'For more information:', 'stag' ) . '</strong></p>' .
/* translators: %s: Link to Github wiki. */
'<p>' . sprintf( __( 'Visit the <a href="%s" target="_blank">documentation</a> on the Github.', 'stag' ), esc_url( 'https://github.com/mauryaratan/stagtools/wiki' ) )
) . '</p>' .
'<p>' . sprintf(
/* translators: %1$s: Link to Github issues, %2$s: Link to Github repo. */
__( '<a href="%1$s" target="_blank">Post an issue</a> on <a href="%2$s" target="_blank">GitHub</a>.', 'stag' ),
esc_url( 'https://github.com/mauryaratan/stagtools/issues' ),
esc_url( 'https://github.com/mauryaratan/stagtools' )
) . '</p>'
);
$currentScreen->add_help_tab(
array(
'id' => 'stagtools-help-oauth',
'title' => __( 'Twitter oAuth Settings', 'stag' ),
'content' => '<p>' . __( 'Here you can find how to add twitter oAuth keys to get Twitter widget working.', 'stag' ) . '</p>' .
'<h5>' . __( 'Where do I find these keys?', 'stag' ) . '</h5>' .
/* translators: %s: Link to Twitter Developer documentation site. */
'<p>' . sprintf( __( 'In order to use the new Twitter widget, you must first register a Twitter app, which will provide you with the keys you see above. Start by <a href="%s" target="_blank">signing-in</a> to the Twitter developer dashboard.', 'stag' ), esc_url( 'https://dev.twitter.com/apps' ) ) . '</p>' .
'<h5>' . __( 'Where are my widgets?', 'stag' ) . '</h5>' .
/* translators: %s: Link to twitter screenshot. */
'<p>' . sprintf( __( 'In order to use the new Twitter widget, you must first register a Twitter app, which will provide you with the keys you see above. Start by <a href="%s" target="_blank">creating a new application</a> to the Twitter developer dashboard.', 'stag' ), esc_url( 'https://cl.ly/image/1H1U1i1T3u0h' ) ) . '</p>' .
'<h5>' . __( 'Can I insert shortcodes manually instead of using shortcode generator?', 'stag' ) . '</h5>' .
/* translators: %s: Link to Github gist for code snippet. */
'<p>' . sprintf( __( 'Yes; although we have a shortcode builder you can also see a list of <a href="%s" target="_blank">all available shortcodes</a> and use it manually in any supported area.', 'stag' ), esc_url( 'https://gist.github.com/mauryaratan/6071262' ) ) . '</p>',
)
);
if ( current_theme_supports( 'post-type', array( 'portfolio' ) ) ) :
$currentScreen->add_help_tab(
array(
'id' => 'stagtools-help-portfolio',
'title' => __( 'Portfolio Settings', 'stag' ),
'content' => '<p>' . __( 'You can use the following settigns to control the slug/taxonomies for custom post type portfolio and skills.', 'stag' ) . '</p>' .
'<p>' . __( '<strong>Portfolio Slug</strong> - This settings is used to set the slug of custom post type ‘portfolio’.', 'stag' ) . '</p>' .
'<p>' . __( '<strong>Skills Slug</strong> - This settings is used to set the slug of custom post taxonomy ‘skill’.', 'stag' ) . '</p>',
)
);
endif;
$currentScreen->add_help_tab(
array(
'id' => 'stagtools-help-social',
'title' => __( 'Using Social Icons', 'stag' ),
'content' => '<h5>' . __( 'Using Social Icons Shortcode' ) . '</h5>' .
'<p>' . __( 'To use the social icon use the following shortcode:', 'stag' ) . '</p>' .
'<pre>[stag_social] // ' . __( 'It would display all social icons with non-empty profile URLs.', 'stag' ) . '</pre>' .
'<pre>[stag_social id="facebook,twitter,google-plus"] // ' . __( 'or you can pass specific ids.', 'stag' ) . '</pre>' .
'<h5>' . __( 'Using Different Styled Icons' ) . '</h5>' .
'<p>' . __( 'You can use the social icons in two different styles: normal and square. Just pass the <code>style</code> argument in sidebar.<br>E.g.: <code>[stag_social id="twitter,facebook" style="square"]</code>.' ) . '</p>',
)
);
}
}
endif;
/**
* Returns the main instance of WC to prevent the need to use globals.
*
* @since 2.0.0
* @return StagTools
*/
function stagtools() {
return StagTools::instance();
}
// Global for backwards compatibility.
$GLOBALS['stagtools'] = stagtools();
/**
* Flush the rewrite rules on activation
*/
function stagtools_activation() {
flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'stagtools_activation' );
/**
* Also flush the rewrite rules on deactivation
*/
function stagtools_deactivation() {
flush_rewrite_rules();
}
register_deactivation_hook( __FILE__, 'stagtools_activation' );