{"action":"created","comment":{"url":"https://api.github.com/repos/Automattic/sensei/pulls/comments/71908090","id":71908090,"diff_hunk":"@@ -3068,40 +3069,40 @@ public static function is_prerequisite_complete( $course_id ){\n     }// end is_prerequisite_complete\n \n \t/**\n-\t * Allowing user to set course archive page as front page\n+\t * Allowing user to set course archive page as front page.\n+\t *\n+\t * Expects to be called during pre_get_posts, but only if page_on_front is set\n+\t * to a non-empty value.\n \t *\n \t * @since 1.9.5\n \t * @param WP_Query $query hooked in from pre_get_posts\n \t */\n \tfunction allow_course_archive_on_front_page( $query ) {\n+\t\t// Flag used to indicate if our test query is running: we use this instead of temporarily\n+\t\t// hooking/unhooking due to a core WP bug @see https://core.trac.wordpress.org/ticket/17817\n+\t\tstatic $running = false;\n \n-\t\tglobal $wp;\n-\n-\t\tif ( ! is_page() ){\n-\t\t\treturn; // This only needs to run on the home page. See https://github.com/Automattic/sensei/issues/1438\n+\t\t// Bail if it's clear we're not looking at a static front page or if the $running flag is\n+\t\t// set @see https://github.com/Automattic/sensei/issues/1438\n+\t\tif ( $running || ! $query->is_main_query() || ! is_page() || is_admin() ) {\n+\t\t\treturn;\n \t\t}\n \n-\t\t// avoid infinite loop\n-\t\tremove_action( 'pre_get_posts', array( $this, 'allow_course_archive_on_front_page' ) );\n-\n+\t\t// Set the flag indicating our test query is (about to be) running\n+\t\t$running = true;\n \t\t$query_check = clone $query;\n \t\t$posts = $query_check->get_posts();\n-\t\t$possible_home_page = array_shift( $posts );\n-\n-\t\t// check all conditions\n-\t\t$not_a_valid_static_front_page = 0 == intval( get_option( 'page_on_front' ) )\n-\t\t                                 || is_admin()\n-\t\t                                 || ! $query->is_main_query()\n-\t\t                                 || ! empty( $wp->query_string )\n-\t\t                                 || ! isset( $possible_home_page->ID )\n-\t\t                                 || 'page' !=$possible_home_page->post_type\n-\t\t                                 || $possible_home_page->ID != get_option( 'page_on_front' ) ;\n-\n-\t\tif ( $not_a_valid_static_front_page ) {\n-\t\t\t// add action again to check subsequent calls\n-\t\t\tadd_action( 'pre_get_posts', array( $this, 'allow_course_archive_on_front_page' ) );\n+\t\t$running = false;","path":"includes/class-sensei-course.php","position":61,"original_position":61,"commit_id":"82aeddd119ebc4a25aaa2f7b34b8f4f8f95485ba","original_commit_id":"82aeddd119ebc4a25aaa2f7b34b8f4f8f95485ba","user":{"login":"georgestephanis","id":941023,"avatar_url":"https://avatars.githubusercontent.com/u/941023?v=3","gravatar_id":"","url":"https://api.github.com/users/georgestephanis","html_url":"https://github.com/georgestephanis","followers_url":"https://api.github.com/users/georgestephanis/followers","following_url":"https://api.github.com/users/georgestephanis/following{/other_user}","gists_url":"https://api.github.com/users/georgestephanis/gists{/gist_id}","starred_url":"https://api.github.com/users/georgestephanis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/georgestephanis/subscriptions","organizations_url":"https://api.github.com/users/georgestephanis/orgs","repos_url":"https://api.github.com/users/georgestephanis/repos","events_url":"https://api.github.com/users/georgestephanis/events{/privacy}","received_events_url":"https://api.github.com/users/georgestephanis/received_events","type":"User","site_admin":false},"body":"If this isn't going to run again for subsequent queries (as per line 3127) and the point of `$running` is to prevent it from recursing into itself, what's the point of toggling it back to false again?  Why not just leave it so the function doesn't get called again?\r\n\r\nOr is it in a way that it can fail multiple times after this point, but only complete once?","created_at":"2016-07-22T16:38:36Z","updated_at":"2016-07-22T16:38:36Z","html_url":"https://github.com/Automattic/sensei/pull/1502#discussion_r71908090","pull_request_url":"https://api.github.com/repos/Automattic/sensei/pulls/1502","_links":{"self":{"href":"https://api.github.com/repos/Automattic/sensei/pulls/comments/71908090"},"html":{"href":"https://github.com/Automattic/sensei/pull/1502#discussion_r71908090"},"pull_request":{"href":"https://api.github.com/repos/Automattic/sensei/pulls/1502"}}},"pull_request":{"url":"https://api.github.com/repos/Automattic/sensei/pulls/1502","id":76349995,"html_url":"https://github.com/Automattic/sensei/pull/1502","diff_url":"https://github.com/Automattic/sensei/pull/1502.diff","patch_url":"https://github.com/Automattic/sensei/pull/1502.patch","issue_url":"https://api.github.com/repos/Automattic/sensei/issues/1502","number":1502,"state":"open","locked":false,"title":"Reduce potential for query conflicts","user":{"login":"barryhughes","id":3594411,"avatar_url":"https://avatars.githubusercontent.com/u/3594411?v=3","gravatar_id":"","url":"https://api.github.com/users/barryhughes","html_url":"https://github.com/barryhughes","followers_url":"https://api.github.com/users/barryhughes/followers","following_url":"https://api.github.com/users/barryhughes/following{/other_user}","gists_url":"https://api.github.com/users/barryhughes/gists{/gist_id}","starred_url":"https://api.github.com/users/barryhughes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/barryhughes/subscriptions","organizations_url":"https://api.github.com/users/barryhughes/orgs","repos_url":"https://api.github.com/users/barryhughes/repos","events_url":"https://api.github.com/users/barryhughes/events{/privacy}","received_events_url":"https://api.github.com/users/barryhughes/received_events","type":"User","site_admin":false},"body":"Hey all,\r\n\r\nWe've hit some further conflicts when The Events Calendar and Sensei run side by side. The work already done in #1438 definitely improved things, but the same core problem still occurs if (for example) The Events Calendar widgets are in place beside a static page.\r\n\r\nThis change resolves that problem and so far as I can establish keeps things functioning as expected in the `allow_course_archive_on_front_page()` method.\r\n\r\nSummary:\r\n\r\n* Only hook `allow_course_archive_on_front_page()` when required (ie, if a static front page is set)\r\n* Avoid unhooking/rehooking self from within the same action, to avoid issues re this [core WP bug](https://core.trac.wordpress.org/ticket/17817)\r\n* Shuffles the logic a little to further avoid running an extra query until it's really necessary\r\n\r\n#1438","created_at":"2016-07-05T21:58:39Z","updated_at":"2016-07-22T16:38:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9596c98d406817826791abb8f0ea8a588212dea7","assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/Automattic/sensei/milestones/36","html_url":"https://github.com/Automattic/sensei/milestones/1.9.7","labels_url":"https://api.github.com/repos/Automattic/sensei/milestones/36/labels","id":1748736,"number":36,"title":"1.9.7","description":"","creator":{"login":"kraftbj","id":88897,"avatar_url":"https://avatars.githubusercontent.com/u/88897?v=3","gravatar_id":"","url":"https://api.github.com/users/kraftbj","html_url":"https://github.com/kraftbj","followers_url":"https://api.github.com/users/kraftbj/followers","following_url":"https://api.github.com/users/kraftbj/following{/other_user}","gists_url":"https://api.github.com/users/kraftbj/gists{/gist_id}","starred_url":"https://api.github.com/users/kraftbj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kraftbj/subscriptions","organizations_url":"https://api.github.com/users/kraftbj/orgs","repos_url":"https://api.github.com/users/kraftbj/repos","events_url":"https://api.github.com/users/kraftbj/events{/privacy}","received_events_url":"https://api.github.com/users/kraftbj/received_events","type":"User","site_admin":false},"open_issues":37,"closed_issues":0,"state":"open","created_at":"2016-05-04T22:10:50Z","updated_at":"2016-07-22T15:21:31Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/Automattic/sensei/pulls/1502/commits","review_comments_url":"https://api.github.com/repos/Automattic/sensei/pulls/1502/comments","review_comment_url":"https://api.github.com/repos/Automattic/sensei/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Automattic/sensei/issues/1502/comments","statuses_url":"https://api.github.com/repos/Automattic/sensei/statuses/82aeddd119ebc4a25aaa2f7b34b8f4f8f95485ba","head":{"label":"barryhughes:fix/mt-46724-sensei-tec-conflict","ref":"fix/mt-46724-sensei-tec-conflict","sha":"82aeddd119ebc4a25aaa2f7b34b8f4f8f95485ba","user":{"login":"barryhughes","id":3594411,"avatar_url":"https://avatars.githubusercontent.com/u/3594411?v=3","gravatar_id":"","url":"https://api.github.com/users/barryhughes","html_url":"https://github.com/barryhughes","followers_url":"https://api.github.com/users/barryhughes/followers","following_url":"https://api.github.com/users/barryhughes/following{/other_user}","gists_url":"https://api.github.com/users/barryhughes/gists{/gist_id}","starred_url":"https://api.github.com/users/barryhughes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/barryhughes/subscriptions","organizations_url":"https://api.github.com/users/barryhughes/orgs","repos_url":"https://api.github.com/users/barryhughes/repos","events_url":"https://api.github.com/users/barryhughes/events{/privacy}","received_events_url":"https://api.github.com/users/barryhughes/received_events","type":"User","site_admin":false},"repo":{"id":62671925,"name":"sensei","full_name":"barryhughes/sensei","owner":{"login":"barryhughes","id":3594411,"avatar_url":"https://avatars.githubusercontent.com/u/3594411?v=3","gravatar_id":"","url":"https://api.github.com/users/barryhughes","html_url":"https://github.com/barryhughes","followers_url":"https://api.github.com/users/barryhughes/followers","following_url":"https://api.github.com/users/barryhughes/following{/other_user}","gists_url":"https://api.github.com/users/barryhughes/gists{/gist_id}","starred_url":"https://api.github.com/users/barryhughes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/barryhughes/subscriptions","organizations_url":"https://api.github.com/users/barryhughes/orgs","repos_url":"https://api.github.com/users/barryhughes/repos","events_url":"https://api.github.com/users/barryhughes/events{/privacy}","received_events_url":"https://api.github.com/users/barryhughes/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/barryhughes/sensei","description":"Sensei the Learning Management Plugin for WordPress","fork":true,"url":"https://api.github.com/repos/barryhughes/sensei","forks_url":"https://api.github.com/repos/barryhughes/sensei/forks","keys_url":"https://api.github.com/repos/barryhughes/sensei/keys{/key_id}","collaborators_url":"https://api.github.com/repos/barryhughes/sensei/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/barryhughes/sensei/teams","hooks_url":"https://api.github.com/repos/barryhughes/sensei/hooks","issue_events_url":"https://api.github.com/repos/barryhughes/sensei/issues/events{/number}","events_url":"https://api.github.com/repos/barryhughes/sensei/events","assignees_url":"https://api.github.com/repos/barryhughes/sensei/assignees{/user}","branches_url":"https://api.github.com/repos/barryhughes/sensei/branches{/branch}","tags_url":"https://api.github.com/repos/barryhughes/sensei/tags","blobs_url":"https://api.github.com/repos/barryhughes/sensei/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/barryhughes/sensei/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/barryhughes/sensei/git/refs{/sha}","trees_url":"https://api.github.com/repos/barryhughes/sensei/git/trees{/sha}","statuses_url":"https://api.github.com/repos/barryhughes/sensei/statuses/{sha}","languages_url":"https://api.github.com/repos/barryhughes/sensei/languages","stargazers_url":"https://api.github.com/repos/barryhughes/sensei/stargazers","contributors_url":"https://api.github.com/repos/barryhughes/sensei/contributors","subscribers_url":"https://api.github.com/repos/barryhughes/sensei/subscribers","subscription_url":"https://api.github.com/repos/barryhughes/sensei/subscription","commits_url":"https://api.github.com/repos/barryhughes/sensei/commits{/sha}","git_commits_url":"https://api.github.com/repos/barryhughes/sensei/git/commits{/sha}","comments_url":"https://api.github.com/repos/barryhughes/sensei/comments{/number}","issue_comment_url":"https://api.github.com/repos/barryhughes/sensei/issues/comments{/number}","contents_url":"https://api.github.com/repos/barryhughes/sensei/contents/{+path}","compare_url":"https://api.github.com/repos/barryhughes/sensei/compare/{base}...{head}","merges_url":"https://api.github.com/repos/barryhughes/sensei/merges","archive_url":"https://api.github.com/repos/barryhughes/sensei/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/barryhughes/sensei/downloads","issues_url":"https://api.github.com/repos/barryhughes/sensei/issues{/number}","pulls_url":"https://api.github.com/repos/barryhughes/sensei/pulls{/number}","milestones_url":"https://api.github.com/repos/barryhughes/sensei/milestones{/number}","notifications_url":"https://api.github.com/repos/barryhughes/sensei/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/barryhughes/sensei/labels{/name}","releases_url":"https://api.github.com/repos/barryhughes/sensei/releases{/id}","deployments_url":"https://api.github.com/repos/barryhughes/sensei/deployments","created_at":"2016-07-05T21:48:36Z","updated_at":"2016-07-05T21:48:38Z","pushed_at":"2016-07-05T22:02:47Z","git_url":"git://github.com/barryhughes/sensei.git","ssh_url":"git@github.com:barryhughes/sensei.git","clone_url":"https://github.com/barryhughes/sensei.git","svn_url":"https://github.com/barryhughes/sensei","homepage":"http://senseilms.com/","size":14080,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Automattic:master","ref":"master","sha":"b1e384d0e586b38a4e042acc812f02a585423ea7","user":{"login":"Automattic","id":887802,"avatar_url":"https://avatars.githubusercontent.com/u/887802?v=3","gravatar_id":"","url":"https://api.github.com/users/Automattic","html_url":"https://github.com/Automattic","followers_url":"https://api.github.com/users/Automattic/followers","following_url":"https://api.github.com/users/Automattic/following{/other_user}","gists_url":"https://api.github.com/users/Automattic/gists{/gist_id}","starred_url":"https://api.github.com/users/Automattic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Automattic/subscriptions","organizations_url":"https://api.github.com/users/Automattic/orgs","repos_url":"https://api.github.com/users/Automattic/repos","events_url":"https://api.github.com/users/Automattic/events{/privacy}","received_events_url":"https://api.github.com/users/Automattic/received_events","type":"Organization","site_admin":false},"repo":{"id":7537577,"name":"sensei","full_name":"Automattic/sensei","owner":{"login":"Automattic","id":887802,"avatar_url":"https://avatars.githubusercontent.com/u/887802?v=3","gravatar_id":"","url":"https://api.github.com/users/Automattic","html_url":"https://github.com/Automattic","followers_url":"https://api.github.com/users/Automattic/followers","following_url":"https://api.github.com/users/Automattic/following{/other_user}","gists_url":"https://api.github.com/users/Automattic/gists{/gist_id}","starred_url":"https://api.github.com/users/Automattic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Automattic/subscriptions","organizations_url":"https://api.github.com/users/Automattic/orgs","repos_url":"https://api.github.com/users/Automattic/repos","events_url":"https://api.github.com/users/Automattic/events{/privacy}","received_events_url":"https://api.github.com/users/Automattic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Automattic/sensei","description":"Sensei the Learning Management Plugin for WordPress","fork":false,"url":"https://api.github.com/repos/Automattic/sensei","forks_url":"https://api.github.com/repos/Automattic/sensei/forks","keys_url":"https://api.github.com/repos/Automattic/sensei/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Automattic/sensei/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Automattic/sensei/teams","hooks_url":"https://api.github.com/repos/Automattic/sensei/hooks","issue_events_url":"https://api.github.com/repos/Automattic/sensei/issues/events{/number}","events_url":"https://api.github.com/repos/Automattic/sensei/events","assignees_url":"https://api.github.com/repos/Automattic/sensei/assignees{/user}","branches_url":"https://api.github.com/repos/Automattic/sensei/branches{/branch}","tags_url":"https://api.github.com/repos/Automattic/sensei/tags","blobs_url":"https://api.github.com/repos/Automattic/sensei/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Automattic/sensei/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Automattic/sensei/git/refs{/sha}","trees_url":"https://api.github.com/repos/Automattic/sensei/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Automattic/sensei/statuses/{sha}","languages_url":"https://api.github.com/repos/Automattic/sensei/languages","stargazers_url":"https://api.github.com/repos/Automattic/sensei/stargazers","contributors_url":"https://api.github.com/repos/Automattic/sensei/contributors","subscribers_url":"https://api.github.com/repos/Automattic/sensei/subscribers","subscription_url":"https://api.github.com/repos/Automattic/sensei/subscription","commits_url":"https://api.github.com/repos/Automattic/sensei/commits{/sha}","git_commits_url":"https://api.github.com/repos/Automattic/sensei/git/commits{/sha}","comments_url":"https://api.github.com/repos/Automattic/sensei/comments{/number}","issue_comment_url":"https://api.github.com/repos/Automattic/sensei/issues/comments{/number}","contents_url":"https://api.github.com/repos/Automattic/sensei/contents/{+path}","compare_url":"https://api.github.com/repos/Automattic/sensei/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Automattic/sensei/merges","archive_url":"https://api.github.com/repos/Automattic/sensei/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Automattic/sensei/downloads","issues_url":"https://api.github.com/repos/Automattic/sensei/issues{/number}","pulls_url":"https://api.github.com/repos/Automattic/sensei/pulls{/number}","milestones_url":"https://api.github.com/repos/Automattic/sensei/milestones{/number}","notifications_url":"https://api.github.com/repos/Automattic/sensei/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Automattic/sensei/labels{/name}","releases_url":"https://api.github.com/repos/Automattic/sensei/releases{/id}","deployments_url":"https://api.github.com/repos/Automattic/sensei/deployments","created_at":"2013-01-10T08:52:41Z","updated_at":"2016-07-21T17:15:07Z","pushed_at":"2016-07-21T17:46:49Z","git_url":"git://github.com/Automattic/sensei.git","ssh_url":"git@github.com:Automattic/sensei.git","clone_url":"https://github.com/Automattic/sensei.git","svn_url":"https://github.com/Automattic/sensei","homepage":"http://senseilms.com/","size":14253,"stargazers_count":117,"watchers_count":117,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":51,"mirror_url":null,"open_issues_count":126,"forks":51,"open_issues":126,"watchers":117,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Automattic/sensei/pulls/1502"},"html":{"href":"https://github.com/Automattic/sensei/pull/1502"},"issue":{"href":"https://api.github.com/repos/Automattic/sensei/issues/1502"},"comments":{"href":"https://api.github.com/repos/Automattic/sensei/issues/1502/comments"},"review_comments":{"href":"https://api.github.com/repos/Automattic/sensei/pulls/1502/comments"},"review_comment":{"href":"https://api.github.com/repos/Automattic/sensei/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Automattic/sensei/pulls/1502/commits"},"statuses":{"href":"https://api.github.com/repos/Automattic/sensei/statuses/82aeddd119ebc4a25aaa2f7b34b8f4f8f95485ba"}}}}
{"actor":{"display_login":"georgestephanis"}}