-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
322 lines (258 loc) · 9.64 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
317
318
319
320
321
322
<?php
/* vim: set expandtab ts=4 sw=4 autoindent smartindent: */
/**
* myfossil functions and definitions
*
* @package myfossil
*/
/**
* Set the content width based on the theme's design and stylesheet.
*/
if (!isset($content_width)) {
$content_width = 640; /* pixels */
}
if (!function_exists('myfossil_setup')):
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function myfossil_setup()
{
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on myfossil, use a find and replace
* to change 'myfossil' to the name of your theme in all the template files
*/
load_theme_textdomain('myfossil', get_template_directory() . '/languages');
// Add default posts and comments RSS feed links to head.
add_theme_support('automatic-feed-links');
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
*/
//add_theme_support( 'post-thumbnails' );
// This theme uses wp_nav_menu() in one location (for now).
register_nav_menus(array(
'primary' => __('Primary Menu', 'myfossil') ,
));
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support('html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
));
/*
* Enable support for Post Formats.
* See http://codex.wordpress.org/Post_Formats
*/
add_theme_support('post-formats', array(
'aside',
'image',
'video',
'quote',
'link',
));
// Setup the WordPress core custom background feature.
add_theme_support('custom-background', apply_filters('myfossil_custom_background_args', array(
'default-color' => 'ffffff',
'default-image' => '',
)));
add_theme_support( 'post-thumbnails' );
/*
* Disable the admin bar
*/
add_filter('show_admin_bar', '__return_false');
}
endif; // myfossil_setup
add_action('after_setup_theme', 'myfossil_setup');
/**
* Register widget area.
*
* @link http://codex.wordpress.org/Function_Reference/register_sidebar
*/
function myfossil_widgets_init()
{
register_sidebar(array(
'name' => __('Sidebar', 'myfossil') ,
'id' => 'sidebar-1',
'description' => '',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
));
}
add_action('widgets_init', 'myfossil_widgets_init');
/**
* Enqueue scripts and styles.
*/
function myfossil_scripts()
{
/* Styles */
wp_enqueue_style('myfossil-style', get_template_directory_uri() .
'/static/css/style.css');
wp_enqueue_style('font-awesome',
"//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css");
wp_enqueue_style('jquery-ui-theme', get_template_directory_uri() .
'/static/css/jquery-ui.theme.min.css');
wp_enqueue_style('jquery-ui-structure', get_template_directory_uri() .
'/static/css/jquery-ui.structure.min.css');
wp_enqueue_style('ionicons',
'//code.ionicframework.com/ionicons/1.5.2/css/ionicons.min.css' );
wp_enqueue_style('mentions', get_template_directory_uri() .
'/static/css/bp-activity-mentions.min.css');
/* Scripts */
/*
wp_enqueue_script( 'bbpress-reply', get_template_directory_uri() .
'/static/js/bbpress-reply.min.js' );
*/
wp_enqueue_script( 'bootstrap', get_template_directory_uri() .
'/static/js/bootstrap.min.js' );
wp_enqueue_script( 'myfossil', get_template_directory_uri() .
'/static/js/myfossil.min.js' );
wp_enqueue_script( 'comment-reply', get_template_directory_uri() .
'/static/js/comment-reply.min.js' );
wp_enqueue_script( 'html5', get_template_directory_uri() .
'/static/js/html5.min.js' );
wp_enqueue_script( 'respond', get_template_directory_uri() .
'/static/js/respond.min.js' );
wp_enqueue_script( 'jquery-ui', get_template_directory_uri() .
'/static/js/jquery-ui.min.js' );
wp_enqueue_script( 'jquery-popup-overlay', get_template_directory_uri() .
'/static/js/jquery.popupoverlay.min.js' );
//wp_enqueue_script ( 'buddypress', get_template_directory_uri () . '/static/js/buddypress.min.js' );
if ( is_singular() && comments_open() && get_option('thread_comments') ) {
wp_enqueue_script('comment-reply');
}
wp_enqueue_script ( 'buddypress', get_template_directory_uri() . '/static/js/jquery.atwho.min.js' );
wp_enqueue_script ( 'bpcar', get_template_directory_uri() . '/static/js/jquery.caret.min.js' );
wp_enqueue_script ( 'bpmen', get_template_directory_uri() . '/static/js/mentions.min.js' );
}
add_action('wp_enqueue_scripts', 'myfossil_scripts');
/**
* Implement the Custom Header feature.
*/
// require get_template_directory() . '/includes/custom-header.php';
/**
* Custom WordPress/BuddyPress filter hooks
*/
require get_template_directory() . '/includes/filters.php';
/**
* Load plugins compatibility file.
*/
require get_template_directory() . '/includes/plugins.php';
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/includes/template-tags.php';
/**
* Custom functions that act independently of the theme templates.
*/
require get_template_directory() . '/includes/extras.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/includes/customizer.php';
/**
* Load Jetpack compatibility file.
*/
require get_template_directory() . '/includes/jetpack.php';
/**
* Load bbPress compatibility file.
*/
// require get_template_directory() . '/includes/bbpress.php';
function parse_meta( $meta ) {
if ( ! $meta ) return array();
$parsed_meta = array();
foreach ( $meta as $k => $v )
if ( !( strpos( $k, '_', 0) === 0 ) )
$parsed_meta[ $k ] = $v[0];
return $parsed_meta;
}
// change Notification labels
function mf_gettext_with_context( $translated, $text, $context, $domain ) {
if ( 'buddypress' !== $domain )
return $translated;
switch ( $text ) {
case 'Read':
if( $context == 'Notification screen nav' )
return 'Viewed';
elseif( $context == 'Notification screen action' )
return 'Mark as Viewed';
else
return 'Read';
case 'Unread':
if( $context == 'Notification screen nav' )
return 'Not Viewed';
elseif( $context == 'Notification screen action' )
return 'Mark as Not Viewed';
else
return 'Unread';
default:
return $translated;
}
return $translated;
}
add_filter( 'gettext_with_context', 'mf_gettext_with_context', 20, 4 );
// change Notification feedback messages
function mf_gettext( $translated_text, $text, $domain ) {
if ( 'buddypress' !== $domain )
return $translated_text;
switch ( $text ) {
case 'Notification successfully marked read.':
return 'Notification successfully marked as Viewed.';
case 'Notification successfully marked unread.':
return 'Notification successfully marked as Not Viewed.';
default:
return $translated_text;
}
}
add_filter( 'gettext', 'mf_gettext', 21, 3 );
// even more change Notification labels -required because BP is inconsistent re gettext usage
function mf_change_notification_mark_link( $retval ) {
$retval = str_replace('Read', 'Mark as Viewed', $retval);
return $retval;
}
add_filter('bp_get_the_notification_mark_link', 'mf_change_notification_mark_link', 22, 1);
function mf_remove_xprofile_links() {
remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 );
}
add_action('bp_setup_globals', 'mf_remove_xprofile_links');
// return an int of the number of Fossils for a specific member
// called in \myfossil-theme\buddypress\members\members-loop.php
function mf_member_fossil_count( $user_id ) {
global $wpdb;
$fossil_count = $wpdb->get_var( "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_type = 'myfossil_fossil' AND post_author = $user_id AND post_status = 'publish'" );
if( $fossil_count == NULL )
$fossil_count = 0;
return $fossil_count;
}
//enable visual editor in forums
function bbp_enable_visual_editor( $args = array() ) {
$args['tinymce'] = true;
return $args;
}
add_filter( 'bbp_after_get_the_content_parse_args', 'bbp_enable_visual_editor' );
//limit access to wp-admin to admins only
add_action( 'init', 'blockusers_init' );
function blockusers_init() {
if ( is_admin() && ! current_user_can( 'administrator' ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
wp_redirect( home_url() );
exit;
}
}
function mf_joined_group_action( $action, $activity ) {
$action = str_replace ( 'joined the group', 'followed the group', $action );
return $action;
}
add_filter( 'bp_groups_format_activity_action_joined_group', 'mf_joined_group_action', 25, 2 );