{"id":20161,"date":"2013-09-21T01:53:22","date_gmt":"2013-09-21T01:53:22","guid":{"rendered":"http:\/\/internetfett.com\/wordpress\/?p=20161"},"modified":"2013-09-21T01:57:04","modified_gmt":"2013-09-21T01:57:04","slug":"local-dev-with-roots-theme","status":"publish","type":"post","link":"http:\/\/internetfett.com\/wordpress\/local-dev-with-roots-theme\/","title":{"rendered":"Local dev with Roots theme"},"content":{"rendered":"<p>If you&#8217;re unaware, PHP 5.4 added a feature that lets you run a local development server on your machine.  I found an article or two on <a href=\"http:\/\/ripeworks.com\/run-wordpress-locally-using-phps-buily-in-web-server\/\" title=\"routing local requests to WordPress\">routing local requests to WordPress<\/a>.<\/p>\n<p>The code works great, but I needed a little extra to get it working with the base theme I use.  <a href=\"http:\/\/roots.io\/\" title=\"Roots\">Roots<\/a> is an amazing starter theme that bundles Bootstrap and a ton of cool features.  It uses <a href=\"http:\/\/gruntjs.com\/\" title=\"Grunt\">Grunt<\/a> to compile LESS into minified CSS.<\/p>\n<p>Roots adds some rewrites to WordPress for better looking asset URLs.  Those need to be added to the router.php file.  Here&#8217;s the full code:<\/p>\n<pre>\r\n$root = $_SERVER['DOCUMENT_ROOT'];\r\nchdir($root);\r\n$path = '\/'.ltrim(parse_url($_SERVER['REQUEST_URI'])['path'],'\/');\r\n$old_path = $path;\r\n$path = preg_replace('\/^\\\/assets\\\/(.*)$\/', '\/wp-content\/themes\/THEME-NAME\/assets\/\\1', $path);\r\n$path = preg_replace('\/^\\\/plugins\\\/(.*)$\/', '\/wp-content\/plugins\/\\1', $path);\r\nif(file_exists($root.$path))\r\n{\r\n\tif(is_dir($root.$path) && substr($path,strlen($path) - 1, 1) !== '\/')\r\n\t{\r\n\t\theader('location: '.rtrim($path,'\/').'\/');\r\n\t\texit;\r\n\t}\t\r\n\tif(strpos($path,'.php') === false) {\r\n\t   if(!strncmp($old_path, '\/assets\/', 8)) die(header('location: '.$path));\r\n\t   if(!strncmp($old_path, '\/plugins\/', 9)) die(header('location: '.$path));\r\n\t   return false;\r\n    } else {\r\n\t\tchdir(dirname($root.$path));\r\n\t\trequire_once $root.$path;\r\n\t}\t\r\n}else include_once 'index.php';\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>How to use PHP 5.4&#8217;s development server with Roots.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[10,3,7],"class_list":["post-20161","post","type-post","status-publish","format-standard","hentry","category-code-snippets","tag-bootstrap","tag-php","tag-wordpress"],"_links":{"self":[{"href":"http:\/\/internetfett.com\/wordpress\/wp-json\/wp\/v2\/posts\/20161","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/internetfett.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/internetfett.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/internetfett.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/internetfett.com\/wordpress\/wp-json\/wp\/v2\/comments?post=20161"}],"version-history":[{"count":0,"href":"http:\/\/internetfett.com\/wordpress\/wp-json\/wp\/v2\/posts\/20161\/revisions"}],"wp:attachment":[{"href":"http:\/\/internetfett.com\/wordpress\/wp-json\/wp\/v2\/media?parent=20161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/internetfett.com\/wordpress\/wp-json\/wp\/v2\/categories?post=20161"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/internetfett.com\/wordpress\/wp-json\/wp\/v2\/tags?post=20161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}