Articles of admin init

Which hook for processing plugin page form data?

Which hook should I use for processing form data from my plugin pages. I currently use “admin_init”. Is that correct? Was this hook intended to be used this way?

Get current session in WP admin

Trying to access sessions in the WP admin and access a variable from it. function tasks_admin_sessions() { if(!session_id()) { session_start(); } } add_action( ‘admin_init’, ‘tasks_admin_sessions’, 1 ); $nonce = $_session[‘wp_nonce’] $completed_url = admin_url( “post.php?post=$post_id&action=trash&_wpnonce=$nonce” ); but I get: Notice: Undefined variable: _session What am I missing in my code to get the session variables?

wp_redirect and current_user_can issues

Put simply, I’m trying to redirect the user after clicking a ‘Save Changes’ button. The plugin uses custom capabilities, and so I want to check the current user has the correct capabilities before progressing with the save and redirect afterwards. However, bit of a dilemma. I have tried loading the function that carries out what […]

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 […]

Is it save to require plugin.php early to be able to use get_plugin_data() earlier?

I’d like to avoid hard coding my plugin’s version at multiple places. To realize this the function get_plugin_data() comes in handy. But here the fun comes to an unpleasant stop. Checking for a plugin update to execute related housekeeping for example should be done early (e.g. plugins_loaded) but unfortunately wp-admin/includes/plugin.php is not loaded before admin_init […]

Difference between hooks Plugin_loaded and admin_int?

As per my understanding, functions attached to plugin_loaded and admin_init hooks are called whenever any admin page is loaded. What’s the difference between them?

Use wp init hook to call other hooks?

I want to know if it is a good practice according to WordPress theme or plugin development. add_action(‘init’,’all_my_hooks’); function all_my_hooks(){ // some initialization stuff here and then add_action(‘admin_init’,—–); add_action(‘admin_menu’,—-); // more like so } thanks

How do I enqueue styles/scripts on certain /wp-admin pages?

I have two simple functions that load stuff using wp_enqueue_style() and wp_enqueue_script(), something like these: function admin_custom_css() { wp_enqueue_style( ‘stylesheet_name’, ‘stylesheet.css’) }; function admin_custom_js { wp_enqueue_script( ‘javascript_file’, ‘script.js’) }; … and a few admin pages, created with add_menu_page() and add_submenu_page() function my_menu() { add_menu_page(‘Page 1’, ‘bar’, ‘something’, ‘else’, ‘foo’); add_submenu_page( ‘theme_menu’, ‘Subpage 1’, ‘Subpage’, ‘something’, […]