acf_field_page_link

The Advanced Custom Fields acf field page link class.

Defined (1)

The class is defined in the following location(s).

/core/fields/page_link.php  
  1. class acf_field_page_link extends acf_field 
  2. /** 
  3. * __construct 
  4. * Set name / label needed for actions / filters 
  5. * @since 3.6 
  6. * @date 23/01/13 
  7. */ 
  8.  
  9. function __construct() 
  10. // vars 
  11. $this->name = 'page_link'; 
  12. $this->label = __("Page Link", 'acf'); 
  13. $this->category = __("Relational", 'acf'); 
  14. $this->defaults = array( 
  15. 'post_type' => array('all'),  
  16. 'multiple' => 0,  
  17. 'allow_null' => 0,  
  18. ); 
  19.  
  20.  
  21. // do not delete! 
  22. parent::__construct(); 
  23.  
  24.  
  25.  
  26. /** 
  27. * load_field() 
  28. *  
  29. * This filter is appied to the $field after it is loaded from the database 
  30. *  
  31. * @type filter 
  32. * @since 3.6 
  33. * @date 23/01/13 
  34. *  
  35. * @param $field - the field array holding all the field options 
  36. *  
  37. * @return $field - the field array holding all the field options 
  38. */ 
  39.  
  40. function load_field( $field ) 
  41.  
  42. // validate post_type 
  43. if( !$field['post_type'] || !is_array($field['post_type']) || in_array('', $field['post_type']) ) 
  44. $field['post_type'] = array( 'all' ); 
  45.  
  46.  
  47. // return 
  48. return $field; 
  49.  
  50.  
  51. /** 
  52. * create_field() 
  53. * Create the HTML interface for your field 
  54. * @param $field - an array holding all the field's data 
  55. * @type action 
  56. * @since 3.6 
  57. * @date 23/01/13 
  58. */ 
  59.  
  60. function create_field( $field ) 
  61. // let post_object create the field 
  62. $field['type'] = 'post_object'; 
  63.  
  64. do_action('acf/create_field', $field ); 
  65.  
  66.  
  67. /** 
  68. * create_options() 
  69. * Create extra options for your field. This is rendered when editing a field. 
  70. * The value of $field['name'] can be used (like bellow) to save extra data to the $field 
  71. * @type action 
  72. * @since 3.6 
  73. * @date 23/01/13 
  74. * @param $field - an array holding all the field's data 
  75. */ 
  76.  
  77. function create_options( $field ) 
  78. $key = $field['name']; 
  79.  
  80. ?> 
  81. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  82. <td class="label"> 
  83. <label for=""><?php _e("Post Type", 'acf'); ?></label> 
  84. </td> 
  85. <td> 
  86. <?php  
  87.  
  88. $choices = array( 
  89. 'all' => __("All", 'acf') 
  90. ); 
  91. $choices = apply_filters('acf/get_post_types', $choices); 
  92.  
  93.  
  94. do_action('acf/create_field', array( 
  95. 'type' => 'select',  
  96. 'name' => 'fields['.$key.'][post_type]',  
  97. 'value' => $field['post_type'],  
  98. 'choices' => $choices,  
  99. 'multiple' => 1,  
  100. )); 
  101.  
  102. ?> 
  103. </td> 
  104. </tr> 
  105. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  106. <td class="label"> 
  107. <label><?php _e("Allow Null?", 'acf'); ?></label> 
  108. </td> 
  109. <td> 
  110. <?php 
  111.  
  112. do_action('acf/create_field', array( 
  113. 'type' => 'radio',  
  114. 'name' => 'fields['.$key.'][allow_null]',  
  115. 'value' => $field['allow_null'],  
  116. 'choices' => array( 
  117. 1 => __("Yes", 'acf'),  
  118. 0 => __("No", 'acf'),  
  119. ),  
  120. 'layout' => 'horizontal',  
  121. )); 
  122.  
  123. ?> 
  124. </td> 
  125. </tr> 
  126. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  127. <td class="label"> 
  128. <label><?php _e("Select multiple values?", 'acf'); ?></label> 
  129. </td> 
  130. <td> 
  131. <?php 
  132.  
  133. do_action('acf/create_field', array( 
  134. 'type' => 'radio',  
  135. 'name' => 'fields['.$key.'][multiple]',  
  136. 'value' => $field['multiple'],  
  137. 'choices' => array( 
  138. 1 => __("Yes", 'acf'),  
  139. 0 => __("No", 'acf'),  
  140. ),  
  141. 'layout' => 'horizontal',  
  142. )); 
  143.  
  144. ?> 
  145. </td> 
  146. </tr> 
  147. <?php 
  148.  
  149.  
  150.  
  151. /** 
  152. * format_value_for_api() 
  153. * This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field 
  154. * @type filter 
  155. * @since 3.6 
  156. * @date 23/01/13 
  157. * @param $value - the value which was loaded from the database 
  158. * @param $post_id - the $post_id from which the value was loaded 
  159. * @param $field - the field array holding all the field options 
  160. * @return $value - the modified value 
  161. */ 
  162.  
  163. function format_value_for_api( $value, $post_id, $field ) 
  164. if( !$value ) 
  165. return false; 
  166.  
  167. if( $value == 'null' ) 
  168. return false; 
  169.  
  170. if( is_array($value) ) 
  171. foreach( $value as $k => $v ) 
  172. $value[ $k ] = get_permalink($v); 
  173. else 
  174. $value = get_permalink($value); 
  175.  
  176. return $value; 
  177.