-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace command with WP Cron + REST endpoints #7
Conversation
mvdhoek1
commented
Jul 12, 2024
![Schermafbeelding 2024-07-12 om 07 46 57](https://private-user-images.githubusercontent.com/11852816/348139680-0e543a88-2546-44db-ab7a-997ed56aa647.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwNDg2MzEsIm5iZiI6MTczOTA0ODMzMSwicGF0aCI6Ii8xMTg1MjgxNi8zNDgxMzk2ODAtMGU1NDNhODgtMjU0Ni00NGRiLWFiN2EtOTk3ZWQ1NmFhNjQ3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA4VDIwNTg1MVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWVhYzk5MGFlNjZjOWNjNmU5NTA2YjgzMjY0OWI5YmMwYTEzZTlhMDhhMTM1NjE5MTUxNTI1NmRhYTQyYzkzNGMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.0nb9K9BtGmGO7k9vYAJmQOgb7JCT3ZBGQ3vNltyi_kw)
![Schermafbeelding 2024-07-12 om 07 46 42](https://private-user-images.githubusercontent.com/11852816/348139683-0d6956fe-7afc-4d0b-a851-ea3d4bc8702e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwNDg2MzEsIm5iZiI6MTczOTA0ODMzMSwicGF0aCI6Ii8xMTg1MjgxNi8zNDgxMzk2ODMtMGQ2OTU2ZmUtN2FmYy00ZDBiLWE4NTEtZWEzZDRiYzg3MDJlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA4VDIwNTg1MVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQzMDhkY2MxYjRiNDIzZmJhYTY2M2JhZGUwM2NhYTFlY2RkMWVjZWYyZjY5NjQ2YTdkMDY3ZjQ0NTljZWFhYTcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.QdZgDL8HttVjCKCWPyq9zF4dXz-m4gvC_l0KwrMsilE)
* | ||
* @return mixed | ||
*/ | ||
public function handleRequestParam(WP_REST_Request $request, string $param, string $type, $default = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Als je args definieert in register_rest_route gebeurt dit allemaal automatisch. (validatie, default enz)
https://developer.wordpress.org/rest-api/extending-the-rest-api/schema/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah goeie, ga ik niet nu meenemen. Wellicht in de volgende versie.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ziet er goed uit! Mooi dat je typehints e.d. hebt toegevoegd.
Zou je willen kijken naar de tijdzone opmerking? Dat is het enige wat misschien nog even aangepast moet worden.
*/ | ||
public function getLegeBySlug(WP_REST_Request $request) | ||
{ | ||
$slug = $request->get_param('slug'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waarom hier geen gebruik van $this->handleRequestParam()
?
{ | ||
$perPage = $query->get('posts_per_page'); | ||
$page = $query->get('paged'); | ||
$page = 0 == $page || -1 == $perPage ? 1 : $page; // If $perPage = -1, $page should be 1. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ik hou ook van compacte code, maar ik vind dit wel moeilijk leesbaar. Haakjes maken het (voor mij althans) iets beter leesbaar: $page = (0 == $page || -1 == $perPage) ? 1 : $page;
.
|
||
protected function timeToExecute(): int | ||
{ | ||
$currentDateTime = new DateTime('now', new DateTimeZone(wp_timezone_string())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wp_timezone_string()
kan ook een offset teruggeven (bijv. +08:45). Zo'n waarde is niet in een format die door DateTimeZone
geaccepteerd wordt ("One of the supported timezone names, an offset value (+0200), or a timezone abbreviation (BST)"). Wellicht hier een try...catch omheen zetten.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Goed dat je het zegt, dit is een betere oplossing:
$currentDateTime = new DateTime('now', wp_timezone());
{ | ||
$slug = $request->get_param('slug'); | ||
|
||
if (empty($slug) || ! is_string($slug)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dit gaat ook vanzelf als je slug als arg registreert.
3220af4
to
130f161
Compare
CHANGELOG.md
Outdated
@@ -1,94 +1,106 @@ | |||
# CHANGELOG | |||
|
|||
## Version 1.2.5 | |||
## [2.0.0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Top om die Version
hier weg te laten maar waarom deze brackets?
@@ -4,7 +4,7 @@ | |||
* Plugin Name: PDC Leges | |||
* Plugin URI: https://www.openwebconcept.nl | |||
* Description: PDC Leges | |||
* Version: 1.2.5 | |||
* Version: 2.0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checking: is dit een major, backwards incompatible version? Is er een upgrade guide nodig?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nee, het huidige commando (<2.0) is straks weg maar zal niets breken, in de README.md staat het wel beschreven:
Since version 2.0.0, the commands have been replaced by WP Cron Events. This change requires less configuration on your server by eliminating the need to add server cron jobs. Just activate the plugin and you're all set.
Remember to remove any previously configured cron jobs from your web server, as they have been deprecated since version 2.0.0.
130f161
to
4695448
Compare
4695448
to
984259c
Compare
'type' => 'integer', | ||
'default' => 10, | ||
], | ||
'page' => [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ik zou hier nog 'minimum' => 1 toevoegen
'permission_callback' => '__return_true', | ||
'args' => [ | ||
'limit' => [ | ||
'description' => 'Number of posts per page.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'minimum' => -1,
'maximum' => 100,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Toegevoegd
'description' => 'Slug of the post.', | ||
'type' => 'string', | ||
'default' => '', | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Als je slug 'required' => true maakt hoef je in de controller niet meer te checken of ie gevuld is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Zal niets doen, zonder slug param komt ie in het algemene endpoint voor het ophalen van alle leges.
3b119b9
to
889cae7
Compare
889cae7
to
daf843e
Compare