Page is loading after submit before the file is processed

I have built a user import page that imports via csv file upload. The issue I am having is that the page is loading before all of the rows (user information) is finished processing/ inserting users. It works fine if there is 1 or 2 users/ rows in csv but beyond that it does not complete the job. Is there a way to delay the page load until the process of importing the users from the csv file is completed? …
Category: Web

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 is fired. Using a later hook is not possible here. This might be a solution for some plugins but it doesn't work for me, as …
Category: Web

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', 'else', 'foo'); } add_action('admin_menu', 'my_menu'); How do I load my two functions only on these pages? Right now I'm using: add_action('admin_init', 'admin_custom_css' ); add_action('admin_init', 'admin_custom_js' …
Category: Web

Admin_init not working in submenu page

I've a plugin divided into multiple pages and files based on classes. The base file (linked from plugin main file) contains code for menu and submenu pages and provides wordpress with their respective files in a subfolder. The problem is, that the admin_init hook isn't working in the submenu page (trying to save values from a form submitted in submenu page). The main page looks like (the admin_init hook works fine if used in this file class itself): class MyPlugin …
Category: Web

How to hook into the subscriber /wp-admin/index.php page?

I want to hook into the subscriber role index.php page (wp-admin/index.php) to add some custom content outside of the widgets. This admin_init works for all admin pages: add_action( 'init', 'test_init'); function test_init(){ add_action( 'admin_init', 'test_admin_init'); } function test_admin_init() { echo "Test Admin Init"; } But this doesn't work for only subscribers: add_action('admin_init', 'add_to_dashboard'); function add_to_dashboard() { if (current_user_can('subscriber') && is_admin()) { add_action( 'admin_init', 'test_admin_init'); } } function test_admin_init() { echo "Test Admin Init"; } And how would this work for …
Category: Web

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 not? $args = array( 'labels' => $labels, 'public' => true, ); register_post_type('random', $args);} add_action('admin_init', 'rdf', 0);
Category: Web

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?
Category: Web

Hide login page and use wp_login_form on ordinary pages

I would like to hide site.com/wp-login.php page but also to use wp_login_form() function where I want. Currently this function doesn't work if I hide login page with this code (it redirects to front page) function go_away() { global $action; // redirect only if action is login (lost password action is ok) if($action === 'login') { wp_redirect(site_url()); exit(); } } add_action( 'login_init' , 'go_away' ); add_action( 'admin_init' , 'go_away' ); And code for login in front-page.php or in sidebar.php is this …
Category: Web

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
Category: Web

How to use hook admin_init for add_action for custom post type column

I'm adding a post thumbnail column to the edit custom post screen. The post thumbnails are showing up fine however I would like to hook it with admin_init to take some load off the website. This is my code for adding the thumbnail's to my edit custom post screen: add_filter( 'manage_edit-model_columns', 'my_columns_filter', 10, 1 ); function my_columns_filter( $columns ) { $column_thumbnail = array( 'thumbnail' => 'Thumbnail' ); $columns = array_slice( $columns, 0, 1, true ) + $column_thumbnail + array_slice( $columns, …
Category: Web

Editor capabilities - admin_init

I'm having a little difficulties with roles and capabilities. Editors gets a 'Cheatin uh?'-message when they try to update the custom theme-settings. Can anyone explain why - or maybe even have a solution? <?php add_action('admin_menu', 'add_global_custom_options'); function add_global_custom_options() { add_menu_page('Indstillinger', 'Indstillinger', 'moderate_comments', 'functions','global_custom_options'); } add_action('admin_init', 'custom_settings_css'); function custom_settings_css() { wp_enqueue_style('custom-settings-css', get_bloginfo('template_directory') . '/theme-files/css/custom-settings.css'); } ?> <?php function global_custom_options() {?> <div class="wrap theme-options"> <h2>Indstillinger</h2> <form method="post" action="options.php"> <?php wp_nonce_field('update-options') ?> <div class="section"> <h3>Settings</h3> <p> <h4>BOXIT</h4> <textarea name="box1" size="45"><?php echo get_option('box1'); ?></textarea> …
Category: Web

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 is mentioned above using 'admin_init' and 'admin_menu'. Using 'admin_init', throws an undefined function error for the 'current_user_can' function, which makes sense since it hasn't been …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.