Skip to content

Commit

Permalink
Merge branch 'release/v1.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
folbert committed Mar 19, 2017
2 parents 64a2288 + f6a1dc6 commit f6eea50
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"!
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions fewbricks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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';
Expand Down
58 changes: 56 additions & 2 deletions lib/brick.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

}

}

0 comments on commit f6eea50

Please sign in to comment.