正如@Milo所说,wordpress。com是一个独立的平台,wordpress上提供的一切。com仅对wordpress上托管的站点可用。com。jetpack插件确实为自托管网站提供了一些功能,但我不确定是哪些功能。
您所说的短代码仅在wordpress托管的网站上可用。com,而不是自托管网站。
我很快重写了script I have recently done to look for filters and action 在WordPress中获取所有可用于自托管站点的短代码。下面是函数
function get_all_filters_and_actions2( $path = \'\' )
{
//Check if we have a path, if not, return false
if ( !$path )
return false;
// Validate and sanitize path
$path = filter_var( $path, FILTER_SANITIZE_URL );
/**
* If valiadtion fails, return false
*
* You can add an error message of something here to tell
* the user that the URL validation failed
*/
if ( !$path )
return false;
// Get each php file from the directory or URL
$dir = new RecursiveDirectoryIterator( $path );
$flat = new RecursiveIteratorIterator( $dir );
$files = new RegexIterator( $flat, \'/\\.php$/i\' );
if ( $files ) {
$output = \'\';
$array = [];
foreach($files as $name=>$file) {
/**
* Match and return all instances of apply_filters(**) or do_action(**)
* The regex will match the following
* - Any depth of nesting of parentheses, so apply_filters( \'filter_name\', parameter( 1,2 ) ) will be matched
* - Whitespaces that might exist between apply_filters or do_action and the first parentheses
*/
// Use file_get_contents to get contents of the php file
$get_file_contents = file( $file );
foreach ( $get_file_contents as $key=>$get_file_content ) {
preg_match_all( \'/add_shortcode\\s*(\\([^()]*(?:(?-1)[^()]*)*+\\))/\', $get_file_content, $matches );
if ( $matches[0] )
$array[$name][$key+1] = $matches[0];
}
}
if ( $array ) {
foreach ( $array as $file_name=>$values ) {
$output .= \'<ul>\';
$output .= \'<strong>File Path: \' . $file_name .\'</strong></br>\';
$output .= \'The following shortcodes are available\';
foreach ( $values as $line_number=>$string ) {
$whitespaces = \' \';
$output .= \'<li>Line reference \' . $line_number . $whitespaces . $string[0] . \'</li>\';
}
$output .= \'</ul>\';
}
}
return $output;
}
return false;
}
因为前端可用的所有短代码都应位于
wp-includes
文件中,我们可以按如下方式运行该函数:(
NOTE 我已经在localhost上测试过了
echo get_all_filters_and_actions2( \'E:\\xampp\\htdocs\\wordpress/wp-includes/\' );
哪个输出
File Path: E:\\xampp\\htdocs\\wordpress/wp-includes\\class-wp-embed.php
The following shortcodes are available
Line reference 31 add_shortcode( \'embed\', \'__return_false\' )
Line reference 60 add_shortcode( \'embed\', array( $this, \'shortcode\' ) )
File Path: E:\\xampp\\htdocs\\wordpress/wp-includes\\media.php
The following shortcodes are available
Line reference 1379 add_shortcode(\'wp_caption\', \'img_caption_shortcode\')
Line reference 1380 add_shortcode(\'caption\', \'img_caption_shortcode\')
Line reference 1490 add_shortcode(\'gallery\', \'gallery_shortcode\')
Line reference 2021 add_shortcode( \'playlist\', \'wp_playlist_shortcode\' )
Line reference 2270 add_shortcode( \'audio\', \'wp_audio_shortcode\' )
Line reference 2525 add_shortcode( \'video\', \'wp_video_shortcode\' )
File Path: E:\\xampp\\htdocs\\wordpress/wp-includes\\shortcodes.php
The following shortcodes are available
Line reference 59 add_shortcode( \'footag\', \'footag_func\' )
Line reference 72 add_shortcode( \'bartag\', \'bartag_func\' )
Line reference 80 add_shortcode( \'baztag\', \'baztag_func\' )
Line reference 89 add_shortcode($tag, $func)
因为函数在
wp-includes\\shortcodes.php
只是评论中的示例,我们只有以下默认自托管站点上可用的短代码
[caption]
[gallery]
[playlist]
[audio]
[video]
[embed]
(
NOTE: 这与WordPress 4.4相同