{"action":"created","comment":{"url":"https://api.github.com/repos/Yoast/wordpress-seo/pulls/comments/39386079","id":39386079,"diff_hunk":"@@ -0,0 +1,195 @@\n+<?php\n+/**\n+ * @package WPSEO\\Admin\n+ */\n+\n+/**\n+ * Adds the UI to change the primary term for a post\n+ */\n+class WPSEO_Primary_Term_Admin {\n+\n+\t/**\n+\t * Constructor.\n+\t */\n+\tpublic function __construct() {\n+\t\tadd_action( 'admin_footer', array( $this, 'wp_footer' ), 10 );\n+\n+\t\tadd_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );\n+\n+\t\tadd_action( 'save_post', array( $this, 'save_primary_terms' ) );\n+\t\tadd_filter( 'post_link_category', array( $this, 'post_link_category' ) );\n+\t}\n+\n+\t/**\n+\t * Add primary term templates\n+\t */\n+\tpublic function wp_footer() {\n+\t\t$taxonomies = $this->get_primary_term_taxonomies();\n+\n+\t\tif ( ! empty( $taxonomies ) ) {\n+\t\t\tinclude_once WPSEO_PATH . '/admin/views/js-templates-primary-term.php';\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * Enqueues all the assets needed for the primary term interface\n+\t *\n+\t * @return void\n+\t */\n+\tpublic function enqueue_assets() {\n+\t\t$taxonomies = $this->get_primary_term_taxonomies();\n+\n+\t\t// Only enqueue if there are taxonomies that need a primary term.\n+\t\tif ( empty( $taxonomies ) ) {\n+\t\t\treturn;\n+\t\t}\n+\n+\t\twp_enqueue_style( 'wpseo-primary-category', plugins_url( 'css/metabox-primary-category' . WPSEO_CSSJS_SUFFIX . '.css', WPSEO_FILE ), array(), WPSEO_VERSION );\n+\n+\t\twp_enqueue_script( 'wpseo-primary-category', plugins_url( 'js/wp-seo-metabox-category' . WPSEO_CSSJS_SUFFIX . '.js', WPSEO_FILE ), array( 'jquery' ), WPSEO_VERSION, true );\n+\n+\t\t$taxonomies = array_map( array( $this, 'map_taxonomies_for_js' ), $taxonomies );\n+\n+\t\t$data = array(\n+\t\t\t'taxonomies' => $taxonomies,\n+\t\t);\n+\t\twp_localize_script( 'wpseo-primary-category', 'wpseoPrimaryCategoryL10n', $data );\n+\t}\n+\n+\t/**\n+\t * Saves all selected primary terms\n+\t *\n+\t * @param int $post_ID Post ID to save primary terms for.\n+\t */\n+\tpublic function save_primary_terms( $post_ID ) {\n+\t\t$taxonomies = $this->get_primary_term_taxonomies( $post_ID );\n+\n+\t\tforeach ( $taxonomies as $taxonomy ) {\n+\t\t\t$this->save_primary_term( $post_ID, $taxonomy );\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * Filters post_link_category to change the category to the chosen category by the user\n+\t *\n+\t * @param stdClass $category The category that is now used for the post link.\n+\t *\n+\t * @return array|null|object|WP_Error The category we want to use for the post link.\n+\t */\n+\tpublic function post_link_category( $category ) {\n+\t\t$primary_category = new WPSEO_Primary_Term( 'category', get_the_ID() );\n+\t\t$primary_category = $primary_category->get_primary_term();\n+\n+\t\tif ( false !== $primary_category && $primary_category !== $category->cat_ID ) {\n+\t\t\t$category = get_category( $primary_category );\n+\t\t}\n+\n+\t\treturn $category;\n+\t}\n+\n+\t/**\n+\t * Returns an array suitable for use in the javascript\n+\t *\n+\t * @param stdClass $taxonomy The taxonomy to map.\n+\t *\n+\t * @return array\n+\t */\n+\tprivate function map_taxonomies_for_js( $taxonomy ) {\n+\t\t$primary_term = new WPSEO_Primary_Term( $taxonomy->name, get_the_ID() );","path":"admin/class-primary-term-admin.php","position":98,"original_position":98,"commit_id":"eb83572d8f4ea863d9cbdc35a848c7fd2f40f32f","original_commit_id":"eb83572d8f4ea863d9cbdc35a848c7fd2f40f32f","user":{"login":"andizer","id":325040,"avatar_url":"https://avatars.githubusercontent.com/u/325040?v=3","gravatar_id":"","url":"https://api.github.com/users/andizer","html_url":"https://github.com/andizer","followers_url":"https://api.github.com/users/andizer/followers","following_url":"https://api.github.com/users/andizer/following{/other_user}","gists_url":"https://api.github.com/users/andizer/gists{/gist_id}","starred_url":"https://api.github.com/users/andizer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andizer/subscriptions","organizations_url":"https://api.github.com/users/andizer/orgs","repos_url":"https://api.github.com/users/andizer/repos","events_url":"https://api.github.com/users/andizer/events{/privacy}","received_events_url":"https://api.github.com/users/andizer/received_events","type":"User","site_admin":false},"body":"If you made a wrapper for this, see comment on [line 81](https://github.com/Yoast/wordpress-seo/pull/2746/files#diff-93ebfff2ef428ae807ba3678c7200502R81). You don't have to do the same logic.","created_at":"2015-09-14T12:09:29Z","updated_at":"2015-09-14T12:09:29Z","html_url":"https://github.com/Yoast/wordpress-seo/pull/2746#discussion_r39386079","pull_request_url":"https://api.github.com/repos/Yoast/wordpress-seo/pulls/2746","_links":{"self":{"href":"https://api.github.com/repos/Yoast/wordpress-seo/pulls/comments/39386079"},"html":{"href":"https://github.com/Yoast/wordpress-seo/pull/2746#discussion_r39386079"},"pull_request":{"href":"https://api.github.com/repos/Yoast/wordpress-seo/pulls/2746"}}},"pull_request":{"url":"https://api.github.com/repos/Yoast/wordpress-seo/pulls/2746","id":40899727,"html_url":"https://github.com/Yoast/wordpress-seo/pull/2746","diff_url":"https://github.com/Yoast/wordpress-seo/pull/2746.diff","patch_url":"https://github.com/Yoast/wordpress-seo/pull/2746.patch","issue_url":"https://api.github.com/repos/Yoast/wordpress-seo/issues/2746","number":2746,"state":"open","locked":false,"title":"Add UI to change the primary category","user":{"login":"atimmer","id":584693,"avatar_url":"https://avatars.githubusercontent.com/u/584693?v=3","gravatar_id":"","url":"https://api.github.com/users/atimmer","html_url":"https://github.com/atimmer","followers_url":"https://api.github.com/users/atimmer/followers","following_url":"https://api.github.com/users/atimmer/following{/other_user}","gists_url":"https://api.github.com/users/atimmer/gists{/gist_id}","starred_url":"https://api.github.com/users/atimmer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atimmer/subscriptions","organizations_url":"https://api.github.com/users/atimmer/orgs","repos_url":"https://api.github.com/users/atimmer/repos","events_url":"https://api.github.com/users/atimmer/events{/privacy}","received_events_url":"https://api.github.com/users/atimmer/received_events","type":"User","site_admin":false},"body":"This PR add functionality to change the primary category in the admin. If the primary category is selected it will be used to change the post link to what the user desires.\r\n\r\nThe code is taxonomy independent so it will work for any taxonomy. Support for a taxonomy can be added through the `wpseo_primary_term_taxonomies` filter.\r\n\r\nFixes #2626 ","created_at":"2015-07-27T12:51:55Z","updated_at":"2015-09-14T12:09:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"64eabb6c2df52f0d4fae165c8102416e3b6253c4","assignee":null,"milestone":{"url":"https://api.github.com/repos/Yoast/wordpress-seo/milestones/14","html_url":"https://github.com/Yoast/wordpress-seo/milestones/2.4","labels_url":"https://api.github.com/repos/Yoast/wordpress-seo/milestones/14/labels","id":1204895,"number":14,"title":"2.4","description":"","creator":{"login":"jdevalk","id":487629,"avatar_url":"https://avatars.githubusercontent.com/u/487629?v=3","gravatar_id":"","url":"https://api.github.com/users/jdevalk","html_url":"https://github.com/jdevalk","followers_url":"https://api.github.com/users/jdevalk/followers","following_url":"https://api.github.com/users/jdevalk/following{/other_user}","gists_url":"https://api.github.com/users/jdevalk/gists{/gist_id}","starred_url":"https://api.github.com/users/jdevalk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdevalk/subscriptions","organizations_url":"https://api.github.com/users/jdevalk/orgs","repos_url":"https://api.github.com/users/jdevalk/repos","events_url":"https://api.github.com/users/jdevalk/events{/privacy}","received_events_url":"https://api.github.com/users/jdevalk/received_events","type":"User","site_admin":false},"open_issues":25,"closed_issues":11,"state":"open","created_at":"2015-07-13T11:06:27Z","updated_at":"2015-09-14T09:26:07Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/Yoast/wordpress-seo/pulls/2746/commits","review_comments_url":"https://api.github.com/repos/Yoast/wordpress-seo/pulls/2746/comments","review_comment_url":"https://api.github.com/repos/Yoast/wordpress-seo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Yoast/wordpress-seo/issues/2746/comments","statuses_url":"https://api.github.com/repos/Yoast/wordpress-seo/statuses/eb83572d8f4ea863d9cbdc35a848c7fd2f40f32f","head":{"label":"Yoast:stories/at/primary-category","ref":"stories/at/primary-category","sha":"eb83572d8f4ea863d9cbdc35a848c7fd2f40f32f","user":{"login":"Yoast","id":4690436,"avatar_url":"https://avatars.githubusercontent.com/u/4690436?v=3","gravatar_id":"","url":"https://api.github.com/users/Yoast","html_url":"https://github.com/Yoast","followers_url":"https://api.github.com/users/Yoast/followers","following_url":"https://api.github.com/users/Yoast/following{/other_user}","gists_url":"https://api.github.com/users/Yoast/gists{/gist_id}","starred_url":"https://api.github.com/users/Yoast/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yoast/subscriptions","organizations_url":"https://api.github.com/users/Yoast/orgs","repos_url":"https://api.github.com/users/Yoast/repos","events_url":"https://api.github.com/users/Yoast/events{/privacy}","received_events_url":"https://api.github.com/users/Yoast/received_events","type":"Organization","site_admin":false},"repo":{"id":6723399,"name":"wordpress-seo","full_name":"Yoast/wordpress-seo","owner":{"login":"Yoast","id":4690436,"avatar_url":"https://avatars.githubusercontent.com/u/4690436?v=3","gravatar_id":"","url":"https://api.github.com/users/Yoast","html_url":"https://github.com/Yoast","followers_url":"https://api.github.com/users/Yoast/followers","following_url":"https://api.github.com/users/Yoast/following{/other_user}","gists_url":"https://api.github.com/users/Yoast/gists{/gist_id}","starred_url":"https://api.github.com/users/Yoast/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yoast/subscriptions","organizations_url":"https://api.github.com/users/Yoast/orgs","repos_url":"https://api.github.com/users/Yoast/repos","events_url":"https://api.github.com/users/Yoast/events{/privacy}","received_events_url":"https://api.github.com/users/Yoast/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Yoast/wordpress-seo","description":"Yoast SEO for WordPress","fork":false,"url":"https://api.github.com/repos/Yoast/wordpress-seo","forks_url":"https://api.github.com/repos/Yoast/wordpress-seo/forks","keys_url":"https://api.github.com/repos/Yoast/wordpress-seo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Yoast/wordpress-seo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Yoast/wordpress-seo/teams","hooks_url":"https://api.github.com/repos/Yoast/wordpress-seo/hooks","issue_events_url":"https://api.github.com/repos/Yoast/wordpress-seo/issues/events{/number}","events_url":"https://api.github.com/repos/Yoast/wordpress-seo/events","assignees_url":"https://api.github.com/repos/Yoast/wordpress-seo/assignees{/user}","branches_url":"https://api.github.com/repos/Yoast/wordpress-seo/branches{/branch}","tags_url":"https://api.github.com/repos/Yoast/wordpress-seo/tags","blobs_url":"https://api.github.com/repos/Yoast/wordpress-seo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Yoast/wordpress-seo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Yoast/wordpress-seo/git/refs{/sha}","trees_url":"https://api.github.com/repos/Yoast/wordpress-seo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Yoast/wordpress-seo/statuses/{sha}","languages_url":"https://api.github.com/repos/Yoast/wordpress-seo/languages","stargazers_url":"https://api.github.com/repos/Yoast/wordpress-seo/stargazers","contributors_url":"https://api.github.com/repos/Yoast/wordpress-seo/contributors","subscribers_url":"https://api.github.com/repos/Yoast/wordpress-seo/subscribers","subscription_url":"https://api.github.com/repos/Yoast/wordpress-seo/subscription","commits_url":"https://api.github.com/repos/Yoast/wordpress-seo/commits{/sha}","git_commits_url":"https://api.github.com/repos/Yoast/wordpress-seo/git/commits{/sha}","comments_url":"https://api.github.com/repos/Yoast/wordpress-seo/comments{/number}","issue_comment_url":"https://api.github.com/repos/Yoast/wordpress-seo/issues/comments{/number}","contents_url":"https://api.github.com/repos/Yoast/wordpress-seo/contents/{+path}","compare_url":"https://api.github.com/repos/Yoast/wordpress-seo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Yoast/wordpress-seo/merges","archive_url":"https://api.github.com/repos/Yoast/wordpress-seo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Yoast/wordpress-seo/downloads","issues_url":"https://api.github.com/repos/Yoast/wordpress-seo/issues{/number}","pulls_url":"https://api.github.com/repos/Yoast/wordpress-seo/pulls{/number}","milestones_url":"https://api.github.com/repos/Yoast/wordpress-seo/milestones{/number}","notifications_url":"https://api.github.com/repos/Yoast/wordpress-seo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Yoast/wordpress-seo/labels{/name}","releases_url":"https://api.github.com/repos/Yoast/wordpress-seo/releases{/id}","created_at":"2012-11-16T15:16:29Z","updated_at":"2015-09-13T07:01:27Z","pushed_at":"2015-09-14T10:02:13Z","git_url":"git://github.com/Yoast/wordpress-seo.git","ssh_url":"git@github.com:Yoast/wordpress-seo.git","clone_url":"https://github.com/Yoast/wordpress-seo.git","svn_url":"https://github.com/Yoast/wordpress-seo","homepage":"http://yoast.com/wordpress/seo/","size":26244,"stargazers_count":528,"watchers_count":528,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":316,"mirror_url":null,"open_issues_count":256,"forks":316,"open_issues":256,"watchers":528,"default_branch":"trunk"}},"base":{"label":"Yoast:trunk","ref":"trunk","sha":"5a50879f77e8031b5f823236f5161763fe4b4a73","user":{"login":"Yoast","id":4690436,"avatar_url":"https://avatars.githubusercontent.com/u/4690436?v=3","gravatar_id":"","url":"https://api.github.com/users/Yoast","html_url":"https://github.com/Yoast","followers_url":"https://api.github.com/users/Yoast/followers","following_url":"https://api.github.com/users/Yoast/following{/other_user}","gists_url":"https://api.github.com/users/Yoast/gists{/gist_id}","starred_url":"https://api.github.com/users/Yoast/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yoast/subscriptions","organizations_url":"https://api.github.com/users/Yoast/orgs","repos_url":"https://api.github.com/users/Yoast/repos","events_url":"https://api.github.com/users/Yoast/events{/privacy}","received_events_url":"https://api.github.com/users/Yoast/received_events","type":"Organization","site_admin":false},"repo":{"id":6723399,"name":"wordpress-seo","full_name":"Yoast/wordpress-seo","owner":{"login":"Yoast","id":4690436,"avatar_url":"https://avatars.githubusercontent.com/u/4690436?v=3","gravatar_id":"","url":"https://api.github.com/users/Yoast","html_url":"https://github.com/Yoast","followers_url":"https://api.github.com/users/Yoast/followers","following_url":"https://api.github.com/users/Yoast/following{/other_user}","gists_url":"https://api.github.com/users/Yoast/gists{/gist_id}","starred_url":"https://api.github.com/users/Yoast/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yoast/subscriptions","organizations_url":"https://api.github.com/users/Yoast/orgs","repos_url":"https://api.github.com/users/Yoast/repos","events_url":"https://api.github.com/users/Yoast/events{/privacy}","received_events_url":"https://api.github.com/users/Yoast/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Yoast/wordpress-seo","description":"Yoast SEO for WordPress","fork":false,"url":"https://api.github.com/repos/Yoast/wordpress-seo","forks_url":"https://api.github.com/repos/Yoast/wordpress-seo/forks","keys_url":"https://api.github.com/repos/Yoast/wordpress-seo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Yoast/wordpress-seo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Yoast/wordpress-seo/teams","hooks_url":"https://api.github.com/repos/Yoast/wordpress-seo/hooks","issue_events_url":"https://api.github.com/repos/Yoast/wordpress-seo/issues/events{/number}","events_url":"https://api.github.com/repos/Yoast/wordpress-seo/events","assignees_url":"https://api.github.com/repos/Yoast/wordpress-seo/assignees{/user}","branches_url":"https://api.github.com/repos/Yoast/wordpress-seo/branches{/branch}","tags_url":"https://api.github.com/repos/Yoast/wordpress-seo/tags","blobs_url":"https://api.github.com/repos/Yoast/wordpress-seo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Yoast/wordpress-seo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Yoast/wordpress-seo/git/refs{/sha}","trees_url":"https://api.github.com/repos/Yoast/wordpress-seo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Yoast/wordpress-seo/statuses/{sha}","languages_url":"https://api.github.com/repos/Yoast/wordpress-seo/languages","stargazers_url":"https://api.github.com/repos/Yoast/wordpress-seo/stargazers","contributors_url":"https://api.github.com/repos/Yoast/wordpress-seo/contributors","subscribers_url":"https://api.github.com/repos/Yoast/wordpress-seo/subscribers","subscription_url":"https://api.github.com/repos/Yoast/wordpress-seo/subscription","commits_url":"https://api.github.com/repos/Yoast/wordpress-seo/commits{/sha}","git_commits_url":"https://api.github.com/repos/Yoast/wordpress-seo/git/commits{/sha}","comments_url":"https://api.github.com/repos/Yoast/wordpress-seo/comments{/number}","issue_comment_url":"https://api.github.com/repos/Yoast/wordpress-seo/issues/comments{/number}","contents_url":"https://api.github.com/repos/Yoast/wordpress-seo/contents/{+path}","compare_url":"https://api.github.com/repos/Yoast/wordpress-seo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Yoast/wordpress-seo/merges","archive_url":"https://api.github.com/repos/Yoast/wordpress-seo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Yoast/wordpress-seo/downloads","issues_url":"https://api.github.com/repos/Yoast/wordpress-seo/issues{/number}","pulls_url":"https://api.github.com/repos/Yoast/wordpress-seo/pulls{/number}","milestones_url":"https://api.github.com/repos/Yoast/wordpress-seo/milestones{/number}","notifications_url":"https://api.github.com/repos/Yoast/wordpress-seo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Yoast/wordpress-seo/labels{/name}","releases_url":"https://api.github.com/repos/Yoast/wordpress-seo/releases{/id}","created_at":"2012-11-16T15:16:29Z","updated_at":"2015-09-13T07:01:27Z","pushed_at":"2015-09-14T10:02:13Z","git_url":"git://github.com/Yoast/wordpress-seo.git","ssh_url":"git@github.com:Yoast/wordpress-seo.git","clone_url":"https://github.com/Yoast/wordpress-seo.git","svn_url":"https://github.com/Yoast/wordpress-seo","homepage":"http://yoast.com/wordpress/seo/","size":26244,"stargazers_count":528,"watchers_count":528,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":316,"mirror_url":null,"open_issues_count":256,"forks":316,"open_issues":256,"watchers":528,"default_branch":"trunk"}},"_links":{"self":{"href":"https://api.github.com/repos/Yoast/wordpress-seo/pulls/2746"},"html":{"href":"https://github.com/Yoast/wordpress-seo/pull/2746"},"issue":{"href":"https://api.github.com/repos/Yoast/wordpress-seo/issues/2746"},"comments":{"href":"https://api.github.com/repos/Yoast/wordpress-seo/issues/2746/comments"},"review_comments":{"href":"https://api.github.com/repos/Yoast/wordpress-seo/pulls/2746/comments"},"review_comment":{"href":"https://api.github.com/repos/Yoast/wordpress-seo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Yoast/wordpress-seo/pulls/2746/commits"},"statuses":{"href":"https://api.github.com/repos/Yoast/wordpress-seo/statuses/eb83572d8f4ea863d9cbdc35a848c7fd2f40f32f"}}}}