本文整理汇总了PHP中wp_normalize_path函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_normalize_path函数的具体用法?PHP wp_normalize_path怎么用?PHP wp_normalize_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_normalize_path函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cs_get_path_locate
function cs_get_path_locate()
{
if (!function_exists('get_plugins') || !function_exists('is_plugin_active')) {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
}
foreach (get_plugins() as $key => $value) {
if (strpos($key, 'cs-framework.php') !== false) {
if (is_plugin_active($key)) {
$basename = '/' . str_replace('/cs-framework.php', '', $key);
$dir = WP_PLUGIN_DIR . $basename;
$uri = WP_PLUGIN_URL . $basename;
}
}
}
if (!isset($basename)) {
$dirname = wp_normalize_path(dirname(__FILE__));
$plugin_dir = wp_normalize_path(WP_PLUGIN_DIR);
$located_plugin = preg_match('#' . $plugin_dir . '#', $dirname) ? true : false;
$directory = $located_plugin ? $plugin_dir : get_template_directory();
$directory_uri = $located_plugin ? WP_PLUGIN_URL : get_template_directory_uri();
$basename = str_replace(wp_normalize_path($directory), '', $dirname);
$dir = $directory . $basename;
$uri = $directory_uri . $basename;
}
return apply_filters('cs_get_path_locate', array('basename' => wp_normalize_path($basename), 'dir' => wp_normalize_path($dir), 'uri' => $uri));
}
示例2: get_from_api
private function get_from_api()
{
// The path to the PHP array file containing the fonts.
// This is auto-generated by running "grunt googlefonts"
$path = wp_normalize_path(dirname(__FILE__) . '/googlefonts-array.php');
// Get the contents of the file
$fonts_array = (include $path);
$final_fonts = array();
if (isset($fonts_array['items'])) {
$all_variants = array();
foreach ($fonts_array['items'] as $font) {
// If font-family is not set then skip this item.
if (!isset($font['family'])) {
continue;
}
$final_fonts[$font['family']] = array('variants' => array(), 'subsets' => array());
if (isset($font['variants']) && is_array($font['variants'])) {
foreach ($font['variants'] as $variant) {
$final_fonts[$font['family']]['variants'][] = $this->convert_font_variants($variant);
}
}
if (isset($font['subsets']) && is_array($font['subsets'])) {
foreach ($font['subsets'] as $subset) {
$final_fonts[$font['family']]['subsets'][] = $this->convert_font_subsets($subset);
}
}
}
}
return $final_fonts;
}
示例3: render
/**
* Get shortcode output
*
* @param string $shortcode Shortcode tag
* @param array $atts Shortcode attributes
* @param string|null $content Shortcode content
*
* @return string Shortcode HTML
*/
private function render($shortcode, $atts = array(), $content = null)
{
/**
* @var string $html Shortcode html output
*/
$html = '';
/**
* @var string Absolute path to default shortcodes templates directory
*/
$default = wp_normalize_path(APPICA_CORE_ROOT . '/templates/shortcodes');
/**
* Filter the absolute path to shortcodes folder.
* Allow to override any shortcode templates.
*
* @since 1.0.0
*
* @param string $default Default absolute path to shortcode templates folder
*/
$path = apply_filters('appica_shortcodes_templates_path', $default);
$path = untrailingslashit($path);
// finally, path to shortcode template
$template = "{$path}/{$shortcode}.php";
// if user template doesn't exists - use default one
if (!is_readable($template)) {
$template = "{$default}/{$shortcode}.php";
}
if (is_readable($template)) {
ob_start();
require $template;
$html = ob_get_contents();
ob_end_clean();
}
return $html;
}
示例4: kirki_autoload_classes
/**
* The Kirki class autoloader.
* Finds the path to a class that we're requiring and includes the file.
*/
function kirki_autoload_classes($class_name)
{
$paths = array();
if (0 === stripos($class_name, 'Kirki')) {
$path = dirname(__FILE__) . '/includes/';
$filename = 'class-' . strtolower(str_replace('_', '-', $class_name)) . '.php';
$paths[] = $path . $filename;
$paths[] = dirname(__FILE__) . '/includes/lib/' . $filename;
$substr = str_replace('Kirki_', '', $class_name);
$exploded = explode('_', $substr);
$levels = count($exploded);
$previous_path = '';
for ($i = 0; $i < $levels; $i++) {
$paths[] = $path . $previous_path . strtolower($exploded[$i]) . '/' . $filename;
$previous_path .= strtolower($exploded[$i]) . '/';
}
foreach ($paths as $path) {
$path = wp_normalize_path($path);
if (file_exists($path)) {
include_once $path;
return;
}
}
}
}
示例5: set_url
/**
* Properly set the Kirki URL for assets.
* Determines if Kirki is installed as a plugin, in a child theme, or a parent theme
* and then does some calculations to get the proper URL for its CSS & JS assets.
*/
public function set_url()
{
// The path of the Kirki's parent-folder.
$path = wp_normalize_path(dirname(Kirki::$path));
// Get parent-theme path.
$parent_theme_path = get_template_directory();
$parent_theme_path = wp_normalize_path($parent_theme_path);
// Get child-theme path.
$child_theme_path = get_stylesheet_directory_uri();
$child_theme_path = wp_normalize_path($child_theme_path);
Kirki::$url = plugin_dir_url(dirname(__FILE__) . 'kirki.php');
// Is Kirki included in a parent theme?
if (false !== strpos(Kirki::$path, $parent_theme_path)) {
Kirki::$url = get_template_directory_uri() . str_replace($parent_theme_path, '', Kirki::$path);
}
// Is there a child-theme?
if ($child_theme_path !== $parent_theme_path) {
// Is Kirki included in a child theme?
if (false !== strpos(Kirki::$path, $child_theme_path)) {
Kirki::$url = get_template_directory_uri() . str_replace($child_theme_path, '', Kirki::$path);
}
}
// Apply the kirki/config filter.
$config = apply_filters('kirki/config', array());
if (isset($config['url_path'])) {
Kirki::$url = esc_url_raw($config['url_path']);
}
}
示例6: beans_define_constants
/**
* Define constants.
*
* @ignore
*/
function beans_define_constants()
{
// Define version.
define('BEANS_VERSION', '1.2.4');
// Define paths.
define('BEANS_THEME_PATH', wp_normalize_path(trailingslashit(get_template_directory())));
define('BEANS_PATH', BEANS_THEME_PATH . 'lib/');
define('BEANS_ASSETS_PATH', BEANS_PATH . 'assets/');
define('BEANS_LANGUAGES_PATH', BEANS_PATH . 'languages/');
define('BEANS_RENDER_PATH', BEANS_PATH . 'render/');
define('BEANS_TEMPLATES_PATH', BEANS_PATH . 'templates/');
define('BEANS_STRUCTURE_PATH', BEANS_TEMPLATES_PATH . 'structure/');
define('BEANS_FRAGMENTS_PATH', BEANS_TEMPLATES_PATH . 'fragments/');
// Define urls.
define('BEANS_THEME_URL', trailingslashit(get_template_directory_uri()));
define('BEANS_URL', BEANS_THEME_URL . 'lib/');
define('BEANS_ASSETS_URL', BEANS_URL . 'assets/');
define('BEANS_LESS_URL', BEANS_ASSETS_URL . 'less/');
define('BEANS_JS_URL', BEANS_ASSETS_URL . 'js/');
define('BEANS_IMAGE_URL', BEANS_ASSETS_URL . 'images/');
// Define admin paths.
define('BEANS_ADMIN_PATH', BEANS_PATH . 'admin/');
// Define admin url */
define('BEANS_ADMIN_URL', BEANS_URL . 'admin/');
define('BEANS_ADMIN_ASSETS_URL', BEANS_ADMIN_URL . 'assets/');
define('BEANS_ADMIN_JS_URL', BEANS_ADMIN_ASSETS_URL . 'js/');
}
示例7: _get_phpdoc_data
/**
* Generate the data from the PHPDoc markup.
*
* @param string $path Directory or file to scan for PHPDoc
* @param string $format What format the data is returned in: [json|array].
*
* @return string|array
*/
protected function _get_phpdoc_data($path, $format = 'json')
{
$output_cache_file = dirname(__DIR__) . '/cache-phpdoc.json';
/**
* Force delete last cache of phpdoc
* Compare directory and WordPress Version for detecting
*/
$delete_output_cache_file = false;
$wp_parser_root_import_dir = get_option('wp_parser_root_import_dir', '');
$directory_to_compare = wp_normalize_path(__DIR__);
if (false !== strpos($wp_parser_root_import_dir, $directory_to_compare)) {
$current_wp_version = get_bloginfo('version');
$wp_parser_imported_wp_version = get_option('wp_parser_imported_wp_version', $current_wp_version);
$delete_output_cache_file = $wp_parser_imported_wp_version != $current_wp_version;
}
/**
* Delete last cache of phpdoc, true for deleting or false to skip
*
* Default: false or compare wordpress version see above
*/
$delete_output_cache_file = apply_filters('sublime_delete_phpdoc_output_cache', $delete_output_cache_file);
if ($delete_output_cache_file) {
if (false !== stream_resolve_include_path($output_cache_file)) {
unlink($output_cache_file);
}
}
if (false !== stream_resolve_include_path($output_cache_file)) {
if ($output = file_get_contents($output_cache_file)) {
$output = 'json' == $format ? $output : json_decode($output, true);
}
} else {
WP_CLI::line(sprintf('Extracting PHPDoc from %s. This may take a few minutes...', $path));
$is_file = is_file($path);
$files = $is_file ? array($path) : Importer::set_parser_phpdoc($path);
$path = $is_file ? dirname($path) : $path;
if ($files instanceof WP_Error) {
WP_CLI::error(sprintf('Problem with %1$s: %2$s', $path, $files->get_error_message()));
exit;
}
$output = Importer::get_parser_phpdoc($files, $path);
/**
* Generate cache file from phpdoc, true for generate or false to skip
*
* Default: true
*/
if (apply_filters('sublime_create_phpdoc_output_cache', true)) {
file_put_contents($output_cache_file, json_encode($output, JSON_PRETTY_PRINT));
}
if ('json' == $format) {
$output = json_encode($output, JSON_PRETTY_PRINT);
}
}
if ($helper_directory = realpath(dirname(__DIR__) . '/missing')) {
$helpers = glob($helper_directory . '/*.php');
if (is_array($helpers)) {
$output = array_merge($output, Importer::get_parser_phpdoc($helpers, $helper_directory));
}
}
return $output;
}
示例8: page_init
public function page_init()
{
register_setting('extrp', 'extrp_option', array($this, 'sanitize'));
register_setting('extrp_tool', 'extrp_option_tool', array($this, 'sanitize'));
$this->with_relevanssi = get_option('extrp_with_relevanssi');
$this->plugin_data = get_plugin_data(wp_normalize_path(EXTRP_PLUGIN_PATH . '/extended-related-posts.php'));
$this->updates = extrp_plugin_updates();
}
示例9: dashboard_notice
public function dashboard_notice()
{
$path = wp_normalize_path(Upfront::get_root_dir() . '/library/external/dashboard-notice/wpmudev-dash-notification.php');
if (!file_exists($path)) {
return false;
}
require_once $path;
}
示例10: testCustomDatabaseDumpPath
/**
* Make sure setting a custom path + database dump filename correctly sets the database dump filepath
*
*/
public function testCustomDatabaseDumpPath()
{
HM\BackUpWordPress\Path::get_instance()->set_path(WP_CONTENT_DIR . '/custom');
$this->backup->set_database_dump_filename('dump.sql');
$this->assertEquals(wp_normalize_path(WP_CONTENT_DIR . '/custom/dump.sql'), $this->backup->get_database_dump_filepath());
$this->backup->dump_database();
$this->assertFileExists($this->backup->get_database_dump_filepath());
}
示例11: test_should_return_correct_basename_for_symlinked_plugins
/**
* @ticket 29154
*/
function test_should_return_correct_basename_for_symlinked_plugins()
{
global $wp_plugin_paths;
$old_wp_plugin_paths = $wp_plugin_paths;
$wp_plugin_paths[wp_normalize_path(WP_PLUGIN_DIR) . '/a-symlinked-plugin'] = 'C:/www/path/plugins/a-plugin';
$basename = plugin_basename('c:\\www\\path\\plugins\\a-plugin\\plugin.php');
$wp_plugin_paths = $old_wp_plugin_paths;
$this->assertSame('a-symlinked-plugin/plugin.php', $basename);
}
示例12: _map_file_to_relative_origin
private function _map_file_to_relative_origin($file)
{
$file = wp_normalize_path(realpath($file));
$plugin_path_rx = preg_quote(wp_normalize_path(WP_PLUGIN_DIR), '/');
$muplugin_path_rx = preg_quote(wp_normalize_path(WPMU_PLUGIN_DIR), '/');
$theme_path_rx = preg_quote(wp_normalize_path(get_theme_root()), '/');
$path_prefix = false;
if (preg_match('/^' . $plugin_path_rx . '/', $file)) {
$path_prefix = $plugin_path_rx;
} else {
if (preg_match('/^' . $muplugin_path_rx . '/', $file)) {
$path_prefix = $muplugin_path_rx;
} else {
if (preg_match('/^' . $theme_path_rx . '/', $file)) {
$path_prefix = $theme_path_rx;
}
}
}
if (empty($path_prefix)) {
return $this->_get_l10n(self::ORIGIN_INTERNAL);
}
// Not a pugin, mu-plugin or a theme
$clean_path = explode('/', ltrim(preg_replace('/^' . $path_prefix . '/', '', $file), '/'));
$basename = !empty($clean_path[0]) ? $clean_path[0] : false;
if (empty($basename)) {
return $this->_get_l10n(self::ORIGIN_INTERNAL);
}
// We had an issue along the way and can't figure it out further
if (!function_exists('get_plugin_data')) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$all_plugins = get_plugins();
if ($path_prefix === $plugin_path_rx || $path_prefix === $muplugin_path_rx) {
// It's a plugin, get the name
$info = false;
foreach ($all_plugins as $plugin => $pinfo) {
if (!preg_match('/^' . preg_quote(trailingslashit($basename), '/') . '/', $plugin)) {
continue;
}
$info = $pinfo;
break;
}
if (empty($info)) {
// Let's give it one last go for mu-plugins
$info = get_plugin_data($file);
}
return !empty($info['Name']) ? $info['Name'] : $this->_get_l10n(self::ORIGIN_PLUGIN);
} else {
if ($theme_path_rx === $path_prefix) {
$info = wp_get_theme($basename);
$name = is_object($info) && method_exists($info, 'get') ? $info->get('Name') : false;
return !empty($name) ? $name : $this->_get_l10n(self::ORIGIN_THEME);
}
}
return $this->_get_l10n(self::ORIGIN_INTERNAL);
}
示例13: get_path
/**
* Get the path to the directory where backups will be stored
*/
public function get_path()
{
// Calculate the path if needed
if (empty($this->path) || !wp_is_writable($this->path)) {
$this->calculate_path();
}
// Ensure the backup directory is protected
$this->protect_path();
return wp_normalize_path($this->path);
}
示例14: normalize_path
/**
* Make all slashes unique.
*
* @param string $path
*
* @return string
*/
private function normalize_path($path)
{
// WP 3.9 and newer.
if (function_exists('wp_normalize_path')) {
return wp_normalize_path($path);
}
$path = str_replace('\\', '/', $path);
$path = preg_replace('|/+|', '/', $path);
return $path;
}
示例15: stt2extat_template_path
/**
* filter of template path
* use it to modified the theme
*
* @since 1.0.0
*
* fixes variables
*
* @since 1.1.6
*
*/
function stt2extat_template_path()
{
$template_name = get_option('stt2extat_template_name');
$template_path = wp_normalize_path(STT2EXTAT_PATH_LIB_CONTENT . 'templates/');
$path = $template_path . 'default';
if ($template_name) {
$path = $template_path . $template_name;
}
return $path;
}