{"action":"opened","issue":{"url":"https://api.github.com/repos/DevinVinson/WordPress-Plugin-Boilerplate/issues/364","labels_url":"https://api.github.com/repos/DevinVinson/WordPress-Plugin-Boilerplate/issues/364/labels{/name}","comments_url":"https://api.github.com/repos/DevinVinson/WordPress-Plugin-Boilerplate/issues/364/comments","events_url":"https://api.github.com/repos/DevinVinson/WordPress-Plugin-Boilerplate/issues/364/events","html_url":"https://github.com/DevinVinson/WordPress-Plugin-Boilerplate/issues/364","id":129617688,"number":364,"title":"Place for wp_enqueue_script","user":{"login":"CezarisLT","id":1041335,"avatar_url":"https://avatars.githubusercontent.com/u/1041335?v=3","gravatar_id":"","url":"https://api.github.com/users/CezarisLT","html_url":"https://github.com/CezarisLT","followers_url":"https://api.github.com/users/CezarisLT/followers","following_url":"https://api.github.com/users/CezarisLT/following{/other_user}","gists_url":"https://api.github.com/users/CezarisLT/gists{/gist_id}","starred_url":"https://api.github.com/users/CezarisLT/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CezarisLT/subscriptions","organizations_url":"https://api.github.com/users/CezarisLT/orgs","repos_url":"https://api.github.com/users/CezarisLT/repos","events_url":"https://api.github.com/users/CezarisLT/events{/privacy}","received_events_url":"https://api.github.com/users/CezarisLT/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-01-28T23:34:31Z","updated_at":"2016-01-28T23:34:31Z","closed_at":null,"body":"Hi I just started using this plugin to better organise my code and I think its great but I have a problem. I need the javascript to only load on when the admin page is visible. How do I do this? Like I know all the `add_menu_page()` code but not sure where to put the `wp_enqueue_script` and `wp_localize_script` for ajax to work with this layout.\r\n\r\nMy current setup is `class-name-admin.php`\r\n\r\n```PHP\r\nclass Name_Admin {\r\n    private $plugin_name;\r\n    // ....\r\n    \r\n    public function enqueue_scripts() {\r\n        wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'assets/js/name-admin.min.js', array( 'jquery' ), $this->version );\r\n        wp_localize_script($this->plugin_name, $this->plugin_name+\"_obj\", array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );\r\n    }\r\n\r\n    public function page_setup(){\r\n        add_menu_page(\"name\", \"name\", 'manage_options', $this->plugin_name, array( $this, 'show_page'));\r\n    }\r\n\r\n    public function show_page(){\r\n       //TODO:  enqueue_scripts to load here\r\n       // $this->enqueue_scripts(); // not working;\r\n       // show_page -> page_setup -> Name::define_admin_hooks -> add_action -> Loader\r\n       echo require \"partials/name-admin-page.php\"; \r\n    }\r\n}\r\n````\r\nAnd the `class-name.php`\r\n\r\n```PHP\r\nclass Name {\r\n    // ...\r\n    private function define_admin_hooks() {\r\n        $plugin_admin = new Name_Admin( $this->get_plugin_name(), $this->get_version(), $this->loader );\r\n        $this->loader->add_action( 'admin_menu', $plugin_admin, 'page_setup');\r\n    }\r\n}\r\n```"}}