1
votes

I wrote my own plugin to display some information in a dynamic way. Everything worked perfectly on my localhost but when i did the migration to the server the shortcode of my plugin(and only that one) is displayed as text.

I checked and the plugin is still activated.

this is my plugin:

<?php
/*
Plugin Name: video-linker
Plugin URI: http://example.com
Description: Youku, Youtube and Vimeo linker
Version: 1.0
Author: Arno Turelinckx
Author URI: http://example.com
*/

$youku = '';
$youtube = '';
$vimeo = '';
$image = '';

function visualize_buttons($atts) {

    //get the links from the shortcode
    $attributes = shortcode_atts( array(
        'youku' => '',
        'youtube' => '',
        'vimeo' => '',
        'image' => '',
    ), $atts );

    $youku = $attributes['youku'];
    $youtube = $attributes['youtube'];
    $vimeo = $attributes['vimeo'];
    $image = $attributes['image'];

    echo '<div style="position: relative;">';
        echo '<div class="video-linker-image" style="background-image: url('.$image.');background-size: cover;"></div>';
        echo '<ul class="video-linker">';
            echo '<h2>Watch the video</h2>';
            echo '<li class="video-linker-youku"><a href="'.$youku.'" target="_blank"></a></li>';
            echo '<li class="video-linker-youtube"><a href="'.$youtube.'" target="_blank"><i class="icon-youtube"></i></a></li>';
            echo '<li class="video-linker-vimeo"><a href="'.$vimeo.'" target="_blank"><i class="icon-vimeo"></i></a></li>';
        echo '</ul>';
    echo '</div>';
}

function cf_shortcode($atts) {
    ob_start();
    visualize_buttons($atts);

    return ob_get_clean();
}

add_shortcode( 'video-linker', 'cf_shortcode' );

?>

And this is the way I call the shortcode in my page:

[video-linker youku=”” youtube=”” vimeo=”” image=”url_to_image.jpg”]

Any idea what the problem could be?

Any help is appreciated.

1
Why are you using output buffering? Any special reason for it? - dingo_d
It is my first time i created a plugin, the tutorial told me to use it - Arno Turelinckx
I think that you can do it without ob. Look the official pages of add_shortcode(). No output buffering there... - dingo_d
Okay, I just deleted it. But this still doesn't fix my problems :/ Do you have any other tips? - Arno Turelinckx
Did you make sure that your plugin is activated. You must reactivate the plugin after migration. - Pieter Goosen

1 Answers

0
votes

I edited the code. This should work, I put it in wentysixteen in functions.php and it worked:

<?php
/*
Plugin Name: video-linker
Plugin URI: http://example.com
Description: Youku, Youtube and Vimeo linker
Version: 1.0
Author: Arno Turelinckx
Author URI: http://example.com
*/

    function cf_shortcode($atts) {
    extract(shortcode_atts( array(
        'youku' => '',
        'youtube' => '',
        'vimeo' => '',
        'image' => '',
    ), $atts));


    $youku   = isset( $atts['youku'] ) ? $atts['youku'] : '';
    $youtube = isset( $atts['youtube'] ) ? $atts['youtube'] : '';
    $vimeo   = isset( $atts['vimeo'] ) ? $atts['vimeo'] : '';
    $image   = isset( $atts['image'] ) ? $atts['image'] : '';

    $return = '<div style="position: relative;">';
    $return .= ($image != '') ? '<div class="video-linker-image" style="background-image: url('.esc_url($image).');background-size: cover;"></div>' : '';
    $return .= '<ul class="video-linker">
            <h2>Watch the video</h2>';
    $return .= ($youku != '') ? '<li class="video-linker-youku"><a href="'.esc_url($youku).'" target="_blank"></a></li>' : '';
    $return .= ($youtube != '') ? '<li class="video-linker-youtube"><a href="'.esc_url($youtube).'" target="_blank"><i class="icon-youtube"></i></a></li>' : '';
    $return .= ($vimeo != '') ? '<li class="video-linker-vimeo"><a href="'.esc_url($vimeo).'" target="_blank"><i class="icon-vimeo"></i></a></li>' : '';
    $return .= '</ul>
        </div>';
    return $return;
}

add_shortcode( 'video_linker', 'cf_shortcode' );