Articles of init

Can i use init hook for API purpose?

My question title might be little confuse. Here is the scenario, For example: I am giving an API service from my wordpress site. Using it others can know few information. Like if they send a User ID in query URL then i’ll send them user phone number. For Example: If they access the site with […]

Action 'init' function doesn't return variable

I have a function which checks if $_POST is set (a form which submits to the same page). I need to have it initialized before the page is loaded because the function will do a header redirect if the validation goes through without errors. So the function is registered like this: add_action(‘init’, ‘signup_validate_insert’); And the […]

How to do a task only once for logged in users

I want to do a task only once after an user has visited my site. I am currently doing like this: function my_task(){ //do my tasks } add_action(‘init’, ‘my_task’); I am doing this from a plugin. This actually loads my_task() function every time users load any page of wordpress. But I only want to load […]

Basic function call on init failing

I’ve been banging my head against this for a while. I have this very straight-forward code in my plugin: add_action(‘init’, ‘register_shortcodes’); $shortcodeRegistrationRan = False; function register_shortcodes() { global $shortcodeRegistrationRan; $shortcodeRegistrationRan = True; echo “Ran = True”; add_shortcode( ‘accountability’, array($hfMain, ‘processAccountabilityShortcode’) ); } The problem is $shortcodeRegistrationRan never gets set to True, nor does “Ran = […]

Plugin init hook fires repeatedly

I ‘ve just noticed that the init event of a plugin I write myself keeps firing every minute or so if any dashboard’s page is loaded in the browser, without interacting with it or even focus on it. Is this behavior expected? I cant find any information about it, am I missing something ?

What is the entry point of a WordPress theme?

When WordPress is loading and the theme is parsed, which file is loaded first? Is it one of the template hierarchy members or is it functions.php? Are there exceptions to the load order of files in the theme? Do you know where in the core-files (source code) this happens? During my “investigation”, I error-logged every […]

add_action in a custom plugin

I did a plugin to create a when the cookie is FALSE. Actually, the was working, but when I was about to create the cookie, it said that my header was already sent. Then, I had the code add_action(‘init’, ‘newsletterSuscriber’); but it still returned an error like this one. Warning: call_user_func_array() expects parameter 1 to […]

WordPress ignore init for crawlers

I just realized that crawlers like google are triggering massive activity from all add_action binded to ‘init‘. Is this normal behaviour? Is it possible to trigger ‘init’ only for legit visitors?

Why can't a custom postype be registered with “admin_init” hook?

Why do I need to use the “init” hook instead of the “admin_init” hook? init:fires after the core of the wordpress is loaded but before headers are sent admin init:before any other hook when the user accesses the admin area?? so what does that mean exactly? it is certainly after the init hook, is it […]

Form Shortcode not saving data to WP database

I’m developing a plugin that creates a custom table upon plugin activation. The plugin allows users to add a form shortcode to collect data for leads. I’ve got to the point where either the data saves but I can’t create a new post (I’ll get the “headers already sent” when the publish button is cliked […]