Overriding a function in a WordPress plugin


Is it possible to override a function being called by a WordPress plugin? Working on customizing a WordPress plugin, I need to make some changes in some code blocks. Among the most critical blocks that I am going to modify are the functions that deal with saving and displaying dates. As our local date is different from the Gregorian date, the date format that the plugin is based upon. Hence, I need to override some parts of the plugins to meet the local needs.
I have changed the codes inside the main plugin itself, yet as you all know, its not a good practice to change the codes inside the original plugin since the moment the plugin is updated, the modified files get overwritten by the original ones, and hence, all the modified code gets deleted. So, I am going to write a new plugin to do this process all automatically, and there is no worries for the times that the main plugin gets updated.

To recap, inside the new plugin I am going to tell WordPress that whenever the main plugin calls up the following function, just take its parameter and then run it though another function, for instance, displayDateLocal($id). Just take a brief look at this code.

function displayDate ($id) {
$userActivityDate = Br::show_activity_date($id);
    $return = apply_filters('user_activity', $userActivityDate);}

As you can definitely guess in the second line of the function, it just calls another function, that is, ‘show_activity_date’. This comes up with Gregorian date, which is not appropriate for our local purposes, and accordingly this line needs be modified if it going to be localized and useful in our case.
Hence, I need to tell WordPress that whenever displayDate($id) is called, just get the parameter and run it through another function, called, for example, displayLocalDate(). Inside this function, I have changed the date structure, and everything is fine if I am able to do this to override the code in the original function in the main plugin.
Thanks in advance.

H. M.. 8 months 2020-11-22T09:10:20-05:00 0 Answers 13 views 0

Leave an answer