{"id":105,"date":"2014-01-04T23:32:44","date_gmt":"2014-01-05T05:32:44","guid":{"rendered":"http:\/\/laubsterboy.com\/blog\/?p=105"},"modified":"2014-01-04T23:32:44","modified_gmt":"2014-01-05T05:32:44","slug":"running-a-development-copy-of-wordpress-multisite-part-2","status":"publish","type":"post","link":"https:\/\/www.johnrussell.dev\/blog\/2014\/01\/running-a-development-copy-of-wordpress-multisite-part-2\/","title":{"rendered":"Running a Development Copy of WordPress Multisite &#8211; Part 2"},"content":{"rendered":"<p>I recently made a <a title=\"Running a Development Copy of WordPress Multisite\" href=\"http:\/\/laubsterboy.com\/blog\/2014\/01\/running-a-development-copy-of-wordpress-multisite\/\">detailed post<\/a> explaining how I created a production and development environment that share a database using WordPress in a Multisite configuration.<\/p>\n<p>One thing that I felt was missing from the production environment was the ability to quickly jump from production to development while making changes to site content. With the new WordPress adminbar it&#8217;s already easy to jump back and forth between the post\/page and the dashboard, but I wanted a way to view the current site or current page in the development environment. So, I created a plugin that adds a menu to the WordPress adminbar that lists links to the development environment for the &#8220;Current Site&#8221;, &#8220;Current Page&#8221; (if a page is being viewed), and links to the homepage for each site within the WordPress Multisite network.<\/p>\n<p>Since I will not likely ever enter this into the WordPress plugin repository I will simply post the code here. All you need to do is copy the following code into a text editor and save it as a php file and upload it into your production site&#8217;s plugin directory.\u00a0<em>Note that this will only work if you have created a production and development environment in accordance with my <a title=\"Running a Development Copy of WordPress Multisite\" href=\"http:\/\/laubsterboy.com\/blog\/2014\/01\/running-a-development-copy-of-wordpress-multisite\/\">guide<\/a>.<\/em><\/p>\n<pre class=\"lang:php decode:true crayon-selected\">&lt;?php\n\/*\nPlugin Name: Development Menu\nPlugin URI: http:\/\/www.laubsterboy.com\nDescription: Adds WordPress Admin Bar menu items to link back to the development version of a site\nVersion: 0.0.1\nAuthor: John Russell\nAuthor URI: http:\/\/www.laubsterboy.com\nLicense: GPLv2 or later\n*\/\n\n\/*\nThis program is free software; you can redistribute it and\/or\nmodify it under the terms of the GNU General Public License\nas published by the Free Software Foundation; either version 2\nof the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program; if not, write to the Free Software\nFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\n*\/\n\nclass DevelopmentMenu {\n\n\tfunction __construct() {\n\t\tif (defined('WP_DEVELOPMENT_DOMAIN')) add_action('admin_bar_menu', array($this, \"development_links\"));\n\t}\n\n\tfunction add_root_menu($name, $id, $href = FALSE) {\n\t\tglobal $wp_admin_bar;\n\t\tif ( !is_super_admin() || !is_admin_bar_showing() )\n\t\t    return;\n\n\t\t$wp_admin_bar-&gt;add_menu( array(\n\t\t    'id'   =&gt; $id,\n\t\t    'meta' =&gt; array(),\n\t\t    'title' =&gt; $name,\n\t\t    'href' =&gt; $href ) );\n\t}\n\n\tfunction add_sub_menu($name, $link, $root_menu, $id, $meta = FALSE) {\n\t\tglobal $wp_admin_bar;\n\t\tif (!is_super_admin() || !is_admin_bar_showing()) return;\n\n\t\t$wp_admin_bar-&gt;add_menu( array(\n\t\t  'parent' =&gt; $root_menu,\n\t\t  'id' =&gt; $id,\n\t\t  'title' =&gt; $name,\n\t\t  'href' =&gt; $link,\n\t\t  'meta' =&gt; $meta\n\t\t) );\n\t}\n\n\tfunction get_development_url($url) {\n\t\t\/\/ Takes in a URL with the production host and returns the same URL with the development host\n\t\t$return_value;\n\t\t$url_components = parse_url($url);\n\n\t\t$return_value = $url_components['scheme'] . ':\/\/' . WP_DEVELOPMENT_DOMAIN . $url_components['path'];\n\n\t\treturn $return_value;\t\n\t}\n\n\tfunction development_links() {\n\t\t$blog_details = get_blog_details();\n\t\tif (is_admin()) $screen = get_current_screen();\n\n\t\t$this-&gt;add_root_menu(\"Development Sites\", \"devrt\");\n\t\t$this-&gt;add_sub_menu(\"Current Site\", WP_DEVELOPMENT_DOMAIN . $blog_details-&gt;path, \"devrt\", \"devcurrsite\" );\n\t\tif (isset($screen) &amp;&amp; $screen-&gt;base == 'post') {\n\t\t\t$this-&gt;add_sub_menu(\"Current Page\", $this-&gt;get_development_url(get_permalink()), \"devrt\", \"devcurrpage\" );\n\t\t} elseif (!is_admin()) {\n\t\t\tif (is_main_site() || $_SERVER['HTTP_HOST'] == WP_PRODUCTION_DOMAIN) {\n\t\t\t\t\/\/ Current page link to development for main site or sites with no CNAME (using IP address)\n\t\t\t\t$this-&gt;add_sub_menu(\"Current Page\", $this-&gt;get_development_url(stripos($_SERVER['SERVER_PROTOCOL'],'https') === true ? 'https:\/\/' : 'http:\/\/' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']), \"devrt\", \"devcurrpage\" );\n\t\t\t} else {\n\t\t\t\t$this-&gt;add_sub_menu(\"Current Page\", $this-&gt;get_development_url(stripos($_SERVER['SERVER_PROTOCOL'],'https') === true ? 'https:\/\/' : 'http:\/\/' . $_SERVER['HTTP_HOST'] . rtrim($blog_details-&gt;path, '\/') . $_SERVER['REQUEST_URI']), \"devrt\", \"devcurrpage\" );\n\t\t\t}\n\t\t}\n\t\t\/\/ For Multisite\n\t\tif (is_multisite()) {\n\t\t    global $wpdb, $path;\n\t\t    $blog_ids = $wpdb-&gt;get_col(\"SELECT blog_id FROM $wpdb-&gt;blogs\");\n\t\t    foreach($blog_ids as $blog_id) {\n\t\t        $blog_details = get_blog_details($blog_id);\n\t\t        $this-&gt;add_sub_menu($blog_details-&gt;blogname, WP_DEVELOPMENT_DOMAIN . $blog_details-&gt;path, 'devrt', 'devblog'.$blog_id);\n\t\t    }\n\t\t}\n\t}\n}\n\nadd_action(\"init\", \"DevelopmentMenuInit\");\nfunction DevelopmentMenuInit() {\n    global $DevelopmentMenu;\n    $DevelopmentMenu = new DevelopmentMenu();\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently made a detailed post explaining how I created a production and development environment that share a database using WordPress in a Multisite configuration. One thing that I felt was missing from the production environment was the ability to quickly jump from production to development while making changes to site content. With the new [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-105","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Running a Development Copy of WordPress Multisite - Part 2 - John Russell Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.johnrussell.dev\/blog\/2014\/01\/running-a-development-copy-of-wordpress-multisite-part-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Running a Development Copy of WordPress Multisite - Part 2 - John Russell Blog\" \/>\n<meta property=\"og:description\" content=\"I recently made a detailed post explaining how I created a production and development environment that share a database using WordPress in a Multisite configuration. One thing that I felt was missing from the production environment was the ability to quickly jump from production to development while making changes to site content. With the new [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.johnrussell.dev\/blog\/2014\/01\/running-a-development-copy-of-wordpress-multisite-part-2\/\" \/>\n<meta property=\"og:site_name\" content=\"John Russell Blog\" \/>\n<meta property=\"article:published_time\" content=\"2014-01-05T05:32:44+00:00\" \/>\n<meta name=\"author\" content=\"John Russell\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@laubsterboy\" \/>\n<meta name=\"twitter:site\" content=\"@laubsterboy\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"John Russell\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.johnrussell.dev\/blog\/2014\/01\/running-a-development-copy-of-wordpress-multisite-part-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.johnrussell.dev\/blog\/2014\/01\/running-a-development-copy-of-wordpress-multisite-part-2\/\"},\"author\":{\"name\":\"John Russell\",\"@id\":\"https:\/\/www.johnrussell.dev\/blog\/#\/schema\/person\/296c0c6bd1deeeb20834393e1e16325c\"},\"headline\":\"Running a Development Copy of WordPress Multisite &#8211; Part 2\",\"datePublished\":\"2014-01-05T05:32:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.johnrussell.dev\/blog\/2014\/01\/running-a-development-copy-of-wordpress-multisite-part-2\/\"},\"wordCount\":216,\"commentCount\":0,\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.johnrussell.dev\/blog\/2014\/01\/running-a-development-copy-of-wordpress-multisite-part-2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.johnrussell.dev\/blog\/2014\/01\/running-a-development-copy-of-wordpress-multisite-part-2\/\",\"url\":\"https:\/\/www.johnrussell.dev\/blog\/2014\/01\/running-a-development-copy-of-wordpress-multisite-part-2\/\",\"name\":\"Running a Development Copy of WordPress Multisite - Part 2 - John Russell Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.johnrussell.dev\/blog\/#website\"},\"datePublished\":\"2014-01-05T05:32:44+00:00\",\"author\":{\"@id\":\"https:\/\/www.johnrussell.dev\/blog\/#\/schema\/person\/296c0c6bd1deeeb20834393e1e16325c\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.johnrussell.dev\/blog\/2014\/01\/running-a-development-copy-of-wordpress-multisite-part-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.johnrussell.dev\/blog\/2014\/01\/running-a-development-copy-of-wordpress-multisite-part-2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.johnrussell.dev\/blog\/2014\/01\/running-a-development-copy-of-wordpress-multisite-part-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.johnrussell.dev\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Running a Development Copy of WordPress Multisite &#8211; Part 2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.johnrussell.dev\/blog\/#website\",\"url\":\"https:\/\/www.johnrussell.dev\/blog\/\",\"name\":\"John Russell Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.johnrussell.dev\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.johnrussell.dev\/blog\/#\/schema\/person\/296c0c6bd1deeeb20834393e1e16325c\",\"name\":\"John Russell\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.johnrussell.dev\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/00ce0f258fcc5e5d29897a5e81316009713e9104cfaf49f481c5bce3f81c7cb1?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/00ce0f258fcc5e5d29897a5e81316009713e9104cfaf49f481c5bce3f81c7cb1?s=96&d=mm&r=g\",\"caption\":\"John Russell\"},\"url\":\"https:\/\/www.johnrussell.dev\/blog\/author\/laubsterboy\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Running a Development Copy of WordPress Multisite - Part 2 - John Russell Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.johnrussell.dev\/blog\/2014\/01\/running-a-development-copy-of-wordpress-multisite-part-2\/","og_locale":"en_US","og_type":"article","og_title":"Running a Development Copy of WordPress Multisite - Part 2 - John Russell Blog","og_description":"I recently made a detailed post explaining how I created a production and development environment that share a database using WordPress in a Multisite configuration. One thing that I felt was missing from the production environment was the ability to quickly jump from production to development while making changes to site content. With the new [&hellip;]","og_url":"https:\/\/www.johnrussell.dev\/blog\/2014\/01\/running-a-development-copy-of-wordpress-multisite-part-2\/","og_site_name":"John Russell Blog","article_published_time":"2014-01-05T05:32:44+00:00","author":"John Russell","twitter_card":"summary_large_image","twitter_creator":"@laubsterboy","twitter_site":"@laubsterboy","twitter_misc":{"Written by":"John Russell","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.johnrussell.dev\/blog\/2014\/01\/running-a-development-copy-of-wordpress-multisite-part-2\/#article","isPartOf":{"@id":"https:\/\/www.johnrussell.dev\/blog\/2014\/01\/running-a-development-copy-of-wordpress-multisite-part-2\/"},"author":{"name":"John Russell","@id":"https:\/\/www.johnrussell.dev\/blog\/#\/schema\/person\/296c0c6bd1deeeb20834393e1e16325c"},"headline":"Running a Development Copy of WordPress Multisite &#8211; Part 2","datePublished":"2014-01-05T05:32:44+00:00","mainEntityOfPage":{"@id":"https:\/\/www.johnrussell.dev\/blog\/2014\/01\/running-a-development-copy-of-wordpress-multisite-part-2\/"},"wordCount":216,"commentCount":0,"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.johnrussell.dev\/blog\/2014\/01\/running-a-development-copy-of-wordpress-multisite-part-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.johnrussell.dev\/blog\/2014\/01\/running-a-development-copy-of-wordpress-multisite-part-2\/","url":"https:\/\/www.johnrussell.dev\/blog\/2014\/01\/running-a-development-copy-of-wordpress-multisite-part-2\/","name":"Running a Development Copy of WordPress Multisite - Part 2 - John Russell Blog","isPartOf":{"@id":"https:\/\/www.johnrussell.dev\/blog\/#website"},"datePublished":"2014-01-05T05:32:44+00:00","author":{"@id":"https:\/\/www.johnrussell.dev\/blog\/#\/schema\/person\/296c0c6bd1deeeb20834393e1e16325c"},"breadcrumb":{"@id":"https:\/\/www.johnrussell.dev\/blog\/2014\/01\/running-a-development-copy-of-wordpress-multisite-part-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.johnrussell.dev\/blog\/2014\/01\/running-a-development-copy-of-wordpress-multisite-part-2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.johnrussell.dev\/blog\/2014\/01\/running-a-development-copy-of-wordpress-multisite-part-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.johnrussell.dev\/blog\/"},{"@type":"ListItem","position":2,"name":"Running a Development Copy of WordPress Multisite &#8211; Part 2"}]},{"@type":"WebSite","@id":"https:\/\/www.johnrussell.dev\/blog\/#website","url":"https:\/\/www.johnrussell.dev\/blog\/","name":"John Russell Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.johnrussell.dev\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.johnrussell.dev\/blog\/#\/schema\/person\/296c0c6bd1deeeb20834393e1e16325c","name":"John Russell","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.johnrussell.dev\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/00ce0f258fcc5e5d29897a5e81316009713e9104cfaf49f481c5bce3f81c7cb1?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/00ce0f258fcc5e5d29897a5e81316009713e9104cfaf49f481c5bce3f81c7cb1?s=96&d=mm&r=g","caption":"John Russell"},"url":"https:\/\/www.johnrussell.dev\/blog\/author\/laubsterboy\/"}]}},"_links":{"self":[{"href":"https:\/\/www.johnrussell.dev\/blog\/wp-json\/wp\/v2\/posts\/105","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johnrussell.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johnrussell.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johnrussell.dev\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johnrussell.dev\/blog\/wp-json\/wp\/v2\/comments?post=105"}],"version-history":[{"count":0,"href":"https:\/\/www.johnrussell.dev\/blog\/wp-json\/wp\/v2\/posts\/105\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.johnrussell.dev\/blog\/wp-json\/wp\/v2\/media?parent=105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johnrussell.dev\/blog\/wp-json\/wp\/v2\/categories?post=105"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johnrussell.dev\/blog\/wp-json\/wp\/v2\/tags?post=105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}