diff --git a/CHANGELOG.md b/CHANGELOG.md index 9afa0e9..8145e5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ 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.5] + +### Feat + +- Add 'show on' setting to openpub-settings. +- Add 'show on' setting in editor of openpub-item. +- Add filtering on 'show on' to items endpoint. + ## Version [2.0.4] ### Feat diff --git a/README.md b/README.md index 3444f42..a4023fc 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,22 @@ -# README # +# README This README documents whatever steps are necessary to get this plugin up and running. -## How do I get set up ## +## How do I get set up -* Unzip and/or move all files to the /wp-content/plugins/openpub-base directory -* Log into WordPress admin and activate the ‘OpenPub Base’ plugin through the ‘Plugins’ menu -* Go to the 'OpenPub instellingen pagina' in the left-hand menu to enter some of the required settings +- Unzip and/or move all files to the /wp-content/plugins/openpub-base directory +- Log into WordPress admin and activate the ‘OpenPub Base’ plugin through the ‘Plugins’ menu +- Go to the 'OpenPub instellingen pagina' in the left-hand menu to enter some of the required settings -## Hooks ## +## Hooks See [Hooks](/docs/hooks.md) -## REST API ## +## REST API See [REST API](/docs/restapi.md) -## Translations ## +## Translations If you want to use your own set of labels/names/descriptions and so on you can do so. All text output in this plugin is controlled via the gettext methods. @@ -32,7 +32,7 @@ This plugin provides an easy interface for custom translations and a way to stor For instructions how to use the 'Loco Translate' plugin, we advice you to read the Beginners's guide page on their website: https://localise.biz/wordpress/plugin/beginners or start at the homepage: https://localise.biz/wordpress/plugin -## Running tests ## +## Running tests To run the Unit tests go to a command-line. @@ -48,15 +48,33 @@ For code coverage report, generate report with command line command and view res phpunit --coverage-html ./tests/coverage ``` -## Contribution guidelines ## +## Shared environment -### Writing tests ### +If the openpub environment is shared by multiple websites and it is required to configure the websites where an openpub-item should be displayed on, follow the steps below: + +- Go to the 'OpenPub instellingen pagina' in the left-hand menu and look for the setting 'Show on'. Check the checkbox. + +When this setting is enabled this plugin creates a taxonomy 'Show on'. + +- Add terms to the taxonomy so the terms can be used in the editor of an openpub-item. + +This plugin also adds a select element to the editor of an openpub-item. + +- Look for the select beneath the heading 'External'. +- Select the websites you want this item to be displayed on. + +The selected websites are able now to make requests to the items endpoint and only retrieve openpub-items that are intended for the selected website. +Example url: https://url/wp-json/owc/openpub/v1/items?source={blog_slug} + +## Contribution guidelines + +### Writing tests Have a look at the code coverage reports to see where more coverage can be obtained. Write tests Create a Pull request to the OWC repository -### Who do I talk to ### +### Who do I talk to IF you have questions about or suggestions for this plugin, please contact [Holgers Peters](mailto:hpeters@Buren.nl) from Gemeente Buren. diff --git a/config/api.php b/config/api.php index d2bf522..4e1ef7a 100644 --- a/config/api.php +++ b/config/api.php @@ -24,7 +24,7 @@ 'notes' => OWC\OpenPub\Base\RestAPI\ItemFields\NotesField::class, 'synonyms' => OWC\OpenPub\Base\RestAPI\ItemFields\SynonymsField::class, 'taxonomies' => OWC\OpenPub\Base\RestAPI\ItemFields\TaxonomyField::class, - 'escape_element' => OWC\OpenPub\Base\RestAPI\ItemFields\EscapeElementField::class, + 'escape_element' => OWC\OpenPub\Base\RestAPI\ItemFields\EscapeElementField::class ], ], 'theme' => [ diff --git a/config/metaboxes.php b/config/metaboxes.php index dd1fa26..c368cff 100644 --- a/config/metaboxes.php +++ b/config/metaboxes.php @@ -26,8 +26,8 @@ 'id' => 'openpub_expirationdate', 'name' => __('Select end date', 'openpub-base'), 'type' => 'datetime', - 'save_format' => 'Y-m-d H:i', - ], + 'save_format' => 'Y-m-d H:i' + ] ], 'links' => [ 'heading' => [ @@ -83,7 +83,7 @@ ], ], ], - 'other' => [ + 'other' => [ 'heading' => [ 'type' => 'heading', 'name' => __('Other', 'openpub-base'), @@ -96,7 +96,7 @@ 'cols' => 20, 'rows' => 5, ], - ], + ] ], ], ]; diff --git a/config/settings.php b/config/settings.php index 8dac708..ef66810 100644 --- a/config/settings.php +++ b/config/settings.php @@ -28,9 +28,15 @@ ], 'openpub_use_escape_element' => [ 'name' => __('Escape element', 'openpub-base'), - 'desc' => __('Enable escape element.', 'openpub-base'), + 'desc' => __("Use an element to leave the website without being able to navigate back via the browser 'Back' button.", 'openpub-base'), 'id' => 'setting_use_escape_element', 'type' => 'checkbox', + ], + 'openpub_enable_show_on' => [ + 'name' => __('Show on', 'openpub-base'), + 'desc' => __('Used for configuring on which websites an openpub-item should be displayed on.', 'openpub-base'), + 'id' => 'setting_openpub_enable_show_on', + 'type' => 'checkbox' ] ], ], diff --git a/config/show_on_metabox.php b/config/show_on_metabox.php new file mode 100644 index 0000000..83871a6 --- /dev/null +++ b/config/show_on_metabox.php @@ -0,0 +1,26 @@ + [ + 'id' => 'show_on', + 'title' => __('External', 'openpub-base'), + 'post_types' => ['openpub-item'], + 'context' => 'normal', + 'priority' => 'low', + 'autosave' => true, + 'fields' => [ + 'settings' => [ + [ + 'name' => __('Show on', 'openpub-base'), + 'desc' => __('Select websites where this item should be displayed on.', 'openpub-base'), + 'id' => 'show_on_active', + 'type' => 'taxonomy', + 'taxonomy' => 'openpub-show-on', + 'field_type' => 'select_advanced', + 'required' => 1, + 'multiple' => 1 + ], + ] + ] + ] +]; diff --git a/config/taxonomies.php b/config/taxonomies.php index a3958e5..ee0d495 100644 --- a/config/taxonomies.php +++ b/config/taxonomies.php @@ -10,15 +10,9 @@ 'args' => [ 'show_in_rest' => true, 'show_admin_column' => true, - 'capabilities' => [ - // 'manage_terms' => 'manage_openpub_categories', - // 'edit_terms' => 'manage_openpub_categories', - // 'delete_terms' => 'manage_openpub_categories', - // 'assign_terms' => 'edit_openpub_posts' - ] + 'capabilities' => [] ], 'names' => [ - # Override the base names used for labels: 'singular' => _x('Audience', 'Taxonomy definition', 'openpub-base'), 'plural' => _x('Audiences', 'Taxonomy definition', 'openpub-base'), 'slug' => 'openpub-doelgroep' @@ -30,15 +24,9 @@ 'args' => [ 'show_in_rest' => true, 'show_admin_column' => true, - 'capabilities' => [ - // 'manage_terms' => 'manage_openpub_categories', - // 'edit_terms' => 'manage_openpub_categories', - // 'delete_terms' => 'manage_openpub_categories', - // 'assign_terms' => 'edit_openpub_posts' - ] + 'capabilities' => [] ], 'names' => [ - # Override the base names used for labels: 'singular' => _x('Type', 'Taxonomy definition', 'openpub-base'), 'plural' => _x('Types', 'Taxonomy definition', 'openpub-base'), 'slug' => 'openpub-type' @@ -49,18 +37,23 @@ 'args' => [ 'show_in_rest' => true, 'show_admin_column' => true, - 'capabilities' => [ - // 'manage_terms' => 'manage_openpub_categories', - // 'edit_terms' => 'manage_openpub_categories', - // 'delete_terms' => 'manage_openpub_categories', - // 'assign_terms' => 'edit_openpub_posts' - ] + 'capabilities' => [] ], 'names' => [ - # Override the base names used for labels: 'singular' => _x('Usage', 'Taxonomy definition', 'openpub-base'), 'plural' => _x('Usages', 'Taxonomy definition', 'openpub-base'), 'slug' => 'openpub-toepassing' ] - ] + ], + 'openpub-show-on' => [ + 'object_types' => ['openpub-item'], + 'args' => [ + 'show_in_rest' => false, + 'show_admin_column' => true + ], + 'names' => [ + 'singular' => __('Show on', 'openpub-base'), + 'plural' => __('Show on', 'openpub-base') + ] + ], ]; diff --git a/languages/openpub-base-nl_NL.mo b/languages/openpub-base-nl_NL.mo index 0848285..4759465 100644 Binary files a/languages/openpub-base-nl_NL.mo and b/languages/openpub-base-nl_NL.mo differ diff --git a/languages/openpub-base-nl_NL.po b/languages/openpub-base-nl_NL.po index 7a844f1..22eb7ce 100644 --- a/languages/openpub-base-nl_NL.po +++ b/languages/openpub-base-nl_NL.po @@ -25,6 +25,18 @@ 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 +msgid "Show on" +msgstr "Tonen op" + +#: config/settings.php:31 +msgid "Use an element to leave the website without being able to navigate back via the browser 'Back' button." +msgstr "Gebruik een element waarmee de website verlaten kan worden zonder dat er terug genavigeerd kan worden via de 'Vorige' knop in de browser." + +#: config/settings.php:37 +msgid "Used for configuring on which websites an openpub-item should be displayed on." +msgstr "Wordt gebruikt voor het instellen van de websites waarop een openpub-item weergegeven moet worden." + #: config/escape_element_metabox.php:14 msgid "Enable escape element" msgstr "Gebruik ontsnap element" @@ -41,13 +53,21 @@ msgstr "Ja" msgid "No" msgstr "Nee" +#: config/show_on_metabox.php:6 +msgid "External" +msgstr "Extern" + +#: config/show_on_metabox.php:15 +msgid "Select websites where this item should be displayed on." +msgstr "Selecteer websites waarop dit item getoond moet worden." + #: config/metaboxes.php:6 msgid "Data" msgstr "Gegevens" #: config/metaboxes.php:14 msgid "Highlighted item" -msgstr "Uitgelichte item" +msgstr "Uitgelicht item" #: config/metaboxes.php:15 msgid "Use this option to select current item to be a highlighted (featured) item" @@ -58,65 +78,62 @@ msgid "Synonyms" msgstr "Synoniemen" #: config/metaboxes.php:21 -msgid "" -"Use this option to add an comma separated list of synonyms or related terms" -msgstr "" -"Gebruik deze mogelijkheid om een komma gescheiden lijst van synoniemen of " -"gerelateerde termen mee te geven" +msgid "Use this option to add an comma separated list of synonyms or related terms" +msgstr "Gebruik deze mogelijkheid om een komma gescheiden lijst van synoniemen of gerelateerde termen mee te geven" #: config/metaboxes.php:27 msgid "Select end date" msgstr "Selecteer een einddatum" -#: config/metaboxes.php:34 +#: config/metaboxes.php:35 msgid "Links" msgstr "Links" -#: config/metaboxes.php:41 +#: config/metaboxes.php:42 msgid "Add new link" msgstr "Voeg nieuwe link toe" -#: config/metaboxes.php:45 +#: config/metaboxes.php:46 msgid "Link title" msgstr "Link titel" -#: config/metaboxes.php:46 config/metaboxes.php:73 +#: config/metaboxes.php:47 config/metaboxes.php:74 msgid "Use the title to replace the URL" msgstr "Wordt gebruikt om de link te tonen ipv de URL" -#: config/metaboxes.php:51 +#: config/metaboxes.php:52 msgid "Link URL" msgstr "Link URL" -#: config/metaboxes.php:52 config/metaboxes.php:79 config/settings.php:14 +#: config/metaboxes.php:53 config/metaboxes.php:80 config/settings.php:13 msgid "URL including http(s)://" msgstr "URL inclusief http(s)://" -#: config/metaboxes.php:61 +#: config/metaboxes.php:62 msgid "Downloads" msgstr "Downloads" -#: config/metaboxes.php:68 +#: config/metaboxes.php:69 msgid "Add new download" msgstr "Voeg nieuwe download toe" -#: config/metaboxes.php:72 +#: config/metaboxes.php:73 msgid "Download title" msgstr "Download titel" -#: config/metaboxes.php:78 +#: config/metaboxes.php:79 msgid "Download URL" msgstr "Download URL" -#: config/metaboxes.php:88 +#: config/metaboxes.php:89 msgid "Other" msgstr "Overig" -#: config/metaboxes.php:91 +#: config/metaboxes.php:92 msgid "Notes" msgstr "Vrij notitieveld" -#: config/metaboxes.php:92 +#: config/metaboxes.php:93 msgid "(the law, authority, local regulations, etc.)" msgstr "(wetgeving, bevoegd gezag, uitvoerder, lokale regelgeving)" @@ -404,27 +421,27 @@ msgstr "Gebruik portal url in de api." msgid "Enable escape element." msgstr "Gebruik ontsnap element." -#: config/settings.php:40 +#: config/settings.php:46 msgid "Elasticsearch" msgstr "Elasticsearch" -#: config/settings.php:47 +#: config/settings.php:53 msgid "Instance url" msgstr "Instance url" -#: config/settings.php:48 config/settings.php:54 +#: config/settings.php:54 config/settings.php:60 msgid "URL inclusief http(s)://" msgstr "URL inclusief http(s)://" -#: config/settings.php:53 +#: config/settings.php:59 msgid "Instance shield" msgstr "Instance user/wachtwoord" -#: config/settings.php:59 +#: config/settings.php:65 msgid "Instance prefix" msgstr "Instance prefix" -#: config/settings.php:60 +#: config/settings.php:66 msgid "Use this prefix to group multiple instances" msgstr "" "Dit voorvoegsel wordt gebruikt om meerdere bronnen in ElasticSearch te " @@ -449,32 +466,32 @@ msgctxt "OpenPub settings tab" msgid "Elasticsearch" msgstr "Elasticsearch" -#: config/taxonomies.php:22 +#: config/taxonomies.php:16 msgctxt "Taxonomy definition" msgid "Audience" msgstr "Doelgroep" -#: config/taxonomies.php:23 +#: config/taxonomies.php:17 msgctxt "Taxonomy definition" msgid "Audiences" msgstr "Doelgroepen" -#: config/taxonomies.php:42 +#: config/taxonomies.php:30 msgctxt "Taxonomy definition" msgid "Type" msgstr "Type" -#: config/taxonomies.php:43 +#: config/taxonomies.php:31 msgctxt "Taxonomy definition" msgid "Types" msgstr "Typen" -#: config/taxonomies.php:61 +#: config/taxonomies.php:43 msgctxt "Taxonomy definition" msgid "Usage" msgstr "Toepassing" -#: config/taxonomies.php:62 +#: config/taxonomies.php:44 msgctxt "Taxonomy definition" msgid "Usages" msgstr "Toepassingen" diff --git a/languages/openpub-base.pot b/languages/openpub-base.pot index 15f4152..2d722c3 100644 --- a/languages/openpub-base.pot +++ b/languages/openpub-base.pot @@ -30,6 +30,18 @@ msgstr "" msgid "Escape element" msgstr "" +#: config/settings.php:36 config/show_on_metabox.php:14 config/taxonomies.php:69 config/taxonomies.php:70 +msgid "Show on" +msgstr "" + +#: config/settings.php:31 +msgid "Use an element to leave the website without being able to navigate back via the browser 'Back' button." +msgstr "" + +#: config/settings.php:37 +msgid "Used for configuring on which websites an openpub-item should be displayed on." +msgstr "" + #: config/escape_element_metabox.php:14 msgid "Enable escape element" msgstr "" @@ -46,72 +58,87 @@ msgstr "" msgid "No" msgstr "" +#: config/show_on_metabox.php:6 +msgid "External" +msgstr "" + +#: config/show_on_metabox.php:15 +msgid "Select websites where this item should be displayed on." +msgstr "" + #: config/metaboxes.php:6 msgid "Data" msgstr "" #: config/metaboxes.php:14 -msgid "Synonyms" +msgid "Highlighted item" msgstr "" #: config/metaboxes.php:15 -msgid "" -"Use this option to add an comma separated list of synonyms or related terms" +msgid "Use this option to select current item to be a highlighted (featured) item" +msgstr "" + +#: config/metaboxes.php:20 +msgid "Synonyms" msgstr "" #: config/metaboxes.php:21 -msgid "Select end date" +msgid "Use this option to add an comma separated list of synonyms or related terms" msgstr "" -#: config/metaboxes.php:28 +#: config/metaboxes.php:27 +msgid "Select end date" +msgstr " + +#: config/metaboxes.php:35 msgid "Links" msgstr "" -#: config/metaboxes.php:35 +#: config/metaboxes.php:42 msgid "Add new link" msgstr "" -#: config/metaboxes.php:39 +#: config/metaboxes.php:46 msgid "Link title" msgstr "" -#: config/metaboxes.php:40 config/metaboxes.php:67 +#: config/metaboxes.php:47 config/metaboxes.php:74 msgid "Use the title to replace the URL" msgstr "" -#: config/metaboxes.php:45 +#: config/metaboxes.php:52 msgid "Link URL" msgstr "" -#: config/metaboxes.php:46 config/metaboxes.php:73 config/settings.php:14 +#: config/metaboxes.php:53 config/metaboxes.php:80 config/settings.php:13 msgid "URL including http(s)://" msgstr "" -#: config/metaboxes.php:55 +#: config/metaboxes.php:62 msgid "Downloads" msgstr "" -#: config/metaboxes.php:62 +#: config/metaboxes.php:69 msgid "Add new download" msgstr "" -#: config/metaboxes.php:66 +#: config/metaboxes.php:73 msgid "Download title" msgstr "" -#: config/metaboxes.php:72 +#: config/metaboxes.php:79 msgid "Download URL" msgstr "" -#: config/metaboxes.php:82 +#: config/metaboxes.php:89 msgid "Other" msgstr "" -#: config/metaboxes.php:85 +#: config/metaboxes.php:92 msgid "Notes" -msgstr "" +msgstr " -#: config/metaboxes.php:86 +#: config/metaboxes.php:93 msgid "(the law, authority, local regulations, etc.)" msgstr "" @@ -297,27 +324,27 @@ msgstr "" msgid "Enable escape element." msgstr "" -#: config/settings.php:40 +#: config/settings.php:46 msgid "Elasticsearch" msgstr "" -#: config/settings.php:47 +#: config/settings.php:53 msgid "Instance url" msgstr "" -#: config/settings.php:48 config/settings.php:54 +#: config/settings.php:54 config/settings.php:60 msgid "URL inclusief http(s)://" msgstr "" -#: config/settings.php:53 +#: config/settings.php:59 msgid "Instance shield" msgstr "" -#: config/settings.php:59 +#: config/settings.php:65 msgid "Instance prefix" msgstr "" -#: config/settings.php:60 +#: config/settings.php:66 msgid "Use this prefix to group multiple instances" msgstr "" @@ -345,32 +372,32 @@ msgctxt "OpenPub settings tab" msgid "Elasticsearch" msgstr "" -#: config/taxonomies.php:22 +#: config/taxonomies.php:16 msgctxt "Taxonomy definition" msgid "Audience" msgstr "" -#: config/taxonomies.php:23 +#: config/taxonomies.php:17 msgctxt "Taxonomy definition" msgid "Audiences" msgstr "" -#: config/taxonomies.php:42 +#: config/taxonomies.php:30 msgctxt "Taxonomy definition" msgid "Type" msgstr "" -#: config/taxonomies.php:43 +#: config/taxonomies.php:31 msgctxt "Taxonomy definition" msgid "Types" msgstr "" -#: config/taxonomies.php:61 +#: config/taxonomies.php:43 msgctxt "Taxonomy definition" msgid "Usage" msgstr "" -#: config/taxonomies.php:62 +#: config/taxonomies.php:44 msgctxt "Taxonomy definition" msgid "Usages" msgstr "" diff --git a/openpub-base.php b/openpub-base.php index 95d7d24..a3ebe71 100644 --- a/openpub-base.php +++ b/openpub-base.php @@ -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.4 + * Version: 2.0.5 * Author: Yard | Digital Agency * Author URI: https://www.yard.nl/ * License: GPL-3.0 diff --git a/src/Base/Foundation/Plugin.php b/src/Base/Foundation/Plugin.php index 05729ad..b7e10da 100644 --- a/src/Base/Foundation/Plugin.php +++ b/src/Base/Foundation/Plugin.php @@ -25,7 +25,7 @@ class Plugin * * @var string VERSION */ - const VERSION = '2.0.4'; + const VERSION = '2.0.5'; /** * Path to the root of the plugin. diff --git a/src/Base/Metabox/MetaboxServiceProvider.php b/src/Base/Metabox/MetaboxServiceProvider.php index c9fe264..2ff82a3 100644 --- a/src/Base/Metabox/MetaboxServiceProvider.php +++ b/src/Base/Metabox/MetaboxServiceProvider.php @@ -20,8 +20,14 @@ public function registerMetaboxes($rwmbMetaboxes) { $configMetaboxes = $this->plugin->config->get('metaboxes'); + // add metabox if plugin setting is checked. if ($this->plugin->settings->useEscapeElement()) { - $configMetaboxes = array_merge($configMetaboxes, $this->plugin->config->get('escape_element_metabox')); + $configMetaboxes = $this->getEscapeElementMetabox($configMetaboxes); + } + + // add metabox if plugin setting is checked. + if ($this->plugin->settings->useShowOn()) { + $configMetaboxes = $this->getShowOnMetabox($configMetaboxes); } $metaboxes = []; @@ -32,4 +38,14 @@ public function registerMetaboxes($rwmbMetaboxes) return array_merge($rwmbMetaboxes, apply_filters("owc/openpub/base/before-register-metaboxes", $metaboxes)); } + + protected function getEscapeElementMetabox(array $configMetaboxes): array + { + return array_merge($configMetaboxes, $this->plugin->config->get('escape_element_metabox')); + } + + protected function getShowOnMetabox(array $configMetaboxes): array + { + return array_merge($configMetaboxes, $this->plugin->config->get('show_on_metabox')); + } } diff --git a/src/Base/Repositories/Item.php b/src/Base/Repositories/Item.php index f8bacfc..6e9aa6c 100644 --- a/src/Base/Repositories/Item.php +++ b/src/Base/Repositories/Item.php @@ -51,7 +51,7 @@ public static function addExpirationParameters(): array } /** - * Add parameters to meta_query to remove items that are expired or not expired + * Add parameters to meta_query to remove items that are expired or not expired. * * @param boolean $highlighted * @@ -69,4 +69,25 @@ public static function addHighlightedParameters(bool $highlighted): array ], ]; } + + /** + * Add parameters to tax_query to filter items on selected blog slugs. + * + * @param string $blogSlug + * + * @return array + */ + public static function addShowOnParameter(string $blogSlug): array + { + return [ + 'tax_query' => [ + [ + 'taxonomy' => 'openpub-show-on', + 'terms' => sanitize_text_field($blogSlug), + 'field' => 'slug', + 'operator' => 'IN' + ] + ] + ]; + } } diff --git a/src/Base/RestAPI/Controllers/ItemController.php b/src/Base/RestAPI/Controllers/ItemController.php index 95c743e..ae1f13f 100644 --- a/src/Base/RestAPI/Controllers/ItemController.php +++ b/src/Base/RestAPI/Controllers/ItemController.php @@ -28,6 +28,10 @@ public function getItems(WP_REST_Request $request) $items->query(Item::addHighlightedParameters($this->getHighlightedParam($request))); } + if ($this->hasShowOnParam($request)) { + $items->query(Item::addShowOnParameter($request->get_param('source'))); + } + $data = $items->all(); $query = $items->getQuery(); @@ -173,4 +177,17 @@ protected function validateBoolean(string $value): bool return true; } + + protected function hasShowOnParam(WP_REST_Request $request): bool + { + if (empty($request->get_param('source'))) { + return false; + } + + if (is_numeric($request->get_param('source'))) { + return false; + } + + return true; + } } diff --git a/src/Base/Settings/SettingsPageOptions.php b/src/Base/Settings/SettingsPageOptions.php index 090e33a..75a991f 100644 --- a/src/Base/Settings/SettingsPageOptions.php +++ b/src/Base/Settings/SettingsPageOptions.php @@ -47,13 +47,19 @@ public function useEscapeElement(): bool return $this->settings['_owc_setting_use_escape_element'] ?? false; } + public function useShowOn(): bool + { + return $this->settings['_owc_setting_openpub_enable_show_on'] ?? false; + } + public static function make(): self { $defaultSettings = [ '_owc_setting_portal_url' => '', '_owc_setting_portal_openpub_item_slug' => '', '_owc_setting_use_portal_url' => 0, - '_owc_setting_use_escape_element' => 0 + '_owc_setting_use_escape_element' => 0, + '_owc_setting_openpub_enable_show_on' => false ]; return new static(wp_parse_args(get_option('_owc_openpub_base_settings'), $defaultSettings)); diff --git a/src/Base/Taxonomy/TaxonomyServiceProvider.php b/src/Base/Taxonomy/TaxonomyServiceProvider.php index ac8b5a8..236933d 100644 --- a/src/Base/Taxonomy/TaxonomyServiceProvider.php +++ b/src/Base/Taxonomy/TaxonomyServiceProvider.php @@ -29,12 +29,31 @@ public function register(): void */ public function registerTaxonomies(): void { - if (function_exists('register_extended_taxonomy')) { - $this->configTaxonomies = $this->plugin->config->get('taxonomies'); - foreach ($this->configTaxonomies as $taxonomyName => $taxonomy) { - // Examples of registering taxonomies: http://johnbillion.com/extended-cpts/ - register_extended_taxonomy($taxonomyName, $taxonomy['object_types'], $taxonomy['args'], $taxonomy['names']); - } + if (!function_exists('register_extended_taxonomy')) { + return; } + + $this->configTaxonomies = $this->filterConfigTaxonomies(); + + foreach ($this->configTaxonomies as $taxonomyName => $taxonomy) { + // Examples of registering taxonomies: http://johnbillion.com/extended-cpts/ + register_extended_taxonomy($taxonomyName, $taxonomy['object_types'], $taxonomy['args'], $taxonomy['names']); + } + } + + /** + * Filter taxonomies based on plugin settings. + * + * @return array + */ + protected function filterConfigTaxonomies(): array + { + if ($this->plugin->settings->useShowOn()) { + return $this->plugin->config->get('taxonomies'); + } + + return array_filter($this->plugin->config->get('taxonomies'), function ($taxonomyKey) { + return $taxonomyKey !== 'openpub-show-on'; + }, ARRAY_FILTER_USE_KEY); } }