Customizing the functions of a WordPress plugin

  function, php, wordpress

I need to customize a WordPress plugin so as to fit our local needs. I’ve actually changed some files from the plugin itself to fulfill the local needs, and they work like a charm. But as you all know, its definitely not a good practice, since the moment the main plugin is updated, the modified files will get overwritten, and then everything is gone.
I actually want to create a new plugin and inside it I want to tell WordPress that whenever a certain function is called, just don’t do it and do another function as I determine it for WordPress. See the following code, please:

function access_from( $id, $user_id, $product_id) {
   ...   
         local_visible = Br::turn_gregorian_timestamp_to_local($visible_since);
         $current_time = Br::get_local_timestamp();
         if ( $current_time < $local_visible ) {
            $return = apply_filters('product_access_from__visibility_since', $local_visible, $product_id, $user_id );
         }
      }
   }

This is not the whole code. This is only a part of it. I have just brought the parts that I need to modify so that the plugin’s date and time will suit us. So here is the scenario: How should I tell WordPress to call a specific function whenever another function is called and does it the way I determine. So that I will be able to modify some parts of plugin related to date and time. In our case, we are going to actually tell WordPress that whenever the function access_from is called, just take its values, and put them in my modified access_from function, for example called new_access_from.

Many thanks in advance.

Source: Ask PHP

LEAVE A COMMENT