You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi @kevindees,
I'm at it again, sorry. This is a follow-up on #250. I need WP to interoperate with a custom set of APIs and, to do that, I need to either use the actions or, better still, to override the update/destroy methods for a custom WPUser CPT and a number of other WPPost CPTs. Following Your answer at #250 I got the onActionSave and it works fine but I couldn't make the destroy actions work. Following, there are barebones examples of functions.php, CarController, UserController, Car, User.
I don't see any evident issue but deleting posts or users don't cause any callback to be called nonetheless.
Note: I'm assuming that the destory action is called when I want to delete a user or when I delete a post from the trash and the action of trashing the post as an update, which I think is correct.
Thanks
<?phpnamespaceApp\Models;
useTypeRocket\Models\WPPost;
class Car extends WPPost
{
publicconstPOST_TYPE = 'car';
}
CarController:
<?phpnamespaceApp\Controllers;
useApp\Models\Car;
useTypeRocket\Controllers\WPPostController;
useTypeRocket\Http\Request;
useTypeRocket\Http\Response;
useTypeRocket\Models\AuthUser;
class CarController extends WPPostController
{
protected$modelClass = Car::class;
publicfunctiononActionSave($args) {
/** my custom logic here */
}
publicfunctiononActionUpdate($car) {
/** my custom logic here */
}
publicfunctiononActionDestroy($car) {
/** my custom logic here */
}
publicfunctionupdate($id, Request$request, Response$response, AuthUser$user)
{
/** my custom logic before update here */parent::update($id, $request, $response, $user);
}
publicfunctiondestroy($id, Request$request, Response$response, AuthUser$user)
{
/** my custom logic before destroy here */parent::destroy($id, $request, $response, $user);
}
}
User:
<?phpnamespaceApp\Models;
useTypeRocket\Models\WPUser;
class User extends WPUser
{
}
UserController:
<?phpnamespaceApp\Controllers;
useApp\Models\User;
useTypeRocket\Controllers\WPUserController;
class UserController extends WPUserController
{
protected$modelClass = User::class;
publicfunctiononActionSave($args) {
/** my custom logic here */
}
publicfunctiononActionUpdate($car) {
/** my custom logic here */
}
publicfunctiononActionDestroy($car) {
/** my custom logic here */
}
}
All the above is run using Typerocket v5.1 on WP 6 and PHP 7.4. I tested the behavior on TR installed as a mu-plugin using composer and on TR installed as a plugin.
The text was updated successfully, but these errors were encountered:
TLDR; The short answer is that the TypeRocket does not call a controller's destroy() method when using WordPress delete functionality. This only happens for the edit screen. You will need to use WordPress hooks to implement your functionality for deletes.
The destroy function only works when using the TypeRocket REST-like API. The main reason for the implementation, the way it is now, is that delete hooks would happen at the model level and not the controller level - unless you only wanted specific actions to happen on a delete-controller-specific request (which might be what you are wanting). This is also true for edit/create functionality.
We may look into connecting the destroy controller methods down the road but WordPress does not make building those connections very straight forward.
is there a way simply fire the delete event in the controllers whenever the WP hook is called? Someway to get the flow back to the standard lifecycle if though some actions are thrown unconventionally, so to speak.
As a note to the first part of Your answer:
This only happens for the edit screen.
I tried as I understood your comment, I hit the delete button on the edit screen and it does not fire the delete action but an update because it actually is a "trash" action.
Hi @kevindees,
I'm at it again, sorry. This is a follow-up on #250. I need WP to interoperate with a custom set of APIs and, to do that, I need to either use the actions or, better still, to override the update/destroy methods for a custom WPUser CPT and a number of other WPPost CPTs. Following Your answer at #250 I got the onActionSave and it works fine but I couldn't make the destroy actions work. Following, there are barebones examples of
functions.php
,CarController
,UserController
,Car
,User
.I don't see any evident issue but deleting posts or users don't cause any callback to be called nonetheless.
Note: I'm assuming that the destory action is called when I want to delete a user or when I delete a post from the trash and the action of trashing the post as an update, which I think is correct.
Thanks
functions.php
:Car
model:CarController
:User
:UserController
:All the above is run using Typerocket v5.1 on WP 6 and PHP 7.4. I tested the behavior on TR installed as a mu-plugin using composer and on TR installed as a plugin.
The text was updated successfully, but these errors were encountered: