I have a plugin that needs a (very) custom feature, for a site I’m making.
I’ve found it in the code, where I can remove some lines of code, so the feature is accessible as I would like. But I’m not sure how to maintain this custom fix in the future.
There is no hook for the fix.
Problems
- If the plugin is updated, then the fix will disappear.
- If I download the plugin and commit it to my repository, then I’ll have a snapshot of what the fix was, but it’s not a good way to maintain it.
- I’m not sure if it’s possible to ‘freeze’ a plugin, so it cannot be updated. But even if that was possible, then that’s obviously also error-prone.
Are there any good ways to get this done?
Further elaboration
It’s a permission thing, where a custom user type, with very fewer capabilities, to be able to access a function (downloading a package slip).
So what I do is that I change this:
...
...
...
// check if user is logged in
if ( ! is_user_logged_in() ) {
$allowed = false;
}
// Check the user privileges
if( !( current_user_can( 'manage_woocommerce_orders' ) || current_user_can( 'edit_shop_orders' ) ) && !isset( $_GET['my-account'] ) ) {
$allowed = false;
}
// User call from my-account page
if ( !current_user_can('manage_options') && isset( $_GET['my-account'] ) ) {
// Only for single orders!
if ( count( $order_ids ) > 1 ) {
$allowed = false;
}
// Check if current user is owner of order IMPORTANT!!!
if ( ! current_user_can( 'view_order', $order_ids[0] ) ) {
$allowed = false;
}
}
to this:
// check if user is logged in
if ( ! is_user_logged_in() ) {
$allowed = false;
}
// // Check the user privileges
// if( !( current_user_can( 'manage_woocommerce_orders' ) || current_user_can( 'edit_shop_orders' ) ) && !isset( $_GET['my-account'] ) ) {
// $allowed = false;
// }
//
// // User call from my-account page
// if ( !current_user_can('manage_options') && isset( $_GET['my-account'] ) ) {
// // Only for single orders!
// if ( count( $order_ids ) > 1 ) {
// $allowed = false;
// }
//
// // Check if current user is owner of order IMPORTANT!!!
// if ( ! current_user_can( 'view_order', $order_ids[0] ) ) {
// $allowed = false;
// }
// }
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
As @kero noted, your best option is to contact the developer and ask if they are open to including an appropriate hook – what you need is a filter to allow customization for the value of $allowed.
However, barring that, one potential (albeit not perfect) solution is to ignore updates for the plugin. You can do that as follows:
function filter_plugin_updates( $value ) {
unset( $value->response['some_plugin/some_plugin.php'] );
return $value;
}
add_filter( 'site_transient_update_plugins', 'filter_plugin_updates' );
Then you would not get update notifications or automatic updates for the plugin. That would allow you to re-apply your change manually to the update and handle things manually.
Obviously, if you can get the developer onboard with a filter hook, you’re better off. But if you’re handling things manually, this keeps you from blowing out your customization unintentionally.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0