1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: bradvin |
5
|
|
|
* Date: 2017/04/19 |
6
|
|
|
* Time: 1:19 PM |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
if ( ! class_exists( 'FooGallery_Admin_Gallery_MetaBox_Settings' ) ) { |
11
|
|
|
|
12
|
|
|
class FooGallery_Admin_Gallery_MetaBox_Settings { |
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* FooGallery_Admin_Gallery_MetaBox_Settings constructor. |
16
|
|
|
*/ |
17
|
|
|
function __construct() { |
|
|
|
|
18
|
|
|
//enqueue assets for the new settings tabs |
19
|
|
|
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) ); |
20
|
|
|
|
21
|
|
|
//get the section slug |
22
|
|
|
add_filter( 'foogallery_gallery_settings_metabox_section_slug', array( $this, 'get_section_slug' ) ); |
23
|
|
|
|
24
|
|
|
//set default settings tab icons |
25
|
|
|
add_filter( 'foogallery_gallery_settings_metabox_section_icon', array( $this, 'add_section_icons') ); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/*** |
29
|
|
|
* Enqueue the assets needed by the settings |
30
|
|
|
* @param $hook_suffix |
31
|
|
|
*/ |
32
|
|
|
function enqueue_assets( $hook_suffix ){ |
|
|
|
|
33
|
|
|
if( in_array( $hook_suffix, array( 'post.php', 'post-new.php' ) ) ) { |
34
|
|
|
$screen = get_current_screen(); |
35
|
|
|
|
36
|
|
|
if ( is_object( $screen ) && FOOGALLERY_CPT_GALLERY == $screen->post_type ){ |
37
|
|
|
|
38
|
|
|
// Register, enqueue scripts and styles here |
39
|
|
|
wp_enqueue_script( 'foogallery-admin-settings', FOOGALLERY_URL . '/js/foogallery.admin.min.js', array('jquery'), FOOGALLERY_VERSION ); |
40
|
|
|
wp_enqueue_style( 'foogallery-admin-settings', FOOGALLERY_URL . '/css/foogallery.admin.min.css', array(), FOOGALLERY_VERSION ); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Returns the section slug that can be used in the settings tabs |
47
|
|
|
* @param $section |
48
|
|
|
* @return string |
49
|
|
|
*/ |
50
|
|
|
function get_section_slug( $section ) { |
|
|
|
|
51
|
|
|
switch ( $section ) { |
52
|
|
|
case __('General', 'foogallery'): |
53
|
|
|
return 'general'; |
54
|
|
|
case __('Advanced', 'foogallery'): |
55
|
|
|
return 'advanced'; |
56
|
|
|
case __('Appearance', 'foogallery'): |
57
|
|
|
return 'appearance'; |
58
|
|
|
case __('Video', 'foogallery'): |
59
|
|
|
return 'video'; |
60
|
|
|
case __('Hover Effects', 'foogallery'): |
61
|
|
|
return 'hover effects'; |
62
|
|
|
case __('Captions', 'foogallery'): |
63
|
|
|
return 'captions'; |
64
|
|
|
case __('Paging', 'foogallery'): |
65
|
|
|
return 'paging'; |
66
|
|
|
} |
67
|
|
|
return strtolower( $section ); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Returns the Dashicon that can be used in the settings tabs |
72
|
|
|
* @param $section_slug |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
|
|
function add_section_icons( $section_slug ) { |
|
|
|
|
76
|
|
|
switch ( $section_slug ) { |
77
|
|
|
case 'general': |
78
|
|
|
return 'dashicons-format-image'; |
79
|
|
|
case 'advanced': |
80
|
|
|
return 'dashicons-admin-generic'; |
81
|
|
|
case 'appearance': |
82
|
|
|
return 'dashicons-admin-appearance'; |
83
|
|
|
case 'video': |
84
|
|
|
return 'dashicons-format-video'; |
85
|
|
|
case 'hover effects': |
86
|
|
|
return 'dashicons-admin-tools'; |
87
|
|
|
case 'captions': |
88
|
|
|
return 'dashicons-testimonial'; |
89
|
|
|
case 'paging': |
90
|
|
|
return 'dashicons-admin-page'; |
91
|
|
|
} |
92
|
|
|
return $section_slug; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.