Skip to content

Commit 76fc58a

Browse files
Mike van den Hoekmvdhoek1
Mike van den Hoek
authored andcommitted
(feat): implements CMB2
1 parent 1cfeabd commit 76fc58a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+620
-1045
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## Version [3.0.0]
9+
10+
### Feat
11+
12+
- Implement CMB2 metabox plugin
13+
- Clean-up/refactoring
14+
815
## Version [2.3.3]
916

1017
## Feat

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22

33
This README documents whatever steps are necessary to get this plugin up and running.
44

5+
## :bangbang: Please take notice :bangbang:
6+
7+
Since version 3.0.0 CMB2 is used instead of the metabox.io plugin.
8+
Projects that have used earlier versions need to execute two commands from their terminal.
9+
If these commands are not executed there is a potential loss of data inside the meta table for all connected openpub-items.
10+
11+
### Command 1: wp convert:highlighted
12+
13+
When using the metabox.io plugin the value of meta field '\_owc_openpub_highlighted_item' was '0' or '1'.
14+
CMB2 saves this value as 'on' or does not save a value at all when the checkbox is unchecked.
15+
16+
### Command 2: wp convert:expiration-date
17+
18+
When using the metabox.io plugin the value of meta field '\_owc_openpub_expirationdate' was a date + time (2023-02-20 00:00).
19+
CMB2 saves this value as a timestamp
20+
521
## Installation
622

723
### For users

TODO.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# TO-DO
2+
3+
- :skull_and_crossbones: Check translations inside the .po and .pot files (especially line numbers)
4+
- :ok_hand: Check if other plugins, with this plugin as dependency, still work
5+
- :brain: Find a better way, in consultation, to convert the applicable meta values instead of manual execution of commands.

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"require": {
2727
"johnbillion/extended-cpts": "^4.0",
2828
"php": "^7.4|^8.0",
29+
"wpackagist-plugin/cmb2": "2.10.*",
2930
"wpackagist-plugin/elasticpress": "^4.0",
3031
"yahnis-elsts/plugin-update-checker": "^5.0"
3132
},

composer.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/cmb2_metaboxes.php

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?php
2+
3+
return [
4+
'base' => [
5+
'id' => 'openpub_metadata_base',
6+
'title' => __('Data', 'openpub-base'),
7+
'object_types' => ['openpub-item'],
8+
'context' => 'normal',
9+
'priority' => 'high',
10+
'autosave' => true,
11+
'fields' => [
12+
'general' => [
13+
'highlighted' => [
14+
'name' => __('Highlighted item', 'openpub-base'),
15+
'desc' => __('Use this option to select current item to be a highlighted (featured) item', 'openpub-base'),
16+
'id' => 'openpub_highlighted_item',
17+
'type' => 'checkbox',
18+
],
19+
'synonyms' => [
20+
'name' => __('Synonyms', 'openpub-base'),
21+
'desc' => __('Use this option to add an comma separated list of synonyms or related terms', 'openpub-base'),
22+
'id' => 'openpub_tags',
23+
'type' => 'textarea',
24+
],
25+
'expiration' => [
26+
'id' => 'openpub_expirationdate',
27+
'name' => __('Select end date', 'openpub-base'),
28+
'type' => 'text_datetime_timestamp',
29+
'date_format' => 'd-m-Y',
30+
'time_format' => 'H:i:s'
31+
]
32+
],
33+
],
34+
],
35+
'base_links' => [
36+
'id' => 'openpub_metadata_links',
37+
'title' => __('Links', 'openpub-base'),
38+
'object_types' => ['openpub-item'],
39+
'context' => 'normal',
40+
'priority' => 'high',
41+
'autosave' => true,
42+
'fields' => [
43+
'links' => [
44+
'links' => [
45+
'id' => 'openpub_links_group',
46+
'type' => 'group',
47+
'options' => [
48+
'add_button' => __('Add new link group', 'openpub-base'),
49+
'remove_button' => __('Remove link group', 'openpub-base'),
50+
],
51+
'fields' => [
52+
[
53+
'id' => 'openpub_links_title',
54+
'name' => __('Link title', 'openpub-base'),
55+
'desc' => __('Use the title to replace the URL', 'openpub-base'),
56+
'type' => 'text',
57+
],
58+
[
59+
'id' => 'openpub_links_url',
60+
'name' => __('Link URL', 'openpub-base'),
61+
'desc' => __('URL including http(s)://', 'openpub-base'),
62+
'type' => 'text',
63+
],
64+
],
65+
],
66+
],
67+
]
68+
],
69+
'base_downloads' => [
70+
'id' => 'openpub_metadata_downloads',
71+
'title' => __('Downloads', 'openpub-base'),
72+
'object_types' => ['openpub-item'],
73+
'context' => 'normal',
74+
'priority' => 'high',
75+
'autosave' => true,
76+
'fields' => [
77+
'downloads' => [
78+
'heading' => [
79+
'type' => 'heading',
80+
'name' => __('Downloads', 'openpub-base'),
81+
],
82+
'downloads' => [
83+
'id' => 'openpub_downloads_group',
84+
'type' => 'group',
85+
'options' => [
86+
'add_button' => __('Add new download group', 'openpub-base'),
87+
'remove_button' => __('Remove download group', 'openpub-base'),
88+
],
89+
'fields' => [
90+
[
91+
'id' => 'openpub_downloads_title',
92+
'name' => __('Download title', 'openpub-base'),
93+
'desc' => __('Use the title to replace the URL', 'openpub-base'),
94+
'type' => 'text',
95+
],
96+
[
97+
'id' => 'openpub_downloads_url',
98+
'name' => __('Download URL', 'openpub-base'),
99+
'desc' => __('URL including http(s)://', 'openpub-base'),
100+
'type' => 'text',
101+
],
102+
],
103+
],
104+
],
105+
]
106+
],
107+
'base_other' => [
108+
'id' => 'openpub_metadata_other',
109+
'title' => __('Other', 'openpub-base'),
110+
'object_types' => ['openpub-item'],
111+
'context' => 'normal',
112+
'priority' => 'high',
113+
'autosave' => true,
114+
'fields' => [
115+
'other' => [
116+
'heading' => [
117+
'type' => 'heading',
118+
'name' => __('Other', 'openpub-base'),
119+
],
120+
'notes' => [
121+
'name' => __('Notes', 'openpub-base'),
122+
'desc' => __('(the law, authority, local regulations, etc.)', 'openpub-base'),
123+
'id' => 'openpub_notes',
124+
'type' => 'textarea',
125+
'cols' => 20,
126+
'rows' => 5,
127+
],
128+
]
129+
]
130+
],
131+
];

config/cmb2_settings_pages.php

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
return [
4+
'base' => [
5+
'id' => '_owc_openpub_base_settings',
6+
'title' => __('OpenPub settings', 'openpub-base'),
7+
'object_types' => ['options-page'],
8+
'option_key' => '_owc_openpub_base_settings',
9+
'tab_group' => 'base',
10+
'tab_title' => __('General', 'openpub-base'),
11+
'fields' => [
12+
'portal_url' => [
13+
'name' => __('Portal URL', 'openpub-base'),
14+
'desc' => __('URL including http(s)://', 'openpub-base'),
15+
'id' => 'setting_portal_url',
16+
'type' => 'text',
17+
],
18+
'openpub_item_slug' => [
19+
'name' => __('Portal OpenPub item slug', 'openpub-base'),
20+
'desc' => __('URL for OpenPub items in the portal, eg "onderwerp"', 'openpub-base'),
21+
'id' => 'setting_portal_openpub_item_slug',
22+
'type' => 'text',
23+
],
24+
'openpub_use_portal_url' => [
25+
'name' => __('Portal url', 'openpub-base'),
26+
'desc' => __('Use portal url in api.', 'openpub-base'),
27+
'id' => 'setting_use_portal_url',
28+
'type' => 'checkbox',
29+
],
30+
'openpub_use_escape_element' => [
31+
'name' => __('Escape element', 'openpub-base'),
32+
'desc' => __("Use an element to leave the website without being able to navigate back via the browser 'Back' button.", 'openpub-base'),
33+
'id' => 'setting_use_escape_element',
34+
'type' => 'checkbox',
35+
],
36+
'openpub_enable_show_on' => [
37+
'name' => __('Show on', 'openpub-base'),
38+
'desc' => __('Used for configuring on which websites an OpenPub item should be displayed on.', 'openpub-base'),
39+
'id' => 'setting_openpub_enable_show_on',
40+
'type' => 'checkbox'
41+
],
42+
'openpub_expired_heading' => [
43+
'type' => 'heading',
44+
'name' => __('Expired', 'openpub-base'),
45+
'desc' => __('OpenPub items without an expiration date expire automatically when the field below has a value bigger than 0. Existing OpenPub items without an expiration date will be assigned a value of the published date plus the value given in days. New OpenPub items will have a value of the current date plus the value given in days.', 'openpub-base'),
46+
],
47+
'openpub_expired_auto_after_days' => [
48+
'name' => __('Days to expire', 'openpub-base'),
49+
'desc' => __('After how many days should an item expire?', 'openpub-base'),
50+
'id' => 'setting_openpub_expired_auto_after_days',
51+
'type' => 'number'
52+
]
53+
]
54+
]
55+
];

config/core.php

+4-18
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
OWC\OpenPub\Base\PostsToPosts\PostsToPostsServiceProvider::class,
1515
OWC\OpenPub\Base\Metabox\MetaboxServiceProvider::class,
1616
OWC\OpenPub\Base\RestAPI\RestAPIServiceProvider::class,
17-
OWC\OpenPub\Base\ElasticPress\ElasticPressServiceProvider::class,
1817
OWC\OpenPub\Base\Admin\AdminServiceProvider::class,
1918
OWC\OpenPub\Base\Varnish\VarnishServiceProvider::class,
2019

@@ -27,7 +26,6 @@
2726
],
2827

2928
'cli' => [
30-
OWC\OpenPub\Base\ElasticPress\ElasticPressServiceProvider::class,
3129
],
3230
],
3331

@@ -47,27 +45,15 @@
4745
'dependencies' => [
4846
[
4947
'type' => 'plugin',
50-
'label' => 'RWMB Metabox',
51-
'version' => '4.14.0',
52-
'file' => 'meta-box/meta-box.php',
53-
],
54-
[
55-
'type' => 'plugin',
56-
'label' => 'Meta Box Group',
57-
'version' => '1.2.14',
58-
'file' => 'metabox-group/meta-box-group.php',
48+
'label' => 'CMB2',
49+
'version' => '2.10.1',
50+
'file' => 'cmb2/init.php',
5951
],
6052
[
6153
'type' => 'class',
6254
'label' => '<a href="https://github.com/johnbillion/extended-cpts" target="_blank">Extended CPT library</a>',
6355
'name' => 'Extended_CPT',
64-
],
65-
[
66-
'type' => 'plugin',
67-
'label' => 'ElasticPress',
68-
'version' => '2.7.0',
69-
'file' => 'elasticpress/elasticpress.php',
70-
],
56+
]
7157
],
7258

7359
];

config/escape_element_metabox.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
'escape_element' => [
55
'id' => 'escape_element',
66
'title' => __('Escape element', 'openpub-base'),
7-
'post_types' => ['openpub-item'],
7+
'object_types' => ['openpub-item'],
88
'context' => 'normal',
99
'priority' => 'low',
1010
'autosave' => true,

config/posttypes.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@
4343
$item = (new Item)
4444
->query(apply_filters('owc/openpub/rest-api/items/query/single', array_merge([], (new Item)->addExpirationParameters())))
4545
->find($post->ID);
46-
if (!$item) {
46+
if (! $item) {
4747
echo sprintf('<span style="color: red">%s</span>', __('Expired', 'openpub-base'));
4848
} else {
4949
$willExpire = get_post_meta($item['id'], '_owc_openpub_expirationdate', true);
50-
if (!$willExpire) {
50+
if (! $willExpire) {
5151
echo sprintf('<span>%s</span>', __('No expire date', 'openpub-base'));
5252
} else {
53-
echo sprintf('<span style="color: green">%s %s</span>', __('Will expire on', 'openpub-base'), date_i18n(get_option('date_format') . ', ' . get_option('time_format'), strtotime($willExpire)));
53+
echo sprintf('<span style="color: green">%s %s</span>', __('Will expire on', 'openpub-base'), date_i18n(get_option('date_format') . ', ' . get_option('time_format'), $willExpire));
5454
}
5555
}
5656
},

0 commit comments

Comments
 (0)