-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocation.php
69 lines (53 loc) · 1.31 KB
/
location.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
<?php
if(!defined('ABSPATH')){
exit;
}
if(!class_exists('ACF_Location_Custom_Options_Page')):
class ACF_Location_Custom_Options_Page extends ACF_Location {
public function initialize()
{
$this->name = 'custom_options_page';
$this->label = __('Custom Options Page');
$this->category = 'forms';
$this->object_type = 'option';
}
public function get_values($rule)
{
$choices = array();
$pages = acf_get_custom_options_pages();
if(!empty($pages))
{
foreach($pages as $page)
{
$choices[$page->ID] = $page->post_title;
}
}
else
{
$choices[] = __('No pages exist');
}
return $choices;
}
public function match($rule, $screen, $field_group)
{
global $acf_CustomOptionsPages;
$page_slug = !empty($_GET['page']) ? sanitize_text_field($_GET['page']) : '';
if(empty($page_slug) || empty($acf_CustomOptionsPages)){
return false;
}
$current_page = null;
foreach ($acf_CustomOptionsPages as $page)
{
if($page['menu_slug'] == $page_slug){
$current_page = $page;
break;
}
}
if(empty($current_page)){
return false;
}
return true;
}
}
acf_register_location_type('ACF_Location_Custom_Options_Page');
endif;