{"action":"created","issue":{"url":"https://api.github.com/repos/scribu/wp-posts-to-posts/issues/555","repository_url":"https://api.github.com/repos/scribu/wp-posts-to-posts","labels_url":"https://api.github.com/repos/scribu/wp-posts-to-posts/issues/555/labels{/name}","comments_url":"https://api.github.com/repos/scribu/wp-posts-to-posts/issues/555/comments","events_url":"https://api.github.com/repos/scribu/wp-posts-to-posts/issues/555/events","html_url":"https://github.com/scribu/wp-posts-to-posts/issues/555","id":263060192,"number":555,"title":"Tables wp_p2p and wp_p2pmeta not created upon plugin activation","user":{"login":"Flimm","id":355454,"avatar_url":"https://avatars3.githubusercontent.com/u/355454?v=4","gravatar_id":"","url":"https://api.github.com/users/Flimm","html_url":"https://github.com/Flimm","followers_url":"https://api.github.com/users/Flimm/followers","following_url":"https://api.github.com/users/Flimm/following{/other_user}","gists_url":"https://api.github.com/users/Flimm/gists{/gist_id}","starred_url":"https://api.github.com/users/Flimm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Flimm/subscriptions","organizations_url":"https://api.github.com/users/Flimm/orgs","repos_url":"https://api.github.com/users/Flimm/repos","events_url":"https://api.github.com/users/Flimm/events{/privacy}","received_events_url":"https://api.github.com/users/Flimm/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-10-05T09:33:16Z","updated_at":"2018-02-15T06:35:28Z","closed_at":null,"author_association":"NONE","body":"Let's say that I install the \"Posts 2 Posts\" plugin on a brand new WordPress installation, using the WP CLI, like this:\r\n\r\n```\r\n$ wp plugin install --activate posts-to-posts\r\nInstalling Posts 2 Posts (1.6.5)\r\nDownloading install package from https://downloads.wordpress.org/plugin/posts-to-posts.1.6.5.zip...\r\nUsing cached file '.wp-cli/cache/plugin/posts-to-posts-1.6.5.zip'...\r\nUnpacking the package...\r\nInstalling the plugin...\r\nPlugin installed successfully.\r\nActivating 'posts-to-posts'...\r\nPlugin 'posts-to-posts' activated.\r\nSuccess: Installed 1 of 1 plugins.\r\n```\r\n\r\nAt this point, the plugin has been installed and activated. However, the tables have not been created yet:\r\n\r\n```\r\n> show tables;\r\n+-----------------------+\r\n| Tables_in_dt          |\r\n+-----------------------+\r\n| wp_commentmeta        |\r\n| wp_comments           |\r\n| wp_links              |\r\n| wp_options            |\r\n| wp_postmeta           |\r\n| wp_posts              |\r\n| wp_term_relationships |\r\n| wp_term_taxonomy      |\r\n| wp_termmeta           |\r\n| wp_terms              |\r\n| wp_usermeta           |\r\n| wp_users              |\r\n+-----------------------+\r\n```\r\n\r\nAs you can see, the tables `wp_p2p` and `wp_p2pmeta` are missing. If there are any other plugins that depend on this functionality, this could cause errors like this one to appear:\r\n\r\n```\r\nWordPress database error: [Table 'wordpress.wp_p2p' doesn't exist]\r\n```\r\n\r\nBased on reading the source code, it looks like the tables are created when an instance of the class `P2P_Tools_Page` is created for the first time here:\r\n\r\nhttps://github.com/scribu/wp-posts-to-posts/blob/d2f297dbe257a09438da6ffe22c9a876acb7b49b/posts-to-posts.php#L53\r\n\r\nThis is inside the function `_p2p_load_admin`, which is only called if `is_admin()` is true. Instead, the tables should be created upon plugin registration.\r\n\r\nOf course, the workaround is to visit the WordPress admin before using the site. Sure enough, as soon as the WordPress admin dashboard is visited, the tables are created.\r\n\r\nRequiring visiting the WordPress admin makes it harder to automate setting up new websites with certain plugins using the WP CLI."},"comment":{"url":"https://api.github.com/repos/scribu/wp-posts-to-posts/issues/comments/365838001","html_url":"https://github.com/scribu/wp-posts-to-posts/issues/555#issuecomment-365838001","issue_url":"https://api.github.com/repos/scribu/wp-posts-to-posts/issues/555","id":365838001,"user":{"login":"Flimm","id":355454,"avatar_url":"https://avatars3.githubusercontent.com/u/355454?v=4","gravatar_id":"","url":"https://api.github.com/users/Flimm","html_url":"https://github.com/Flimm","followers_url":"https://api.github.com/users/Flimm/followers","following_url":"https://api.github.com/users/Flimm/following{/other_user}","gists_url":"https://api.github.com/users/Flimm/gists{/gist_id}","starred_url":"https://api.github.com/users/Flimm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Flimm/subscriptions","organizations_url":"https://api.github.com/users/Flimm/orgs","repos_url":"https://api.github.com/users/Flimm/repos","events_url":"https://api.github.com/users/Flimm/events{/privacy}","received_events_url":"https://api.github.com/users/Flimm/received_events","type":"User","site_admin":false},"created_at":"2018-02-15T06:35:28Z","updated_at":"2018-02-15T06:35:28Z","author_association":"NONE","body":"I've just been using the workaround mentioned in the issue description."}}
{"actor":{"display_login":"Flimm"}}