-
Notifications
You must be signed in to change notification settings - Fork 4
/
functions.php
232 lines (197 loc) · 9.83 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
<?php
/* -- Enqueue necessary CSS and JS files for Child Theme -- */
function fs_theme_enqueue_stuff() {
// Divi assigns its style.css with this handle
$parent_handle = 'divi-style';
// Get the current child theme data
$current_theme = wp_get_theme();
// get the parent version number of the current child theme
$parent_version = $current_theme->parent()->get('Version');
// get the version number of the current child theme
$child_version = $current_theme->get('Version');
// we check file date of child stylesheet and script, so we can append to version number string (for cache busting)
$style_cache_buster = date("YmdHis", filemtime( get_stylesheet_directory() . '/style.css'));
$script_cache_buster = date("YmdHis", filemtime( get_stylesheet_directory() . '/script.js'));
// first we pull in the parent theme styles that it needs
wp_enqueue_style( $parent_handle, get_template_directory_uri() . '/style.css', array(), $parent_version );
// then we get the child theme style.css file, which is dependent on the parent theme style, then append string of child version and file date
wp_enqueue_style( 'fs-child-style', get_stylesheet_uri(), array( $parent_handle ), $child_version .'-'. $style_cache_buster );
// will grab the script file from the child theme directory, and is reliant on jquery and the divi-custom-script (so it comes after that one)
wp_enqueue_script( 'fs-child-script', get_stylesheet_directory_uri() . '/script.js', array('jquery', 'divi-custom-script'), $child_version .'-'. $script_cache_buster, true);
}
add_action( 'wp_enqueue_scripts', 'fs_theme_enqueue_stuff' );
/* -- Enqueue WP Admin files for Child Theme -- */
function fs_theme_enqueue_admin_stuff() {
// Get the current child theme data
$current_theme = wp_get_theme();
// get the version number of the current child theme
$child_version = $current_theme->get('Version');
// we check file date of WP backend stylesheet, so we can append to version number string (for cache busting)
$style_cache_buster = date("YmdHis", filemtime( get_stylesheet_directory() . '/wp-admin.css'));
// Begin enqueue for CSS file that loads in WP backend
wp_enqueue_style( 'fs-child-style-admin', get_stylesheet_directory_uri() . '/wp-admin.css', array(), $child_version .'-'. $style_cache_buster );
}
add_action( 'admin_enqueue_scripts', 'fs_theme_enqueue_admin_stuff' );
/* -- Helpers -- */
// Creates shortcode to allow automatically pulling in the Site Title (from General Settings)
// This is used by default in the copyright text within the Code module of the Global Footer in the Divi Theme Builder
function fs_site_title_shortcode() {
return get_bloginfo( 'name' );
}
add_shortcode( 'fs_site_title','fs_site_title_shortcode' );
/* -- WP Dashboard Widgets -- */
// Remove certain widgets from the backend WP Dashboard page
function fs_remove_dashboard_widget() {
// Pressable widget
remove_meta_box( 'pressable_dashboard_widget', 'dashboard', 'normal' );
}
add_action( 'wp_dashboard_setup', 'fs_remove_dashboard_widget' );
/* -- Divi -- */
// Creates shortcode to allow placing Divi Library module inside of another module's text area. Creates a shortcode to show the Library module.
// https://www.creaweb2b.com/en/how-to-add-a-divi-section-or-module-inside-another-module/
// example usage: [showmodule id="123"]
function showmodule_shortcode($moduleid) {
extract(shortcode_atts(array('id' =>'*'),$moduleid));
return do_shortcode('[et_pb_section global_module="'.$id.'"][/et_pb_section]');
}
add_shortcode('showmodule', 'showmodule_shortcode');
// Adds new admin column to show the shortcode ID in the Divi Library page table
function fs_create_shortcode_column( $columns ) {
$columns['fs_shortcode_id'] = 'Library Item Shortcode';
return $columns;
}
// Display shortcode column info on Divi Library page table
function fs_shortcode_column_content( $column, $id ) {
if( 'fs_shortcode_id' == $column ) {
echo '<p>[showmodule id="' . $id . '"]</p>';
}
}
// create new shortcode column in et_pb_layout screen
add_filter( 'manage_et_pb_layout_posts_columns', 'fs_create_shortcode_column', 5 );
// add the shortcode content to the new column
add_action( 'manage_et_pb_layout_posts_custom_column', 'fs_shortcode_column_content', 5, 2 );
/* -- Gravity Forms -- */
// This filter can be used to prevent the page from auto jumping to form confirmation upon form submission
// add_filter( 'gform_confirmation_anchor', '__return_false' );
// use a custom Gravity Forms AJAX spinner
add_filter( 'gform_ajax_spinner_url', 'fs_custom_gforms_spinner', 10, 2 );
function fs_custom_gforms_spinner( $image_src, $form ) {
$upload_dir = wp_upload_dir();
$lime_spinner_url = $upload_dir['baseurl'] . '/lime-spinner-rotate.svg';
return $lime_spinner_url;
}
/* -- BlogVault -- */
if (!function_exists('fs_check_blogvault_is_active')) {
// Hide Blogvault from non @freshysites.com users
function fs_check_blogvault_is_active() {
// Check if Blogvault plugin is active
if ( is_plugin_active( 'blogvault-real-time-backup/blogvault.php' ) ) {
// hide it from the Plugins list table
add_filter('all_plugins', 'fs_remove_blogvault_admin_plugin_list');
function fs_remove_blogvault_admin_plugin_list($plugins) {
// get current User
$user = wp_get_current_user();
// get their email address
$email = $user->user_email;
// check the email's domain
$domain = 'freshysites.com';
// check if email address matches domain list
$banned = strpos($email, $domain) === false;
// if current user's email addess doesn't match domain list, then hide the plugin in the list
if( $user && $banned ) {
unset($plugins['blogvault-real-time-backup/blogvault.php']);
}
return $plugins;
}
// hide it from the Admin sidebar menu
add_action('admin_menu', 'fs_remove_blogvault_admin_menu_links', 999);
function fs_remove_blogvault_admin_menu_links() {
// get current User
$user = wp_get_current_user();
// get their email address
$email = $user->user_email;
// check the email's domain
$domain = 'freshysites.com';
// check if email address matches domain list
$banned = strpos($email, $domain) === false;
// if current user's email address doesn't match domain list, then hide the menu items
if( $user && $banned ) {
remove_menu_page('bvbackup');
}
}
}
}
add_action( 'admin_init', 'fs_check_blogvault_is_active' );
}
/* -- All in One SEO Pack -- */
// disable the SEO menu in the admin toolbar
add_filter( 'aioseo_show_in_admin_bar', '__return_false' );
// disable the AIOSEO Details column for users that don't have a certain email address
// https://wordpress.org/support/topic/remove-aioseo-details-via-remove_action/#post-16434394
if ( !function_exists('remove_aioseo_column') ) {
add_action( 'current_screen', 'remove_aioseo_column', 0 );
function remove_aioseo_column() {
// get current User
$user = wp_get_current_user();
// get their email address
$email = $user->user_email;
// check the email's domain
$domain = 'freshysites.com';
// check if email address matches domain list
$banned = strpos($email, $domain) === false;
// get allt he actions and filters
global $wp_filter;
// if it's current screen isn't set, then get out of the function
if ( empty( $wp_filter['current_screen'][1] ) ) {
return;
}
// go through each current screen details
foreach ( $wp_filter['current_screen'][1] as $actionName => $params ) {
if (
empty( $params['function'][0] ) ||
! is_object( $params['function'][0] ) ||
stripos( get_class( $params['function'][0] ), 'aioseo' ) === false
) {
continue;
}
// if user is banned (without a particular email address domain), then hide the AIOSEO Details screen option (and thus the AIOSEO column)
if ( $user && $banned ) {
remove_action( 'current_screen', $params['function'], 1 );
}
}
}
}
/* -- Plugin Notes Plus -- */
// Remove the Plugin Notes Plus data for all users other than the ones we approve below
// based on their user email domain, or their user ID
// using their own filter, we hide its output
if ( !function_exists('fs_remove_plugin_notes_data_for_most_users') ) {
add_filter( 'plugin-notes-plus_hide_notes', 'fs_remove_plugin_notes_data_for_most_users' );
function fs_remove_plugin_notes_data_for_most_users( $hide_notes ) {
// get current user data
$current_user = wp_get_current_user();
// get their email address
$email = $current_user->user_email;
// ** SET ALLOWED EMAIL DOMAIN HERE **
// domain to check in the email address
$domain = 'freshysites.com';
// check if user's email address matches the one we check against
// we check to see if it returns false, and if so, they are deemed a user with $banned_user_email
// because otherwise, it would return the position of the first occurrence of the $domain string within the $email string... but if it returns FALSE, then the string was not found
$banned_user_email = strpos($email, $domain) === false;
// ** SET LIST OF ALLOWED USER IDs HERE **
// list of allowed user IDs (add more within the array, as a comma separated list) e.g., array(3, 345, 995, 6);
$allowed_user_ids = array();
// if the current user ID is not withinout list of $allowed_user_ids, then they are deemed a user with $banned_user_id
$banned_user_id = !in_array($current_user->ID, $allowed_user_ids);
// if the current user is both a banned email and a banned user ID, then hide the plugin data output
// otherwise, if not BOTH of these, they are at least either an allowed email or an allowed user ID, so we want to let them through
// that's why we need to check if BOTH banned options are true, so that if only one is true, and the other is false, it will still show for that user
if ( $banned_user_email && $banned_user_id) {
// then hide the Plugin Notes Plus output
$hide_notes = true;
}
// return the notes (unless we are hiding them, based on above logic)
return $hide_notes;
}
}