diff --git a/Aeria/Aeria.php b/Aeria/Aeria.php index 67152ef..cb66378 100755 --- a/Aeria/Aeria.php +++ b/Aeria/Aeria.php @@ -33,7 +33,7 @@ */ class Aeria extends Container { - public const VERSION = '3.0.6'; + public const VERSION = '3.0.7'; /** * Constructs the Aeria container * diff --git a/Aeria/Field/Fields/PostTypesField.php b/Aeria/Field/Fields/PostTypesField.php new file mode 100644 index 0000000..9bdd2af --- /dev/null +++ b/Aeria/Field/Fields/PostTypesField.php @@ -0,0 +1,57 @@ + + * @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license + * @link https://github.com/caffeinalab/aeria + */ +class PostTypesField extends SelectField +{ + + protected $original_config; + /** + * Constructs the field + * + * @param string $parent_key the field's parent key + * @param array $config the field's config + * @param array $sections Aeria's sections config + * @param array $index index for of the subfield + * + * @return void + * + * @access public + * @since Method available since Release 3.0.7 + */ + public function __construct($parent_key, $config, $sections, $index = null) { + parent::__construct($parent_key, $config, $sections, $index); + + $this->original_config = json_decode(json_encode($config)); + + $this->config['type'] = 'select'; + + $this->config['options'] = [ + array( 'label' => 'page', 'value' => 'page'), + array( 'label' => 'post', 'value' => 'post'), + ]; + + $post_types = get_post_types(array( + 'public' => true, + '_builtin' => false + )); + + $this->config['options'] = array_merge( + $this->config['options'], + array_map( function ($post_type) { + return array( 'label' => $post_type, 'value' => $post_type); + }, array_values($post_types) ) + ); + } +} diff --git a/Aeria/Kernel/Tasks/CreateField.php b/Aeria/Kernel/Tasks/CreateField.php index 686271e..510ec33 100644 --- a/Aeria/Kernel/Tasks/CreateField.php +++ b/Aeria/Kernel/Tasks/CreateField.php @@ -5,7 +5,7 @@ use Aeria\Kernel\AbstractClasses\Task; /** * This task is in charge of creating fields. - * + * * @category Kernel * @package Aeria * @author Simone Montali @@ -36,6 +36,7 @@ public function do(array $args) $args['service']['field']->register('select', \Aeria\Field\Fields\SelectField::class); $args['service']['field']->register('switch', \Aeria\Field\Fields\SwitchField::class); $args['service']['field']->register('relation', \Aeria\Field\Fields\RelationField::class); + $args['service']['field']->register('post_types', \Aeria\Field\Fields\PostTypesField::class); $args['service']['field']->register('maps', \Aeria\Field\Fields\MapField::class); $args['service']['field']->register('daterange', \Aeria\Field\Fields\DateRangeField::class); // example of multiple registered fields with the same handler; not diff --git a/aeria.php b/aeria.php index 2d87737..51ca77d 100755 --- a/aeria.php +++ b/aeria.php @@ -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.6 + * Version: 3.0.7 * Author: Caffeina * Author URI: https://caffeina.com * Text Domain: aeria