-
Notifications
You must be signed in to change notification settings - Fork 11
/
icons-for-features.php
689 lines (656 loc) · 16.8 KB
/
icons-for-features.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
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
<?php
/**
* Plugin Name: Icons For Features
* Plugin URI: http://www.woothemes.com/products/icons-for-features/
* Description: Hey there! Do you want to display awesome icons for each of your features? Look no further, I'm here to help!
* Version: 1.1.0
* Author: WooThemes
* Author URI: http://woothemes.com/
* Requires at least: 3.8.1
* Tested up to: 4.3.1
*
* Text Domain: icons-for-features
* Domain Path: /languages/
*
* @package Icons_For_Features
* @category Core
* @author Matty
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Returns the main instance of Icons_For_Features to prevent the need to use globals.
*
* @since 1.0.0
* @return object Icons_For_Features
*/
function Icons_For_Features() {
return Icons_For_Features::instance();
} // End Icons_For_Features()
Icons_For_Features();
/**
* Main Icons_For_Features Class
*
* @class Icons_For_Features
* @version 1.0.0
* @since 1.0.0
* @package Kudos
* @author Matty
*/
final class Icons_For_Features {
/**
* Icons_For_Features The single instance of Icons_For_Features.
* @var object
* @access private
* @since 1.0.0
*/
private static $_instance = null;
/**
* The token.
* @var string
* @access public
* @since 1.0.0
*/
public $token;
/**
* The version number.
* @var string
* @access public
* @since 1.0.0
*/
public $version;
/**
* An instance of the Icons_For_Features_Admin class.
* @var object
* @access public
* @since 1.0.0
*/
public $admin;
/**
* The name of the hook on which we will be working our magic.
* @var string
* @access public
* @since 1.0.0
*/
public $hook;
/**
* Constructor function.
* @access public
* @since 1.0.0
* @return void
*/
public function __construct () {
$this->token = 'icons-for-features';
$this->plugin_url = plugin_dir_url( __FILE__ );
$this->plugin_path = plugin_dir_path( __FILE__ );
$this->version = '1.1.0';
register_activation_hook( __FILE__, array( $this, 'install' ) );
add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
/* Conditionally load the admin. */
if ( is_admin() ) {
add_action( 'admin_init', array( $this, 'register_styles' ) );
require_once( 'classes/class-icons-for-features-admin.php' );
$this->admin = new Icons_For_Features_Admin();
} else {
add_action( 'wp_enqueue_scripts', array( $this, 'register_styles' ) );
// An unfortunate caveat, as we need to wait for the entire page to load, in order to determine whether or not there have been Features called.
add_action( 'wp_footer', array( $this, 'maybe_enqueue_styles' ) );
add_filter( 'woothemes_features_item_template', array( $this, 'add_feature_icon_placeholder' ), 10, 2 );
add_filter( 'woothemes_features_template', array( $this, 'override_feature_icon_placeholder' ), 10, 2 );
add_filter( 'woothemes_features_html', array( $this, 'maybe_remove_override_filter' ) );
}
} // End __construct()
/**
* Main Icons_For_Features Instance
*
* Ensures only one instance of Icons_For_Features is loaded or can be loaded.
*
* @since 1.0.0
* @static
* @see Icons_For_Features()
* @return Main Icons_For_Features instance
*/
public static function instance () {
if ( is_null( self::$_instance ) )
self::$_instance = new self();
return self::$_instance;
} // End instance()
/**
* Load the localisation file.
* @access public
* @since 1.0.0
* @return void
*/
public function load_plugin_textdomain() {
load_plugin_textdomain( 'icons-for-features', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
} // End load_plugin_textdomain()
/**
* Cloning is forbidden.
*
* @since 1.0.0
*/
public function __clone () {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?' ), '1.0.0' );
} // End __clone()
/**
* Unserializing instances of this class is forbidden.
*
* @since 1.0.0
*/
public function __wakeup () {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?' ), '1.0.0' );
} // End __wakeup()
/**
* Installation. Runs on activation.
* @access public
* @since 1.0.0
* @return void
*/
public function install () {
$this->_log_version_number();
} // End install()
/**
* Log the plugin version number.
* @access public
* @since 1.0.0
* @return void
*/
private function _log_version_number () {
// Log the version number.
update_option( $this->_token . '_version', $this->_version );
} // End _log_version_number()
/**
* Force has_post_thumbnail() to return false, to "skip over" images where there is an icon for the feature.
* This caters for older versions of the Features by WooThemes plugin, where there are a few useful filters that are missing.
* @access public
* @since 1.0.0
* @param boolean $response Force this to be false, somehow.
* @param int $object_id The current object ID.
* @param string $meta_key The specified meta key to retrieve.
* @param boolean $single Whether this is a singular instance key or not.
* @return boolean Always return a boolean.
*/
public function override_has_post_thumbnail ( $response, $object_id, $meta_key, $single ) {
if ( '_thumbnail_id' != $meta_key ) return $response;
if ( '' != get_post_meta( intval( $object_id ), '_icon', true ) ) $response = false;
return $response;
} // End override_has_post_thumbnail()
/**
* Remove the filter used to force has_post_thumbnail() to return false.
* @access public
* @since 1.0.0
* @return void
*/
public function maybe_remove_override_filter ( $html ) {
remove_filter( 'get_post_metadata', array( $this, 'override_has_post_thumbnail' ), 10, 4 );
return $html;
} // End maybe_remove_override_filter()
/**
* Add an %%ICON%% placeholder to the feature template, replacing %%IMAGE%%, if it exists.
* If no %%IMAGE%% tag is present, the administrator doesn't want an image to display, so don't display an icon (respect their wishes).
* @access public
* @since 1.0.0
* @return void
*/
public function add_feature_icon_placeholder ( $tpl, $args ) {
add_filter( 'get_post_metadata', array( $this, 'override_has_post_thumbnail' ), 10, 4 );
$tpl = str_replace( '%%IMAGE%%', '%%ICON%%%%IMAGE%%', $tpl );
return $tpl;
} // End add_feature_icon_placeholder()
/**
* Override the %%ICON%% template tag, if an icon is available. If not, remove the template tag.
* @access public
* @since 1.0.0
* @return void
*/
public function override_feature_icon_placeholder ( $html, $post ) {
$icon = $this->get_the_icon_html( get_the_ID() );
$html = str_replace( '%%ICON%%', $icon, $html );
return $html;
} // End override_feature_icon_placeholder()
/**
* Register the CSS files to be loaded for this plugin.
* @access public
* @since 1.0.0
* @return void
*/
public function register_styles () {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_register_style( $this->token . '-icons', esc_url( $this->plugin_url . 'assets/lib/font-awesome/css/font-awesome' . $suffix . '.css' ), array(), '4.0.3', 'all' );
wp_register_style( $this->token . '-icons-loader', esc_url( $this->plugin_url . 'assets/css/style.css' ), array( $this->token . '-icons' ), $this->version, 'all' );
wp_register_style( $this->token . '-icons-admin', esc_url( $this->plugin_url . 'assets/css/admin.css' ), array( $this->token . '-icons' ), $this->version, 'all' );
wp_register_style( $this->token . '-icons-chosen', esc_url( $this->plugin_url . 'assets/lib/chosen/chosen' . $suffix . '.css' ), array( $this->token . '-icons' ), $this->version, 'all' );
} // End register_styles()
/**
* Conditionally load the CSS files for this plugin.
* @access public
* @since 1.0.0
* @return void
*/
public function maybe_enqueue_styles () {
if ( ( is_singular() && 'feature' == get_post_type() ) || is_post_type_archive( 'feature' ) || did_action( 'woothemes_features_before' ) ) {
wp_enqueue_style( $this->token . '-icons-loader' );
}
} // End maybe_enqueue_styles()
/**
* Get the HTML for the stored icon for a given feature.
* @access public
* @since 1.0.0
* @param int $post_id The feature for which to retrieve the icon.
* @return string Formatted icon HTML.
*/
public function get_the_icon_html ( $post_id = null ) {
if ( is_null( $post_id ) ) $post_id = get_the_ID();
$response = '';
$icon = get_post_meta( intval( $post_id ), '_icon', true );
$url = get_post_meta( intval( $post_id ), '_url', true );
$title = get_the_title( intval( $post_id ) );
$icon_color_html = '';
$icon_color = get_post_meta( intval( $post_id ), '_icon_color', true );
if ( '' != $icon && in_array( $icon, $this->get_supported_icon_list() ) ) {
if ( '' != $icon_color ) { $icon_color_html = 'style="color: ' . esc_attr( $icon_color ) . ';"'; }
if ( '' != $url ) {
$response = '<a title="' . esc_attr ( $title ) . '" href="' . esc_url( $url ) . '"><div class="icon-preview fa ' . esc_attr( $icon ) . '" ' . $icon_color_html . '></div></a>' . "\n";
} else {
$response = '<div class="icon-preview fa ' . esc_attr( $icon ) . '" ' . $icon_color_html . '></div>' . "\n";
}
}
return (string)apply_filters( 'icons_for_features_get_the_icon_html', $response );
} // End get_the_icon_html()
/**
* Transform a given icon key into a human-readable label.
* @access public
* @since 1.0.0
* @param string $key Given icon key.
* @return string Formatted icon label.
*/
public function get_icon_label ( $key ) {
$label = $key;
$label = str_replace( 'fa-', '', $label );
$label = str_replace( '-', ' ', $label );
if ( ' o' == substr( $label, -2 ) ) {
$label = substr( $label, 0, ( strlen( $label ) -2 ) );
}
$label = ucwords( $label );
return $label;
} // End get_icon_label()
/**
* Returns a filterable list of supported icon keys.
* @access public
* @since 1.0.0
* @return array Supported icon keys.
*/
public function get_supported_icon_list () {
return (array)apply_filters( 'icons_for_features_supported_icons', array(
'fa-glass',
'fa-music',
'fa-search',
'fa-envelope-o',
'fa-heart',
'fa-star',
'fa-star-o',
'fa-user',
'fa-film',
'fa-th-large',
'fa-th',
'fa-th-list',
'fa-check',
'fa-times',
'fa-search-plus',
'fa-search-minus',
'fa-power-off',
'fa-signal',
'fa-cog',
'fa-trash-o',
'fa-home',
'fa-file-o',
'fa-clock-o',
'fa-road',
'fa-download',
'fa-arrow-circle-o-down',
'fa-arrow-circle-o-up',
'fa-inbox',
'fa-play-circle-o',
'fa-repeat',
'fa-refresh',
'fa-list-alt',
'fa-lock',
'fa-flag',
'fa-headphones',
'fa-volume-off',
'fa-volume-down',
'fa-volume-up',
'fa-qrcode',
'fa-barcode',
'fa-tag',
'fa-tags',
'fa-book',
'fa-bookmark',
'fa-print',
'fa-camera',
'fa-font',
'fa-bold',
'fa-italic',
'fa-text-height',
'fa-text-width',
'fa-align-left',
'fa-align-center',
'fa-align-right',
'fa-align-justify',
'fa-list',
'fa-outdent',
'fa-indent',
'fa-video-camera',
'fa-picture-o',
'fa-pencil',
'fa-map-marker',
'fa-adjust',
'fa-tint',
'fa-pencil-square-o',
'fa-share-square-o',
'fa-check-square-o',
'fa-arrows',
'fa-step-backward',
'fa-fast-backward',
'fa-backward',
'fa-play',
'fa-pause',
'fa-stop',
'fa-forward',
'fa-fast-forward',
'fa-step-forward',
'fa-eject',
'fa-chevron-left',
'fa-chevron-right',
'fa-plus-circle',
'fa-minus-circle',
'fa-times-circle',
'fa-check-circle',
'fa-question-circle',
'fa-info-circle',
'fa-crosshairs',
'fa-times-circle-o',
'fa-check-circle-o',
'fa-ban',
'fa-arrow-left',
'fa-arrow-right',
'fa-arrow-up',
'fa-arrow-down',
'fa-share',
'fa-expand',
'fa-compress',
'fa-plus',
'fa-minus',
'fa-asterisk',
'fa-exclamation-circle',
'fa-gift',
'fa-leaf',
'fa-fire',
'fa-eye',
'fa-eye-slash',
'fa-exclamation-triangle',
'fa-plane',
'fa-calendar',
'fa-random',
'fa-comment',
'fa-magnet',
'fa-chevron-up',
'fa-chevron-down',
'fa-retweet',
'fa-shopping-cart',
'fa-folder',
'fa-folder-open',
'fa-arrows-v',
'fa-arrows-h',
'fa-bar-chart-o',
'fa-twitter-square',
'fa-facebook-square',
'fa-camera-retro',
'fa-key',
'fa-cogs',
'fa-comments',
'fa-thumbs-o-up',
'fa-thumbs-o-down',
'fa-star-half',
'fa-heart-o',
'fa-sign-out',
'fa-linkedin-square',
'fa-thumb-tack',
'fa-external-link',
'fa-sign-in',
'fa-trophy',
'fa-github-square',
'fa-upload',
'fa-lemon-o',
'fa-phone',
'fa-square-o',
'fa-bookmark-o',
'fa-phone-square',
'fa-twitter',
'fa-facebook',
'fa-github',
'fa-unlock',
'fa-credit-card',
'fa-rss',
'fa-hdd-o',
'fa-bullhorn',
'fa-bell',
'fa-certificate',
'fa-hand-o-right',
'fa-hand-o-left',
'fa-hand-o-up',
'fa-hand-o-down',
'fa-arrow-circle-left',
'fa-arrow-circle-right',
'fa-arrow-circle-up',
'fa-arrow-circle-down',
'fa-globe',
'fa-wrench',
'fa-tasks',
'fa-filter',
'fa-briefcase',
'fa-arrows-alt',
'fa-users',
'fa-link',
'fa-cloud',
'fa-flask',
'fa-scissors',
'fa-files-o',
'fa-paperclip',
'fa-floppy-o',
'fa-square',
'fa-bars',
'fa-list-ul',
'fa-list-ol',
'fa-strikethrough',
'fa-underline',
'fa-table',
'fa-magic',
'fa-truck',
'fa-pinterest',
'fa-pinterest-square',
'fa-google-plus-square',
'fa-google-plus',
'fa-money',
'fa-caret-down',
'fa-caret-up',
'fa-caret-left',
'fa-caret-right',
'fa-columns',
'fa-sort',
'fa-sort-asc',
'fa-sort-desc',
'fa-envelope',
'fa-linkedin',
'fa-undo',
'fa-gavel',
'fa-tachometer',
'fa-comment-o',
'fa-comments-o',
'fa-bolt',
'fa-sitemap',
'fa-umbrella',
'fa-clipboard',
'fa-lightbulb-o',
'fa-exchange',
'fa-cloud-download',
'fa-cloud-upload',
'fa-user-md',
'fa-stethoscope',
'fa-suitcase',
'fa-bell-o',
'fa-coffee',
'fa-cutlery',
'fa-file-text-o',
'fa-building-o',
'fa-hospital-o',
'fa-ambulance',
'fa-medkit',
'fa-fighter-jet',
'fa-beer',
'fa-h-square',
'fa-plus-square',
'fa-angle-double-left',
'fa-angle-double-right',
'fa-angle-double-up',
'fa-angle-double-down',
'fa-angle-left',
'fa-angle-right',
'fa-angle-up',
'fa-angle-down',
'fa-desktop',
'fa-laptop',
'fa-tablet',
'fa-mobile',
'fa-circle-o',
'fa-quote-left',
'fa-quote-right',
'fa-spinner',
'fa-circle',
'fa-reply',
'fa-github-alt',
'fa-folder-o',
'fa-folder-open-o',
'fa-smile-o',
'fa-frown-o',
'fa-meh-o',
'fa-gamepad',
'fa-keyboard-o',
'fa-flag-o',
'fa-flag-checkered',
'fa-terminal',
'fa-code',
'fa-reply-all',
'fa-mail-reply-all',
'fa-star-half-o',
'fa-location-arrow',
'fa-crop',
'fa-code-fork',
'fa-chain-broken',
'fa-question',
'fa-info',
'fa-exclamation',
'fa-superscript',
'fa-subscript',
'fa-eraser',
'fa-puzzle-piece',
'fa-microphone',
'fa-microphone-slash',
'fa-shield',
'fa-calendar-o',
'fa-fire-extinguisher',
'fa-rocket',
'fa-maxcdn',
'fa-chevron-circle-left',
'fa-chevron-circle-right',
'fa-chevron-circle-up',
'fa-chevron-circle-down',
'fa-html5',
'fa-css3',
'fa-anchor',
'fa-unlock-alt',
'fa-bullseye',
'fa-ellipsis-h',
'fa-ellipsis-v',
'fa-rss-square',
'fa-play-circle',
'fa-ticket',
'fa-minus-square',
'fa-minus-square-o',
'fa-level-up',
'fa-level-down',
'fa-check-square',
'fa-pencil-square',
'fa-external-link-square',
'fa-share-square',
'fa-compass',
'fa-caret-square-o-down',
'fa-caret-square-o-up',
'fa-caret-square-o-right',
'fa-eur',
'fa-gbp',
'fa-usd',
'fa-inr',
'fa-jpy',
'fa-rub',
'fa-krw',
'fa-btc',
'fa-file',
'fa-file-text',
'fa-sort-alpha-asc',
'fa-sort-alpha-desc',
'fa-sort-amount-asc',
'fa-sort-amount-desc',
'fa-sort-numeric-asc',
'fa-sort-numeric-desc',
'fa-thumbs-up',
'fa-thumbs-down',
'fa-youtube-square',
'fa-youtube',
'fa-xing',
'fa-xing-square',
'fa-youtube-play',
'fa-dropbox',
'fa-stack-overflow',
'fa-instagram',
'fa-flickr',
'fa-adn',
'fa-bitbucket',
'fa-bitbucket-square',
'fa-tumblr',
'fa-tumblr-square',
'fa-long-arrow-down',
'fa-long-arrow-up',
'fa-long-arrow-left',
'fa-long-arrow-right',
'fa-apple',
'fa-windows',
'fa-android',
'fa-linux',
'fa-dribbble',
'fa-skype',
'fa-foursquare',
'fa-trello',
'fa-female',
'fa-male',
'fa-gittip',
'fa-sun-o',
'fa-moon-o',
'fa-archive',
'fa-bug',
'fa-vk',
'fa-weibo',
'fa-renren',
'fa-pagelines',
'fa-stack-exchange',
'fa-arrow-circle-o-right',
'fa-arrow-circle-o-left',
'fa-caret-square-o-left',
'fa-dot-circle-o',
'fa-wheelchair',
'fa-vimeo-square',
'fa-try',
'fa-plus-square-o'
) );
} // End get_supported_icon_list()
} // End Class
?>