diff --git a/README.md b/README.md index bf98d55..468a148 100644 --- a/README.md +++ b/README.md @@ -252,6 +252,8 @@ Each brick has its own class placed in the folder named "bricks". Each class hav Including external files like in i and ii will have some minor impact on performance but if you feel that having the HTML in an external file is the way to go, go ahead. The `get_field()`-function being used is a wrapper function for ACFs own `get_field()` which takes care of adding any needed prefixes to get the value. Note that we are using the name values that we set when adding fields under step 3 above. + + We have also added the function `get_field_values()` to the main brick class. It enables you to pass an array of field names and get an array with the values back in return. #### Is that all Fewbricks can do? Nope. Like we said, you can create flexible content, repeaters, bricks incorporating other bricks and also create field groups on the fly. For more on how to do this, check the files in the directories "field-groups", "demo", "bricks" and "brick-layouts". Don't miss the brick named "demo-flexible-brick"! diff --git a/changelog.md b/changelog.md index 45eeec4..e6b6201 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,10 @@ # Fewbricks changelog +## 1.6 - March 19, 2017 +* Added function `get_field_values()`to `brick` +* Added function `get_get_html_arg()` to `brick` +* Added ability to pass $post_id to `have_rows()` in `brick` + ## 1.5.1 - February 13, 2017 * Changed name on filter for project files base path diff --git a/fewbricks.php b/fewbricks.php index 7c56e04..7cd6906 100644 --- a/fewbricks.php +++ b/fewbricks.php @@ -5,7 +5,7 @@ Plugin URI: https://github.com/fewagency/fewbricks Description: A module extension to Advanced Custom Fields Author: Björn Folbert -Version: 1.5.1 +Version: 1.6 Author URI: http://folbert.com License: GPLv3 */ @@ -31,7 +31,7 @@ add_action('init', function() { // set auto-update params - $plugin_current_version = '1.5.1'; + $plugin_current_version = '1.6'; $plugin_remote_path = 'http://fewbricks.folbert.com/update/update.php'; $plugin_slug = plugin_basename(__FILE__); $license_user = 'null'; diff --git a/lib/brick.php b/lib/brick.php index ddd8738..fe4b4ca 100644 --- a/lib/brick.php +++ b/lib/brick.php @@ -466,12 +466,17 @@ protected function get_field($data_name, $post_id = false, $prepend_this_name = /** * Wrapper function for ACFs have_rows() * @param $name + * @param bool $post_id Specific post ID where your value was entered. + * Defaults to current post ID (not required). This can also be options / taxonomies / users / etc + * See https://www.advancedcustomfields.com/resources/have_rows/ * @return bool */ - protected function have_rows($name) + protected function have_rows($name, $post_id = false) { - if ($this->is_option) { + if($post_id !== false) { + $outcome = have_rows($this->name . '_' . $name, $post_id); + } elseif ($this->is_option) { $outcome = have_rows($this->get_data_name('_' . $name), 'option'); } else { $outcome = have_rows($this->name . '_' . $name); @@ -1131,4 +1136,53 @@ protected function create_sub_brick_object($sub_brick_name, $name_setting) } + /** + * Get multiple field values in one function call. Pass an array where each item can be either: + * - a field name + * - an array where the index is the field name and the value is the name you want to store the value + * in in the returned array: ['field_name_1', 'field_name_2', ['field_name_3' => 'name_to_save_as']] + * @param array $field_names + * @return array + */ + public function get_field_values($field_names) + { + + $values = []; + + foreach($field_names AS $field_name) { + + if(is_array($field_name)) { + $key = key($field_name); + $values[$field_name[$key]] = $this->get_field($key); + } else { + $values[$field_name] = $this->get_field($field_name); + } + } + + return $values; + + } + + /** + * Get value of html_arg. + * @param $name + * @param bool $default_value Value to return if the arg has not been set + * @return bool + */ + public function get_get_html_arg($name, $default_value = false) { + + if(isset($this->get_html_args[$name])) { + + $outcome = $this->get_html_args[$name]; + + } else { + + $outcome = $default_value; + + } + + return $outcome; + + } + } \ No newline at end of file