Advertisement
ClarusDignus

More dynamic create path for renamed wp-content

Feb 6th, 2015
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.40 KB | None | 0 0
  1. $path = "/home/somesite/public_html/wp-content/themes/some-theme";
  2. echo getBase($path); /* /home/somesite/public_html/ */
  3.  
  4. function getBase($path) {
  5.     $i = substr($path,-1) == '/' ? 4 : 3;
  6.     $end = strlen($path);
  7.     $offset = 0;
  8.     while($i > 0) {
  9.         $end = strrpos($path, '/', -$offset);
  10.         $offset = strlen($path) - $end+1;
  11.         $i--;
  12.     }
  13.     return substr($path, 0, $end+1);
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement