acf_field_generous_slider

The Advanced Custom Fields: Generous acf field generous slider class.

Defined (2)

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

/v5/acf-generous-slider.php  
  1. class acf_field_generous_slider extends acf_field { 
  2.  
  3. /** 
  4. * The id of the field. 
  5. * @since 5.0.0 
  6. * @var array $name Single word, no spaces. 
  7. */ 
  8. var $name; 
  9.  
  10. /** 
  11. * The label for the field. 
  12. * @since 5.0.0 
  13. * @var string $label Visible when selecting a field type. 
  14. */ 
  15. var $label; 
  16.  
  17. /** 
  18. * The type of ACF field. 
  19. * @since 5.0.0 
  20. * @var string $category basic|content|choice|relational|layout|custom 
  21. */ 
  22. var $category; 
  23.  
  24. /** 
  25. * Default settings which are merged into the field object. 
  26. * @since 5.0.0 
  27. * @var array $defaults The defaults for the field. 
  28. */ 
  29. var $defaults; 
  30.  
  31. /** 
  32. * Array of strings that are used in JavaScript. This allows JS strings 
  33. * to be translated in PHP and loaded via: 
  34. * var message = acf._e('generous_slider', 'error'); 
  35. * @since 5.0.0 
  36. * @var array $l10n The defaults for the field. 
  37. */ 
  38. var $l10n; 
  39.  
  40. /** 
  41. * Initialize the class. 
  42. * Setup the field type data. 
  43. * @since 5.0.0 
  44. */ 
  45. function __construct() { 
  46. $this->name = 'generous_slider'; 
  47. $this->label = __( 'Generous Slider', 'acf-generous_slider' ); 
  48. $this->category = 'basic'; 
  49. $this->defaults = array(); 
  50. $this->l10n = array(); 
  51.  
  52. parent::__construct(); 
  53.  
  54. /** 
  55. * Creates the HTML interface for the field 
  56. * @since 3.6 
  57. * @param array $field The field array holding all the field options. 
  58. */ 
  59. function render_field( $field ) { 
  60.  
  61. global $wp_plugin_generous; 
  62.  
  63. $options = $wp_plugin_generous->get_options(); 
  64.  
  65. if ( isset( $options['username'] ) && $options['username'] !== '') { 
  66.  
  67. $field_id = ''; 
  68. $field_title = ''; 
  69.  
  70. if ( isset( $field['value'], $field['value']['id'] ) ) { 
  71. $field_id = $field['value']['id']; 
  72.  
  73. if ( isset( $field['value']['title'] ) ) { 
  74. $field_title = $field['value']['title']; 
  75.  
  76. $prefix = 'acf-generous-slider--search'; 
  77.  
  78. echo "<input type=\"text\" name=\"{$field['name']}[title]\" class=\"{$prefix}-input-title\" value=\"" . htmlspecialchars( $field_title ) . "\" />"; 
  79. echo "<input type=\"hidden\" name=\"{$field['name']}[id]\" class=\"{$prefix}-input-id\" value=\"{$field_id}\" />"; 
  80. echo "<input type=\"hidden\" class=\"{$prefix}-account\" value=\"{$options['username']}\" />"; 
  81.  
  82. echo "<div class=\"{$prefix}-results\"></div>"; 
  83.  
  84. } else { 
  85.  
  86. echo "<span>Generous username not found. Check plugin settings.</span>"; 
  87.  
  88.  
  89.  
  90. /** 
  91. * This action is called in the admin_enqueue_scripts action on the edit 
  92. * screen where your field is created. Use this action to add CSS + JavaScript 
  93. * to assist your create_field() action. 
  94. * Info: http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts 
  95. * @since 3.6 
  96. */ 
  97. function input_admin_enqueue_scripts() { 
  98.  
  99. $dir = plugin_dir_url( dirname( __FILE__ ) ); 
  100.  
  101. wp_register_script( 'acf-input-generous_slider', "{$dir}assets/js/input.js" ); 
  102. wp_register_style( 'acf-input-generous_slider', "{$dir}assets/css/input.css" ); 
  103.  
  104. wp_enqueue_script('acf-input-generous_slider'); 
  105. wp_enqueue_style('acf-input-generous_slider'); 
  106.  
  107.  
  108.  
  109. /** 
  110. * Updates the value for the database. 
  111. * This filter is applied to the $value before it is updated in the db. 
  112. * @since 3.6 
  113. * @param array $value The value which will be saved in the database. 
  114. * @param int $post_id The $post_id of which the value will be saved. 
  115. * @param array $field The field array holding all the field options. 
  116. * @return array $value The modified value. 
  117. */ 
  118. function update_value( $value, $post_id, $field ) { 
  119.  
  120. if ( '' === $value['id'] ) { 
  121. $value = false; 
  122.  
  123. return $value; 
  124.  
  125. /** 
  126. * Validates the value prior to saving to database. 
  127. * This filter is used to perform validation on the value prior to saving. 
  128. * All values are validated regardless of the field's required setting. This 
  129. * allows you to validate and return messages to the user if the value is not correct. 
  130. * @since 5.0 
  131. * @param bool $valid Validation status based on the value and the fields required setting. 
  132. * @param mixed $value The $_POST value. 
  133. * @param array $field The field array holding all the field options. 
  134. * @param string $input The corresponding input name for $_POST value 
  135. * @return bool $value If values are valid. 
  136. */ 
  137. function validate_value( $valid, $value, $field, $input ) { 
  138. if( '' === $value['id'] ) { 
  139. $valid = false; 
  140.  
  141. return $valid; 
  142.  
  143. /** 
  144. * Formats the value for the frontend. 
  145. * This filter is applied to the $value after it is loaded from the db and 
  146. * before it is passed back to the API functions such as the_field. 
  147. * @since 3.6 
  148. * @param array $value The value which will be saved in the database. 
  149. * @param int $post_id The $post_id of which the value will be saved. 
  150. * @param array $field The field array holding all the field options. 
  151. * @return array $value The modified value. 
  152. */ 
  153. function format_value( $value, $post_id, $field ) { 
  154. if ( isset( $value['id'] ) ) { 
  155. $api = new WP_Generous_Api(); 
  156. return $api->get_slider( $value['id'] ); 
  157. } else { 
  158. return false; 
  159.  
/v4/acf-generous-slider.php  
  1. class acf_field_generous_slider extends acf_field { 
  2.  
  3. /** 
  4. * The id of the field. 
  5. * @since 3.6 
  6. * @var array $name Single word, no spaces. 
  7. */ 
  8. var $name; 
  9.  
  10. /** 
  11. * The label for the field. 
  12. * @since 3.6 
  13. * @var string $label Visible when selecting a field type. 
  14. */ 
  15. var $label; 
  16.  
  17. /** 
  18. * The type of ACF field. 
  19. * @since 3.6 
  20. * @var string $category Basic|Content|Choice|Relational|Layout 
  21. */ 
  22. var $category; 
  23.  
  24. /** 
  25. * The settings for the field. 
  26. * @since 3.6 
  27. * @var array $settings The settings for the field. 
  28. */ 
  29. var $settings; 
  30.  
  31. /** 
  32. * Default settings which are merged into the field object. 
  33. * @since 3.6 
  34. * @var array $defaults The defaults for the field. 
  35. */ 
  36. var $defaults; 
  37.  
  38. /** 
  39. * Initialize the class. 
  40. * Set name, label needed for actions, filters. 
  41. * @since 3.6 
  42. */ 
  43. function __construct() { 
  44. $this->name = 'generous_slider'; 
  45. $this->label = __( 'Generous Slider'); 
  46. $this->category = __( 'Basic', 'acf' ); 
  47. $this->defaults = array(); 
  48. $this->settings = array( 
  49. 'path' => apply_filters( 'acf/helpers/get_path', __FILE__ ),  
  50. 'dir' => apply_filters( 'acf/helpers/get_dir', __FILE__ ),  
  51. 'version' => '0.1.0' 
  52. ); 
  53.  
  54. parent::__construct(); 
  55.  
  56. /** 
  57. * Create extra options for your field. This is rendered when editing a field. 
  58. * The value of $field['name'] can be used (like below) to save extra data to the $field 
  59. * @since 3.6 
  60. * @param array $field The field array holding all the field options. 
  61. */ 
  62. function create_options( $field ) { 
  63. $key = $field['name']; 
  64.  
  65. /** 
  66. * Creates the HTML interface for the field 
  67. * @since 3.6 
  68. * @param array $field The field array holding all the field options. 
  69. */ 
  70. function create_field( $field ) { 
  71.  
  72. global $wp_plugin_generous; 
  73.  
  74. $options = $wp_plugin_generous->get_options(); 
  75.  
  76. if( isset( $options['username'] ) && $options['username'] !== '') { 
  77.  
  78. $field_id = ''; 
  79. $field_title = ''; 
  80.  
  81. if ( isset( $field['value'], $field['value']['id'] ) ) { 
  82. $field_id = $field['value']['id']; 
  83.  
  84. if ( isset( $field['value']['title'] ) ) { 
  85. $field_title = $field['value']['title']; 
  86.  
  87. $prefix = 'acf-generous-slider--search'; 
  88.  
  89. echo "<input type=\"text\" name=\"{$field['name']}[title]\" class=\"{$prefix}-input-title\" value=\"" . htmlspecialchars( $field_title ) . "\" />"; 
  90. echo "<input type=\"hidden\" name=\"{$field['name']}[id]\" class=\"{$prefix}-input-id\" value=\"{$field_id}\" />"; 
  91. echo "<input type=\"hidden\" class=\"{$prefix}-account\" value=\"{$options['username']}\" />"; 
  92.  
  93. echo "<div class=\"{$prefix}-results\"></div>"; 
  94.  
  95. } else { 
  96.  
  97. echo "<span>Generous username not found. Check plugin settings.</span>"; 
  98.  
  99.  
  100.  
  101. /** 
  102. * This action is called in the admin_enqueue_scripts action on the edit 
  103. * screen where your field is created. Use this action to add CSS + JavaScript 
  104. * to assist your create_field() action. 
  105. * Info: http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts 
  106. * @since 3.6 
  107. */ 
  108. function input_admin_enqueue_scripts() { 
  109.  
  110. wp_register_script( 'acf-input-generous_slider', plugin_dir_url( dirname( __FILE__ ) ) . 'assets/js/input.js', array('acf-input'), $this->settings['version'] ); 
  111. wp_register_style( 'acf-input-generous_slider', plugin_dir_url( dirname( __FILE__ ) ) . 'assets/css/input.css', array('acf-input'), $this->settings['version'] );  
  112.  
  113. wp_enqueue_script(array( 
  114. 'acf-input-generous_slider',  
  115. )); 
  116.  
  117. wp_enqueue_style(array( 
  118. 'acf-input-generous_slider',  
  119. )); 
  120.  
  121.  
  122. /** 
  123. * This action is called in the admin_head action on the edit screen where 
  124. * your field is created. Use this action to add CSS and JavaScript to assist 
  125. * your create_field() action. 
  126. * Info: http://codex.wordpress.org/Plugin_API/Action_Reference/admin_head 
  127. * @since 3.6 
  128. */ 
  129. function input_admin_head() { 
  130. // Note: This function can be removed if not used 
  131.  
  132. /** 
  133. * This action is called in the admin_enqueue_scripts action on the edit 
  134. * screen where your field is edited. Use this action to add CSS + JavaScript 
  135. * to assist your create_field_options() action. 
  136. * Info: http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts 
  137. * @since 3.6 
  138. */ 
  139. function field_group_admin_enqueue_scripts() { 
  140. // Note: This function can be removed if not used 
  141.  
  142. /** 
  143. * This action is called in the admin_head action on the edit screen where 
  144. * your field is edited. Use this action to add CSS and JavaScript to assist 
  145. * your create_field_options() action. 
  146. * Info: http://codex.wordpress.org/Plugin_API/Action_Reference/admin_head 
  147. * @since 3.6 
  148. */ 
  149. function field_group_admin_head() { 
  150. // Note: This function can be removed if not used 
  151.  
  152. /** 
  153. * Loads the value after the database. 
  154. * This filter is applied to the $value after it is loaded from the db. 
  155. * @since 3.6 
  156. * @param array $value The value found in the database. 
  157. * @param int $post_id The $post_id from which the value was loaded. 
  158. * @param array $field The field array holding all the field options. 
  159. * @return array|false $value The new value with slider data, or false. 
  160. */ 
  161. function load_value( $value, $post_id, $field ) { 
  162. return $value; 
  163.  
  164. /** 
  165. * Updates the value for the database. 
  166. * This filter is applied to the $value before it is updated in the db. 
  167. * @since 3.6 
  168. * @param array $value The value which will be saved in the database. 
  169. * @param int $post_id The $post_id of which the value will be saved. 
  170. * @param array $field The field array holding all the field options. 
  171. * @return array $value The modified value. 
  172. */ 
  173. function update_value( $value, $post_id, $field ) { 
  174. if ( '' === $value['id'] ) { 
  175. $value = false; 
  176.  
  177. return $value; 
  178.  
  179. /** 
  180. * Formats the value before the field is created in the admin. 
  181. * This filter is applied to the $value after it is loaded from the db and 
  182. * before it is passed to the create_field action. 
  183. * @since 3.6 
  184. * @param array $value The value which will be saved in the database. 
  185. * @param int $post_id The $post_id of which the value will be saved. 
  186. * @param array $field The field array holding all the field options. 
  187. * @return array $value The modified value. 
  188. */ 
  189. function format_value( $value, $post_id, $field ) { 
  190. return $value; 
  191.  
  192. /** 
  193. * Formats the value for the frontend. 
  194. * This filter is applied to the $value after it is loaded from the db and 
  195. * before it is passed back to the API functions such as the_field. 
  196. * @since 3.6 
  197. * @param array $value The value which will be saved in the database. 
  198. * @param int $post_id The $post_id of which the value will be saved. 
  199. * @param array $field The field array holding all the field options. 
  200. * @return array $value The modified value. 
  201. */ 
  202. function format_value_for_api( $value, $post_id, $field ) { 
  203. if ( isset( $value['id'] ) ) { 
  204. $api = new WP_Generous_Api(); 
  205. return $api->get_slider( $value['id'] ); 
  206. } else { 
  207. return false; 
  208.  
  209. /** 
  210. * Updates the field after it is loaded from the database. 
  211. * This filter is applied to the $field after it is loaded from the database. 
  212. * @since 3.6 
  213. * @param array $field The field array holding all the field options. 
  214. * @return array $field The modified field. 
  215. */ 
  216. function load_field( $field ) { 
  217. return $field; 
  218.  
  219. /** 
  220. * Updates the field before it's saved to the database. 
  221. * This filter is applied to the $field before it is saved to the database. 
  222. * @since 3.6 
  223. * @param array $field The field array holding all the field options. 
  224. * @param int $post_id The field group ID (post_type = acf). 
  225. * @return array $field The modified field. 
  226. */ 
  227. function update_field( $field, $post_id ) { 
  228. return $field; 
  229.