Fixed save callback to call before save OR delete (rather than only on the save branch)#1
Fixed save callback to call before save OR delete (rather than only on the save branch)#1bobbysmith007 wants to merge 1 commit intoAutomattic:mainfrom
Conversation
the save branch) Also made the argument order match $custom_metadata_manager-> save_metadata_field for ease of calling the default method. (Essentially I am trying to allow custom save permissions).
|
We already have a |
|
The problem I was having with required_cap, was that it completely removes the field. I started with a display_callback that removed the input tags in favor of a span when needed. This caused the data to always be removed when the user saved their own profile. function eit_readonly_display_cb($slug, $field, $otype, $oid, $value){
global $custom_metadata_manager;
if(current_user_can('edit_users')){
$field->display_callback = null;
$custom_metadata_manager->_display_metadata_field($slug, $field, $otype, $oid);
}
else{
$label = $field->label;
if(is_array($value)) $value = implode(', ',$value);
echo "<span class=\"readonly custom-metafield $slug\">$label: $value</span>";
}
}Its certainly possible I am missing an obviously better way to accomplish these tasks. Aside from that though, it seemed to make more sense to call the "save_callback" before saving/deleting ANY changes. Previously it would only call on the save branch (not when deleting values). It also seemed to make more sense to allow the callback to call the original function in certain situations, which made the public save function a more obvious place to call from. |
|
Fair enough. I'll review your proposed changes in more details and act accordingly either later today or over the weekend. Thanks for the input! |
Also made the argument order match $custom_metadata_manager->
save_metadata_field for ease of calling the default
method. (Essentially I am trying to allow custom save permissions).
This seems like it could break existing code, but it also seems like a better use / definition of save_callback than previously.
This is my callback, does that seem like a reasonable use case for the save callback?
Is it safe to clear the save_callback then recall the default? It seems like this should work, but I dont yet have a grasp on how everything is fitting together.
Hope this helps,
Russ