/** * Retrieve a URL within the plugins or mu-plugins directory. * * Defaults to the plugins directory URL if no arguments are supplied. * * @since 0.0.1 * * @param string $path Optional. Extra path appended to the end of the URL, including * the relative directory if $plugin is supplied. Default empty. * @param string $plugin Optional. A full path to a file inside a plugin or mu-plugin. * The URL will be relative to its directory. Default empty. * Typically this is done by passing `__FILE__` as the argument. * @return string Plugins URL link with optional paths appended. */ function plugins_url($path = '', $plugin = '') { $path = hq_normalize_path($path); $plugin = hq_normalize_path($plugin); $mu_plugin_dir = hq_normalize_path(HQMU_PLUGIN_DIR); if (!empty($plugin) && 0 === strpos($plugin, $mu_plugin_dir)) { $url = HQMU_PLUGIN_URL; } else { $url = HQ_PLUGIN_URL; } $url = set_url_scheme($url); if (!empty($plugin) && is_string($plugin)) { $folder = dirname(plugin_basename($plugin)); if ('.' != $folder) { $url .= '/' . ltrim($folder, '/'); } } if ($path && is_string($path)) { $url .= '/' . ltrim($path, '/'); } /** * Filter the URL to the plugins directory. * * @since 0.0.1 * * @param string $url The complete URL to the plugins directory including scheme and path. * @param string $path Path relative to the URL to the plugins directory. Blank string * if no path is specified. * @param string $plugin The plugin file path to be relative to. Blank string if no plugin * is specified. */ return apply_filters('plugins_url', $url, $path, $plugin); }
/** * Register a plugin's real path. * * This is used in plugin_basename() to resolve symlinked paths. * * @since 0.0.1 * * @see plugin_basename() * * @global array $hq_plugin_paths * * @staticvar string $hq_plugin_path * @staticvar string $hqmu_plugin_path * * @param string $file Known path to the file. * @return bool Whether the path was able to be registered. */ function hq_register_plugin_realpath($file) { global $hq_plugin_paths; // Normalize, but store as static to avoid recalculation of a constant value static $hq_plugin_path = null, $hqmu_plugin_path = null; if (!isset($hq_plugin_path)) { $hq_plugin_path = hq_normalize_path(HQ_PLUGIN_DIR); $hqmu_plugin_path = hq_normalize_path(HQMU_PLUGIN_DIR); } $plugin_path = hq_normalize_path(dirname($file)); $plugin_realpath = hq_normalize_path(dirname(realpath($file))); if ($plugin_path === $hq_plugin_path || $plugin_path === $hqmu_plugin_path) { return false; } if ($plugin_path !== $plugin_realpath) { $hq_plugin_paths[$plugin_path] = $plugin_realpath; } return true; }