2

I'm using the OnlyWire plugin to syndicate my posts in WordPress to their various networks. Unfortunately they've forgotten to add strip_shortcodes functionality to their plugin.

I'm using VisualComposer to format my posts which uses lots of short codes to add structure to the content of your post. Then when I post to OnlyWire I end up with all the short codes included.

I've tried several examples I've found here and elsewhere but I can't seem to get the strip_shortcodes function to rerender the stripped version.

Here's their post function here:

function ow_post($postID)
{
    global $wpdb;

    // Get the correct post ID if revision.
    if ($wpdb->get_var("SELECT post_type FROM $wpdb->posts WHERE ID=$postID") == 'revision')
    {
        $postID = $wpdb->get_var("SELECT post_parent FROM $wpdb->posts WHERE ID=$postID");
    }

    if (isset($_POST['ow_post']) && $_POST['ow_post'] == 'on')
    {
        // the checkbox is selected, let's post to onlywire with user credentials
        $username = get_option('ow_username');
        $password = get_option('ow_password');
        if ($username && $password)
        {

            $post      = get_post($postID);
            $tagstring = "";
            $prefix    = '';

            if(get_the_tags($post->ID))
            {
            foreach (get_the_tags($post->ID) as $tag)
            {
                $tagstring .= $prefix.str_replace(" ","-",trim($tag->name));
                $prefix = ',';
            }
            }

            $d                   = 'm\/d\/Y h\:i\:s T';
            $data['url']         = urlencode(get_permalink($postID));
            $data['title']       = trim(urlencode($post->post_title));
            $data['tags']        = trim($tagstring);
            $data['scheduled']   = urlencode(get_post_time($d, true, $post, false));


            if (strlen(strip_tags($post->post_content)) > 250)
            {
                $data['description'] = urlencode(substr(strip_tags($post->post_content), 0, 250) . " ...");
            }
        else
        {
        $data['description'] = urlencode(strip_tags($post->post_content));
        }   


            if (get_option('ow_service_logins') != false)
            {
                $data['networks'] = trim(get_option('ow_service_logins'));
            }

            createBookmark($data, $username, $password);
        }
    }
}

I created a callback:

function ow_strip_shortcodes ( $content ) {
    $content = strip_shortcodes( $content );
    return $content;
}

and tried adding a filter to it like so:

$post      = get_post($postID);
$tagstring = "";
$prefix    = '';

apply_filters('the_content', 'ow_strip_shortcodes');

but that doesn't seem to work ...

I'm sure it's something simple but I don't work much on Wordpress so I don't know the structure all that well.

--EDIT--

Adding to this, I've discovered that strip_shortcodes was working but my content was nested within the shortcodes thus it was being stripped as well.

Can someone please help with a regex that will replace all instances of brackets and the content inside them, yet leave the plain text intact?

Here is an example of a partial post:

[vc_row][vc_column width="1/1"][vc_column_text] Introductory text goes in this block
[/vc_column_text][/vc_column][/vc_row] 

All instances of [vc_*] and [/vc_*] need to be eliminated leaving only Introductory text goes in this block

4

0 回答 0