Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm implementing a web widget and for this reason i'd like my script to respond to the request as soon as possible, to avoid loading unneccessary thing.
I've found out that calling get_permalink( $page_id ) before the init phase return this error

[19-Sep-2012 12:10:12 UTC] PHP Fatal error: Call to a member function get_page_permastruct() on a non-object in C:\Program Files (x86)\Zend\Apache2\htdocs\wordpress\wp-includes\link-template.php on line 276

I was wondering is there a way in which i can retrieve the permalink of the page without waiting for the init phase?

share|improve this question

2 Answers 2

setup_theme is the earliest action you can call get_permalink() on. the rewrite class gets instantiated after plugins_loaded and before setup_theme in wp-settings.php, which is the object the error refers to. get_page_permastruct() is a method of the rewrite class.

share|improve this answer

The error message means that $page_id is not set. Try using get_query_var('p') instead?

share|improve this answer
    
I'm pretty sure you're wrong. It clearly says that it wants to call get_page_permastruct() method on $wp_rewrite object, but this object isn't initialized so its undefined and this call ends with fatal error. If you were right, it would be notice/warning not fatal error. –  Krzysiek Dróżdż Jun 20 '13 at 18:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.