Overriding WordPress plugin code in my child theme

There is part of a plugin I am using that I need to override in my child theme, namely one of the template files. Is there an easy way to do this?
dfehlingAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dfehlingAuthor Commented:
Thanks, Julian - sure!

The file in the plugin that I need to override  begins with this:

<?php

class Template_Tags extends Template_Block {

    public function __construct( $type = 'my-tags' )
    {
        (and then the rest of the function here)
}
?>

Open in new window


The file is quite fairly long - around 200 lines - but there are several places I where needed to edit it to get it to work the way I want, so overriding the whole file is ideal, but there may be a simpler way to override the class or the function.

With other plugins, I was able to either copy the file I wanted to override into my child theme with the same folder structure. Or I was able to copy just the function into my child theme functions.php. In this case, neither of those worked.
Julian HansenCommented:
In this case, neither of those worked.
Probably because it is a plugin. Unless the author of the plugin has provided specific hooks to change the bits you want to change then you are going to have to change the class file directly.

This obviously has the side effect of potentially loosing your updates in the next update of the plugin.

Without seeing the code and knowing what bits you want to change - not easy to provide advice or say why this particular pluggin is behaving differently from others.
dfehlingAuthor Commented:
The author has provided hooks, but not for this particular class. Nor do I have any instructions on how to use the hooks.

I have attached the original file and the edited one I want to replace it with. I have several more edits to make in the way the $terms are displayed, but maybe this is enough to get me started. Ultimately, my goal is to change the $term links to not link to the archive.php file , but rather to a customized link that I will build dynamically from the slugs (so far I have removed the links by changing get_the_term_list to get_the_terms and the default_output function).

Thanks in advance!
tags.php
tags-new.php
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

Ray PaseurCommented:
Maybe step back a bit and ask yourself, "What does this plug-in do?"  Then see if there is a more popular plug-in that can do the basics and may be susceptible of modification for your exact needs.  WordPress has many thousands of contributors and most of the well-understood applications have been investigated and built.  My first criterion for selecting a plug-in is popularity, because that means a lot of sets of eyes have seen it and liked it.
dfehlingAuthor Commented:
Ray - I'd already explored many plugins for this purpose and this one comes the closest to our needs by far. It's just a matter of changing this one thing that has me a bit baffled.
Julian HansenCommented:
It's just a matter of changing this one thing that has me a bit baffled.
This is what I would do - but I am not a fan of WP and hunting around trying to find some functionality some other person may have written that approximates my need while checking for security holes etc etc just seems like a big waste of time to me. If licensing permits copy the plugin change it to do what you want - change the plugin name and install it as a new plugin.
Then when / if the plugin is updated repeat the process. But as I said that is what I would do - maybe someone else has a better solution.
dfehlingAuthor Commented:
I still haven't received any solutions. I have been able to override bits of a plugin before in a child theme, so I know there should be a way to do this. Just not sure what code I need to wrap it in and where it should go.
Julian HansenCommented:
Just so I understand - the only change you made was line 140 which changed from
$this->add_style( 'width', '60px', 'name' );

Open in new window

to
$this->add_style( 'width', '100px', 'name' );

Open in new window


If this is a style change - can't you just add to the stylesheet?

Looking at the code - there has been no provision for any sort of hook for that particular functionality.
There may be other parts to this plugin but if this is all it is incredibly simple - I would personally copy it and make my own plugin.
dfehlingAuthor Commented:
No - I am actually changing more to the file. I changed the way the $terms get built in  private function tags_list( $recipe ), and how they are displayed in the bottom section of the file (removing the default link using archive.php.)  Do you see hooks on how to change those portions and if so, how/where do I use them?

Copying and making my own plugin is not an option. This is a premium plugin I have purchased for my client and it fits 95% of their needs. Making my own plugin makes me personally  responsible for ensuring its compatibility with every WordPress update forever.
Julian HansenCommented:
Hooks are basically function calls to methods or functions that may or may not be defined by the person using the plugin. It would look something like
if (method_exists(this, "hookname"))

Open in new window

or
if (function_exists("hookname")) 

Open in new window

I don't see anything that is obviously a hook but to be honest this class looks so simple it would be a bit of over-engineering to include them.

As I said before - copy it - rename it, modify it and use the modified version.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dfehlingAuthor Commented:
I will contact the plugin developer to see if he can add the functionality I need.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
WordPress

From novice to tech pro — start learning today.