How to Modify a WordPress Plugin Function

I installed a plugin on my WordPress website and need to customize one of its functions. What’s the best way to modify a plugin function? Should I add the changes to my theme’s functions.php file?

Here’s the plugin function I want to modify:

/**
 * display_lesson_enrollment_form function.
 *
 * @access public
 * @param int $lesson_id
 * @return void
 */
function display_lesson_enrollment_form( $lesson_id ) {

    $requirements_met = check_lesson_prerequisites( $lesson_id );

    if ( $requirements_met ) {
    ?><form method="POST" action="<?php echo esc_url( get_permalink() ); ?>">

            <input type="hidden" name="<?php echo esc_attr( 'custom_lesson_enroll_nonce' ); ?>" id="<?php echo esc_attr( 'custom_lesson_enroll_nonce' ); ?>" value="<?php echo esc_attr( wp_create_nonce( 'custom_lesson_enroll_nonce' ) ); ?>" />

            <span><input name="lesson_enroll" type="submit" class="enroll-button" value="<?php echo apply_filters( 'lesson_enroll_text', __( 'Begin this Lesson', 'custom-plugin' ) ); ?>"/></span>

        </form><?php
    } // End condition check
} // End display_lesson_enrollment_form()

Manually modifying plugin functions sucks - breaks every update and the unhooking/rehooking code turns into a mess.

I’ve hit this problem dozens of times. You want to automate the whole thing so it survives updates without touching code.

Set up a workflow that watches your plugin for changes and auto-applies your mods. Trigger it when WordPress updates plugins or run it on schedule.

The workflow:

  • Catches plugin updates
  • Backs up your current customizations
  • Applies your mods to the new version
  • Tests everything works
  • Rolls back if stuff breaks

I use this for all our WordPress sites now. Way more reliable than hoping hooks exist or remembering to manually update custom functions after every plugin update.

This automation saves hours of maintenance and prevents those “oh crap the site broke” moments.

Check if the plugin has template files you can override first - way easier than messing with functions directly. Most plugins keep their display templates in a /templates folder that you can copy to your theme directory. You’ll have full control over the HTML without touching any PHP. For the enrollment form, look in the plugin folder for template files like enrollment-form.php or lesson-form.php. Copy whatever you need to /your-theme/plugin-name/ and edit the HTML there. This survives plugin updates and you don’t have to deal with hook manipulation. If there aren’t any templates, the unhook/rehook method works fine, but template overrides are much cleaner.

Avoid altering plugin files directly, as any changes will be lost upon an update. The ideal approach is to create a custom plugin or integrate your modifications within the theme’s functions.php file. For your situation, you should unhook the original function by identifying the action hook it uses to call display_lesson_enrollment_form, then apply remove_action() to detach it. Following that, use add_action() to link your modified version. Be sure to rename the function—perhaps to custom_display_lesson_enrollment_form()—to prevent naming conflicts. This ensures your changes remain intact after updates and maintain site stability.

Nobody mentioned extending the plugin class if it’s object-oriented. Most modern plugins use classes, so you can create a subclass and override specific methods without touching the original code. This works great when the function you want to change is part of a larger class structure. Just extend the main plugin class, override the display_lesson_enrollment_form method with your changes, then swap out the plugin’s instance with your extended version using WordPress init hooks. You get surgical control over what gets modified and it stays update-safe. Takes a bit more PHP knowledge but creates way cleaner code than unhook/rehook, especially for complex changes.

Check if the plugin has hooks first - way easier than all that complicated stuff. Most plugins include filters like lesson_enroll_text that you can use straight from functions.php. No need to unhook anything or recreate the entire function.

Using a child theme is advisable for modifying plugin functions, as it maintains the integrity of your site during plugin updates. If the plugin allows template overrides, you can simply copy the necessary files to your child theme. Additionally, explore available action hooks and filters associated with the plugin, as they provide a way to adjust the functionality or output without altering the core plugin files. Always review the plugin’s documentation for any suggested customization methods.