Skip to content

Commit

Permalink
Enable ctaLabel option in repeater field - Version bump to 3.0.16
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Parziale committed Nov 18, 2019
1 parent 88d2f1f commit 764ce53
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 63 deletions.
2 changes: 1 addition & 1 deletion Aeria/Aeria.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
class Aeria extends Container
{
public const VERSION = '3.0.15';
public const VERSION = '3.0.16';
/**
* Constructs the Aeria container
*
Expand Down
109 changes: 55 additions & 54 deletions Aeria/Meta/Meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,48 @@
use Aeria\Config\Traits\ValidateConfTrait;
use Aeria\Container\Interfaces\ValidateConfInterface;
use Aeria\Field\FieldError;
use Aeria\Meta\MetaProcessor;
use Aeria\RenderEngine\RenderEngine;

/**
* Meta is in charge of creating, saving and rendering metaboxes
* Meta is in charge of creating, saving and rendering metaboxes.
*
* @category Meta
* @package Aeria
*
* @author Jacopo Martinelli <jacopo.martinelli@caffeina.com>
* @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license
* @link https://github.com/caffeinalab/aeria
*
* @see https://github.com/caffeinalab/aeria
*/
class Meta implements ValidateConfInterface
{
use ValidateConfTrait;
protected $sections;

/**
* Returns a validation structure for meta configs
* Returns a validation structure for meta configs.
*
* @return array the validation structure
*
* @access public
* @since Method available since Release 3.0.0
*/
public function getValidationStructure() : array
public function getValidationStructure(): array
{
return [
'id' => $this->makeRegExValidator(
"/^[a-z0-9_-]{1,20}$/"
)
'/^[a-z0-9_-]{1,20}$/'
),
];
}

/**
* Creates the requested metaboxes
* Creates the requested metaboxes.
*
* @param array $config the Meta configs
* @param array $config the Meta configs
* @param array $sections the sections configuration
* @param RenderEngine $render_service the service in charge of rendering HTML
*
* @return array the field's values, an array containing the gallery's children
*
* @access public
* @since Method available since Release 3.0.0
*/
public function create($config, $sections, $render_service)
Expand All @@ -58,46 +59,45 @@ public function create($config, $sections, $render_service)
$priority = isset($config['priority']) ? $config['priority'] : 'default';
$templates = isset($config['templates']) ? $config['templates'] : [];

if(isset($config['post_type']) && count($config['post_type']) === 0){
$post_types = false;
} else if (!isset($config['post_type'])){
$post_types = 'post';
if (isset($config['post_type']) && count($config['post_type']) === 0) {
$post_types = false;
} elseif (!isset($config['post_type'])) {
$post_types = 'post';
} else {
$post_types = $config['post_type'];
$post_types = $config['post_type'];
}
if($post_types !== false){
add_meta_box(
'aeria-' . $config['id'],
if ($post_types !== false) {
add_meta_box(
'aeria-'.$config['id'],
$config['title'],
Meta::class . '::renderHTML',
Meta::class.'::renderHTML',
$post_types,
$context,
$priority,
["config" => $config,"sections"=> $sections, "render_service" => $render_service]
['config' => $config, 'sections' => $sections, 'render_service' => $render_service]
);
}

if (!isset($wp_meta_boxes[get_post_type()][$context][$priority]['aeria-' . $config['id']]) && in_array(get_page_template_slug(), $templates)){
add_meta_box(
'aeria-' . $config['id'],
if (!isset($wp_meta_boxes[get_post_type()][$context][$priority]['aeria-'.$config['id']]) && in_array(get_page_template_slug(), $templates)) {
add_meta_box(
'aeria-'.$config['id'],
$config['title'],
Meta::class . '::renderHTML',
Meta::class.'::renderHTML',
get_post_type(),
$context,
$priority,
["config" => $config,"sections"=> $sections, "render_service" => $render_service]
['config' => $config, 'sections' => $sections, 'render_service' => $render_service]
);
}
}

/**
* Validates the meta configuration
* Validates the meta configuration.
*
* @param array $conf the Meta configuration to validate
*
* @return void
* @throws ConfigValidationException in case of an invalid config
*
* @access private
* @since Method available since Release 3.0.0
*/
private function validate($conf)
Expand All @@ -107,80 +107,79 @@ private function validate($conf)
throw $exception;
}
}

/**
* Returns the required fields to get a WP nonce
* Returns the required fields to get a WP nonce.
*
* @param WP_Post $post current post object
*
* @return array the nonce fields
*
* @access private
* @since Method available since Release 3.0.0
*/
private static function nonceIDs($post)
{
return [
'action' => 'update-'.basename(__FILE__).$post->ID,
'field' => 'update_aeria_meta'
'field' => 'update_aeria_meta',
];
}

/**
* Calls the render service to render HTML
* Calls the render service to render HTML.
*
* @param WP_Post $post the current post object
* @param WP_Post $post the current post object
* @param array $extra other required data to render HTML
*
* @return void
*
* @access public
* @static
*
* @since Method available since Release 3.0.0
*/
static function renderHTML($post, $extra)
public static function renderHTML($post, $extra)
{
$metabox = $extra["args"]["config"];
$sections = $extra["args"]["sections"];
$render_service = $extra["args"]["render_service"];
$metabox = $extra['args']['config'];
$sections = $extra['args']['sections'];
$render_service = $extra['args']['render_service'];
$nonceIDs = static::nonceIDs($post);
wp_nonce_field($nonceIDs['action'], $nonceIDs['field']);
$processor = new MetaProcessor($post->ID, $metabox, $sections, $render_service);
$metabox["fields"] = $processor->getAdmin();
?>
$metabox['fields'] = $processor->getAdmin(); ?>
<!-- <pre>
<?php var_dump($processor->get()); ?>
</pre> -->
<?php
$render_service->render(
'meta_template',
[
"metabox" => $metabox
'metabox' => $metabox,
]
);
}

/**
* Saves the new metadata to WP
* Saves the new metadata to WP.
*
* @param array $metabox the metabox configuration
* @param array $new_values the values fetched from $_POST
* @param Validator $validator_service the validation service for fields
* @param Query $query_service the required query service
* @param array $sections the sections configuration
*
* @return void
* @throws ConfigValidationException in case of an invalid config
*
* @access public
* @since Method available since Release 3.0.0
*/
public static function save($metabox, $new_values, $validator_service, $query_service, $sections, $render_service)
public static function save($metabox, $new_values, $validator_service, $query_service, $sections, $render_service)
{
return function ($post_id,$post) use ($metabox, $new_values, $validator_service, $query_service, $sections, $render_service) {
return function ($post_id, $post) use ($metabox, $new_values, $validator_service, $query_service, $sections, $render_service) {
$postTypes = isset($metabox['post_type']) ? $metabox['post_type'] : [];
$templates = isset($metabox['templates']) ? $metabox['templates'] : [];
$context = isset($metabox['context']) ? $metabox['context'] : 'advanced';
$priority = isset($metabox['priority']) ? $metabox['priority'] : 'default';
// Since this function is triggered when a post is created too, I'm gonna skip it in that case. I'm gonna skip it even if the post_Type is not supported.
if ($new_values==[]
|| !(in_array($post->post_type, $metabox["post_type"]) || in_array(get_page_template_slug(), $templates))
if ($new_values == []
|| !(in_array($post->post_type, $postTypes) || in_array(get_page_template_slug(), $templates))
|| !isset($new_values['update_aeria_meta'])
) {
return $post_id;
Expand All @@ -190,11 +189,13 @@ public static function save($metabox, $new_values, $validator_service, $query_s
$post_type_object = get_post_type_object($new_values['post_type']);
// TODO: Check if current post type is supported: in the 1.0, the supported fields were hardcoded to ['post']
if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
|| (empty($new_values['post_ID']) || empty($new_values['post_type']))
|| (empty($new_values['post_ID']) || empty($new_values['post_type']))
|| (!isset($new_values['post_ID']) || $post_id != $new_values['post_ID'])
|| (!check_admin_referer($nonceIDs['action'], $nonceIDs['field']))
|| (!current_user_can($post_type_object->cap->edit_post, $post_id))
) return $post_id;
) {
return $post_id;
}

$processor = new MetaProcessor($post_id, $metabox, $sections, $render_service, $new_values);
$processor->set(
Expand All @@ -203,7 +204,7 @@ public static function save($metabox, $new_values, $validator_service, $query_s
);

FieldError::make($post_id)
->saveTransient($post_id."-errors");
->saveTransient($post_id.'-errors');
};
}
}
10 changes: 5 additions & 5 deletions Aeria/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ function get_aeria_fields($post)
$metabox = array_merge(
['id' => $name],
$data
);
if ($post->post_type !== 'page' && !in_array($post->post_type, $metabox['post_type'])) {
continue;
}
if ($post->post_type === 'page' && !in_array(get_page_template_slug($post), $metabox['templates'])) {
);
$postTypes = isset($metabox['post_type']) ? $metabox['post_type'] : [];
$templates = isset($metabox['templates']) ? $metabox['templates'] : [];

if (!in_array($post->post_type, $postTypes) && !in_array(get_page_template_slug($post), $templates)) {
continue;
}
$processor = new MetaProcessor($post->ID, $metabox, $sections, $render_service);
Expand Down
2 changes: 1 addition & 1 deletion aeria.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Plugin Name: Aeria
* Plugin URI: https://github.com/caffeinalab/aeria
* Description: Aeria is a modular, lightweight, fast WordPress Application development kit.
* Version: 3.0.15
* Version: 3.0.16
* Author: Caffeina
* Author URI: https://caffeina.com
* Text Domain: aeria
Expand Down
2 changes: 1 addition & 1 deletion assets/js/aeria-editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/aeria.js

Large diffs are not rendered by default.

0 comments on commit 764ce53

Please sign in to comment.