-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.php
executable file
·291 lines (281 loc) · 11.2 KB
/
functions.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
<?php
add_action( 'init', array( 'launch', 'init' ) );
class launch {
public static $options = array(
'logo' => '',
'favicon' => '',
'name' => false,
'percent' => 5,
'mailchimp_user' => '',
'mailchimp_list' => '',
'mailchimp_after' => false,
);
public static function init() {
global $content_width;
self::init_options();
add_action( 'wp_head', array( 'launch', 'head' ) );
add_action( 'wp_enqueue_scripts', array( 'launch', 'styles' ) );
add_action( 'wp_enqueue_scripts', array( 'launch', 'scripts' ) );
register_nav_menu( 'social', __( 'Social links', 'launch' ) );
add_filter( 'bloginfo', array( 'launch', 'title' ), 10, 2);
require_once( 'includes/options.php' );
self::init_settings();
if ( ! isset( $content_width ) ) $content_width = 500;
}
public static function init_settings() {
$settings = array(
'launch' => array(
'title' => __( 'Launch Settings', 'launch' ),
'description' => __( 'Basic theme settings', 'launch' ),
'priority' => 31,
'fields' => array(
'percent' => array(
'setting' => array(
'default' => self::$options['percent'],
),
'control' => array(
'label' => __( 'Percent completed', 'launch' ),
'input_attrs' => array(
'min' => 0,
'max' => 100,
'step' => 1,
),
),
'type' => 'number',
),
'logo' => array(
'setting' => array(
'default' => self::$options['logo'],
),
'control' => array(
'label' => __( 'Logo', 'launch' ),
),
'type' => 'image',
'css' => array(
'selector' => '#header .content span.logo',
'style' => 'background-image',
'prefix' => 'url(\'',
'postfix' => '\')',
),
),
'favicon' => array(
'setting' => array(
'default' => self::$options['favicon'],
),
'control' => array(
'label' => __( 'Favicon', 'launch' ),
),
'type' => 'image',
),
),
),
'mailchimp' => array(
'title' => __( 'Mailchimp', 'launch' ),
'description' => __( 'Mailchimp subscriptiion form', 'launch' ),
'priority' => 33,
'fields' => array(
'mailchimp_user' => array(
'setting' => array(
'default' => self::$options['mailchimp_user'],
),
'control' => array(
'label' => __( 'Mailchimp API key', 'launch' ),
'description' => sprintf ( __( 'Get your API key <a href="%1$s" target="_blank">here</a>', 'launch' ), 'http://kb.mailchimp.com/accounts/management/about-api-keys#Find-or-Generate-Your-API-Key' ),
),
'type' => 'text',
),
'mailchimp_list' => array(
'setting' => array(
'default' => self::$options['mailchimp_list'],
),
'control' => array(
'label' => __( 'Mailchimp list ID', 'launch' ),
),
'type' => 'text',
),
'mailchimp_after' => array(
'setting' => array(
'default' => self::$options['mailchimp_after'],
),
'control' => array(
'label' => __( 'Subscription success text', 'launch' ),
),
'type' => 'text',
),
),
),
);
launch_Options::init( $settings );
// Setup the Theme Customizer settings and controls...
add_action( 'customize_register' , array( 'launch_Options' , 'register' ) );
// Output custom CSS to live site
add_action( 'wp_head' , array( 'launch_Options' , 'header_output' ) );
// Enqueue live preview javascript in Theme Customizer admin screen
$args = array(
'default-color' => '000000',
'default-image' => '%1$s/assets/images/bg.jpg',
);
add_theme_support( 'custom-background', $args );
add_theme_support( 'title-tag' );
add_theme_support( 'automatic-feed-links' );
}
public static function init_options() {
if ( !self::$options['name'] ) {
self::$options['name'] = __( 'The <strong>Launch</strong> Template', 'launch' );
}
if ( !self::$options['mailchimp_after'] ) {
self::$options['mailchimp_after'] = __( 'Thanks for <strong>signing up</strong>. Check your email to <strong>confirm</strong> your subscription.', 'launch' );
}
if ( !self::$options['logo'] ) {
self::$options['logo'] = get_template_directory_uri().'/assets/images/logo.png';
}
if ( !self::$options['favicon'] ) {
self::$options['favicon'] = get_template_directory_uri().'/assets/images/favicon.png';
}
$real_options = array();
foreach(self::$options as $option_id => $value ) {
$value = get_theme_mod($option_id);
if ( $value ) {
$real_options[$option_id] = $value;
}
}
// self::$options = wp_parse_args( $real_options, self::$options );
self::$options = apply_filters( 'launch_options', self::$options );
}
public static function title($output, $show) {
if ( 'name' == $show ) {
$output = launch::strong_filter($output);
}
if ( doing_action( 'wp_head' ) ) {
$output = strip_tags( $output );
}
return $output;
}
public static function strong_filter( $output ) {
$output = preg_replace( '/\*\*(.+?)\*\*/ims', '<strong>$1</strong>', $output );
return $output;
}
public static function scripts() {
wp_register_script( 'launch-script', get_template_directory_uri().'/assets/scripts/main.js', array( 'jquery' ), false, true );
wp_enqueue_script( 'launch-script' );
}
public static function styles() {
wp_register_style( 'launch-fonts', '//fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,700' );
wp_register_style( 'launch-style', get_template_directory_uri().'/style.css', array( 'launch-fonts' ) );
wp_enqueue_style( 'launch-style' );
}
public static function mc_api_url( $api, $list ) {
$response = get_transient( 'launch_mailchimp_'.$list );
if ( !$response ) {
$dc = explode( '-', $api);
$dc = $dc[1];
$url = "https://{$dc}.api.mailchimp.com/2.0/";
$url .= 'lists/list.json';
$args = array(
'apikey' => $api,
'filters' => array(
'list_id' => $list,
),
);
$args = json_encode($args);
$response = wp_remote_post( $url, array( 'body' => $args ) );
if ( isset( $response['body'] ) ) {
$response = json_decode( $response['body'], true );
} else {
$response = false;
}
if ( isset( $response['data'] ) ) {
$response = array_shift( $response['data'] );
} else {
$response = false;
}
if ( isset( $response['subscribe_url_long'] ) ) {
$response = $response['subscribe_url_long'];
} else {
$response = false;
}
if ($response) {
$response = str_replace( '/subscribe', '/subscribe/post-json', $response );
// $response = add_query_arg( array( 'c' => '?' ), $response );
$response .= '&c=?';
}
set_transient( 'launch_mailchimp_'.$list, 1 * HOUR_IN_SECONDS );
}
return $response;
}
public static function head() {
$tags = array(
// 'title' => '<title>'.strip_tags( get_theme_mod( 'name' ) ).'</title>',
'meta-charset' => '<meta charset="'.esc_attr( get_bloginfo( 'charset' ) ).'">',
'meta-ie-edge' => '<meta http-equiv="X-UA-Compatible" content="IE=edge">',
'meta-description' => '<meta name="description" content="'.esc_attr( get_bloginfo( 'description' ) ).'">',
'meta-viewport' => '<meta name="viewport" content="width=device-width, initial-scale=1">',
'favicon' => '<link rel="shortcut icon" href="'.(get_theme_mod( 'favicon' )?get_theme_mod( 'favicon' ):self::$options['favicon']).'" type="image/x-icon" />',
);
$tags = apply_filters( 'launch_head', $tags );
$result = implode( "\n\t\t", $tags );
$result = "\t\t".$result."\n";
echo $result;
}
private static function theme_compatibility_hack() {
if ( is_singular() ) wp_enqueue_script( "comment-reply" );
$args = array();
wp_list_comments( $args );
wp_link_pages( $args );
comments_template( $file, $separate_comments );
comment_form();
paginate_links();
paginate_comments_links();
the_tags();
}
}
class launch_walker extends Walker_Nav_Menu {
public function start_lvl( &$output, $depth = 0, $args = array() ) {
$output .= '';
}
public function end_lvl( &$output, $depth = 0, $args = array() ) {
$output .= "";
}
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$classes[] = 'icon';
if (preg_match('#^(https?:)?//github.com#', $item->url)) {
$classes[] = 'github';
}
if (preg_match('#^(https?:)?//facebook.com#', $item->url)) {
$classes[] = 'facebook';
}
if (preg_match('#^(https?:)?//twitter.com#', $item->url)) {
$classes[] = 'twitter';
}
if (preg_match('#^mailto\:#', $item->url)) {
$classes[] = 'email';
}
$atts = array();
$atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
$atts['target'] = ! empty( $item->target ) ? $item->target : '';
$atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : '';
$atts['href'] = ! empty( $item->url ) ? $item->url : '';
$atts['class'] = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
$atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args );
$attributes = '';
foreach ( $atts as $attr => $value ) {
if ( ! empty( $value ) ) {
$value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
$attributes .= ' ' . $attr . '="' . $value . '"';
}
}
$item_output = $args->before;
$item_output .= "\t\t\t\t\t";
$item_output .= '<a'. $attributes .'>';
/** This filter is documented in wp-includes/post-template.php */
$item_output .= '</a>';
$item_output .= "\n";
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
public function end_el( &$output, $item, $depth = 0, $args = array() ) {
$output .= '';
}
}
?>