Is there a 'good working practise' way to modify the markup that a WordPress plugin produces without editing the plugin's core files. The problem I foresee is that when you update the plugin, the markup that you would have modified overwritten.
I know in Drupal there are template overrides, but I don't know enough about WordPress to do a similar practise.
Any help?
The plugin itself would probably have to be written to allow for it (though see below). There are a few ways to do this: You could have the plugin look for template files that it pulls from an arbitrary location (e.g. "uploads/myplugin") You could possibly store the HTML in the database as a setting. The plugin could be written with an apply_filter hook (just as WordPress itself uses hooks) to allow outside calls that change output (e.g. from a separate plugin or a theme's functions.php). I've used all of these methods.
If you're talking about altering the output of somebody else's plugin, you could possibly ask them to implement one of the above. Push comes to shove you can use JavaScript to manipulate the DOM.
The answer to your question is hooks and templates. If you're lucky, the plugin will use templates for its output and will check your theme to see if you've overridden them, or it may have some filter hooks that let you modify its output. If you're not so lucky, and you can't get the plugin authors to add some for you, you'll need to get more creative.
hook into the WordPress queries that the plugin is
making, and alter them to return different results.
hook into the WordPress get_option() function to change the plugin's settings on the fly.
hook into the page content, and use preg_replace() to hack the HTML.
hook in early in the page generation, call ob_start() to buffer the page output, and hook the wp_footer to call ob_end_clean() and use preg_replace() to hack the HTML.
Just some ideas :)
Obviously, it's best to work with the plugin than against it. You should check to see whether your plugin uses templates, and if it doesn't, search for calls to apply_filter() and do_action(). But sometimes, needs must!
Related
I'm little bit confused on it. When registering sidebar in a function file of Wordpress, we use register_sidebar() function and pass arguments in it.
Without using any action hook, the sidebar works very fine. However, in the codex i've seen a action hook named 'widget_init' is used to register sidebar. So, my confusion is what is the standard approach to register a sidebar, with or without action hook ?
I found this interesting piece on registering sidebars which says
Bad sidebar code
There are some common things I would like to see changed within
themes. Not all of these things are technically incorrect, but they
can present some unintended consequences or are just needless bits of
code.
Problem #1: Randomly dropping code into functions.php
If you’re a theme developer, you should be familiar with WordPress’
built-in hooks. Not only should you be familiar with them, you should
actually be using them.
The biggest issue I see is sidebar code just being dropped into
functions.php. You should create a sidebar registration function and
hook it to widgets_init. You can see an example of this in the
“Registering a dynamic sidebar” section above.
The reason this is important is so that child themes (and even
plugins) can know exactly when a sidebar was registered. This gives
child themes the opportunity unregister a sidebar if needed. Plus, not
doing it this way is just plain sloppy.
As a sidenote to this: You should never just drop code into
functions.php. Always use the hooks WordPress provides to execute your
functions when they should be executed in the WordPress flow.
I'm trying to edit a WordPress plugin. My conventional thinking is telling me to edit HTML but I know WordPress is PHP. I'm not talking about CSS editing either (aesthetics, positioning, color...etc). I know how to do that.
For example let's say I have a plugin Form with an input box with the title "how much" however I want it to say something else like "Dollars"....how do I do this?
Also the plugin admin area doesn't give me the option to change this in the backend. Isn't there another way to change that?
Ways to do it:
Search for the string in the plugin's files and check if it offers a filter hook (apply_filters), if it does create a plugin or use functions.php.
Use another plugin to modify the string.
If the plugin has internatinaliztion support, create a translation file for your language and translate only that string. Use en_US if your WPLANG is empty.
Hack the plugin itself and change the string (bad, this has to be done at each plugin upgrade).
In wordpress I have comeaccross the word hooks, I have implemented few of them in my custom theme's function.php, I am trying to edit someone's code, I see he wrote few hooks inside the plugins settings.php file itself.
ex- We are using the plugin Contact Form 7, and wanted to add some more data to email before sending them, hence he wrote the hooks inside settings.php which I am not sure is correct or wrong.
Can some-one advice me as what is the best place to write our hooks for wordpress plugins so that it will not affect the plugin when there is an upgrade.
Continue to use functions.php. If it starts to become a bit cluttered separate into includes. ie...
include_once('inc/cf7_custom.php');
I'm wondering if it is possible to write a plugin which shows nothing but only let the visitor access the feed url. The admin page should be accessible by the administrator as well.
The background of this idea is that I've written a custom feed generator and implemented it in a WordPress site. Since the site is only for the feeds, I'd like to make the site invisible to the public except the feed outputs.
I'm aware that there are Maintenance Mode and Members Only plugins. The problem is that the maintenance mode prohibits feed access and the member only mode bans general visitors.
So I'm wondering if there is a simple way to do this. I'd like to avoid editing mod_rewrite because I'm planning to make it as a plugin if possible. If it is not realistic to do it without mod_rewrite, I will try editing mod_rewrite.
Thanks for your input.
If you never want anything to render this could easily be fixed using the template_redirect hook. For example:
function stop_rendering() {
exit;
}
add_action( 'template_redirect', 'stop_rendering');
So, basically you don't want the theme to render? What about /categories, /tags, /archives etc.?
If that's all you want to do, you could just create a blank theme with the style.css (blank besides the theme info comment block) and the index.php template.
I would like to know which WP plugin should I choose to allow every user who come to my page to add a post to my page form the frontend.
He just click on a button add a new post or something like that. Than a form appear and he inserts the title and uploads an image.
After that its published as a post.
Is there a solution like this available for WP?
Thanks in advance.
From what I know, there is no existing plugin doing it as you need. Even if it existed, I wouldn't recommend it's use for security reasons; it is hard to follow every uses and make sure visitors would post the way you want.
You are definitely better to code it by your own, and it's quite simple using the wp_insert_post function. This function will work anywhere you put it inside Wordpress (no need to build a plugin from scratch), so a simple form with validation would make it.
Hope it guides you on what you're looking for.