Register custom theme path

@param string $dir Directory to register (Relative to WP_CONTENT_DIR).
@param bool   $persistent Whether to update WordPress options or not.
@return boolean|WP_Error True on success, false or WP_Error otherwise
332473
public function register_path( $dir = null, $persistent = true ) {
		$result = false;

		// Cast parameters to known values.
		$dir = (string) $dir;
		$persistent = (bool) $persistent;

		if ( empty( $dir ) ) {
			$dir = $this->get_default_path();
		}

		$path_fail_reason = $this->validate_path( $dir );
		if ( $path_fail_reason ) {
			return new WP_Error( 'custom_theme_path_invalid', "Custom themes directory is invalid: $path_fail_reason", $dir );
		}

		// Register custom-theme path for "on the fly".
		$result = register_theme_directory( $dir );

		if ( ! $persistent ) {
			return $result;
		}

		// WordPress option is already set.
		if ( get_option( 'stylesheet_root' ) === $dir ) {
			return $result;
		}

		// Update WordPress option if persistence is required.
		//
		// Not returning the result of this operation as it can
		// be confusing - false is returned either on failure or
		// when the option value was the same and wasn't updated.
		update_option( 'stylesheet_root', $dir );
	}
604858
public function setLocation($dir = 'bulletproof', $permission = 0666)
    {
      $isDirectoryValid = $this->isDirectoryValid($dir);

      if (!$isDirectoryValid) {
        $this->error = sprintf($this->commonUploadErrors[$this->language]['ERROR_04'], $dir);
        return false;
      }

      $create = !is_dir($dir) ? @mkdir('' . $dir, (int) $permission, true) : true;

      if (!$create) {
        $this->error = sprintf($this->commonUploadErrors[$this->language]['ERROR_05'], $dir);
        return false;
      }

      $this->location = $dir;

      return $this;
    }
85405
public function setTmpDir ($dir)
		{
			$this->_tmpDir = $dir . '/' . $this->_params[ 'identifier' ];
			if (!is_dir($this->_tmpDir))
				FileHelper::createDirectory($this->_tmpDir);
		}
1214085
public function cd($dir = '')
    {
        if ($dir == '' || substr($dir, 0, 1) !== '/') {
            $dir = $this->dir . '/' . $dir;
        }

        $this->errorHandler->start();
        if (($dir = $this->driver->realpath($this->resource, $dir)) !== false) {
            $this->dir = $dir;
            $this->errorHandler->stop();

            return true;
        }

        $this->errorHandler->stop();

        return false;
    }
702741
public static function createDir($dir, $mode = 0777)
    {
        if (is_dir($dir) || @mkdir($dir, $mode)) return TRUE;
        if (!static::createDir(dirname($dir), $mode)) return FALSE;
        return @mkdir($dir, $mode);
    }
220715
public function mkdir($path, $mode, $options = 0)
    {
        self::restore();
        $path = self::overlayPath($path);
        $success = mkdir($path, $mode, (bool)($options & STREAM_MKDIR_RECURSIVE));
        self::register();
        return $success;
    }
901179
public static function dieIfDirectoriesNotWritable($directoriesToCheck = null)
    {
        $resultCheck = self::checkDirectoriesWritable($directoriesToCheck);
        if (array_search(false, $resultCheck) === false) {
            return;
        }

        $directoryList = '';
        foreach ($resultCheck as $dir => $bool) {
            $realpath = Filesystem::realpath($dir);
            if (!empty($realpath) && $bool === false) {
                $directoryList .= self::getMakeWritableCommand($realpath);
            }
        }

        // Also give the chown since the chmod is only 755
        if (!SettingsServer::isWindows()) {
            $realpath = Filesystem::realpath(PIWIK_INCLUDE_PATH . '/');
            $directoryList = "<code>chown -R ". self::getUserAndGroup() ." " . $realpath . "</code><br />" . $directoryList;
        }

        if (function_exists('shell_exec')) {
            $currentUser = self::getUser();
            if (!empty($currentUser)) {
                $optionalUserInfo = " (running as user '" . $currentUser . "')";
            }
        }

        $directoryMessage  = "<p><b>Matomo couldn't write to some directories $optionalUserInfo</b>.</p>";
        $directoryMessage .= "<p>Try to Execute the following commands on your server, to allow Write access on these directories"
            . ":</p>"
            . "<blockquote>$directoryList</blockquote>"
            . "<p>If this doesn't work, you can try to create the directories with your FTP software, and set the CHMOD to 0755 (or 0777 if 0755 is not enough). To do so with your FTP software, right click on the directories then click permissions.</p>"
            . "<p>After applying the modifications, you can <a href='index.php'>refresh the page</a>.</p>"
            . "<p>If you need more help, try <a target='_blank' rel='noreferrer noopener' href='https://matomo.org'>Matomo.org</a>.</p>";

        $ex = new MissingFilePermissionException($directoryMessage);
        $ex->setIsHtmlMessage();

        throw $ex;
    }
302643
public static function registerAutoloadDirectory($directory)
    {
        if (!class_exists('Doctrine\Common\ClassLoader', false)) {
            require_once $directory . "/Doctrine/Common/ClassLoader.php";
        }

        $loader = new ClassLoader("Doctrine", $directory);
        $loader->register();

        $loader = new ClassLoader("Symfony\Component", $directory . "/Doctrine");
        $loader->register();
    }
11930
public function setInstallDir($dir)
    {
        $dir = $this->addTrailingSlash($dir);

        if (!is_dir($dir)) {
            $this->log->addDebug(sprintf('Creating new install directory "%s"', $dir));

            if (!mkdir($dir, 0755, true)) {
                $this->log->addCritical(sprintf('Could not create install directory "%s"', $dir));

                return false;
            }
        }

        $this->installDir = $dir;

        return true;
    }
1331920
public static function registerTheme($theme)
    {
        $themes = (array) $theme;
        array_walk($themes, function (&$name) {
            $name .= '.js';
        });
        static::$_themeJsFiles = array_unique(array_merge(static::$_themeJsFiles, $themes));
        if (static::$_themeJsFiles) {
            ThemeAsset::register(Yii::$app->getView())->js = static::$_themeJsFiles;
        }
    }
968712
protected function ensureDirectory($dir)
    {
        if ($this->filesystem->isDirectory($dir)) {
            return true;
        }

        if (!@$this->filesystem->makeDirectory($dir)) {
            throw new RuntimeException("Cannot create base directory '$dir'");
        }

        return true;
    }
829659
private function createDir($path, $chmod = 0777, $recursive = true)
    {
        if (!mkdir($path, $chmod, $recursive)) {
            throw new RuntimeException(
                sprintf(
                    'The directory path "%s" could not be created.',
                    $path
                )
            );
        }
    }
360519
def in_theme_dir(*paths)
      return nil unless theme

      paths.reduce(theme.root) do |base, path|
        Jekyll.sanitized_path(base, path)
      end
    end
1063206
private void registerDirectory(Path dir) throws IOException {
        Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {

            @Override
            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
                WatchKey key = dir.register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
                watchKeyToDirectory.put(key, dir);

                return FileVisitResult.CONTINUE;
            }

        });
    }
239413
public function createDirectory($directory, $chmod = null, $recurisve = true)
    {
        $chmod     = $chmod ?: $this->chmod;
        $directory = sprintf('%s/%s', $this->rootDir, trim($directory, '/'));

        if (!$this->fileSystem->exists($directory)) {
            try {
                $this->fileSystem->mkdir($directory);
            } catch (FsIOException $e) {
                throw new IOException($e->getMessage(), $e->getCode(), $e);
            }
        }

        return true;
    }
970058
function directoryPath(&$directory) {
    if (substr($directory, 0, 1) != '/') {
      // Relative, and so assumed to be in Drupal's files folder: prepend this to
      // the given directory.
      // sanity check. need to verify /files exists before we do anything. see http://drupal.org/node/367138
      $files = file_create_path();
      file_check_directory($files, FILE_CREATE_DIRECTORY);
      $directory = file_create_path($directory);
    }
  }
860826
protected function register_autoload() {
        $src_dir = $this->get_src_path();

        if ( file_exists( $src_dir ) ) {
            register_wp_autoload( $this->options->namespace, $src_dir );
        }
    }