|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the WPFoundation library. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (c) 2015-present LIN3S <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace LIN3S\WPFoundation\Configuration\Acf; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @author Beñat Espiña <[email protected]> |
|
16
|
|
|
* @author Jon Torrado <[email protected]> |
|
17
|
|
|
*/ |
|
18
|
|
|
abstract class Acf implements AcfInterface |
|
19
|
|
|
{ |
|
20
|
|
|
public function __construct() |
|
21
|
|
|
{ |
|
22
|
|
|
$customToolbars = $this->wyswygToolbars(); |
|
23
|
|
|
add_filter('acf/rest_api/post/get_fields', [$this, 'acfGetFields']); |
|
|
|
|
|
|
24
|
|
|
add_filter('acf/fields/wysiwyg/toolbars', function (array $toolbars) use ($customToolbars) { |
|
|
|
|
|
|
25
|
|
|
return array_merge($toolbars, $customToolbars); |
|
26
|
|
|
}); |
|
27
|
|
|
add_filter('admin_menu', function () { |
|
|
|
|
|
|
28
|
|
|
if (!acf_current_user_can_admin()) { |
|
29
|
|
|
$this->removeSectionsForNotAdminUsers(); |
|
30
|
|
|
} |
|
31
|
|
|
}); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function acfGetFields(array $data) : array |
|
35
|
|
|
{ |
|
36
|
|
|
if (!empty($data)) { |
|
37
|
|
|
array_walk_recursive($data, ['self', 'serializeFeaturedImage']); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
return $data; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function serializeFeaturedImage(&$item) : void |
|
44
|
|
|
{ |
|
45
|
|
|
if (!is_object($item)) { |
|
46
|
|
|
return null; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$item->featured = [ |
|
50
|
|
|
'thumbnail' => wp_get_attachment_image_src(get_post_thumbnail_id($item->ID), 'thumbnail'), |
|
51
|
|
|
'medium' => wp_get_attachment_image_src(get_post_thumbnail_id($item->ID), 'medium'), |
|
52
|
|
|
'large' => wp_get_attachment_image_src(get_post_thumbnail_id($item->ID), 'full'), |
|
53
|
|
|
'xlarge' => wp_get_attachment_image_src(get_post_thumbnail_id($item->ID), 'full'), |
|
54
|
|
|
]; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
private function removeSectionsForNotAdminUsers() : void |
|
58
|
|
|
{ |
|
59
|
|
|
remove_menu_page('profile.php'); |
|
60
|
|
|
remove_menu_page('tools.php'); |
|
61
|
|
|
remove_menu_page('options-general.php'); |
|
62
|
|
|
remove_menu_page('edit.php'); |
|
63
|
|
|
remove_menu_page('admin.php'); |
|
64
|
|
|
remove_submenu_page('users.php', 'profile.php'); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|