-
Notifications
You must be signed in to change notification settings - Fork 566
Before/after field row hooks #946
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
Conversation
|
IMPORTANT! Writing this PR I noticed a wrong hooks order that needs to be solved at CMB2.php Hooks are called in this order: And they should be called at this order: Why? Because this means call this hooks is really dangerous because you could break your html if you expect a relative order, for example, if two plugins using this hooks to print something, the most common workflow is use same relative callbacks ( A visual example with two plugins (Plugin 1 and Plugin 2): Result: <div>
<p>
</div>
</p>New order: Result: <div>
<p>
</p>
</div>I keep the same order as before/after form to this PR because I do not know if this is the desired order, anyway if you confirm that you want to change this order, I will update this PR too |
This is an excellent point. Would appreciate a separate PR to resolve that order, if you are up for it. If so, please also add a changelog entry, similar to this: a03b471 (since it is a backwards-compatibility concern). |
|
New hooks order to match coming CMB2 PR: Ok @jtsternberg I will PR it in a separate PR with changelog notes |
|
RE: this PR, i'm not super sure this is the way to handle this. Ideally, we could do something with |
This is a backwards-compatibility break. If your theme or plugin is
using some of next action hooks and your are connecting the output
between them then take a look a this explanation
Hooks have been called in this order (until this PR):
`cmb2_before_form`
`cmb2_before_{$object_type}_form_{$cmb_id}`
`cmb2_after_form`
`cmb2_after_{$object_type}_form_{$cmb_id}`
And now they are called at this order:
`cmb2_before_form`
`cmb2_before_{$object_type}_form_{$cmb_id}`
`cmb2_after_{$object_type}_form_{$cmb_id}`
`cmb2_after_form`
Why? Because this means call this hooks is really dangerous because you
could break your html if you expect a relative order, for example, if
two plugins using this hooks to print something, the most common
workflow is use same relative callbacks (`cmb2_before_form` and
`cmb2_after_form`) or (`cmb2_before_{$object_type}_form_{$cmb_id}` and
`cmb2_after_{$object_type}_form_{$cmb_id}`)
A visual example with two plugins (Plugin 1 and Plugin 2):
Current order:
`cmb2_before_form` Plugin 1 opens a div
`cmb2_before_{$object_type}_form_{$cmb_id}` Plugin 2 prints a p
`cmb2_after_form` Plugin 1 closes the div
`cmb2_after_{$object_type}_form_{$cmb_id}` Plugin 2 closes the p
Result:
``` html
<div>
<p>
</div>
</p>
```
New order:
`cmb2_before_form` Plugin 1 opens a div
`cmb2_before_{$object_type}_form_{$cmb_id}` Plugin 2 prints a p
`cmb2_after_{$object_type}_form_{$cmb_id}` Plugin 2 closes the p
`cmb2_after_form` Plugin 1 closes the div
Result:
``` html
<div>
<p>
</p>
</div>
```
This reverts commit bcb882c.
This reverts commit 54cfa40.
|
Dat github desktop :/ What do you mean @jtsternberg ? |
This reverts commit eaaa4f2.
|
I am not able to open a new PR without this field row hooks and the amount of reverts generated from github desktop app, so on get this pulled (or declined) I will folk again CMB2 repo |
|
No news about this? |
Fixes #876
Added
cmb2_before_field_row
cmb2_before_{$field_type}field_row
cmb2_after_field_row
cmb2_after{$field_type}_field_row