Support » Plugins » Hacks » Can I get the post ID during the 'init' or 'plugins_loaded' action?

  • I REALLY need to get the post ID during the plugins_loaded action if possible due to the nature of the code. You see, the code itself is sending header information! code below

    function wpcwv2_plugins_loaded()
    	global $post;
    	$pageID = $post->ID;
    	if(is_admin() || is_feed() || is_login_page())
    	$wpcwv2_request = (isset($_GET['wpcwv2']) && !empty($_GET['wpcwv2']) ) ? strtolower($_GET['wpcwv2']) : null;
    	// Switch Requests
    		case 'js':
    				header('Content-type: application/x-javascript');
    				//header('Content-type: application/octet-stream');
    				//header('Content-Length: ' . filesize($file));
    				header('Content-Disposition: inline; filename="wpcwv2.js"');
    				// Echo PATH
    				echo 'var wpcwv2_wpurl = "'.get_bloginfo('wpurl').'";'."\n";
    				echo 'var wpcwv2_url = "'.WP_PLUGIN_URL.'/content-warning";'."\n";
    				echo 'var tb_pathToImage = "'.get_bloginfo('wpurl').'/wp-includes/js/thickbox/loadingAnimation.gif";'."\n";
    				echo 'var tb_closeImage = "'.get_bloginfo('wpurl').'/wp-includes/js/thickbox/tb-close.png";'."\n";
    		case 'message':
    		case 'log':
    		default: return;
    add_action('plugins_loaded', wpcwv2_plugins_loaded);

    Before you say “use the $post global”, i have to say I already did, and I even var_dump’d it to see what it was giving me, it was all NULL…. aside from a few insignificant integers. I haven’t found a fix for this in the four hours I’ve been pounding on it so if any of you have a solution please let me know. I’m stumped lol…

Viewing 2 replies - 1 through 2 (of 2 total)
  • syslogic


    I don’t think so – because this event happens before $wp_query exists.
    Accessing the $post is possible at this time, but it’s just the default object. Template’s functions.php might be a better place in timeline.




    Thanks for the info. though I’ve solved it since then. Come to find out I had to rewrite the plugin 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can I get the post ID during the 'init' or 'plugins_loaded' action?’ is closed to new replies.