/core/views/meta_box_location.php

  1. <?php 
  2.  
  3. /** 
  4. * Meta box - locations 
  5. * 
  6. * This template file is used when editing a field group and creates the interface for editing location rules. 
  7. * 
  8. * @type template 
  9. * @date 23/06/12 
  10. */ 
  11.  
  12.  
  13. // global 
  14. global $post; 
  15.  
  16.  
  17. // vars 
  18. $groups = apply_filters('acf/field_group/get_location', array(), $post->ID); 
  19.  
  20.  
  21. // at lease 1 location rule 
  22. if( empty($groups) ) 
  23. $groups = array( 
  24.  
  25. // group_0 
  26. array( 
  27.  
  28. // rule_0 
  29. array( 
  30. 'param' => 'post_type',  
  31. 'operator' => '==',  
  32. 'value' => 'post',  
  33. 'order_no' => 0,  
  34. 'group_no' => 0 
  35.  
  36. ); 
  37.  
  38.  
  39. ?> 
  40. <table class="acf_input widefat" id="acf_location"> 
  41. <tbody> 
  42. <tr> 
  43. <td class="label"> 
  44. <label for="post_type"><?php _e("Rules", 'acf'); ?></label> 
  45. <p class="description"><?php _e("Create a set of rules to determine which edit screens will use these advanced custom fields", 'acf'); ?></p> 
  46. </td> 
  47. <td> 
  48. <div class="location-groups"> 
  49.  
  50. <?php if( is_array($groups) ): ?> 
  51. <?php foreach( $groups as $group_id => $group ):  
  52. $group_id = 'group_' . $group_id; 
  53. ?> 
  54. <div class="location-group" data-id="<?php echo $group_id; ?>"> 
  55. <?php if( $group_id == 'group_0' ): ?> 
  56. <h4><?php _e("Show this field group if", 'acf'); ?></h4> 
  57. <?php else: ?> 
  58. <h4><?php _e("or", 'acf'); ?></h4> 
  59. <?php endif; ?> 
  60. <?php if( is_array($group) ): ?> 
  61. <table class="acf_input widefat"> 
  62. <tbody> 
  63. <?php foreach( $group as $rule_id => $rule ):  
  64. $rule_id = 'rule_' . $rule_id; 
  65. ?> 
  66. <tr data-id="<?php echo $rule_id; ?>"> 
  67. <td class="param"><?php  
  68.  
  69. $choices = array( 
  70. __("Basic", 'acf') => array( 
  71. 'post_type' => __("Post Type", 'acf'),  
  72. 'user_type' => __("Logged in User Type", 'acf'),  
  73. ),  
  74. __("Post", 'acf') => array( 
  75. 'post' => __("Post", 'acf'),  
  76. 'post_category' => __("Post Category", 'acf'),  
  77. 'post_format' => __("Post Format", 'acf'),  
  78. 'post_status' => __("Post Status", 'acf'),  
  79. 'taxonomy' => __("Post Taxonomy", 'acf'),  
  80. ),  
  81. __("Page", 'acf') => array( 
  82. 'page' => __("Page", 'acf'),  
  83. 'page_type' => __("Page Type", 'acf'),  
  84. 'page_parent' => __("Page Parent", 'acf'),  
  85. 'page_template' => __("Page Template", 'acf'),  
  86. ),  
  87. __("Other", 'acf') => array( 
  88. 'ef_media' => __("Attachment", 'acf'),  
  89. 'ef_taxonomy' => __("Taxonomy Term", 'acf'),  
  90. 'ef_user' => __("User", 'acf'),  
  91. ); 
  92.  
  93.  
  94. // allow custom location rules 
  95. $choices = apply_filters( 'acf/location/rule_types', $choices ); 
  96.  
  97.  
  98. // create field 
  99. $args = array( 
  100. 'type' => 'select',  
  101. 'name' => 'location[' . $group_id . '][' . $rule_id . '][param]',  
  102. 'value' => $rule['param'],  
  103. 'choices' => $choices,  
  104. ); 
  105.  
  106. do_action('acf/create_field', $args);  
  107.  
  108. ?></td> 
  109. <td class="operator"><?php  
  110.  
  111. $choices = array( 
  112. '==' => __("is equal to", 'acf'),  
  113. '!=' => __("is not equal to", 'acf'),  
  114. ); 
  115.  
  116.  
  117. // allow custom location rules 
  118. $choices = apply_filters( 'acf/location/rule_operators', $choices ); 
  119.  
  120.  
  121. // create field 
  122. do_action('acf/create_field', array( 
  123. 'type' => 'select',  
  124. 'name' => 'location[' . $group_id . '][' . $rule_id . '][operator]',  
  125. 'value' => $rule['operator'],  
  126. 'choices' => $choices 
  127. ));  
  128.  
  129. ?></td> 
  130. <td class="value"><?php  
  131.  
  132. $this->ajax_render_location(array( 
  133. 'group_id' => $group_id,  
  134. 'rule_id' => $rule_id,  
  135. 'value' => $rule['value'],  
  136. 'param' => $rule['param'],  
  137. ));  
  138.  
  139. ?></td> 
  140. <td class="add"> 
  141. <a href="#" class="location-add-rule button"><?php _e("and", 'acf'); ?></a> 
  142. </td> 
  143. <td class="remove"> 
  144. <a href="#" class="location-remove-rule acf-button-remove"></a> 
  145. </td> 
  146. </tr> 
  147. <?php endforeach; ?> 
  148. </tbody> 
  149. </table> 
  150. <?php endif; ?> 
  151. </div> 
  152. <?php endforeach; ?> 
  153.  
  154. <h4><?php _e("or", 'acf'); ?></h4> 
  155.  
  156. <a class="button location-add-group" href="#"><?php _e("Add rule group", 'acf'); ?></a> 
  157.  
  158. <?php endif; ?> 
  159.  
  160. </div> 
  161. </td> 
  162. </tr> 
  163. </tbody> 
  164. </table> 
.