Debugging shortcode problems

As @Milo said, wordpress.com is a platform on its own, and everything available on wordpress.com is only available to sites hosted on wordpress.com. The jetpack plugin does however make some features available to self hosted sites but I’m not particulary sure which ones.

The shortcodes you are talking about is only available on sites hosted with wordpress.com, and not self hosted sites.

I have quickly rewritten a script I have recently done to look for filters and action in WordPress to get all shortcodes available to self-hosted sites. Here is the function

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="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                        $output .= '<li>Line reference ' . $line_number . $whitespaces . $string[0] . '</li>';
                    }
                $output .= '</ul>';
            }
        }
        return $output;

    }

    return false;
}

Because all shortcodes available to the frontend should be in the wp-includes file, we can run the function as follow: (NOTE I have tested this on localhost)

echo get_all_filters_and_actions2( 'E:\xampp\htdocs\wordpress/wp-includes/' );

which output

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)

Because the shortcodes picked up by the function in wp-includes\shortcodes.php is only samples in comments, we only really have the following shortcodes available by default on self hosted sites

(NOTE: This is as at WordPress 4.4)

Leave a Comment