-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
286 lines (221 loc) · 6.39 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
<?php
/**
* The theme's functions file that loads on EVERY page, used for uniform functionality.
*
* @since 1.0.0
* @package Love_From_Louie
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
// Make sure PHP version is correct
if ( ! version_compare( PHP_VERSION, '5.3.0', '>=' ) ) {
wp_die( 'ERROR in Love From Louie - Theme 2017 theme: PHP version 5.3 or greater is required.' );
}
// Make sure no theme constants are already defined (realistically, there should be no conflicts)
if ( defined( 'THEME_VER' ) ||
defined( 'THEME_URL' ) ||
defined( 'THEME_DIR' ) ||
defined( 'THEME_FILE' ) ||
isset( $theme_fonts ) ) {
wp_die( 'ERROR in Love From Louie - Theme 2017 theme: There is a conflicting constant. Please either find the conflict or rename the constant.' );
}
/**
* Define Constants based on our Stylesheet Header. Update things only once!
*/
$theme_header = wp_get_theme();
define( 'THEME_VER', $theme_header->get( 'Version' ) );
define( 'THEME_URL', get_template_directory_uri() );
define( 'THEME_DIR', get_template_directory() );
/**
* Fonts for the theme. Must be hosted font (Google fonts for example).
*/
$theme_fonts = array(
'open-sans' => '//fonts.googleapis.com/css?family=Open+Sans:300italic,700,300,800',
'droid-sans' => '//fonts.googleapis.com/css?family=Droid+Sans:regular,bold',
'lobster' => '//fonts.googleapis.com/css?family=Lobster',
'font-awesome' => '//maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css',
);
/**
* Register theme files.
*
* @since 1.0.0
*/
add_action( 'init', function () {
global $theme_fonts;
// Theme styles
wp_register_style(
'love-from-louie',
THEME_URL . '/dist/assets/css/app.css',
null,
defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : THEME_VER
);
// Theme script
wp_register_script(
'love-from-louie',
THEME_URL . '/dist/assets/js/app.js',
array( 'jquery' ),
defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : THEME_VER,
true
);
// Theme fonts
if ( ! empty( $theme_fonts ) ) {
foreach ( $theme_fonts as $ID => $link ) {
wp_register_style(
'love-from-louie' . "-font-$ID",
$link
);
}
}
} );
/**
* Enqueue theme files.
*
* @since 1.0.0
*/
add_action( 'wp_enqueue_scripts', function () {
global $theme_fonts;
// Theme styles
wp_enqueue_style( 'love-from-louie' );
// Theme script
wp_enqueue_script( 'love-from-louie' );
// Theme fonts
if ( ! empty( $theme_fonts ) ) {
foreach ( $theme_fonts as $ID => $link ) {
wp_enqueue_style( 'love-from-louie' . "-font-$ID" );
}
}
} );
/**
* Register nav menus.
*
* @since 1.0.0
*/
add_action( 'after_setup_theme', function () {
register_nav_menu( 'primary-menu', __( 'Primary Menu', 'love-from-louie' ) );
} );
/**
* Register sidebars.
*
* @since 1.0.0
*/
add_action( 'widgets_init', function () {
// Main Sidebar
register_sidebar( array(
'name' => __( 'Main Sidebar', 'love-from-louie' ),
'id' => 'sidebar-main',
'description' => __( 'Displays on Interior Pages.', 'love-from-louie' ),
) );
register_sidebar( array(
'name' => __( 'Footer Left', 'love-from-louie' ),
'id' => 'footer-left',
'description' => __( 'Footer Left.', 'love-from-louie' ),
'before_title' => '<h4 class="widgettitle">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => __( 'Footer Center', 'love-from-louie' ),
'id' => 'footer-center',
'description' => __( 'Footer Center.', 'love-from-louie' ),
'before_title' => '<h4 class="widgettitle">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => __( 'Footer Right', 'love-from-louie' ),
'id' => 'footer-right',
'description' => __( 'Footer Right.', 'love-from-louie' ),
'before_title' => '<h4 class="widgettitle">',
'after_title' => '</h4>',
) );
} );
/**
* Setup theme properties and stuff
*
* @since 1.0.0
* @return void
*/
add_action( 'after_setup_theme', function () {
// Add theme support
require_once __DIR__ . '/core/theme-support.php';
// Add theme functions
require_once __DIR__ . '/includes/theme-functions.php';
// Add Button Shortcode
require_once __DIR__ . '/includes/shortcodes/lfl-button.php';
// Nav Walker for Foundation
require_once __DIR__ . '/includes/class-foundation-nav-walker.php';
// Allow shortcodes in text widget
add_filter( 'widget_text', 'do_shortcode' );
// Create Hero Image Size
add_image_size( 'lfl-hero', false, 600 );
} );
/**
* Add Widgets
*
* @since 1.0.0
*/
add_action( 'widgets_init', function() {
if ( class_exists( 'Give' ) ) {
require_once __DIR__ . '/includes/widgets/class-recent-story-donation-widget.php';
register_widget( 'LFL_Recent_Story_Donation_Widget' );
}
} );
/**
* Force WP Search to work across Post Types
*
* @since 0.1.0
*/
add_filter( 'pre_get_posts', function( $query ) {
if ( $query->is_search ) {
$query->set( 'post_type', array(
'post',
'page',
'lfl-story',
) );
}
return $query;
} );
/**
* Filter the_archive_title() to be less... robotic
*
* @param string Archive Title
*
* @since 1.0.0
* @return string Archive Title
*/
add_filter( 'get_the_archive_title', function( $title ) {
if ( get_post_type() == 'lfl-story' ) {
return _x( 'Our Stories', 'Stories Archive Title', 'love-from-louie' );
}
else {
// Not really necessary
return trim( str_replace( 'Archives:', '', $title ) );
}
} );
/**
* "Donation Total" sounds like Total Number of Donations. It isn't what this String actually means though.
*
* @param string $label Donation Total Label
*
* @since 1.0.0
* @return string Donation Total Label
*/
add_filter( 'give_donation_total_label', function( $label ) {
return _x( 'Donation Amount', 'Give Donation Total Replacement', 'love-from-louie' );
} );
/**
* Add Localized "label" for the Donation Amount field at the top of Give Forms
*
* @since 1.0.0
* @return void
*/
add_action( 'wp_head', function() {
?>
<style type="text/css">
.give-donation-amount:before {
content: '<?php echo _x( 'Donation Amount:', 'Give Donation Total Replacement CSS Content Label Hack', 'love-from-louie' ); ?>' !important;
}
</style>
<?php
} );
// Override some stuff in WooCommerce
locate_template( '/includes/hooks/product-hooks.php', true, true );
require_once __DIR__ . '/admin/admin.php';