| 1 |
<?php |
| 2 |
|
| 3 |
global $post; |
| 4 |
|
| 5 |
// shows hidden custom fields |
| 6 |
echo "<style type='text/css'>#postcustom .hidden { display: table-row; }</style>"; |
| 7 |
|
| 8 |
// add metabox, style and javascript to acf page |
| 9 |
//if($_GET['post_type'] == 'acf') |
| 10 |
//{ |
| 11 |
// not edit screen |
| 12 |
//} |
| 13 |
|
| 14 |
$currentFile = $_SERVER["SCRIPT_NAME"]; |
| 15 |
$parts = Explode('/', $currentFile); |
| 16 |
$currentFile = $parts[count($parts) - 1]; |
| 17 |
|
| 18 |
if($currentFile == 'edit.php') |
| 19 |
{ |
| 20 |
|
| 21 |
} |
| 22 |
elseif(get_post_type($post) == 'acf') |
| 23 |
{ |
| 24 |
|
| 25 |
// Custom field page for ACF |
| 26 |
echo '<script type="text/javascript" src="'.$this->dir.'/js/functions.fields.js" ></script>'; |
| 27 |
|
| 28 |
echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/css/style.global.css" />'; |
| 29 |
echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/css/style.fields.css" />'; |
| 30 |
echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/css/style.location.css" />'; |
| 31 |
echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/css/style.options.css" />'; |
| 32 |
|
| 33 |
add_meta_box('acf_fields', 'Fields', array($this, '_fields_meta_box'), 'acf', 'normal', 'high'); |
| 34 |
add_meta_box('acf_location', 'Assign to edit page</span><span class="description">- Specify exactly where you want your Advanced Custom Fields fields to appear', array($this, '_location_meta_box'), 'acf', 'normal', 'high'); |
| 35 |
add_meta_box('acf_options', 'Advanced Options</span><span class="description">- Customise the edit page', array($this, '_options_meta_box'), 'acf', 'normal', 'high'); |
| 36 |
} |
| 37 |
else |
| 38 |
{ |
| 39 |
// any other edit page |
| 40 |
$acfs = get_pages(array( |
| 41 |
'numberposts' => -1, |
| 42 |
'post_type' => 'acf', |
| 43 |
'sort_column' => 'menu_order', |
| 44 |
)); |
| 45 |
|
| 46 |
// blank array to hold acfs |
| 47 |
$add_acf = array(); |
| 48 |
|
| 49 |
if($acfs) |
| 50 |
{ |
| 51 |
foreach($acfs as $acf) |
| 52 |
{ |
| 53 |
$add_box = false; |
| 54 |
|
| 55 |
// get options of matrix |
| 56 |
$location = $this->get_acf_location($acf->ID); |
| 57 |
//print_r($location); |
| 58 |
|
| 59 |
// post type |
| 60 |
if($location['post_type'] != '') |
| 61 |
{ |
| 62 |
$post_types = explode(',',str_replace(' ','',$location['post_type'])); |
| 63 |
if(in_array(get_post_type($post), $post_types)) {$add_box = true; } |
| 64 |
} |
| 65 |
|
| 66 |
// page slug |
| 67 |
if($location['page_slug'] != '') |
| 68 |
{ |
| 69 |
$page_slugs = explode(',',str_replace(' ','',$location['page_slug'])); |
| 70 |
if(in_array($post->post_name, $page_slugs)) {$add_box = true; } |
| 71 |
} |
| 72 |
|
| 73 |
// post ID |
| 74 |
if($location['post_id'] != '') |
| 75 |
{ |
| 76 |
$post_ids = explode(',',str_replace(' ','',$location['post_id'])); |
| 77 |
if(in_array($post->ID, $post_ids)) {$add_box = true; } |
| 78 |
} |
| 79 |
|
| 80 |
// page template |
| 81 |
if($location['page_template'] != '') |
| 82 |
{ |
| 83 |
$page_template = explode(',',str_replace(' ','',$location['page_template'])); |
| 84 |
if(in_array(get_post_meta($post->ID,'_wp_page_template',true), $page_template)) {$add_box = true;} |
| 85 |
} |
| 86 |
|
| 87 |
// parent id |
| 88 |
if($location['parent_id'] != '') |
| 89 |
{ |
| 90 |
$parent_ids = explode(',',str_replace(' ','',$location['parent_id'])); |
| 91 |
if(in_array($post->post_parent, $parent_ids)) {$add_box = true;} |
| 92 |
|
| 93 |
} |
| 94 |
|
| 95 |
if($add_box == true) |
| 96 |
{ |
| 97 |
// add acf to array |
| 98 |
$add_acf[] = $acf; |
| 99 |
} |
| 100 |
|
| 101 |
}// end foreach |
| 102 |
|
| 103 |
if(!empty($add_acf)) |
| 104 |
{ |
| 105 |
// add these acf's to the page |
| 106 |
echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/css/style.global.css" />'; |
| 107 |
echo '<link rel="stylesheet" type="text/css" href="'.$this->dir.'/css/style.input.css" />'; |
| 108 |
echo '<script type="text/javascript" src="'.$this->dir.'/js/swap.jquery.js" ></script>'; |
| 109 |
echo '<script type="text/javascript" src="'.$this->dir.'/js/functions.input.js" ></script>'; |
| 110 |
|
| 111 |
add_meta_box('acf_input', 'ACF Fields', array($this, '_input_meta_box'), get_post_type($post), 'normal', 'high', array('acfs' => $add_acf)); |
| 112 |
} |
| 113 |
|
| 114 |
}// end if |
| 115 |
} |
| 116 |
|
| 117 |
?> |