Skip to content

Commit

Permalink
(refactor): 'show on' taxonomy is only allowed to be managed by admin…
Browse files Browse the repository at this point in the history
…istrators
  • Loading branch information
mvdhoek1 committed May 27, 2021
1 parent 06aab34 commit 20db422
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 7 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Version [2.0.7]

### Refactor

- Add filtering on 'show on' to active items endpoint.
- 'show on' taxonomy is only allowed to be managed by administrators.

## Version [2.0.6]

### Refactor
Expand Down
8 changes: 7 additions & 1 deletion config/taxonomies.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@
'object_types' => ['openpub-item'],
'args' => [
'show_in_rest' => false,
'show_admin_column' => true
'show_admin_column' => true,
'capabilities' => [
'manage_terms' => 'manage_options',
'edit_terms' => 'manage_options',
'delete_terms' => 'manage_options',
'assign_terms' => 'manage_categories'
]
],
'names' => [
'singular' => __('Show on', 'openpub-base'),
Expand Down
2 changes: 1 addition & 1 deletion languages/openpub-base-nl_NL.po
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ msgstr ""
msgid "Escape element"
msgstr "Ontsnap element"

#: config/settings.php:36 config/show_on_metabox.php:14 config/taxonomies.php:69 config/taxonomies.php:70
#: config/settings.php:36 config/show_on_metabox.php:14 config/taxonomies.php:61 config/taxonomies.php:62
msgid "Show on"
msgstr "Tonen op"

Expand Down
2 changes: 1 addition & 1 deletion languages/openpub-base.pot
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ msgstr ""
msgid "Escape element"
msgstr ""

#: config/settings.php:36 config/show_on_metabox.php:14 config/taxonomies.php:69 config/taxonomies.php:70
#: config/settings.php:36 config/show_on_metabox.php:14 config/taxonomies.php:61 config/taxonomies.php:62
msgid "Show on"
msgstr ""

Expand Down
2 changes: 1 addition & 1 deletion openpub-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin Name: Yard | OpenPub Base
* Plugin URI: https://www.openwebconcept.nl/
* Description: Acts as foundation for other OpenPub related content plugins. This plugin implements actions to allow for other plugins to add and/or change Custom Posttypes, Metaboxes, Taxonomies, en Posts 2 posts relations.
* Version: 2.0.6
* Version: 2.0.7
* Author: Yard | Digital Agency
* Author URI: https://www.yard.nl/
* License: GPL-3.0
Expand Down
2 changes: 1 addition & 1 deletion src/Base/Foundation/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Plugin
*
* @var string VERSION
*/
const VERSION = '2.0.6';
const VERSION = '2.0.7';

/**
* Path to the root of the plugin.
Expand Down
15 changes: 13 additions & 2 deletions src/Base/RestAPI/Controllers/ItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function getItems(WP_REST_Request $request)
$items->query(Item::addHighlightedParameters($this->getHighlightedParam($request)));
}

if ($this->hasShowOnParam($request)) {
if ($this->showOnParamIsValid($request)) {
$items->query(Item::addShowOnParameter($request->get_param('source')));
}

Expand All @@ -53,6 +53,10 @@ public function getActiveItems(WP_REST_Request $request)
->query(apply_filters('owc/openpub/rest-api/items/query', $this->getPaginatorParams($request)))
->query(Item::addExpirationParameters());

if ($this->showOnParamIsValid($request)) {
$items->query(Item::addShowOnParameter($request->get_param('source')));
}

$data = $items->all();
$query = $items->getQuery();

Expand Down Expand Up @@ -178,7 +182,14 @@ protected function validateBoolean(string $value): bool
return true;
}

protected function hasShowOnParam(WP_REST_Request $request): bool
/**
* Validate if show on param is valid.
* Param should be a numeric value.
*
* @param WP_REST_Request $request
* @return boolean
*/
protected function showOnParamIsValid(WP_REST_Request $request): bool
{
if (empty($request->get_param('source'))) {
return false;
Expand Down

0 comments on commit 20db422

Please sign in to comment.