The important thing to note is that admin_init runs on every admin page load. So if you put a redirect inside that hook it will redirect every time you try to do something in the admin.
In this code when the plugin is activated an option is saved in the database, Activated_Plugin. The next time admin_init runs this option is checked and if it exists the option is deleted. This means that the option will only exist for one page load. So if you put code inside this check it will only run once, because the next time admin_init runs the database option won’t exist anymore.
Related Posts:
- I can’t fetch query parameters ($_GET parameters) with get_query_var
- Change Password Hint
- Dynamic URL to reference custom PHP files
- Prevent multiple counts by same user – WP PostViews plugin
- Second select list values are not saved after clicking update
- Use wc_enqueue_js only on specific pages – nested add_action
- How to use a frontend URL with a Plugin
- WordPress template_include filter not working properly
- Theme url in all plugin pages
- “The plugin generated 2694 characters of unexpected output…” on Plugin activation, CREATE TABLE sql command not working
- How to display a value from a radio button in the options menu in wordpress
- Why WordPress architecture is not pure object oriented and it don’t use MVC pattern? [closed]
- How to access function from outside of a class within this class in WP plugin?
- How can i display post loop in table format?
- PHP can I add line numbers to file_get_contents()
- How to call function at the bottom of post using plugin?
- WP add_action factory
- Swapping wp_dropdown_categories function with wp_category_checklist
- How to show phpinfo() only in a new tab?
- How can I remove a function that has been added to wordpress with add_filter?
- what is the best practice to add new field to an api route
- Use custom post type for a store locator
- How do I programmatically set a user as spam in BuddyPress? [closed]
- How to use $_GET function WordPress backend
- WP CRON duplicate wp_insert_post with has < and > tag
- How to send Ajax request from my plugin in admin dashboard?
- Extend PHP regex to cover “srcset” and “style” attributes
- AJAX success response is not working but it’s saving my changes
- Best practice for show data to one specific user?
- How can I hide that I Use WordPress (with W3 Total Cache)
- Saving plugin settings – ERROR: options page not found
- class_exists returns different values [closed]
- Custom array from a query only write the last row of the query
- wp_insert_post: array only. wp_update_post: array|object (?)
- Is it possible to define variables in a wordpress shortcode, and then call the shortcode using a specific variable?
- Building a REST API for your web app exposes primary keys of DB records?
- How to remove the message ‘We could not find any results for your search’ without changing template files and without adding posts/pages?
- Custom meta box values are not getting saved for my custom post type
- Can’t upload CSV file to plugin directory using custom upload form in admin panel
- Validate and Sanitize WP REST API Request using WP JSON Schema?
- Custom Registration username_exists / email_exists
- How can I search all plugins for composer’s vendor/autoload.php?
- Action Hook Inside WordPress Plugin Shortcode
- Can I remove or edit an include() from a function with a filter?
- Call to undefined function error in plugin
- How do I make this Metabox show current DB value?
- Submit form to db
- Get category id when SEO URL is turned on
- Add a custom WooCommerce settings tab with sections
- Ajax on the Administration Side of plugin – wp_localize_script – how to pass value from JQuery to PHP function in class?
- Using ACF Relationship field to set post type to draft or published status
- WordPress can’t use ZipArchive
- How to extend SelectControl with data from my theme
- How to change basename url for wp-admin?
- Only the first image uploads
- WordPress loading progess – wp-blog-header.php
- Illegal string offset checkbox
- Custom plugin: how do I call a PHP file if settings option is set to true?
- Trying to use a variable to set image width
- How can i avoid duplicate same post in wp?
- wp_update_post gives 500 internal error
- How do I disable cache for a certain page?
- How to check if plugin update process completed in wordpress?
- How to identify which php file a plugin is using on page load?
- dashboard widget form not submit mails
- register_setting not save checkbox
- using filter and hook inside class
- How does one make a URL return dynamic JSON with custom Content Type?
- How to give custom roles the capability to edit one Menu instead of every Menu
- Priority call methods – PHPMailer->addAddress(NULL)
- How to properly escape in ternary operators – Wp Coding Standards?
- Add Admin Option w/ Anonymous Function
- add menu page in loop menu order
- defined (‘ABSPATH’) false after AJAX post to other PHP-file
- How to send logs to plugin owner for a plugin?
- Force CSV download with template_redirect
- Private messaging – Getting and displaying the avatar/url of a message recipient
- How to use foreach and if statement within array of arrays?
- widget: input the px value from user and use it as inline style in widget function
- Custom post type single page return to listing page
- WordPress rewrite question
- Using Nonce for my Form
- Create new folder and upload files to custom folder via wp_handle_upload
- How to edit the default database of WordPress [closed]
- SHARING TO FACEBOOK – FROM DYNAMICALLY GENERATED PAGE
- Cookie not created in AJAX request
- How to automatically convert images to WebP on WordPress?
- Check user last login date
- Transate plugin with js & wp_localize_script
- WP Custom tables query
- Import js variables loaded via wp_localize_script() into js module without global scope connection
- Import users and custom user meta from csv
- Authenticate + Authorize WP REST API request before built-in WP JSON Schema Payload Validation?
- Woocommerce Convert existing order to the cart
- Redirect posts to post editor page based on query string
- Load style and script for custom post type metabox
- Permissions error when I use my plugin to delete comments in the front-end
- WordPress wp_set_object_terms does not assign product to custom taxonomy
- Issue with WordPress Plugin Activation Hook and Table Creation
- Too few arguments – wp_login action