Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [init]

Fires in between the time after WordPress core has finished loading but before any headers are sent.

0
votes
0answers
37 views

Why should I need to add init action to include PHP file to WordPress Plugin?

I wanted to include a PHP file to my plugin. So I added following code to top of my plugin. require_once( plugin_dir_path( __FILE__ ) . 'inc/test-file.php'); But it didn't worked. Then I tried ...
0
votes
0answers
45 views

adding an action inside if condition not working

This is my function $enable = false; //if false is provided then the action should run and remove the breadcrumbs if($enable ===false){ add_action( 'init', 'woo_remove_wc_breadcrumbs' ); ...
5
votes
3answers
202 views

Init action hook running late after PayPal's return url?

I have process_ipn method that runs on init action hook. Looks like it is fired after PayPal returns to merchant. Under this method, I could find out the payment status such as completed, pending, ...
0
votes
1answer
258 views

add_action init breaks site on PHP 7.1

If there's no child theme available, I use a custom plugin for some minor changes. The following code for hiding update notifications etc. has always worked perfectly. However, if I switch from PHP 7....
0
votes
1answer
47 views

How to hook WP initialization without modifying functions.php

We've got a few customizations to the standard WP installation, specifically a custom post type, some custom fields implemented using CMB2, and some hooks to admin menu configuration using the ...
0
votes
1answer
69 views

How to use add_action('wp_ajax_[action name]',…) for a specific page with condition?

In my plugin, I'm using wp_ajax, This hook does not work when I wrap the init function call with a condition like this : public function __construct(){ if( isset( $_GET["page"] ) && $_GET["...
0
votes
0answers
205 views

WP_mail() Issue. Duplicate emails if $_GET['A'] == email

I have been scratching my head since last few hours. But still not able to find the cause of the issue. I have created a wp_mail() function which is as follows: if( !empty( $_GET['A'] ) && !...
0
votes
2answers
1k views

Add a filter inside an action init

Hello in the "action init" to fairly large function, but I would like to add a filter to modify the vars variables, for example the wordpress post ID. That is to say: add_action( 'init',function(){ ...
1
vote
3answers
44 views

How to insert a text in all pages and posts before or after specific places?

I have this simple code below: function func1() { echo "this is amazing"; } add_action('reko_hook','func1'); Now, I know that I could use reko_hook(); either inside index.php or page.php where I ...
1
vote
0answers
581 views

set_query_var doesn't seem to work on init hook

Based on the trick of using set_query_var with get_template_part to easily pass variables from one template file to another (see here: Method 3), I thought I could use the same method for passing ...
1
vote
1answer
928 views

wp_redirect() not working on form submission with init hook

I am trying to redirect the user after form submission using wp_redirect() but it it is not working. I am submitting data using init action hook. here is the code. function ...
1
vote
1answer
245 views

wp_redirect on base wp-admin and login

UPDATE: I've done some more research on my problem and have narrowed down the problem further. The question below has been very rewritten from the original. I'm trying set up a plugin to redirect ALL ...
0
votes
3answers
32 views

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?
0
votes
1answer
182 views

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 ...
0
votes
0answers
457 views

Init action and refresh page after form action

My problem is that I can't refresh the page after a form action into a loop. In my case I have a listing post page where I can delete, archive, deliver posts through a modal form, row by row. After ...
2
votes
1answer
73 views

Cron While Editing Post

I have a multi-author blog, on which there are two schedule cron functions. The first function moves all public posts in the pending status after 365 days: if( ! wp_next_scheduled( '...
1
vote
1answer
216 views

Plugins rewrite rules the right way

I need to create rewrite rules for my plugin. This plugin will be running on a very large WordPress Network (+2000 sites) so performance is important. Most tutorials and the codex recommend to ...
1
vote
0answers
101 views

Init plugin again after ajax call finish

We have this website that the navigation between pages work with ajax. in the blog page we use this great plugin to make the ajax load-more posts. all works great but the problem is that when you ...
0
votes
0answers
392 views

Function Hooked on Init Running Multiple Times

I have a method that logs the users login time. public function log_login() { if ( isset($_COOKIE['current_visit']) ) { return; } // Get current user $user = ...
0
votes
3answers
279 views

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 ...
0
votes
1answer
915 views

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 ...
0
votes
0answers
70 views

Can I use a hook other than 'init' to handle form submissions?

I'm developing a plugin that handles form submissions at several different points. As such, I was relying on being able to use global $post and get_query_var to determine which stage the user is at ...
0
votes
1answer
2k views

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('...
0
votes
1answer
49 views

API calls on plugin activation or init?

When I activate my plugin, I need to call an API, to get some items, lets say fruits, flowers and animals. I need to create taxonomy terms out of these items. Then I need to loop over these items and ...
1
vote
0answers
74 views

Best action hook to create custom post and assign taxonomy terms to it on plugin activation?

When I install the plugin, I want to create 10 CPTs of a particular type, which I define in the init action hook, and want to assign 10 terms of a custom taxonomy, which too is defined in an init ...
0
votes
1answer
207 views

Custom setting field value not working inside add_action init hook

I have added custom setting options page under WordPress settings and those are working perfectly. I have tested their values also. But when I am using those values inside function file within ...
1
vote
0answers
112 views

Fire on widgets_init only on dashboard

I have an interesting issue. I need to launch an action on widgets_init, but ONLY on the WordPress Dashboard. So I can't use dashboard related hooks, because they fire too late; it has to be on ...
0
votes
2answers
120 views

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 ...
0
votes
0answers
1k views

update_post_meta returning false when called during init

Given a custom URL like: http://clientsite.com/tvt?pmc_task=member_check&post_id=1041&user=3851&status=approved I'm trying to catch the URL and add the user_id to a custom post meta ...
1
vote
1answer
2k views

WordPress Plugin Boilerplate - add_action hook in static “activate” function

I'm hoping someone can point me in the right direction here. I'm using the Wordpress Plugin Boilerplate to develop a custom plugin. On install, the plugin will register a new post type (course), a ...
0
votes
1answer
471 views

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 ...
1
vote
0answers
287 views

$wpdb->insert running multiple times?

Im trying to run a $wpdb->insert ONCE on every page load (for testing purposes). The insert will insert a meta field for a post type. I have tried hooking the insert function into "init", add it to ...
0
votes
1answer
565 views

Why doesn't global $wp_query not get hooked?

I have a plugin that helps me to make lazy loading on posts of a custom post type. The idea is to add an action to the template_redirect/init and get data from the global $wp_query to make jquery ...
0
votes
1answer
338 views

How to translate Widget Description in constructor?

I'm building a localized widget and the translation works everywhere but in the language string in the constructor. I have read that the whole plugin initialisation has to be bound to the init ...
0
votes
0answers
957 views

Hooking action once but called twice

class GridModSidebars{ public function init(){ add_action('widgets_init', array($this, 'registerSidebars'),20); } public function registerSidebars(){ $args = array( 'name' =&...
1
vote
1answer
549 views

Get log of function/method calls made by do_action() on WordPress initialization

Is there any way I can get a log of the method calls that are made when do_action( 'init') is fired?
1
vote
1answer
104 views

PHP header() gives headers already sent

I am working on a checkout proces in Wordpress where if customer clicks on the checkout button he gets redirected to a payment provider. Important to know: I use a session in this proces. I use PHP ...
0
votes
0answers
226 views

Init hook for header send

I am working on a checkout proces where if I submit the checkout I get an error "headers already send" because I use a PHP header() function to send the customer to my payment provider url. My idea ...
0
votes
2answers
88 views

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 ...
0
votes
1answer
89 views

Why do I need to register my custom post type a second time when flushing rewrite rules?

If I register my custom post type when the init action fires (which is before plugin activation) why do I need to register my custom post type a second time when flushing rewrite rules (on plugin ...
0
votes
1answer
527 views

Init hook function to call other hook in function.php

I am trying to add a function in the init hook that will call another hook like this : add_action( 'init', 'loadAfterUserRegistrationHook' ); function loadAfterUserRegistrationHook(){ ...
1
vote
0answers
295 views

Post submit using shortcode and init

I'm trying to find the best way to return errors to a page once a form submitted by using a shortcode. I'm adding a function to init such as - add_action( 'init', 'contact_form_process_post' ); ...
2
votes
1answer
560 views

add_feed and flush_rewrite_rules

There seems to be quite a controversial opinion on the WordPress flush_rewrite_rules() function. According to the Codex, it is highly discouraged to use this function on the init action hook. ...
-1
votes
1answer
776 views

Best hook for a function which adds shortcodes to the system?

I have a plugin released, and one of my customers was reporting a problem where the plugin was outputting ads in the header area of their website. I have a function defined which contains my ...
1
vote
1answer
984 views

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 ...
1
vote
2answers
2k views

How to setcookie if is_page('page') ? should I use add_action('init') or there is another action?

I want to setcookie if is_page('arabic') or is_page('english') then redirect to home_url() only if the page name/slug arabic or english, I think that init action happen before the code determine the ...
1
vote
1answer
2k views

Problem with is_page & wp_redirect

I use cookies to determine which menu I should use on my website. This is working fine, but I want to force the correct one if someone views the URL directly instead of via the URL with a query string ...
0
votes
0answers
3k views

do_action( 'init' ) in wp-settings.php breaks my website. All plugins and themes disabled

As the title says, do_action( 'init' ) in wp-settings.php breaks my website. All plugins and themes have been disabled. Basically if I comment out line 308 which is simply do_action( 'init' ); then ...
0
votes
0answers
228 views

add_action not working in header?

i need to enable the session variables to my theme , so i have the following code in my theme functions.php function session_manager() { if (!session_id()) { session_start(); // Get ...
1
vote
1answer
686 views

Load ajax if is_home()

I want to show some simple things on homepage with ajax. The problem is I want to load everything when is_home() is true. Php, js, everything. In funtions.php: add_action('init', '...