Actually I have changed some code in WordPress Store Locator. I want it to remain when plugin will update. So I want to create a child plugin for that. Any ideas on how I could manage it?
This varies plugin to plugin, and it sometimes isn't even possible, other times plugins have documentation to extend them easily (such as WooCommerce and Gravity Forms). Some of them create Action Hooks with do_action() that let you extend the functionality easily. A common example is updating a post after a Gravity Form is submitted with their gform_after_submission hook.
Effectively, it depends on what you want to do, and how the plugin implements the functionality you want to change. If they add text with a Closure or Anonymous Function, it will be harder to modify said text, and you may have to look at something strange like doing a run-time find and replace using Output Buffering, typically on the template_redirect hook.
If you want to remove something a plugin does, you can often unhook it with remove_action. This can be a bit tricky depending on how the plugin is instantiated, sometimes its as simple as:
remove_action( 'some_hook', 'function_to_remove' );
Other times it's more complicated like:
global $plugin_class_var;
remove_action( 'some_hook', array($plugin_class_var, 'function_to_remove') );
Those are the basics of extending (or even 'shrinking'?) a plugin's functionality, and it's not always doable appropriately. Unfortunately the narrow answer to your question is outside of the scope of what we can provide from StackOverflow.
From here, you'll need to figure out exactly what you want to do with the plugin, and dig through the plugin's files to see if there's an appropriate hook or function you can use. If you're still stuck, you'll need to post a new question (don't update this one) with your exact desired result and anything you've tried, and the relevant code that goes along with it. "I want to change a plugin without editing core files" isn't nearly specific enough. "I want to replace an icon with a custom icon in this plugin, here's what I've tried" is specific enough to possibly answer.
Good luck!
I just went through myself and I had so many changes that I couldn't just override the actions.
I created this tool that allows you to create a child plugin like a child theme. You can make updates to the plugin and still update it without losing your changes.
I'm posting this here because it relates and hopefully becomes useful to the next person who runs into this issue.
https://github.com/ThomasDepole/wordpress-child-plugin-tool
As per WordPress standard, it's called plugin's addon.
if the plugin has provided any action to update that functionality then you can use it with your addon (child plugin).
Here I am sending a link for reference.
https://developer.wordpress.org/reference/functions/add_action/
Related
This may be an odd question. I'm working on a website someone else built in WordPress. My understanding of the left navigation within the dashboard is that there are some default items that are there upon install like [pages], [posts], [plugins], and to get additional items to show up here you need to install a new plugin.
This site I'm working on has a few options in the left navigation [team members], [services] which do not appear to be tied to any particular 3rd party plugin.
In fact, it looks like they've used the plugin "Advanced Custom Fields" to create their own functionality so their users could easily add/remove team members from a custom built slider.
My Question
How do you get your own tab to show up in the dashboard's left navigation? Can you do this within a child theme, or do you need to modify the core WP files? Is there a particular folder or some documentation anyone could direct me to where I might learn more about how this is being connected behind the scenes?
Thank you kindly in advance.
I'll preface this by saying:
Never ever ever modify Core Files!
Whew! Now that that's out of the way, there may be a few plugins that do this for you, but I'm ultimately unfamiliar with any. The typical way to add Admin Items is with the add_menu_page() and add_submenu_page() functions. They're relatively straight forward to use.
Also, as a side note, when you add a Custom Post Type with register_post_type() (like what ACF does) there are options to add it to the menu, as well as what you want the labels and menu names to be.
If you're adding a Custom Post Type (like Team Members, Books, etc.) you'll almost certainly want to make use of the labels and show_in_menu arguments when you call register_post_type() to get the admin menu to show up. However, if you need to link to arbitrary URLs or custom dashboard pages, you'll want to make use of the add_menu/submenu_page functions above.
For instance, here's a simple snippet that will add a Stack Overflow link to the menu, you can drop this into a child theme, plugin, Must-Use plugin, etc:
function stack_overflow_admin_link(){
echo '<script>window.location.href = 'https://stackoverflow.com'; </script>';
}
add_menu_page( 'Stack Overflow', 'Stack Overflow', 'subscriber', 'stack-overflow', 'stack_overflow_admin_link', 'dashicons-external' );
Hope this helps!
Also I'll elaborate a little bit on my warning! Never ever modify core WordPress files. They will be overwritten with each and every WordPress update. WordPress is relatively well thought out and has countless Action Hooks and Filters that let you inject, modify, remove, and otherwise manipulate data and the user experience without ever touching core files.
As an example, take a look at this screenshot:
I'm currently rebuilding a software suite from the ground-up using WordPress, but the standard WP Admin interface doesn't make sense in many of the contexts we need it, so our interface (a work in progress) looks like this, and it's all handled by a Must-Use plugin and touches absolutely no core files, it just uses clever manipulation of the hooks and filters available throughout WordPress
I made an e-commerce website before where I copied the template files inside WooCommerce and edited them to display the content how I wanted. But now I know of shortcode and WP_Query which can also be used to get the products / categories etc.
So what I am wondering is which method is best and are there times where you would use one method over another?
There is actually a time and place for different methods. Nix the shortcode though. Generally speaking you shouldn't "hard code" shortcodes into a custom theme (there are exceptions of course), unless you mean that you want to build in a shortcode that theme-users have access to.
That said, if you want to emulate WooCommerce's current style/layout with your own flair, or you want to extend the current templates, use the current template override method. Note this will lead to your theme getting "stale" at some point. WC does a decent job of not changing the templates too often, but it does happen and your theme should accommodate when that happens.
If you're doing something different with a list of products entirely that's not necessarily supposed to look ingrained in the WooCommerce structure, then you can use a custom WP_Query or Database query to accommodate your needs.
So effectively:
If you want to tweak, extend, or reduce the current WooCommerce structure, use template overrides
If you want a fully customized solution or need WC Products in a different capacity, use a custom query method.
Everything woocommerce do well.
No need to use WP_Query separately
If you wants customize the theme you can use add_action() and add_filter()
Also you can modify css.
Hooks Referance:
https://businessbloomer.com/woocommerce-visual-hook-guide-single-product-page/
Thanks for your time.
Getting into black magic between plugins here and I don't have too much knowledge on the right WordPressy way to go about this, so:
Let's say I have an arbitrary plugin that adds 3 custom fields to every Post, but it doesn't require them or offer a setting to do so, and I want them required without hacking that plugin. What is the correct WordPress approach to enforce that they are filled with something valid on Publish?
I want to know the most elegant/best practice way to do the following:
Let's say I have some PHP that returns a string (today's weather, for example). I want to be able to include the string within a WordPress Page, but not by using a plug-in to allow PHP within a Page.
So for example:
This is content of the page that is editable via WordPress pages.
Today's weather is THE_WEATHER. This bit is also editable, but as
an editor I can't edit the PHP that just told us what the weather
is, the developer does that.
What is the best practice way to do this (preferably without using plug-ins)?
Offhand, it sounds like you want to define a shortcode that lets you invoke the PHP function you're talking about and insert its result into a page/post. This pretty much means that you're writing either a (very simple) plugin or you're incorporating the shortcode definition into the functions.php file associated with a theme (which can be a simple child theme of the one you're using).
Which to do probably depends on whether or not you're likely to change themes (if it's just one site) or whether or not you need to do the same thing on different sites that can have different themes. If either is the case, then you should write it as a plugin; otherwise you can just make it part of your theme.
Consult the Codex to learn how to define shortcodes.
I'm very new to WP development. I host a website which needs a list of trails (hiking, biking, etc) and I'd like to write a WordPress plugin to do it.
Can someone please tell me if I'm taking the right approach, and if what I'm proposing is possible.
I'd like the site to end up with an auto-generated and filtered index at http://example.com/trail-guide, and the discrete trail info pages at http://example.com/trail-guide/trailname. This data would all be stored in a single database table holding info for each trail, with an admin page for adding, editing, and deleting entries from here.
Is a WP plugin the best way to go about doing this, or should I be looking at something else?
From the way you're describing, your best bet would be to Register A Custom Post Type. This can be done by adding to your existing theme's Functions.php file, or by creating a plugin.
If you don't plan on changing themes, my advice would be to just hardcode everything into your functions.php file. Otherwise, creating a plugin for this particular job would be the safest alternative.
Using this functionality in tandem with Custom Meta Boxes and Custom Taxonomies will allow you to keep everything organized within the Wordpress Framework with your own special data.
This means that these new posts can also be queried at any time through the standard Wordpress Loop or search box.
If you are uncomfortable with writing your own functions to extend your existing framework, you might want to look into some plugins like GD Custom Posts And Taxonomies Tools to manage your own.
Hope this helps.