$current_user or $user_ID global in main plugin file
-
I’m having some trouble pulling in the $current_user or $user_ID global in my main plug in file.
a var dump reveals that neither global is set at this point in the plugin. But it seems like the globals are available in the callback hooks. Help?
Code:
global $wpdb, $current_user, $user_ID; if ( is_admin() ) { function myplugin_activation () { global $wpdb; include ( WP_PLUGIN_DIR . '/soapblocks/php/activate.php' ); } function myplugin_deactivate () { global $wpdb; include ( WP_PLUGIN_DIR . '/mypluginmyplugin/php/deactivate.php' ); } register_activation_hook( __FILE__ , 'myplugin_activation' ); register_deactivation_hook ( __FILE__, 'myplugin_deactivate' ); if ( isset ( $_GET['myplugin_post_id'] ) && is_numeric ( $_GET['myplugin_post_id'] ) ) { $post_id = intval( $_GET['myplugin_post_id'] ); $sql = 'SELECT * FROM ' . $wpdb->prefix . 'myplugin_my_table WHERE my_table_post_id = %d'; $result = $wpdb->get_row( $wpdb->prepare( $sql, $post_id ) ); if ( !$result ) { $sql = 'INSERT INTO ' . $wpdb->prefix . 'myplugin_my_table ( my_table_post_id, my_table_user_id) VALUES ( %d, %d )'; // here is where I'm trying to use the globals $wpdb->query ( $wpdb->prepare ( $sql, $post_id, $user_ID ) ); header('Location: '.preg_replace("/\?myplugin_(?:action)=[0-9]+[&]?/", '', $_SERVER['REQUEST_URI'])); } } }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘$current_user or $user_ID global in main plugin file’ is closed to new replies.