Skip to content

Commit

Permalink
Update priority tasks in kernel, and avoid error in terms field
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Parziale committed Mar 12, 2020
1 parent e29a56f commit 4c40c9a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
34 changes: 21 additions & 13 deletions Aeria/Field/Fields/TermsField.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
class TermsField extends SelectField
{
protected $original_config;

/**
* Transform the config array; note that this does not operate on
* `$this->config`: this way it can be called from outside
* `$this->config`: this way it can be called from outside.
*
* @param array $config the field's config
* @param array $config the field's config
*
* @return array the transformed config
* @return array the transformed config
*/
public static function transformConfig(array $config) {
public static function transformConfig(array $config)
{
$config['type'] = 'select';

$taxonomy = (isset($config['taxonomy'])) ? $config['taxonomy'] : 'category';
Expand All @@ -34,19 +36,25 @@ public static function transformConfig(array $config) {
'hide_empty' => $hide_empty,
));

$config['options'] = array_map(
function ($term) {
return array(
'label' => $term->name,
'value' => $term->term_id,
);
},
array_values($terms)
);
$config['options'] = [];

if (!empty($terms) && !is_wp_error($terms)) {
$config['options'] = array_map(
function ($term) {
return array(
'label' => $term->name,
'value' => $term->term_id,
);
},
array_values($terms)
);
}

unset($config['taxonomy']);

return parent::transformConfig($config);
}

/**
* Constructs the field.
*
Expand Down
16 changes: 7 additions & 9 deletions Aeria/Kernel/Tasks/CreateTaxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,24 @@

/**
* This task is in charge of creating the taxonomies.
*
*
* @category Kernel
* @package Aeria
*
* @author Simone Montali <simone.montali@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 CreateTaxonomy extends Task
{
public $priority = 3;
public $priority = 1;
public $admin_only = false;

/**
* The main task method. It registers the needed taxonomies.
*
* @param array $args the arguments to be passed to the Task
*
* @return void
*
* @access public
* @since Method available since Release 3.0.0
*/
public function do(array $args)
Expand All @@ -40,5 +39,4 @@ public function do(array $args)
}
}
}

}
}

0 comments on commit 4c40c9a

Please sign in to comment.