{"id":12491705,"date":"2020-02-28T16:12:50","date_gmt":"2020-02-28T16:12:50","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/plugin-development-document-sample-code-breaks-wordpress\/"},"modified":"2020-02-28T16:12:50","modified_gmt":"2020-02-28T16:12:50","slug":"plugin-development-document-sample-code-breaks-wordpress","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/plugin-development-document-sample-code-breaks-wordpress\/","title":{"rendered":"plugin development document sample code breaks wordpress"},"content":{"rendered":"<p>I took the sample code from https:\/\/developer.wordpress.org\/plugins\/security\/nonces\/  and created a plugin using but it causes wordpress to crash with the following message:<\/p>\n<p>atal error: Uncaught Error: Call to undefined function wp_get_current_user() in C:\\dev\\xampp\\htdocs\\wpSandBox\\wp-includes\\capabilities.php:652 Stack trace: #0 C:\\dev\\xampp\\htdocs\\wpSandBox\\wp-content\\plugins\\marys_sandbox.php(65): current_user_can(&#8216;edit_others_pos&#8230;&#8217;) #1 C:\\dev\\xampp\\htdocs\\wpSandBox\\wp-settings.php(360): include_once(&#8216;C:\\\\dev\\\\xampp\\\\ht&#8230;&#8217;) #2 C:\\dev\\xampp\\htdocs\\wpSandBox\\wp-config.php(90): require_once(&#8216;C:\\\\dev\\\\xampp\\\\ht&#8230;&#8217;) #3 C:\\dev\\xampp\\htdocs\\wpSandBox\\wp-load.php(37): require_once(&#8216;C:\\\\dev\\\\xampp\\\\ht&#8230;&#8217;) #4 C:\\dev\\xampp\\htdocs\\wpSandBox\\wp-admin\\admin.php(34): require_once(&#8216;C:\\\\dev\\\\xampp\\\\ht&#8230;&#8217;) #5 C:\\dev\\xampp\\htdocs\\wpSandBox\\wp-admin\\plugins.php(10): require_once(&#8216;C:\\\\dev\\\\xampp\\\\ht&#8230;&#8217;) #6 {main} thrown in C:\\dev\\xampp\\htdocs\\wpSandBox\\wp-includes\\capabilities.php on line 652<\/p>\n<p>There has been a critical error on your website. Please check your site admin email inbox for instructions.<\/p>\n<p>&#8212;&#8212;-<\/p>\n<p>the line causing the error is if (current_user_can(&#8216;edit_others_posts&#8217;))<br \/>\nif i remove the if statement it works fine.<\/p>\n<p>sorry i cannot share access to the site as it is on a local installation which i did yesterday so very latest release.<\/p>\n","protected":false},"template":"","class_list":["post-12491705","topic","type-topic","status-publish","hentry","topic-tag-current_user_can","topic-tag-nonces"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/12491705","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/12491705\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=12491705"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}