This repository was archived by the owner on Dec 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfunctions.php
More file actions
189 lines (164 loc) · 5.15 KB
/
functions.php
File metadata and controls
189 lines (164 loc) · 5.15 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
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
<?php
/**
* BuddyPress custom functions.
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
/**
* Register and enqueue custom styles & fonts.
*/
function bp_activity_2017_enqueue_styles() {
if ( ! function_exists( 'bp_get_theme_compat_id' ) ) {
return;
}
$template_pack = bp_get_theme_compat_id();
// Register the TwentySeventeen stylesheet to use it as a dependency.
wp_register_style( 'parent-style', get_template_directory_uri() . '/style.css' );
// Enqueue the Child theme's stylesheet.
wp_enqueue_style(
'child-style',
get_stylesheet_directory_uri() . '/css/activity.css',
array( 'parent-style' ),
''
);
$deps = array();
if ( 'legacy' === $template_pack ) {
$deps = array( 'bp-legacy-js' );
} else {
$deps = array( 'bp-nouveau-activity-post-form' );
}
wp_register_script(
'bp-activity-2017-editor',
get_stylesheet_directory_uri() . '/js/script.js',
$deps,
'1.0.0',
true
);
wp_localize_script( 'bp-activity-2017-editor', 'bpActivity2017Editor', array(
'ajaxurl' => bp_core_ajax_url(),
'view' => __( 'Afficher', 'bp-activity-2017' ),
'nocontent' => __( 'Merci de bien vouloir publier quelque chose !', 'bp-activity-2017' ),
) );
}
add_action( 'wp_enqueue_scripts', 'bp_activity_2017_enqueue_styles' );
/**
* Customize the available buttons for the Activity rich editor.
*
* @param array $buttons The editor's buttons list.
* @return array The editor's buttons list.
*/
function bp_activity_2017_editor_buttons( $buttons = array() ) {
// Remove some buttons
$buttons = array_diff( $buttons, array(
'wp_more',
'spellchecker',
'wp_adv',
'fullscreen',
'alignleft',
'alignright',
'aligncenter',
'formatselect',
'blockquote',
) );
// Add the image one.
array_push( $buttons, 'image' );
return $buttons;
}
/**
* Include paragraphs to allowed tags.
*
* @param array $allowed_tags The Activity allowed tags.
* @return array The Activity allowed tags.
*/
function bp_activity_2017_allowed_tags( $allowed_tags = array() ) {
$allowed_tags['p'] = true;
return $allowed_tags;
}
add_filter( 'bp_activity_allowed_tags', 'bp_activity_2017_allowed_tags', 10, 1 );
/**
* Only allow image attachments to be queried.
*
* @param array $args The Ajax query attachments arguments.
* @return array The Ajax query attachments arguments.
*/
function bp_activity_2017_query_attachments_args( $args = array() ) {
if ( bp_is_activity_component() ) {
$args['post_mime_type'] = 'image';
}
return $args;
}
add_filter( 'ajax_query_attachments_args', 'bp_activity_2017_query_attachments_args', 10, 1 );
/**
* Restrict queriable types to images.
*
* @param array $mimes The available types for query.
* @return array The available types for query.
*/
function bp_activity_2017_mime_types( $types = array() ) {
return array_diff_key( $types, array( 'video' => false, 'audio' => false ) );
}
/**
* Restrict Upload mime types to images.
*
* @param array $mimes The available mime types for upload.
* @return array The available mime types for upload.
*/
function bp_activity_2017_upload_mimes( $mimes = array() ) {
return array_intersect_key( $mimes, array(
'jpg|jpeg|jpe' => true,
'gif' => true,
'png' => true,
) );
}
/**
* Customize the Media Editor strings.
*
* @param array $strings The Media Editor strings.
* @return array The Media Editor strings.
*/
function bp_activity_2017_media_view_strings( $strings = array() ) {
return array_merge( $strings, array(
'insertIntoPost' => __( 'Insérer dans l\'activité', 'bp-activity-2017' ),
'uploadedToThisPost' => __( 'Attaché(s) aux activités', 'bp-activity-2017' ),
) );
}
/**
* The Activity rich editor !
*/
function bp_activity_2017_editor() {
$args = array(
'textarea_name' => 'whats-new',
'wpautop' => true,
'media_buttons' => true,
'editor_class' => 'bp-suggestions',
'textarea_rows' => 10,
'teeny' => false,
'dfw' => false,
'tinymce' => true,
'quicktags' => false
);
$content = '';
if ( isset( $_GET['r'] ) ) {
$content = '@' . esc_textarea( $_GET['r'] );
}
// Enqueue our custom Editor script
wp_enqueue_script( 'bp-activity-2017-editor' );
// Temporarly filters to restrict the Activity editor
add_filter( 'mce_buttons', 'bp_activity_2017_editor_buttons', 10, 1 );
add_filter( 'post_mime_types', 'bp_activity_2017_mime_types', 10, 1 );
add_filter( 'upload_mimes', 'bp_activity_2017_upload_mimes', 10, 1 );
add_filter( 'media_view_strings', 'bp_activity_2017_media_view_strings', 10, 1 );
wp_editor( $content, 'what-is-new', $args );
// Stop filtering the editor.
remove_filter( 'mce_buttons', 'bp_activity_2017_editor_buttons', 10, 1 );
remove_filter( 'post_mime_types', 'bp_activity_2017_mime_types', 10, 1 );
remove_filter( 'upload_mimes', 'bp_activity_2017_upload_mimes', 10, 1 );
remove_filter( 'media_view_strings', 'bp_activity_2017_media_view_strings', 10, 1 );
}
/**
* Load translations...
*/
function bp_activity_2017_load_textdomain() {
load_theme_textdomain( 'bp-activity-2017', get_stylesheet_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'bp_activity_2017_load_textdomain' );