acf_field_font_awesome

The Advanced Custom Fields: Font Awesome acf field font awesome class.

Defined (2)

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

/acf-font-awesome-v4.php  
  1. class acf_field_font_awesome extends acf_field 
  2. // vars 
  3. var $settings, // will hold info such as dir / path 
  4. $defaults, // will hold default field options 
  5. $stylesheet, // will hold fontawesome stylesheet url 
  6. $version; // will hold fontawesome version number 
  7.  
  8. /** 
  9. * __construct 
  10. * Set name / label needed for actions / filters 
  11. * @since 3.6 
  12. * @date 23/01/13 
  13. */ 
  14.  
  15. function __construct() 
  16. $this->name = 'font-awesome'; 
  17. $this->label = __('Font Awesome Icon'); 
  18. $this->category = __("Content", 'acf'); // Basic, Content, Choice, etc 
  19. $this->defaults = array( 
  20. 'enqueue_fa' => 0,  
  21. 'allow_null' => 0,  
  22. 'save_format' => 'element',  
  23. 'default_value' => '',  
  24. 'choices' => $this->get_icons() 
  25. ); 
  26.  
  27. $this->settings = array( 
  28. 'path' => apply_filters('acf/helpers/get_path', __FILE__),  
  29. 'dir' => apply_filters('acf/helpers/get_dir', __FILE__),  
  30. 'version' => '1.5' 
  31. ); 
  32.  
  33. add_filter('acf/load_field', array( $this, 'maybe_enqueue_font_awesome' ) ); 
  34.  
  35. parent::__construct(); 
  36.  
  37. function get_icons() 
  38. require_once ( dirname( __FILE__ ) . '/better-font-awesome-library/better-font-awesome-library.php' ); 
  39.  
  40. $args = array( 
  41. 'version' => 'latest',  
  42. 'minified' => true,  
  43. 'remove_existing_fa' => false,  
  44. 'load_styles' => false,  
  45. 'load_admin_styles' => false,  
  46. 'load_shortcode' => false,  
  47. 'load_tinymce_plugin' => false 
  48. ); 
  49.  
  50. $bfa = Better_Font_Awesome_Library::get_instance( $args ); 
  51. $bfa_icons = $bfa->get_icons(); 
  52. $bfa_prefix = $bfa->get_prefix() . '-'; 
  53. $new_icons = array(); 
  54.  
  55. $this->stylesheet = $bfa->get_stylesheet_url(); 
  56. $this->version = $bfa->get_version(); 
  57.  
  58. foreach ( $bfa_icons as $hex => $class ) { 
  59. $unicode = '&#x' . ltrim( $hex, '\\') . ';'; 
  60. $new_icons[ $bfa_prefix . $class ] = $unicode . ' ' . $bfa_prefix . $class; 
  61.  
  62. $new_icons = array_merge( array( 'null' => '- Select -' ), $new_icons ); 
  63.  
  64. return $new_icons; 
  65.  
  66. /** 
  67. * maybe_enqueue_font_awesome() 
  68. * If Enqueue FA is set to true, enqueue it in the footer. We cannot enqueue in the header because wp_head has already been called 
  69. *  
  70. */ 
  71.  
  72. function maybe_enqueue_font_awesome( $field ) 
  73. if( 'font-awesome' == $field['type'] && $field['enqueue_fa'] ) { 
  74. add_action( 'wp_footer', array( $this, 'frontend_enqueue_scripts' ) ); 
  75.  
  76. return $field; 
  77.  
  78. /** 
  79. * create_options() 
  80. * Create extra options for your field. This is rendered when editing a field. 
  81. * The value of $field['name'] can be used (like bellow) to save extra data to the $field 
  82. * @type action 
  83. * @since 3.6 
  84. * @date 23/01/13 
  85. * @param $field - an array holding all the field's data 
  86. */ 
  87.  
  88. function create_options($field) 
  89. // defaults? 
  90. $field = array_merge($this->defaults, $field); 
  91.  
  92. // key is needed in the field names to correctly save the data 
  93. $key = $field['name']; 
  94.  
  95.  
  96. // Create Field Options HTML 
  97. ?> 
  98. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  99. <td class="label"> 
  100. <label><?php _e("Default Icon", 'acf'); ?></label> 
  101. </td> 
  102. <td> 
  103. <div class="fa-field-wrapper"> 
  104. <div class="fa-live-preview"></div> 
  105. <?php 
  106.  
  107. do_action('acf/create_field', array( 
  108. 'type' => 'select',  
  109. 'name' => 'fields[' . $key . '][default_value]',  
  110. 'value' => $field['default_value'],  
  111. 'class' => 'fontawesome',  
  112. 'choices' => array_merge( array( 'null' => __("Select", 'acf') ), $field['choices'] ) 
  113. )); 
  114.  
  115. ?> 
  116. </div> 
  117. </td> 
  118. </tr> 
  119. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  120. <td class="label"> 
  121. <label><?php _e("Return Value", 'acf'); ?></label> 
  122. <p class="description"><?php _e("Specify the returned value on front end", 'acf'); ?></p> 
  123. </td> 
  124. <td> 
  125. <?php  
  126. do_action('acf/create_field', array( 
  127. 'type' => 'radio',  
  128. 'name' => 'fields['.$key.'][save_format]',  
  129. 'value' => $field['save_format'],  
  130. 'choices' => array( 
  131. 'element' => __("Icon Element", 'acf'),  
  132. 'class' => __("Icon Class", 'acf'),  
  133. 'unicode' => __("Icon Unicode", 'acf'),  
  134. 'object' => __("Icon Object", 'acf'),  
  135. ),  
  136. 'layout' => 'horizontal',  
  137. )); 
  138. ?> 
  139. </td> 
  140. </tr> 
  141.  
  142. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  143. <td class="label"> 
  144. <label><?php _e("Allow Null?", 'acf'); ?></label> 
  145. </td> 
  146. <td> 
  147. <?php  
  148. do_action('acf/create_field', array( 
  149. 'type' => 'radio',  
  150. 'name' => 'fields['.$key.'][allow_null]',  
  151. 'value' => $field['allow_null'],  
  152. 'choices' => array( 
  153. 1 => __("Yes", 'acf'),  
  154. 0 => __("No", 'acf'),  
  155. ),  
  156. 'layout' => 'horizontal',  
  157. )); 
  158. ?> 
  159. </td> 
  160. </tr> 
  161.  
  162. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  163. <td class="label"> 
  164. <label><?php _e("Enqueue FontAwesome?", 'acf'); ?></label> 
  165. <p class="description"><?php _e("Set to 'Yes' to enqueue FA in the footer on any pages using this field.", 'acf'); ?></p> 
  166. </td> 
  167. <td> 
  168. <?php  
  169. do_action('acf/create_field', array( 
  170. 'type' => 'radio',  
  171. 'name' => 'fields['.$key.'][enqueue_fa]',  
  172. 'value' => $field['enqueue_fa'],  
  173. 'choices' => array( 
  174. 1 => __("Yes", 'acf'),  
  175. 0 => __("No", 'acf'),  
  176. ),  
  177. 'layout' => 'horizontal',  
  178. )); 
  179. ?> 
  180. </td> 
  181. </tr> 
  182. <?php 
  183.  
  184.  
  185. /** 
  186. * create_field() 
  187. * Create the HTML interface for your field 
  188. * @param $field - an array holding all the field's data 
  189. * @type action 
  190. * @since 3.6 
  191. * @date 23/01/13 
  192. */ 
  193.  
  194. function create_field( $field ) 
  195. if( 'object' == $field['save_format'] && 'null' !== $field['value'] ) 
  196. $field['value'] = array( $field['value']->class ); 
  197.  
  198. // value must be array 
  199. if( !is_array($field['value']) ) 
  200. // perhaps this is a default value with new lines in it? 
  201. if( strpos($field['value'], "\n") !== false ) 
  202. // found multiple lines, explode it 
  203. $field['value'] = explode("\n", $field['value']); 
  204. else 
  205. $field['value'] = array( $field['value'] ); 
  206.  
  207. // trim value 
  208. $field['value'] = array_map('trim', $field['value']); 
  209.  
  210. // html 
  211. echo '<div class="fa-field-wrapper">'; 
  212. echo '<div class="fa-live-preview"></div>'; 
  213. echo '<select id="' . $field['id'] . '" class="' . $field['class'] . ' fa-select2-field" name="' . $field['name'] . '" >';  
  214.  
  215. // null 
  216. if( $field['allow_null'] ) 
  217. echo '<option value="null">- ' . __("Select", 'acf') . ' -</option>'; 
  218.  
  219. // loop through values and add them as options 
  220. if( is_array($field['choices']) ) 
  221. unset( $field['choices']['null'] ); 
  222.  
  223. foreach( $field['choices'] as $key => $value ) 
  224. $selected = $this->find_selected( $key, $field['value'], $field['save_format'], $field['choices'] ); 
  225. echo '<option value="'.$key.'" '.$selected.'>'.$value.'</option>'; 
  226.  
  227. echo '</select>'; 
  228. echo '</div>'; 
  229.  
  230. function find_selected( $needle, $haystack, $type, $choices ) 
  231. switch( $type ) 
  232. case 'object': 
  233. case 'element': 
  234. $search = array( '<i class="fa ', '"></i>' ); 
  235. $string = str_replace( $search, '', $haystack[0] ); 
  236. break; 
  237.  
  238. case 'unicode': 
  239. $index = $choices[ $needle ]; 
  240. if ( stristr( $index, $haystack[0] ) ) { 
  241. return 'selected="selected"'; 
  242. return ''; 
  243.  
  244. case 'class': 
  245. $string = $haystack[0]; 
  246. break; 
  247.  
  248. if( $string == $needle ) 
  249. return 'selected="selected"'; 
  250.  
  251. return ''; 
  252.  
  253. /** 
  254. * input_admin_enqueue_scripts() 
  255. * This action is called in the admin_enqueue_scripts action on the edit screen where your field is created. 
  256. * Use this action to add css + javascript to assist your create_field() action. 
  257. * $info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts 
  258. * @type action 
  259. * @since 3.6 
  260. * @date 23/01/13 
  261. */ 
  262.  
  263. function input_admin_enqueue_scripts() 
  264. // register acf scripts 
  265. wp_enqueue_script('acf-input-font-awesome-select2', $this->settings['dir'] . 'js/select2/select2.min.js', array(), $this->settings['version']); 
  266. wp_enqueue_script('acf-input-font-awesome-edit-input', $this->settings['dir'] . 'js/edit_input.js', array(), $this->settings['version']); 
  267. wp_enqueue_style('acf-input-font-awesome-input', $this->settings['dir'] . 'css/input.css', array(), $this->settings['version']); 
  268. wp_enqueue_style('acf-input-font-awesome-fa', $this->stylesheet, array(), $this->version); 
  269. wp_enqueue_style('acf-input-font-awesome-select2-css', $this->settings['dir'] . 'css/select2.css', array(), $this->settings['version']); 
  270.  
  271. /** 
  272. * field_group_admin_enqueue_scripts() 
  273. * This action is called in the admin_enqueue_scripts action on the edit screen where your field is edited. 
  274. * Use this action to add css + javascript to assist your create_field_options() action. 
  275. * $info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts 
  276. * @type action 
  277. * @since 3.6 
  278. * @date 23/01/13 
  279. */ 
  280.  
  281. function field_group_admin_enqueue_scripts() 
  282. // register acf scripts 
  283. wp_enqueue_script('font-awesome-select2', $this->settings['dir'] . 'js/select2/select2.min.js', array(), $this->settings['version']); 
  284. wp_enqueue_script('font-awesome-create-input', $this->settings['dir'] . 'js/create_input.js', array(), $this->settings['version']); 
  285. wp_enqueue_style('acf-input-font-awesome-input', $this->settings['dir'] . 'css/input.css', array(), $this->settings['version']); 
  286. wp_enqueue_style('acf-input-font-awesome-fa', $this->stylesheet, array(), $this->version); 
  287. wp_enqueue_style('acf-input-font-awesome-select2-css', $this->settings['dir'] . 'css/select2.css', array(), $this->settings['version']); 
  288.  
  289. /** 
  290. * frontend_enqueue_scripts() 
  291. * This action is called in the wp_enqueue_scripts action on the front end. 
  292. *  
  293. * $info http://codex.wordpress.org/Plugin_API/Action_Reference/wp_enqueue_scripts 
  294. * @type action 
  295. */ 
  296.  
  297. function frontend_enqueue_scripts() 
  298. wp_register_style('font-awesome', $this->stylesheet, array(), $this->version); 
  299.  
  300. wp_enqueue_style( array( 'font-awesome' ) ); 
  301.  
  302. /** 
  303. * load_value() 
  304. * This filter is appied to the $value after it is loaded from the db 
  305. * @type filter 
  306. * @since 3.6 
  307. * @date 23/01/13 
  308. * @param $value - the value found in the database 
  309. * @param $post_id - the $post_id from which the value was loaded from 
  310. * @param $field - the field array holding all the field options 
  311. * @return $value - the value to be saved in te database 
  312. */ 
  313.  
  314. function load_value($value, $post_id, $field) 
  315. if ( 'null' == $value ) { 
  316. return; 
  317.  
  318. switch( $field['save_format'] ) 
  319. case 'object': 
  320. $icon_unicode_string = $this->defaults['choices'][ $value ]; 
  321. $icon_unicode_arr = explode( ' ', $icon_unicode_string ); 
  322. $icon_unicode = $icon_unicode_arr[0]; 
  323. $value = (object) array( 
  324. 'unicode' => $icon_unicode,  
  325. 'class' => $value,  
  326. 'element' => '<i class="fa ' . $value . '"></i>' 
  327. ); 
  328. break; 
  329.  
  330. case 'unicode': 
  331. $icon_unicode_string = $this->defaults['choices'][ $value ]; 
  332. $icon_unicode_arr = explode( ' ', $icon_unicode_string ); 
  333. $value = $icon_unicode_arr[0]; 
  334. break; 
  335.  
  336. case 'element': 
  337. $value = '<i class="fa ' . $value . '"></i>'; 
  338. break; 
  339.  
  340. return $value; 
  341.  
/acf-font-awesome-v5.php  
  1. class acf_field_font_awesome extends acf_field { 
  2.  
  3. var $stylesheet, // will hold fontawesome stylesheet url 
  4. $version; // will hold fontawesome version number 
  5.  
  6. /** 
  7. * __construct 
  8. * This function will setup the field type data 
  9. * @type function 
  10. * @date 5/03/2014 
  11. * @since 5.0.0 
  12. * @param n/a 
  13. * @return n/a 
  14. */ 
  15.  
  16. function __construct() {  
  17.  
  18. $this->name = 'font-awesome'; 
  19. $this->label = __('Font Awesome Icon'); 
  20. $this->category = __("Content", 'acf'); // Basic, Content, Choice, etc 
  21. $this->defaults = array( 
  22. 'enqueue_fa' => 0,  
  23. 'allow_null' => 0,  
  24. 'save_format' => 'element',  
  25. 'default_value' => '',  
  26. 'fa_live_preview' => '',  
  27. 'choices' => $this->get_icons() 
  28. ); 
  29. $this->l10n = array(); 
  30.  
  31. $this->settings = array( 
  32. 'path' => dirname(__FILE__),  
  33. 'dir' => $this->helpers_get_dir( __FILE__ ),  
  34. 'version' => '1.5' 
  35. ); 
  36.  
  37. add_filter('acf/load_field', array( $this, 'maybe_enqueue_font_awesome' ) ); 
  38.  
  39. parent::__construct(); 
  40.  
  41. function get_icons() 
  42. require_once ( dirname( __FILE__ ) . '/better-font-awesome-library/better-font-awesome-library.php' ); 
  43.  
  44. $args = array( 
  45. 'version' => 'latest',  
  46. 'minified' => true,  
  47. 'remove_existing_fa' => false,  
  48. 'load_styles' => false,  
  49. 'load_admin_styles' => false,  
  50. 'load_shortcode' => false,  
  51. 'load_tinymce_plugin' => false 
  52. ); 
  53.  
  54. $bfa = Better_Font_Awesome_Library::get_instance( $args ); 
  55. $bfa_icons = $bfa->get_icons(); 
  56. $bfa_prefix = $bfa->get_prefix() . '-'; 
  57. $new_icons = array(); 
  58.  
  59. $this->stylesheet = $bfa->get_stylesheet_url(); 
  60. $this->version = $bfa->get_version(); 
  61.  
  62. foreach ( $bfa_icons as $hex => $class ) { 
  63. $unicode = '&#x' . ltrim( $hex, '\\') . ';'; 
  64. $new_icons[ $bfa_prefix . $class ] = $unicode . ' ' . $bfa_prefix . $class; 
  65.  
  66. $new_icons = array_merge( array( 'null' => '- Select -' ), $new_icons ); 
  67.  
  68. return $new_icons; 
  69.  
  70. /** 
  71. * maybe_enqueue_font_awesome() 
  72. * If Enqueue FA is set to true, enqueue it in the footer. We cannot enqueue in the header because wp_head has already been called 
  73. *  
  74. */ 
  75.  
  76. function maybe_enqueue_font_awesome( $field ) 
  77. if( 'font-awesome' == $field['type'] && $field['enqueue_fa'] ) { 
  78. add_action( 'wp_footer', array( $this, 'frontend_enqueue_scripts' ) ); 
  79.  
  80. return $field; 
  81.  
  82. /** 
  83. * frontend_enqueue_scripts() 
  84. * This action is called in the wp_enqueue_scripts action on the front end. 
  85. *  
  86. * $info http://codex.wordpress.org/Plugin_API/Action_Reference/wp_enqueue_scripts 
  87. * @type action 
  88. */ 
  89.  
  90. function frontend_enqueue_scripts() 
  91. wp_register_style('font-awesome', $this->stylesheet, array(), $this->version); 
  92.  
  93. wp_enqueue_style( array( 'font-awesome' ) ); 
  94.  
  95. /** 
  96. * render_field_settings() 
  97. * Create extra settings for your field. These are visible when editing a field 
  98. * @type action 
  99. * @since 3.6 
  100. * @date 23/01/13 
  101. * @param $field (array) the $field being edited 
  102. * @return n/a 
  103. */ 
  104.  
  105. function render_field_settings( $field ) 
  106. /** 
  107. * acf_render_field_setting 
  108. * This function will create a setting for your field. Simply pass the $field parameter and an array of field settings. 
  109. * The array of settings does not require a `value` or `prefix`; These settings are found from the $field array. 
  110. * More than one setting can be added by copy/paste the above code. 
  111. * Please note that you must also have a matching $defaults value for the field name (font_size) 
  112. */ 
  113.  
  114. acf_render_field_setting( $field, array( 
  115. 'label' => __('Live Preview', 'acf-font-awesome'),  
  116. 'instructions' => '',  
  117. 'type' => 'message',  
  118. 'name' => 'fa_live_preview',  
  119. 'class' => 'live-preview' 
  120. )); 
  121.  
  122. acf_render_field_setting( $field, array( 
  123. 'label' => __('Default Icon', 'acf-font-awesome'),  
  124. 'instructions' => '',  
  125. 'type' => 'select',  
  126. 'name' => 'default_value',  
  127. 'class' => 'fontawesome',  
  128. 'choices' => $field['choices'] 
  129. )); 
  130.  
  131. acf_render_field_setting( $field, array( 
  132. 'label' => __('Return Value', 'acf-font-awesome'),  
  133. 'instructions' => __('Specify the returned value on front end', 'acf-font-awesome'),  
  134. 'type' => 'radio',  
  135. 'name' => 'save_format',  
  136. 'choices' => array( 
  137. 'element' => __('Icon Element', 'acf-font-awesome'),  
  138. 'class' => __('Icon Class', 'acf-font-awesome'),  
  139. 'unicode' => __('Icon Unicode', 'acf-font-awesome'),  
  140. 'object' => __('Icon Object', 'acf-font-awesome'),  
  141. )); 
  142.  
  143. acf_render_field_setting( $field, array( 
  144. 'label' => __('Allow Null?', 'acf-font-awesome'),  
  145. 'instructions' => '',  
  146. 'type' => 'radio',  
  147. 'name' => 'allow_null',  
  148. 'choices' => array( 
  149. 1 => __('Yes', 'acf-font-awesome'),  
  150. 0 => __('No', 'acf-font-awesome') 
  151. )); 
  152.  
  153. acf_render_field_setting( $field, array( 
  154. 'label' => __('Enqueue FontAwesome?', 'acf-font-awesome'),  
  155. 'instructions' => __('Set to \'Yes\' to enqueue FA in the footer on any pages using this field.', 'acf-font-awesome'),  
  156. 'type' => 'radio',  
  157. 'name' => 'enqueue_fa',  
  158. 'choices' => array( 
  159. 1 => __('Yes', 'acf-font-awesome'),  
  160. 0 => __('No', 'acf-font-awesome') 
  161. )); 
  162.  
  163.  
  164. /** 
  165. * render_field() 
  166. * Create the HTML interface for your field 
  167. * @param $field (array) the $field being rendered 
  168. * @type action 
  169. * @since 3.6 
  170. * @date 23/01/13 
  171. * @param $field (array) the $field being edited 
  172. * @return n/a 
  173. */ 
  174.  
  175. function render_field( $field ) 
  176. if( 'object' == $field['save_format'] && 'null' !== $field['value'] ) 
  177. $field['value'] = array( $field['value']->class ); 
  178.  
  179. // value must be array 
  180. if( !is_array($field['value']) ) 
  181. // perhaps this is a default value with new lines in it? 
  182. if( strpos($field['value'], "\n") !== false ) 
  183. // found multiple lines, explode it 
  184. $field['value'] = explode("\n", $field['value']); 
  185. else 
  186. $field['value'] = array( $field['value'] ); 
  187.  
  188. // trim value 
  189. $field['value'] = array_map('trim', $field['value']); 
  190.  
  191. // html 
  192. echo '<div class="fa-field-wrapper">'; 
  193. echo '<div class="fa-live-preview"></div>'; 
  194. echo '<select id="' . $field['id'] . '" class="' . $field['class'] . ' fa-select2-field" name="' . $field['name'] . '" >';  
  195.  
  196. // null 
  197. if( $field['allow_null'] ) 
  198. echo '<option value="null">- ' . __("Select", 'acf') . ' -</option>'; 
  199.  
  200. // loop through values and add them as options 
  201. if( is_array($field['choices']) ) 
  202. unset( $field['choices']['null'] ); 
  203.  
  204. foreach( $field['choices'] as $key => $value ) 
  205. $selected = $this->find_selected( $key, $field['value'], $field['save_format'], $field['choices'] ); 
  206. echo '<option value="'.$key.'" '.$selected.'>'.$value.'</option>'; 
  207.  
  208. echo '</select>'; 
  209. echo '</div>'; 
  210.  
  211. function find_selected( $needle, $haystack, $type, $choices ) 
  212. switch( $type ) 
  213. case 'object': 
  214. case 'element': 
  215. $search = array( '<i class="fa ', '"></i>' ); 
  216. $string = str_replace( $search, '', $haystack[0] ); 
  217. break; 
  218.  
  219. case 'unicode': 
  220. $index = $choices[ $needle ]; 
  221. if ( stristr( $index, $haystack[0] ) ) { 
  222. return 'selected="selected"'; 
  223. return ''; 
  224.  
  225. case 'class': 
  226. $string = $haystack[0]; 
  227. break; 
  228.  
  229. if( $string == $needle ) 
  230. return 'selected="selected"'; 
  231.  
  232. return ''; 
  233.  
  234. /** 
  235. * input_admin_enqueue_scripts() 
  236. * This action is called in the admin_enqueue_scripts action on the edit screen where your field is created. 
  237. * Use this action to add CSS + JavaScript to assist your render_field() action. 
  238. * @type action (admin_enqueue_scripts) 
  239. * @since 3.6 
  240. * @date 23/01/13 
  241. * @param n/a 
  242. * @return n/a 
  243. */ 
  244.  
  245. function input_admin_enqueue_scripts() { 
  246.  
  247. // register acf scripts 
  248. wp_enqueue_script('acf-input-font-awesome-edit-input', $this->settings['dir'] . 'js/edit_input.js', array(), $this->settings['version']); 
  249. wp_enqueue_style('acf-input-font-awesome-input', $this->settings['dir'] . 'css/input.css', array(), $this->settings['version']); 
  250. wp_enqueue_style('acf-input-font-awesome-fa', $this->stylesheet, array(), $this->version); 
  251.  
  252. /** 
  253. * field_group_admin_enqueue_scripts() 
  254. * This action is called in the admin_enqueue_scripts action on the edit screen where your field is edited. 
  255. * Use this action to add CSS + JavaScript to assist your render_field_options() action. 
  256. * @type action (admin_enqueue_scripts) 
  257. * @since 3.6 
  258. * @date 23/01/13 
  259. * @param n/a 
  260. * @return n/a 
  261. */ 
  262.  
  263. function field_group_admin_enqueue_scripts() { 
  264.  
  265. // register acf scripts 
  266. wp_enqueue_script('font-awesome-create-input', $this->settings['dir'] . 'js/create_input.js', array(), $this->settings['version']); 
  267. wp_enqueue_style('acf-input-font-awesome-input', $this->settings['dir'] . 'css/input.css', array(), $this->settings['version']); 
  268. wp_enqueue_style('acf-input-font-awesome-fa', $this->stylesheet, array(), $this->version); 
  269.  
  270. /** 
  271. * load_value() 
  272. * This filter is applied to the $value after it is loaded from the db 
  273. * @type filter 
  274. * @since 3.6 
  275. * @date 23/01/13 
  276. * @param $value (mixed) the value found in the database 
  277. * @param $post_id (mixed) the $post_id from which the value was loaded 
  278. * @param $field (array) the field array holding all the field options 
  279. * @return $value 
  280. */ 
  281.  
  282. function load_value( $value, $post_id, $field ) { 
  283.  
  284. if ( 'null' == $value ) { 
  285. return; 
  286.  
  287. switch( $field['save_format'] ) 
  288. case 'object': 
  289. $icon_unicode_string = $this->defaults['choices'][ $value ]; 
  290. $icon_unicode_arr = explode( ' ', $icon_unicode_string ); 
  291. $icon_unicode = $icon_unicode_arr[0]; 
  292. $value = (object) array( 
  293. 'unicode' => $icon_unicode,  
  294. 'class' => $value,  
  295. 'element' => '<i class="fa ' . $value . '"></i>' 
  296. ); 
  297. break; 
  298.  
  299. case 'unicode': 
  300. $icon_unicode_string = $this->defaults['choices'][ $value ]; 
  301. $icon_unicode_arr = explode( ' ', $icon_unicode_string ); 
  302. $value = $icon_unicode_arr[0]; 
  303. break; 
  304.  
  305. case 'element': 
  306. $value = '<i class="fa ' . $value . '"></i>'; 
  307. break; 
  308.  
  309. return $value; 
  310.  
  311. /** 
  312. * helpers_get_dir() 
  313. * Helper function taken from ACF 4.x to allow finding of asset paths when plugin is included from outside the plugins directory 
  314. */ 
  315.  
  316. function helpers_get_dir( $file ) { 
  317.  
  318. $dir = trailingslashit( dirname( $file ) ); 
  319. $count = 0; 
  320.  
  321. // sanitize for Win32 installs 
  322. $dir = str_replace('\\' , '/', $dir);  
  323.  
  324. // if file is in plugins folder 
  325. $wp_plugin_dir = str_replace( '\\' , '/', WP_PLUGIN_DIR );  
  326. $dir = str_replace( $wp_plugin_dir, plugins_url(), $dir, $count ); 
  327.  
  328. if ( $count < 1 ) { 
  329. // if file is in wp-content folder 
  330. $wp_content_dir = str_replace( '\\' , '/', WP_CONTENT_DIR );  
  331. $dir = str_replace( $wp_content_dir, content_url(), $dir, $count ); 
  332.  
  333. if ( $count < 1 ) { 
  334. // if file is in ??? folder 
  335. $wp_dir = str_replace( '\\' , '/', ABSPATH );  
  336. $dir = str_replace( $wp_dir, site_url( '/' ), $dir ); 
  337.  
  338. return $dir; 
  339.