Custom action hook needed - on article load - wordpress - php

Hey there. I'm currently learning how to write plugins for wordpress platform and I already know the basics. However, I need to invoke some function when a single article page (single.php) loads. Basically, I want to take that post ID and use it in my algorithm. I can't find any pre-defined action hook in wordpress framework so I thought I could write my very own one, but I don't know what's the mechanism for it. I read several guides on internet but still have no clue how it works. Can someone help me with this? Code examples are welcome.

You can start at the loop_start hook and check is_single() or whatever else you need to determine if you're being called from a singular page. I highly doubt you need to be creating new action hooks in the WordPress core for whatever you're doing.

Related

Typo3 10.4 specific actions on pages

I haven't found anyone asking this question yet although it seems like this should be a more commonly asked question.
Is there a way of selecting which action a plugin should use depending on the page?
If I go to example.com/news then the news plugin should use the listAction but if I go to example.com/clear the news plugin should be using the deleteAllAction. Is there a way to accomplish this? Or rather is there an easier way than using extbase routeEnhancers?
I guess the easiest way would be to register a new plugin with a different action but the same base.

wordpress help... integrating existing PHP code to work side-by-side

I know very little of WP aside form it being a CMS geared towards (or started from) blogging, but may people have found the product capable of functioning as their sites CMS.
I was recently asked to write a PHP app to signup, (with email confirm and email notification to admin), login to make and manage orders. - so a user can register and get an email confirmation... once they are approved, they can log in, and place an order. and manage their information. There is also an admin section to manage the users and requests... ALL very straight ahead.
So I write it - and test it and everything is fine... Until the client tells me that it's going to be part of a WP site.
Problem, the client ONLY knows HTML, NOT PHP... I don't know WP.
When I upload a directory to the root - and try to run the app, I get redirect to /$url .. and a page not found displaying in the WP theme.
I have a feeling it has to do with the AUTH module I'm using... but there is a huge BIG PICTURE issue I need to conquer - how to integrate an existing PHP app into a WP site...
Q: how do I reference and use the WP emailing system?
thx - I know it's a broad question. but if someone can point me into a direction...
I have read the post regarding templates in WP and setting up a template with PHP code so it's executed... but it seems 'wrong' to have to create a template for each php page.
What your app is about ? If you got only the Auth module already coded you should only import user and password because WP does this out-of-the-box.
Wordpress can be twist up for your need but you need to do it in the WP way :).
If you want to add some functions to it check out the plugin library on wordpress.org. If you know wordpress and no plugin match your needs then the best way to go is writing your own plugin : https://codex.wordpress.org/Writing_a_Plugin
Or maybe just add your custom functions into functions.php, see https://codex.wordpress.org/Theme_Development#Functions_File
For pages, you basically have to type of it in WP : articles - i.e. blog posts - and the static pages. You can add some custom one check https://codex.wordpress.org/Post_Types
I know this answer is more a bunch of links but if you don't nothing about WP you should first learn how it works before try to hack it.
Hope it helps !

Executing a none existing hook in Wordpress?

Is there any reason to why, in my case a plugin, to have a do_action(); to a none existing hook/action?
Example from WooCommerce, writepanel-product-data.php:
do_action('woocommerce_product_options_sku');
If I search after woocommerce_product_options_sku I cannot find it. So it just a call for a hook that doesn't exist, but why?
I have seen this multiple times. But have no idea why one does this. Perhaps someone could enlighten me?
This way you can interact with woocommerce plugin without the need of modificate the source code of the plugin.
That is, woocommerce plugin programmers have considered that the developers may need some extra options, so you can program a plugin that uses add_action('woocommerce_product_options_sku', 'your_function'); and that will be called just at the point where do_action ('woocommerce_product_options_sku') was inserted.
If you need more information:
http://wp.smashingmagazine.com/2011/10/07/definitive-guide-wordpress-hooks/
http://wcdocs.woothemes.com/codex/extending/introduction-to-hooks-actions-and-filters/

Understanding "update_option_(option_name)" Wordpress hook

I am creating a plugin for Wordpress and haven't really worked with Wordpress very long and i want to have a function run once a specific option is updated for a blog. I think that update_option_(option_name) is the hook i want but i can't understand or find how to use it and was wondering if anyone had an example or a link to show me how this hook works?
THANKS!!!!
If you run over a specific wordpress function or hook name, just go to google and enter:
codex *function or hookname*
like
codex update_option_(option_name)
for your question.
Normally the first result directs you to the wordpress documentation page (codex) that normally answers most questions. If not, there are more search results that are most often helpful.
Additionally, all hooks are documented inside the wordpress codebase. You only need to read the code where the hook get's invoked to understand what the input values (and if a filter, the output values as well) mean. In your case that hook is located here: http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/functions.php#L513
Hope this helps.

Joomla User creation hooks

Is it possible to create a hook when a user creates an account?
I have googled and found some stuff on hooks and joomla but nothing really concrete.
Anyone knows if this is possible? Or do I really have to mess with the code. I just want to create code that is upgrade safe.
Thanks
Yes, this is possible. You're going to write an user plugin based on user events for plugin system. From your question I believe you want onAfterStoreUser or onBeforeStoreUser event hooks. Check these provided links for official documentation with examples.

Categories