{"id":13840566,"date":"2020-12-28T17:11:12","date_gmt":"2020-12-28T17:11:12","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/wp_register_script-wp_enqueue_script-errors\/"},"modified":"2020-12-28T17:11:12","modified_gmt":"2020-12-28T17:11:12","slug":"wp_register_script-wp_enqueue_script-errors","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/wp_register_script-wp_enqueue_script-errors\/","title":{"rendered":"wp_register_script \/ wp_enqueue_script errors"},"content":{"rendered":"<p>I am getting the following errors:<\/p>\n<blockquote><p>wp_register_script was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. This notice was triggered by the some_handle handle. Please see Debugging in WordPress for more information. (This message was added in version 3.3.0.)<\/p><\/blockquote>\n<blockquote><p>wp_enqueue_script was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. This notice was triggered by the some_handle handle. Please see Debugging in WordPress for more information. (This message was added in version 3.3.0.)<\/p><\/blockquote>\n<p>I&#8217;ve narrowed it down to some logic I&#8217;ve included in my functions.php file. What I am doing here is querying the database of users to see which users selected a certain checkbox on their registration form, though I must not be enqueueing the scripts correctly. Any idea on what I am doing wrong?<\/p>\n<pre><code>\/\/display conditional link:\n\/\/1. get User Status\n $user_id   = get_current_user_id();\n $user_output =  get_user_meta($user_id, &#039;needs_extra_item&#039;, true);\n \/\/echo $user_output[0];\n\n\/\/2. Register the script\nwp_register_script( &#039;some_handle&#039;, &#039;.\/js\/jqueryLaPuerta.js&#039; );\n \n\/\/3. Localize the script with new data\n$some_array = array(\n    &#039;some_string&#039; =&gt; __( $user_output, &#039;plugin-domain&#039; ),\n    &#039;a_value&#039; =&gt; &#039;10&#039;\n);\nwp_localize_script( &#039;some_handle&#039;, &#039;object_name&#039;, $some_array );\n \n\/\/4. Enqueued script with localized data.\nwp_enqueue_script( &#039;some_handle&#039; );<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-13840566","topic","type-topic","status-publish","hentry","topic-tag-wp_enqueue_script","topic-tag-wp_register_script"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/13840566","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\/13840566\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=13840566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}