Skip to content

Commit

Permalink
Update option page generation & add a new api route /terms - Version …
Browse files Browse the repository at this point in the history
…bump to 3.0.6
  • Loading branch information
Alberto Parziale committed Oct 14, 2019
1 parent 087ad83 commit 3d97101
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 34 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.5';
public const VERSION = '3.0.6';
/**
* Constructs the Aeria container
*
Expand Down
4 changes: 3 additions & 1 deletion Aeria/Kernel/ServiceProviders/KernelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Aeria\Taxonomy\Taxonomy;
use Aeria\Kernel\Loader;
use Aeria\Kernel\Tasks\{
CreateAdminScripts,
CreateControllers,
CreateField,
CreateMeta,
Expand All @@ -23,7 +24,7 @@

/**
* KernelServiceProvider is in charge of registering the Kernel to the container
*
*
* @category Kernel
* @package Aeria
* @author Jacopo Martinelli <[email protected]>
Expand Down Expand Up @@ -63,6 +64,7 @@ public function boot(Container $container): bool
$kernel = $container->make('kernel');
$config = $container->make('config');
Loader::loadConfig($config, $container);
$kernel->register(new CreateAdminScripts());
$kernel->register(new CreateControllers());
$kernel->register(new CreateField());
$kernel->register(new CreateMeta());
Expand Down
42 changes: 42 additions & 0 deletions Aeria/Kernel/Tasks/CreateAdminScripts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Aeria\Kernel\Tasks;

use Aeria\Kernel\AbstractClasses\Task;

/**
* This task is in charge of creating options pages.
*
* @category Kernel
* @package Aeria
* @author Simone Montali <[email protected]>
* @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license
* @link https://github.com/caffeinalab/aeria
*/
class CreateAdminScripts extends Task
{
public $priority = 6;
public $admin_only = true;
/**
* The main task method. It registers the option pages.
*
* @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)
{
add_action(
'admin_head',
function () use ($args) {
global $_wp_admin_css_colors;
$admin_colors = $_wp_admin_css_colors;
$aeria_colors = $admin_colors[get_user_option('admin_color')]->colors;
$args['service']['render_engine']->render('color_encoder_template', ['colors' => $aeria_colors]);
}
);
}
}
6 changes: 3 additions & 3 deletions Aeria/Kernel/Tasks/CreateOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
* This task is in charge of creating options pages.
*
*
* @category Kernel
* @package Aeria
* @author Simone Montali <[email protected]>
Expand All @@ -32,7 +32,7 @@ public function do(array $args)
$default_icon_data = file_get_contents(dirname(__DIR__, 2).'/aeria.svg');
$default_icon = 'data:image/svg+xml;base64,'.base64_encode($default_icon_data);
if (isset($args['config']['aeria']['options'])) {
$section_config = isset($args['config']['aeria']['section']) ? $args['config']['aeria']['section'] : null;
$section_config = isset($args['config']['aeria']['section']) ? $args['config']['aeria']['section'] : [];

foreach ($args['config']['aeria']['options'] as $name => $data) {
$config =[];
Expand Down Expand Up @@ -65,4 +65,4 @@ function () use ($args) {
);
}

}
}
11 changes: 9 additions & 2 deletions Aeria/Kernel/Tasks/CreateRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

/**
* This task is in charge of creating the router and its routes.
*
*
* @category Kernel
* @package Aeria
* @author Simone Montali <[email protected]>
Expand Down Expand Up @@ -55,6 +55,13 @@ public function do(array $args)
return $args['service']['query']->getTaxonomies($wp_req->get_params());
}
);
$args['service']['router']->get(
'/terms', function ($request) use ($args) {
$wp_req = $request->wp_request;

return $args['service']['query']->getTerms($wp_req->get_params());
}
);
$args['service']['router']->get(
"/validate-by-id", function ($request) use ($args) {
$wp_req = $request->wp_request;
Expand All @@ -74,4 +81,4 @@ public function do(array $args)
}
$args['service']['router']->boot();
}
}
}
42 changes: 22 additions & 20 deletions Aeria/OptionsPage/OptionsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use Aeria\Field\FieldError;
use Aeria\RenderEngine\RenderEngine;
/**
* OptionsPage is in charge of generating pages in WP's options
*
* OptionsPage is in charge of generating pages in WP's options
*
* @category Options
* @package Aeria
* @author Simone Montali <[email protected]>
Expand Down Expand Up @@ -56,7 +56,7 @@ public function register($option_page)
&&isset($option_page["validator_service"])
&&isset($option_page["query_service"])
)
$this->optionPages[]=$option_page;
$this->option_pages[]=$option_page;
return null;
}
/**
Expand All @@ -72,35 +72,37 @@ public function register($option_page)
*/
public function boot($aeria_config, $render_service)
{
$editor_enabled = false;
$default_icon_data = file_get_contents(dirname(__DIR__).'/aeria.svg');
$default_icon = 'data:image/svg+xml;base64,'.base64_encode($default_icon_data);
// Registering aeria's editor page
if (empty($GLOBALS['admin_page_hooks']["aeria_options"])) {
if ($editor_enabled) {
add_menu_page(
"Aeria editor",
"Aeria",
"manage_options",
"aeria_options",
'',
$default_icon
);
);
add_submenu_page(
"aeria_options",
"Editor",
"Editor",
"manage_options",
"aeria_options",
function () use ($aeria_config, $render_service) {
static::renderHTML(
"aeria_editor",
$aeria_config,
$render_service
);
}
);
}
add_submenu_page(
"aeria_options",
"Editor",
"Editor",
"manage_options",
"aeria_options",
function () use ($aeria_config, $render_service) {
static::renderHTML(
"aeria_editor",
$aeria_config,
$render_service
);
}
);

// Registering other option pages
foreach ($this->optionPages as $singleOptionPage) {
foreach ($this->option_pages as $singleOptionPage) {
// Check if nav menu parent exists
if (empty($GLOBALS['admin_page_hooks'][$singleOptionPage["parent"]])) {
add_menu_page(
Expand Down
50 changes: 44 additions & 6 deletions Aeria/Query/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function deleteOption($key)
/**
* Gets the saved post types
*
* @param array $parameters the additional query parameters - check
* @param array $parameters the additional query parameters - check
* WP codex to know more
*
* @return array of the post types
Expand Down Expand Up @@ -83,7 +83,7 @@ public function getPostTypes($parameters)
/**
* Gets the saved taxonomies
*
* @param array $parameters the additional query parameters - check
* @param array $parameters the additional query parameters - check
* WP codex to know more
*
* @return array of the taxonomies
Expand All @@ -101,15 +101,53 @@ public function getTaxonomies($parameters)
foreach ($taxonomies as $index => $taxonomy) {
if ((preg_match('/'.$searchField.'/', $taxonomy->name)&&((in_array($postType, $taxonomy->object_type)) || $postType == "") || $searchField=="")) {
$response[$index]["label"] = $taxonomy->labels->name;
$response[$index]["value"] = $taxonomy->name;
$response[$index]["value"] = $taxonomy->name;
}
}
return $response;
}

/**
* Gets the saved terms.
*
* @param array $parameters the additional query parameters - check
* WP codex to know more
*
* @return array of terms
*
* @since Method available since Release 3.0.0
*/
public function getTerms($parameters)
{
$searchField = (isset($parameters['s'])) ? $parameters['s'] : '';
$sender = (isset($parameters['sender'])) ? $parameters['sender'] : null;
$taxonomy = (isset($parameters['taxonomy'])) ? $parameters['taxonomy'] : 'category';
$hide_empty = (isset($parameters['hide_empty'])) ? $parameters['hide_empty'] : true;
$terms = get_terms(array(
'search' => $searchField,
'taxonomy' => $taxonomy,
'hide_empty' => $hide_empty,
));

switch ($sender) {
case 'SelectOptions':
return array_map(function ($term) {
return array(
'value' => $term->term_id,
'label' => $term->name,
);
}, array_values($terms));
break;
default:
return $terms;
break;
}
}

/**
* Gets the requested posts
*
* @param array $parameters the additional query parameters - check
* @param array $parameters the additional query parameters - check
* WP codex to know more
*
* @return array of the requested posts
Expand Down Expand Up @@ -171,7 +209,7 @@ public function getPosts($parameters)
/**
* Registers a new query
*
* @param array $parameters the additional query parameters - check
* @param array $parameters the additional query parameters - check
* WP codex to know more
*
* @return array of the requested posts
Expand All @@ -185,7 +223,7 @@ public function register($name, $querier)
}
/**
* Overrides php __call. If the function is present in the class prototypes, it
* gets called.
* gets called.
*
* @param string $name the function name
* @param array $args the arguments to be passed to the function
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.5
* Version: 3.0.6
* Author: Caffeina
* Author URI: https://caffeina.com
* Text Domain: aeria
Expand Down

0 comments on commit 3d97101

Please sign in to comment.