class-subscribe-and-connect-frontend.php
3.88 KB
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
<?php
class Subscribe_And_Connect_Frontend {
/**
* The URL to the plugin's folder.
* @access private
* @var string
* @since 1.0.0
*/
private $_plugin_url;
/**
* The path to the plugin's folder.
* @access private
* @var string
* @since 1.0.0
*/
private $_plugin_path;
/**
* Constructor.
* @access public
* @since 1.0.0
* @return void
*/
public function __construct ( $file ) {
$this->_plugin_url = plugin_dir_url( $file );
$this->_plugin_path = plugin_dir_path( $file );
add_action( 'wp_enqueue_scripts', array( $this, 'register_frontend_styles' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_frontend_styles' ) );
add_action( 'wp_footer', array( $this, 'maybe_load_theme_stylesheets' ) );
} // End __construct()
/**
* Generic getter for private data.
* @access public
* @since 1.0.0
* @param string $key The key to retrieve.
* @return string The information stored.
*/
public function __get ( $key ) {
switch ( $key ) {
case 'plugin_url':
return $this->_plugin_url;
break;
case 'plugin_path':
return $this->_plugin_path;
break;
default:
break;
}
} // End __get()
/**
* Register frontend stylesheets.
* @access public
* @since 1.0.0
* @return void
*/
public function register_frontend_styles () {
global $subscribe_and_connect;
wp_register_style( 'subscribe-and-connect', $this->__get( 'plugin_url' ) . 'assets/css/frontend.css', '', $subscribe_and_connect->version );
} // End register_frontend_styles()
/**
* Enqueue frontend stylesheets.
* @access public
* @since 1.0.0
* @return void
*/
public function enqueue_frontend_styles () {
wp_enqueue_style( 'subscribe-and-connect' );
} // End enqueue_frontend_styles()
/**
* Make sure the desired theme is valid. If not, return 'default'.
* @access public
* @since 1.0.0
* @param array $args Arguments for the current theme.
* @return string The slug of the theme, or 'default'.
*/
public function is_valid_theme ( $key ) {
$response = false;
if ( in_array( $key, array_keys( Subscribe_And_Connect_Utils::get_icon_themes() ) ) ) {
$response = true;
}
return $response;
} // End is_valid_theme()
/**
* Make sure the desired theme is valid. If not, return 'default'.
* @access public
* @since 1.0.0
* @param array $args Arguments for the current theme.
* @return string The slug of the theme, or 'default'.
*/
public function get_sanitized_theme_key ( $args ) {
$theme = 'icons';
$key = '';
if ( in_array( $key, array_keys( Subscribe_And_Connect_Utils::get_icon_themes() ) ) ) {
$theme = esc_attr( strtolower( $key ) );
}
return $theme;
} // End get_sanitized_theme_key()
/**
* Get data for a specified theme.
* @access public
* @since 1.0.0
* @param array $args Arguments for the current theme.
* @return string The slug of the theme, or 'default'.
*/
public function get_theme_data ( $key ) {
$theme = array( 'name' => 'icons', 'stylesheet' => '' );
$available_themes = Subscribe_And_Connect_Utils::get_icon_themes();
if ( in_array( $key, array_keys( $available_themes ) ) ) {
$theme = $available_themes[esc_attr( $key )];
}
return $theme;
} // End get_theme_data()
/**
* Maybe load the stylesheet for the theme in use.
* @access public
* @since 1.0.0
* @return void
*/
public function maybe_load_theme_stylesheets () {
global $subscribe_and_connect;
$subscribe_and_connect->setup_settings();
$settings = $subscribe_and_connect->get_settings();
$theme_data = $this->get_theme_data( $settings['display']['theme'] );
if ( isset( $theme_data['stylesheet'] ) && ( '' != $theme_data['stylesheet'] ) ) {
wp_enqueue_style( 'subscribe-and-connect-theme-' . esc_attr( $settings['display']['theme'] ), esc_url( $theme_data['stylesheet'] ) );
}
} // End maybe_load_theme_stylesheets()
} // End Class
?>