本文整理汇总了PHP中add_filters函数的典型用法代码示例。如果您正苦于以下问题:PHP add_filters函数的具体用法?PHP add_filters怎么用?PHP add_filters使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_filters函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: i4web_root_relative_url
/**
* Root relative URLs
*
* WordPress likes to use absolute URLs on everything - let's clean that up.
* Inspired by http://www.456bereastreet.com/archive/201010/how_to_make_wordpress_urls_root_relative/
*
* You can enable/disable this feature in config.php:
* current_theme_supports('root-relative-urls');
*
* @author Scott Walkinshaw <scott.walkinshaw@gmail.com>
*/
function i4web_root_relative_url($input)
{
preg_match('|https?://([^/]+)(/.*)|i', $input, $matches);
if (!isset($matches[1]) || !isset($matches[2])) {
return $input;
} elseif ($matches[1] === $_SERVER['SERVER_NAME'] || $matches[1] === $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']) {
return wp_make_link_relative($input);
} else {
return $input;
}
}
function i4web_enable_root_relative_urls()
{
return !(is_admin() || in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'))) && current_theme_supports('root-relative-urls');
}
if (i4web_enable_root_relative_urls()) {
$root_rel_filters = array('bloginfo_url', 'the_permalink', 'wp_list_pages', 'wp_list_categories', 'i4web_wp_nav_menu_item', 'the_content_more_link', 'the_tags', 'get_pagenum_link', 'get_comment_link', 'month_link', 'day_link', 'year_link', 'tag_link', 'the_author_posts_link', 'script_loader_src', 'style_loader_src');
add_filters($root_rel_filters, 'i4web_root_relative_url');
}
示例2: roots_root_relative_url
$output = roots_root_relative_url($input);
preg_match_all('!([^/]+)/([^/]+)!', $output, $matches);
if (isset($matches[1]) && isset($matches[2])) {
if ($matches[1][0] === $matches[2][0]) {
$output = substr($output, strlen($matches[1][0]) + 1);
}
}
return $output;
}
function roots_enable_root_relative_urls()
{
return !(is_admin() && in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'))) && current_theme_supports('root-relative-urls');
}
if (roots_enable_root_relative_urls()) {
$root_rel_filters = array('bloginfo_url', 'theme_root_uri', 'stylesheet_directory_uri', 'template_directory_uri', 'plugins_url', 'the_permalink', 'wp_list_pages', 'wp_list_categories', 'wp_nav_menu', 'the_content_more_link', 'the_tags', 'get_pagenum_link', 'get_comment_link', 'month_link', 'day_link', 'year_link', 'tag_link', 'the_author_posts_link');
add_filters($root_rel_filters, 'roots_root_relative_url');
add_filter('script_loader_src', 'roots_fix_duplicate_subfolder_urls');
add_filter('style_loader_src', 'roots_fix_duplicate_subfolder_urls');
}
/**
* Wrap embedded media as suggested by Readability
*
* @link https://gist.github.com/965956
* @link http://www.readability.com/publishers/guidelines#publisher
*/
function roots_embed_wrap($cache, $url, $attr = '', $post_ID = '')
{
return '<div class="entry-content-asset">' . $cache . '</div>';
}
add_filter('embed_oembed_html', 'roots_embed_wrap', 10, 4);
add_filter('embed_googlevideo', 'roots_embed_wrap', 10, 2);
示例3: add_filters
'the_permalink',
'wp_list_pages',
'wp_list_categories',
'wp_nav_menu',
'the_content_more_link',
'the_tags',
'get_pagenum_link',
'get_comment_link',
'month_link',
'day_link',
'year_link',
'tag_link',
'the_author_posts_link'
);
add_filters($tags, 'roots_root_relative_url');
add_filter('script_loader_src', 'roots_fix_duplicate_subfolder_urls');
add_filter('style_loader_src', 'roots_fix_duplicate_subfolder_urls');
}
// remove root relative URLs on any attachments in the feed
function roots_root_relative_attachment_urls() {
if (!is_feed()) {
add_filter('wp_get_attachment_url', 'roots_root_relative_url');
add_filter('wp_get_attachment_link', 'roots_root_relative_url');
}
}
add_action('pre_get_posts', 'roots_root_relative_attachment_urls');
示例4: soil_root_relative_url
* WordPress likes to use absolute URLs on everything - let's clean that up.
* Inspired by http://www.456bereastreet.com/archive/201010/how_to_make_wordpress_urls_root_relative/
*
* You can enable/disable this feature in functions.php (or lib/config.php if you're using Roots):
* add_theme_support('soil-relative-urls');
*/
function soil_root_relative_url($input)
{
preg_match('|https?://([^/]+)(/.*)|i', $input, $matches);
if (!isset($matches[1]) || !isset($matches[2])) {
return $input;
} elseif ($matches[1] === $_SERVER['SERVER_NAME'] || $matches[1] === $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']) {
return wp_make_link_relative($input);
} else {
return $input;
}
}
function soil_enable_root_relative_urls()
{
return !(is_admin() || in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php')));
}
if (soil_enable_root_relative_urls()) {
$root_rel_filters = array('bloginfo_url', 'the_permalink', 'wp_list_pages', 'wp_list_categories', 'soil_wp_nav_menu_item', 'the_content_more_link', 'the_tags', 'get_pagenum_link', 'get_comment_link', 'month_link', 'day_link', 'year_link', 'tag_link', 'the_author_posts_link', 'script_loader_src', 'style_loader_src');
add_filters($root_rel_filters, 'soil_root_relative_url');
}
function add_filters($tags, $function)
{
foreach ($tags as $tag) {
add_filter($tag, $function);
}
}
示例5: add_actions
function add_actions($tags, $function_to_add, $priority = 10, $accepted_args = 1) {
return add_filters($tags, $function_to_add, $priority, $accepted_args);
}
示例6: roots_add_rewrites
* /wp-content/themes/themename/img/ to /img/
* /wp-content/plugins/ to /plugins/
*
* If you aren't using Apache, alternate configuration settings can be found in the docs.
*
* @link https://github.com/retlehs/roots/blob/master/doc/rewrites.md
*/
function roots_add_rewrites($content)
{
global $wp_rewrite;
$roots_new_non_wp_rules = array('assets/css/(.*)' => THEME_PATH . '/assets/css/$1', 'assets/js/(.*)' => THEME_PATH . '/assets/js/$1', 'assets/img/(.*)' => THEME_PATH . '/assets/img/$1', 'plugins/(.*)' => RELATIVE_PLUGIN_PATH . '/$1');
$wp_rewrite->non_wp_rules = array_merge($wp_rewrite->non_wp_rules, $roots_new_non_wp_rules);
return $content;
}
function roots_clean_urls($content)
{
if (strpos($content, RELATIVE_PLUGIN_PATH) > 0) {
return str_replace('/' . RELATIVE_PLUGIN_PATH, '/plugins', $content);
} else {
return str_replace('/' . THEME_PATH, '', $content);
}
}
if (!is_multisite() && !is_child_theme()) {
if (current_theme_supports('rewrites')) {
add_action('generate_rewrite_rules', 'roots_add_rewrites');
}
if (!is_admin() && current_theme_supports('rewrites')) {
$tags = array('plugins_url', 'bloginfo', 'stylesheet_directory_uri', 'template_directory_uri', 'script_loader_src', 'style_loader_src');
add_filters($tags, 'roots_clean_urls');
}
}
示例7: ya_add_rewrites
* /wp-content/themes/themename/img/ to /img/
* /wp-content/plugins/ to /plugins/
*
* If you aren't using Apache, alternate configuration settings can be found in the docs.
*
* @link https://github.com/retlehs/roots/blob/master/doc/rewrites.md
*/
function ya_add_rewrites($content)
{
global $ya_rewrite;
$ya_new_non_wp_rules = array('css/(.*)' => THEME_PATH . '/css/$1', 'js/(.*)' => THEME_PATH . '/js/$1', 'assets/img/(.*)' => THEME_PATH . '/assets/img/$1', 'assets/font/(.*)' => THEME_PATH . '/assets/font/$1', 'plugins/(.*)' => RELATIVE_PLUGIN_PATH . '/$1');
$ya_rewrite->non_wp_rules = array_merge($ya_rewrite->non_wp_rules, $ya_new_non_wp_rules);
return $content;
}
function ya_clean_urls($content)
{
if (strpos($content, FULL_RELATIVE_PLUGIN_PATH) === 0) {
return str_replace(FULL_RELATIVE_PLUGIN_PATH, WP_BASE . '/plugins', $content);
} else {
return str_replace('/' . THEME_PATH, '', $content);
}
}
if (!is_multisite() && !is_child_theme() && get_option('permalink_structure')) {
if (current_theme_supports('rewrites')) {
add_action('generate_rewrite_rules', 'ya_add_rewrites');
}
if (!is_admin() && current_theme_supports('rewrites')) {
$tags = array('plugins_url', 'bloginfo', 'stylesheet_directory_uri', 'template_directory_uri', 'script_loader_src', 'style_loader_src');
add_filters($tags, 'ya_clean_urls');
}
}
示例8: spring_root_relative_url
<?php
/**
* Root relative URLs
*
* WordPress likes to use absolute URLs on everything - let's clean that up.
* Inspired by http://www.456bereastreet.com/archive/201010/how_to_make_wordpress_urls_root_relative/
*
* You can enable/disable this feature in config.php:
* current_theme_supports('root-relative-urls');
*
* @author Scott Walkinshaw <scott.walkinshaw@gmail.com>
*/
function spring_root_relative_url($input)
{
preg_match('|https?://([^/]+)(/.*)|i', $input, $matches);
if (isset($matches[1]) && isset($matches[2]) && $matches[1] === $_SERVER['SERVER_NAME']) {
return wp_make_link_relative($input);
} else {
return $input;
}
}
function spring_enable_root_relative_urls()
{
return !(is_admin() || in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'))) && current_theme_supports('root-relative-urls');
}
if (spring_enable_root_relative_urls()) {
$root_rel_filters = array('bloginfo_url', 'the_permalink', 'wp_list_pages', 'wp_list_categories', 'spring_wp_nav_menu_item', 'the_content_more_link', 'the_tags', 'get_pagenum_link', 'get_comment_link', 'month_link', 'day_link', 'year_link', 'tag_link', 'the_author_posts_link', 'script_loader_src', 'style_loader_src');
add_filters($root_rel_filters, 'spring_root_relative_url');
}
示例9: shoestrap_root_relative_url
$output = shoestrap_root_relative_url($input);
preg_match_all('!([^/]+)/([^/]+)!', $output, $matches);
if (isset($matches[1][0]) && isset($matches[2][0])) {
if ($matches[1][0] === $matches[2][0]) {
$output = substr($output, strlen($matches[1][0]) + 1);
}
}
return $output;
}
function shoestrap_enable_root_relative_urls()
{
return !(is_admin() && in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'))) && current_theme_supports('root-relative-urls');
}
if (shoestrap_enable_root_relative_urls()) {
$root_rel_filters = array('bloginfo_url', 'theme_root_uri', 'stylesheet_directory_uri', 'template_directory_uri', 'plugins_url', 'the_permalink', 'wp_list_pages', 'wp_list_categories', 'wp_nav_menu', 'the_content_more_link', 'the_tags', 'get_pagenum_link', 'get_comment_link', 'month_link', 'day_link', 'year_link', 'tag_link', 'the_author_posts_link');
add_filters($root_rel_filters, 'shoestrap_root_relative_url');
add_filter('script_loader_src', 'shoestrap_fix_duplicate_subfolder_urls');
add_filter('style_loader_src', 'shoestrap_fix_duplicate_subfolder_urls');
}
/**
* Wrap embedded media as suggested by Readability
*
* @link https://gist.github.com/965956
* @link http://www.readability.com/publishers/guidelines#publisher
*/
function shoestrap_embed_wrap($cache, $url, $attr = '', $post_ID = '')
{
return '<div class="entry-content-asset">' . $cache . '</div>';
}
add_filter('embed_oembed_html', 'shoestrap_embed_wrap', 10, 4);
add_filter('embed_googlevideo', 'shoestrap_embed_wrap', 10, 2);
示例10: str_replace
if (strpos($content, FULL_RELATIVE_PLUGIN_PATH) === 0) {
return str_replace(FULL_RELATIVE_PLUGIN_PATH, WP_BASE . '/plugins', $content);
} else {
return str_replace('/' . THEME_PATH, '', $content);
}
}
if (!is_multisite() && !is_child_theme() && get_option('permalink_structure')) {
if (current_theme_supports('rewrite-urls')) {
add_action('generate_rewrite_rules', 'shoestrap_add_rewrites');
}
if (current_theme_supports('h5bp-htaccess')) {
add_action('generate_rewrite_rules', 'shoestrap_add_h5bp_htaccess');
}
if (!is_admin() && current_theme_supports('rewrite-urls')) {
$tags = array('plugins_url', 'bloginfo', 'stylesheet_directory_uri', 'template_directory_uri', 'script_loader_src', 'style_loader_src');
add_filters($tags, 'shoestrap_clean_urls');
}
}
// Add the contents of h5bp-htaccess into the .htaccess file
function shoestrap_add_h5bp_htaccess($content)
{
global $wp_rewrite;
$home_path = function_exists('get_home_path') ? get_home_path() : ABSPATH;
$htaccess_file = $home_path . '.htaccess';
$mod_rewrite_enabled = function_exists('got_mod_rewrite') ? got_mod_rewrite() : false;
if (!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks() || is_writable($htaccess_file)) {
if ($mod_rewrite_enabled) {
$h5bp_rules = extract_from_markers($htaccess_file, 'HTML5 Boilerplate');
if ($h5bp_rules === array()) {
$filename = dirname(__FILE__) . '/h5bp-htaccess';
return insert_with_markers($htaccess_file, 'HTML5 Boilerplate', extract_from_markers($filename, 'HTML5 Boilerplate'));
示例11: alfath_root_relative_url
<?php
/**
* Root relative URLs
*
* WordPress likes to use absolute URLs on everything - let's clean that up.
* Inspired by http://www.456bereastreet.com/archive/201010/how_to_make_wordpress_urls_root_relative/
*
* You can enable/disable this feature in config.php:
* current_theme_supports('alfath-relative-urls');
*
* @author Scott Walkinshaw <scott.walkinshaw@gmail.com>
*/
function alfath_root_relative_url($input)
{
preg_match('|https?://([^/]+)(/.*)|i', $input, $matches);
if (isset($matches[1]) && isset($matches[2]) && $matches[1] === $_SERVER['SERVER_NAME']) {
return wp_make_link_relative($input);
} else {
return $input;
}
}
function alfath_enable_root_relative_urls()
{
return !(is_admin() || in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'))) && current_theme_supports('alfath-relative-urls');
}
if (alfath_enable_root_relative_urls()) {
$root_rel_filters = array('bloginfo_url', 'the_permalink', 'wp_list_pages', 'wp_list_categories', 'alfath_wp_nav_menu_item', 'the_content_more_link', 'the_tags', 'get_pagenum_link', 'get_comment_link', 'month_link', 'day_link', 'year_link', 'tag_link', 'the_author_posts_link', 'script_loader_src', 'style_loader_src');
add_filters($root_rel_filters, 'alfath_root_relative_url');
}