-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.php
59 lines (53 loc) · 2.69 KB
/
helper.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
<?php
if (!defined('ABSPATH')) exit;
class Castors_Helper {
public static function array_insert_after_key(&$array, $key, $array_to_insert)
{
$key_pos = array_search($key, array_keys($array));
if($key_pos !== false){
$key_pos++;
$second_array = array_splice($array, $key_pos);
$array = array_merge($array, $array_to_insert, $second_array);
}
}
public static function add_caps($role, $singular, $plural = null, $others = false, $terms = false) {
if ($plural === null) {
$plural = $singular . 's';
}
get_role($role)->add_cap('edit_' . $singular);
get_role($role)->add_cap('read_' . $singular);
get_role($role)->add_cap('delete_' . $singular);
get_role($role)->add_cap('edit_' . $plural);
if ($others) {
get_role($role)->add_cap('edit_others_' . $plural);
}
get_role($role)->add_cap('publish_' . $plural);
get_role($role)->add_cap('read_private_' . $plural);
if ($terms) {
get_role($role)->add_cap('manage_' . $singular . '_terms');
}
}
public static function remove_caps($role, $singular, $plural = null) {
if ($plural === null) {
$plural = $singular . 's';
}
get_role($role)->remove_cap('edit_' . $singular);
get_role($role)->remove_cap('read_' . $singular);
get_role($role)->remove_cap('delete_' . $singular);
get_role($role)->remove_cap('edit_' . $plural);
get_role($role)->remove_cap('edit_others_' . $plural);
get_role($role)->remove_cap('publish_' . $plural);
get_role($role)->remove_cap('read_private_' . $plural);
get_role($role)->remove_cap('manage_' . $singular . '_terms');
}
public static function set_post_metadata_value(&$value, $key, $id) {
$value = get_post_meta($id, $key, true) ?: $value;
}
public static function listTransferScripts($field, $settings) {
wp_enqueue_style('castors-jquery-transfer-icon-style', CASTORS_THEME_URI . 'js/jquery-transfer/icon_font/css/icon_font.css');
wp_enqueue_style('castors-jquery-transfer-style', CASTORS_THEME_URI . 'js/jquery-transfer/css/jquery.transfer.css');
wp_enqueue_script('castors-jquery-transfer', CASTORS_THEME_URI . 'js/jquery-transfer/js/jquery.transfer.js', ['jquery-core'], false, ['strategy' =>'defer', 'in_footer' => true]);
wp_enqueue_script('castors-list-transfer', CASTORS_THEME_URI . 'js/transfer.min.js', ['castors-jquery-transfer'], false, ['strategy' =>'defer', 'in_footer' => true]);
wp_localize_script('castors-list-transfer', 'transferListItems', ['field' => $field, 'settings' => $settings]);
}
}