{"action":"created","issue":{"url":"https://api.github.com/repos/AffiliateWP/AffiliateWP/issues/1038","labels_url":"https://api.github.com/repos/AffiliateWP/AffiliateWP/issues/1038/labels{/name}","comments_url":"https://api.github.com/repos/AffiliateWP/AffiliateWP/issues/1038/comments","events_url":"https://api.github.com/repos/AffiliateWP/AffiliateWP/issues/1038/events","html_url":"https://github.com/AffiliateWP/AffiliateWP/issues/1038","id":124237182,"number":1038,"title":"Fix Fatal Error undefined function `affwp_get_pages` in certain situations.","user":{"login":"nerrad","id":1429108,"avatar_url":"https://avatars.githubusercontent.com/u/1429108?v=3","gravatar_id":"","url":"https://api.github.com/users/nerrad","html_url":"https://github.com/nerrad","followers_url":"https://api.github.com/users/nerrad/followers","following_url":"https://api.github.com/users/nerrad/following{/other_user}","gists_url":"https://api.github.com/users/nerrad/gists{/gist_id}","starred_url":"https://api.github.com/users/nerrad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nerrad/subscriptions","organizations_url":"https://api.github.com/users/nerrad/orgs","repos_url":"https://api.github.com/users/nerrad/repos","events_url":"https://api.github.com/users/nerrad/events{/privacy}","received_events_url":"https://api.github.com/users/nerrad/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-12-29T16:49:12Z","updated_at":"2015-12-29T17:22:47Z","closed_at":null,"body":"This is a strange one.  I'm getting this fatal error when attempting to do a custom upload action (via ajax) on one of our plugin settings page with Affiliate WP active.\r\n\r\n```\r\nPHP message: PHP Fatal error: Call to undefined function affwp_get_pages() in {redacted}/staging/wp-content/plugins/affiliate-wp/includes/admin/settings/class-settings.php on line 319\" while reading response header from upstream, client: {redacted}, server: {redacted}, request: \"POST /wp-content/plugins/plugin-update-engine/js/plupload-handlers/upload.php?slug=espresso-recurring HTTP/1.1\", upstream: \"fastcgi://unix:/var/run/php5-fpm.sock:\", host: \"{redacted}\", referrer: \"{redacted}/wp-admin/admin.php?page=plugin_update_page&action=edit&checked%5B0%5D=5520&plugin_status=all&paged=2&s&_wpnonce=702c5827d6\"\r\n```\r\n\r\nThe issue is (as the error reveals) `Affiliate_WP_Settings::register_settings` is calling `affwp_get_pages` when its not declared.  The weird thing is.  I see that `affwp_get_pages` is declared in `display-settings.php` which is required in `affiliate-wp.php` inside a `is_admin()` check and `Affiliate_WP_Settings::register_settings` is called via a callback on the `admin_init` hook (which should only fire when `is_admin()` is true).  So it's kind of puzzling that `affwp_get_pages` isn't available.  But its containing file obviously isn't getting loaded.\r\n\r\nI'll investigate some more and will submit a pull request if I can find a clean fix but wanted to get this up in case you guys were already aware and have a fix in place.\r\n"},"comment":{"url":"https://api.github.com/repos/AffiliateWP/AffiliateWP/issues/comments/167834531","html_url":"https://github.com/AffiliateWP/AffiliateWP/issues/1038#issuecomment-167834531","issue_url":"https://api.github.com/repos/AffiliateWP/AffiliateWP/issues/1038","id":167834531,"user":{"login":"nerrad","id":1429108,"avatar_url":"https://avatars.githubusercontent.com/u/1429108?v=3","gravatar_id":"","url":"https://api.github.com/users/nerrad","html_url":"https://github.com/nerrad","followers_url":"https://api.github.com/users/nerrad/followers","following_url":"https://api.github.com/users/nerrad/following{/other_user}","gists_url":"https://api.github.com/users/nerrad/gists{/gist_id}","starred_url":"https://api.github.com/users/nerrad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nerrad/subscriptions","organizations_url":"https://api.github.com/users/nerrad/orgs","repos_url":"https://api.github.com/users/nerrad/repos","events_url":"https://api.github.com/users/nerrad/events{/privacy}","received_events_url":"https://api.github.com/users/nerrad/received_events","type":"User","site_admin":false},"created_at":"2015-12-29T17:22:47Z","updated_at":"2015-12-29T17:22:47Z","body":"yah confirmed.  Our custom upload handler is calling `wp_load.php` early (which then loads any other plugins but `is_admin()` will return false.` Then later loads `wp-admin/admin.php`  which will in turn trigger the `do_action(`admin_init`)` hook.   We were able to fix our plugin.  It's really old code so there's lots of `doing_it_wrong()` in it.  I *still* think however your loading process here is a bit fragile.  But it is likely only edgecases like ours that will reveal that so totally understand if you decide to just close this issue."}}