-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
316 lines (231 loc) · 9.49 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
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
<?php
// Include Beans
require_once( get_template_directory() . '/lib/init.php' );
/* Helpers and utility functions */
require_once 'include/helpers.php';
// Remove Beans Default Styling
remove_theme_support( 'beans-default-styling' );
// Enqueue uikit assets
beans_add_smart_action( 'beans_uikit_enqueue_scripts', 'flipster_enqueue_assets', 5 );
function flipster_enqueue_assets() {
//Enqueue fonts
wp_enqueue_style( 'tm-google-fonts', 'https://fonts.googleapis.com/css?family=Titillium+Web:400,700', false );
// Enqueue uikit overwrite theme folder
beans_uikit_enqueue_theme( 'flipster', get_stylesheet_directory_uri() . '/assets/less/uikit' );
// Add the theme style as a uikit fragment to have access to all the variables
beans_compiler_add_fragment( 'uikit', get_stylesheet_directory_uri() . '/assets/less/style.less', 'less' );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
wp_enqueue_script( 'comment-reply' );
}
//Setup Theme
beans_add_smart_action( 'init', 'flipster_init' );
function flipster_init() {
// Remove page post type comment support
remove_post_type_support( 'page', 'comments' );
// Register additional menus, we already have a Primary menu registered
register_nav_menu('footer-menu', __( 'Footer Menu', 'flipster'));
}
// Setup document fragements, markups and attributes
beans_add_smart_action( 'wp', 'flipster_setup_document' );
function flipster_setup_document() {
// Header and Primary Menu
beans_remove_attribute( 'beans_site_branding', 'class', 'uk-float-left' );
beans_remove_attribute( 'beans_primary_menu', 'class', 'uk-float-right' );
// Layout
if(beans_get_layout( ) != 'c') {
beans_remove_attribute( 'beans_primary', 'class', 'uk-width-medium-7-10' );
beans_add_attribute( 'beans_primary', 'class', 'uk-width-large-7-10' );
beans_remove_attribute( 'beans_sidebar_primary', 'class', 'uk-width-medium-3-10' );
beans_add_attribute( 'beans_sidebar_primary', 'class', 'uk-width-large-3-10 uk-visible-large' );
}
// Breadcrumb
if(!is_archive()) {
beans_remove_action( 'beans_breadcrumb' );
}
else {
beans_remove_action('beans_post_archive_title');
}
// Navigation
beans_add_attribute( 'beans_sub_menu_wrap', 'class', 'uk-dropdown-center' );
beans_remove_attribute( 'beans_menu_item_child_indicator', 'class', 'uk-margin-small-left' );
// Post content
beans_add_attribute( 'beans_post_content', 'class', 'uk-text-large' );
// Post meta
beans_remove_action( 'beans_post_meta_categories' );
beans_remove_output( 'beans_post_meta_categories_prefix' );
beans_remove_output( 'beans_post_meta_date_prefix' );
beans_add_attribute( 'beans_post_meta_date', 'class', 'uk-text-muted' );
// Post embed
beans_add_attribute( 'beans_embed_oembed', 'class', 'tm-cover-article' );
// Comment form
beans_add_attribute( 'beans_comment_form_wrap', 'class', 'tm-cover-article' );
beans_add_attribute( 'beans_comment_fields_inner_wrap', 'class', 'uk-grid-small' );
beans_add_attribute( 'beans_comment_form_submit', 'class', 'uk-button-large' );
if ( !is_user_logged_in() )
beans_replace_attribute( 'beans_comment_form_comment', 'class', 'uk-width-medium-1-1', 'uk-width-medium-6-10' );
else {
//Add edit post link when user is logged in
if( is_singular() )
beans_add_smart_action('beans_post_header_before_markup', 'flipster_edit_link');
}
// Only applies to singular and not pages
if ( is_singular() && !is_page() ) {
//remove featured image
beans_remove_action( 'beans_post_image' );
// Post title
beans_add_attribute( 'beans_post_title', 'class', 'uk-margin-bottom' );
//Widget area after post content
beans_add_smart_action( 'the_content', 'flipster_widget_after_post_content' );
// Post author profile
add_action( 'beans_comments_before_markup', 'flipster_author_profile' );
}
// Search
if ( is_search() )
beans_remove_action( 'beans_post_image' );
}
function flipster_edit_link() {
edit_post_link( __( 'Edit', 'flipster' ), '<div class="uk-margin-bottom-small uk-text-small uk-align-right"><i class="uk-icon-pencil-square-o"></i> ', '</div>' );
}
// Author profile in posts
function flipster_author_profile() {
echo beans_open_markup( 'flipster_author_profile', 'div', array( 'class' => 'uk-panel' ) );
echo '<h3 class="uk-panel-title">'.__('About the author', 'flipster').'</h3>';
echo '<div class="uk-clearfix">';
echo '<div class="uk-align-left">'.get_avatar( get_the_author_meta('ID'), 96 ).'</div>';
echo '<div class="uk-text-large uk-text-bold">'.get_the_author_meta('display_name').'</div>';
echo wpautop(get_the_author_meta('description'));
echo '</div>';
echo beans_close_markup( 'flipster_author_profile', 'div' );
}
// Modify beans layout (filter)
beans_add_smart_action( 'beans_layout_grid_settings', 'flipster_layout_grid_settings' );
function flipster_layout_grid_settings( $layouts ) {
return array_merge( $layouts, array(
'grid' => 10,
'sidebar_primary' => 3,
'sidebar_secondary' => 3,
) );
}
// Modify beans post meta items (filter)
beans_add_smart_action( 'beans_post_meta_items', 'flipster_post_meta_items' );
function flipster_post_meta_items( $items ) {
// Remove author meta
unset( $items['author'] );
unset( $items['comments']);
// Add categories meta
$items['categories'] = 20;
return $items;
}
// Remove comment after note (filter)
beans_add_smart_action( 'comment_form_defaults', 'flipster_comment_form_defaults' );
function flipster_comment_form_defaults( $args ) {
$args['comment_notes_after'] = '';
return $args;
}
// Add avatar uikit circle class (filter)
beans_add_smart_action( 'get_avatar', 'flipster_avatar' );
function flipster_avatar( $output ) {
return str_replace( "class='avatar", "class='avatar uk-border-circle", $output ) ;
}
// Modify the tags cloud widget
beans_add_smart_action( 'wp_generate_tag_cloud', 'flipster_widget_tags_cloud' );
function flipster_widget_tags_cloud( $output ) {
return preg_replace( "#style='font-size:.+pt;'#", '', $output );
}
/* Widget areas */
// Register a widget area below header.
add_action( 'widgets_init', 'flipster_below_header_widget_area' );
function flipster_below_header_widget_area() {
beans_register_widget_area( array(
'name' => 'Below Header',
'id' => 'below-header',
'beans_type' => 'stack'
) );
}
beans_add_smart_action('beans_main_prepend_markup', 'flipster_below_header_widget_output');
//Display the Widget area
function flipster_below_header_widget_output() {
?>
<div class="tm-below-header-widget-area">
<?php echo beans_widget_area( 'below-header' ); ?>
</div>
<?php
}
// Register a widget area below blogroll.
add_action( 'widgets_init', 'flipster_below_blogroll_widget_area' );
function flipster_below_blogroll_widget_area() {
beans_register_widget_area( array(
'name' => 'Below Blogroll',
'id' => 'below-blogroll',
'beans_type' => 'stack'
) );
}
beans_add_smart_action('beans_posts_pagination_before_markup', 'flipster_below_blogroll_widget_output');
//Display the Widget area
function flipster_below_blogroll_widget_output() {
?>
<div class="tm-below-blogroll-widget-area">
<?php echo beans_widget_area( 'below-blogroll' ); ?>
</div>
<?php
}
// Register a widget area below post content.
add_action( 'widgets_init', 'flipster_below_post_widget_area' );
function flipster_below_post_widget_area() {
beans_register_widget_area( array(
'name' => 'Below Post',
'id' => 'below-post',
'beans_type' => 'stack'
) );
}
//Display the Widget area
function flipster_widget_after_post_content( $content ) {
$output = $content;
$output .= '<div class="tm-below-post-widget-area">';
$output .= beans_widget_area( 'below-post' );
$output .= '</div>';
return $output;
}
// Add the footer menu
beans_add_smart_action( 'beans_footer_prepend_markup', 'flipster_footer_menu' );
function flipster_footer_menu() {
wp_nav_menu( array( 'theme_location' => 'footer-menu',
'container' => 'nav',
'container_class' => 'tm-footer-menu uk-navbar uk-margin-bottom',
'menu_class' => 'uk-navbar-nav uk-text-small',
'fallback_cb' => false
));
}
// Add footer content (filter)
beans_add_smart_action( 'beans_footer_credit_right_text_output', 'flipster_footer' );
function flipster_footer() { ?>
<a href="https://templateflip.com/themes/flipster/" target="_blank" title="Flipster theme for WordPress">Flipster</a> theme for <a href="http://wordpress.org" target="_blank">WordPress</a>. Built-with <a href="http://www.getbeans.io/" title="Beans Framework for WordPress" target="_blank">Beans</a>.
<?php }
//Setup Widgets
beans_add_smart_action( 'widgets_init', 'flipster_register_widgets');
function flipster_register_widgets() {
//Include widget classes
require_once('widgets/posts.php');
require_once('widgets/ads.php');
// Regidter widgets
register_widget('Flipster_Posts_Widget');
register_widget('Flipster_Ads_Widget');
}
//Customizer fields
//Additional Header & Footer Codes (for Google Analytics)
add_action( 'init', 'flipster_customization_fields' );
function flipster_customization_fields() {
$fields = array(
array(
'id' => 'flipster_head_code',
'label' => __( 'Additional Head Code', 'flipster' ),
'type' => 'textarea',
'default' => ''
)
);
beans_register_wp_customize_options( $fields, 'flipster_custom_code', array( 'title' => __( 'Custom Code', 'flipster' ), 'priority' => 1100 ) );
}
add_action('beans_head_append_markup', 'flipster_custom_foorer_code');
function flipster_custom_foorer_code() {
echo get_theme_mod( 'flipster_head_code', '' );
}