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 page requests - front-end, admin, login, etc - to an additional code validation page (whether that's advisable or not is moot, it's what the client wants). Based on the functions, hooks, and filters I need to use, I've determined that the earliest possible hook I …
I have tried to integrate wordpress into my existing website as the documentation archive using the existing login session. I have installed wordpress under /wp of the root app. In my main app, I set the session: isValidUser = true when the user successfully logs in. Now, in WordPress, I added the following code in functions.php which seemed to do the trick: add_action('init', 'validate_session', 1); function validate_session() { if(!session_id()) { session_start(); } //Only allow the viewing of doco if logged …
I updated to WordPress 5.7 and Contact Form 7 v5.4. The new version is not compatible anymore with a js file (line 6 "wpcf7.initForm"), that a previous developer wrote for our theme. Unfortunately I can't find a way to adapt the code so initForm get's recognized again. There are several suggestions with extra functions and I tried to copy them to different lines in the file, but the error won't disappear. Can someone please tell me, how I can correctly …
Hello in the init action, I would like to add a filter to a fairly large function to modify variables in the $vars array, for example the Wordpress post ID. That is to say: add_action( 'init',function(){ //code add_filter( 'query_vars',function($vars){ $vars[] = array('ID' => $myid); return $vars; }); }); Is this possible? EDIT: I am doing A/B/C tests of pages and with the same url I want to show a page with another ID, (i.e. edit the ID of the current …
I'm using register_block_type to register my blocks. I'm not sure what is the best hook to use, between init and enqueue_block_editor_assets. I suppose that enqueue_block_editor_assets it is loaded after, because I can use get_the_ID What are the pro and cons of both?
first I did my homework by checking the answer on this question and this question, both didn't work. after long debuging the function I want to remove is protected in 2 nested classes, and follows this path: class Sub_class{ function __construct(){ add_action('my_action_name',array(&$this, 'the_hated_function'), 200); } function the_hated_function(){ // does some bs } } class Mother_class{ public $my_propreity; function __construct(){ add_action( 'init', array( &$this, 'init' ), 10 ); } function init(){ if(/* condition */ true){ $this->my_propreity = new Sub_class(); } } …
Im Trying to set an user role. if an specific user role (sales-agents) create an user. the created user should have the role b2b instead of customer here is my try: add_action( 'init', 'b2b_set_user_role' ); function b2b_set_user_role() { if ( is_user_logged_in() && wcb2bsa_has_role( get_current_user_id(), 'sales_agent' ) ) { $user->remove_role( ‘customer’ ); $user->add_role( ‘b2b’ ); } } i hope someone can help me
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 understand how much loading there needs to be done. The plugin php file looks like this: function pbd_alp_init() { global $wp_query; // Add code to index pages. if( !is_singular() ) { // can i select a specific post type here? wp_enqueue_script( 'pbd-alp-load-posts', …
When we want to load WP core with: define( 'SHORTINIT', true ); require( __DIR__ .'/wp-load.php'); Which WordPress functions are available for us? i.e. get_option, WP_Query ... or which ones are available then? Is there any documentation?
I am working now on a Settings page. As I will need data about post types, taxonomies, and posts repeatedly in my setting page, I preferred to get these variables in the global scope and call them in the setting fields to minimize the database queries. This was working well for built-in post types and taxonomies(i.e posts, pages, categories, and tags). However, neither custom post types nor custom taxonomies data can be retrieved as they are registered when the init …
I want to intercept requests to public files in WordPress, more specifically all requests to any file located in /wp-content/uploads. Using request or even init filters didn't help, e.g. add_action('init', function() { $currentURI = $_SERVER['REQUEST_URI']; if (strpos($currentURI, '-sab-v') !== false) { return; } }); should catch the request to http://localhost:8080/wp-content/uploads/afghanistan-sab-v1-1-586f2f0eb1464db28d20848756de2671.zip, but doesn't. The same if I use the request filter instead. I know the code doesn't do anything, but breakpoints tell me it's not even triggered. It does of course …
I've got the following usual menu registration function: function my_register_menus(){ register_nav_menus( array( 'primary-menu' => __( 'Primary Menu', 'text_Domain' ), 'footer-menu' => __( 'Footer Menu', 'text_Domain' ), ) ); } add_action( 'init', 'my_register_menus', 0 ); and this is what I call in my header.php: wp_nav_menu( array( 'theme_location' => 'primary-menu' )); Now, in the WP Admin > Nav Menus when I assign a menu to the primary-menu location, the menu doesn't show at all in the theme. If I un-check the menu …
I have two plugins I'm looking at currently. Each has a function called plugin_classes which attaches other classes to the base class. Both of these plugins have init and hooks functions. In the first the call to $this->plugin_classes() occurs in the hooks function while in the second it is called in the init function. In both cases the hooks functions call the init functions. So AFAIK it seems that there is no real difference other than in the plugin using …
I have a cron job on my wordpress site. which I would like to run every hour. I also have a custom login function on my site: users are directed to my site via another site which passes login information via cookies. When I get run of my custom login, the cron event runs fine. When I leave it in, the cron event just doesn't seem to run. I'm not sure how the two are related. Here's how the cron …
my code is add_action('init', 'user_logged_in'); function user_logged_in(){ if( is_user_logged_in() && is_page('login')){ wp_redirect(home_url()); exit; } } the page slug and name is "login" I do not want the logged in member to access the login page. But this code does not work in functions.php. Can you tell me what went wrong?
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 callback. I tried doing it on register_activation_hook, but the CPT's terms are not set. Is there a way to achieve this?
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 ab_process_application_form() { if (isset($_POST['new_application']) && isset($_POST['ab_application_nonce'])) { if (wp_verify_nonce($_POST['ab_application_nonce'], 'ab_application_form_nonce')) { // all $_POST and validation code ... // add record to database $insert_id = $db->insert($data, $format); // trigger action after form submit do_action('ab_application_submitted', $insert_id, $firstname, $lastname, $post_campaign); // redirect after form submitted wp_redirect(home_url('/application/thank-you')); } else { echo 'Not …
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 header() function to sent the customer to this location. My problem: Now when you click the button, there is no redirect, but an error instead. Warning: Cannot modify header information - headers already sent by (output started at /var/www/vhosts/website.com/httpdocs/wp-content/themes/template/header.php:24) in /var/www/vhosts/website.com/httpdocs/wp-content/themes/template/page-checkout.php on line …