lundi 2 novembre 2015

shortcodes (ultimate) doen't works within homemade wordpress spoiler

My issue:

I've created an homemade spoiler, based on this tutorial. It works great. However, the shortcodes-ultimate's shortcodes don't work when they are in the spoiler : it simply displays their source-code as plain text.

My question is how to "enable" those shortcodes within my spoiler?

Example : Spoiler unfolded


My code:

  • WP page

    [su_button url="http://ift.tt/1N7qpl0" download = "FileName.txt" background="#FF6B53" size="2" icon="icon: download" rel="download = 'fileName'"]download[/su_button]
    
    [dag_spoiler title="My spoiler"]
        [su_button url="http://ift.tt/1N7qpl0" download = "FileName.txt" background="#FF6B53" size="2" icon="icon: download" rel="download = 'fileName'"]download[/su_button]
    [/dag_spoiler]
    
    

    (the two buttons are strictly identical)

  • Homemade spoiler shortcode

PHP code

<?php
/**
 * @package dag_spoiler
 * @version 0.1
 */
/*
Plugin Name: ebo Spoiler
Plugin URI: http://ift.tt/1l394Ty
Description: Spoilers!
Author: ebo ft. Designer and Geek
Version: 0.1
Author URI: http://ift.tt/1N7qmWd
*/


/**
* Adds a spoiler shortcode to WordPress.
* 
* @return   none    outputs HTML
*/

function dag_spoiler_func( $atts, $content = null ) {
    $default_title = __('Spoiler alert!');
    $helptext_show = __('fa-plus');
    $helptext_hide = __('fa-minus');
    extract( shortcode_atts( array(
    'title' => 'Click to show spoiler',
    ), $atts ) );
    $spoiler = 
    /*'<style>'.
    '.dag_spoiler .dag_spoiler_header::before {'.
        'data-dag-spoiler-show="'. $helptext_show .'" '.
        'data-dag-spoiler-hide="'. $helptext_hide.'" '.
    '}'.
    '</style>'.*/
    '<div class="dag_spoiler">' .
    '<p class="dag_spoiler_header" ' . 
    'data-dag-spoiler-show="' . $helptext_show .'" '.
    'data-dag-spoiler-hide="' . $helptext_hide . '">' . $title . '</p>' .
    '<div class="dag_spoiler_content">' .
    /*'<p class="dag_spoiler_header">'. $title . '</p>' .
    '<div class="dag_spoiler_content">' .*/
    $content . 
    '</div>' . 
    '</div>';

    return $spoiler;
}
add_shortcode( 'dag_spoiler', 'dag_spoiler_func' );

/*EOF*/

/**
 * Enqueue plugin css and javascript
 */

add_action( 'wp_enqueue_scripts', 'dag_enqueue' );
function dag_enqueue() {
    wp_register_style( 'dag-spoiler-style', plugins_url('/ebo-spoiler.css', __FILE__) );
    wp_enqueue_style( 'dag-spoiler-style' );
    /*wp_enqueue_script( 'jquery' );*/
    wp_register_script( 'dag-spoiler-js', plugins_url('/ebo-spoiler.js', __FILE__) );
    wp_enqueue_script( 'dag-spoiler-js' );
}
add_action( 'wp_enqueue_scripts', 'dag_enqueue' );
?>

JS source-code

jQuery(document).ready( jQuery(function( $ ) {
    $(".dag_spoiler_header").each(function(){
    $(this).click( function() {
        var help_text_span = $(this).children('span.dag_spoiler_help_text');
        $(this).siblings('.dag_spoiler_content').slideToggle( "slow", function() {
        help_text_span.html(
            help_text_span.html() == '<i class="fa '+hide_text+'"></i>' ? '<i class="fa '+show_text+'"></i>' : '<i class="fa '+hide_text+'"></i>'
        );
        });
    });
    var show_text = $(this).attr('data-dag-spoiler-show');
    var hide_text = $(this).attr('data-dag-spoiler-hide');
    $(this).prepend(' <span class="dag_spoiler_help_text" style="margin-right: 15px; margin-left: 5px; font-size: 14px;"> <i class="fa '+show_text+'"></i></span>');
    });
}));

(just for exhaustiveness) CSS

.dag_spoiler {
    margin: .5em 0 .5em 0;
}

.dag_spoiler .dag_spoiler_header {
    cursor: pointer;
    font-size: 13px;
    font-weight: bold;
    line-height: 20px;
    min-height: 20px;
    padding-bottom: 7px;
    padding-left: 0;
    padding-right: 7px;
    padding-top: 7px;
    position: relative;
    font-weight: bold;
}

.dag_spoiler .dag_spoiler_header::before {
    font-family: FontAwesome;
    font-weight: normal;
    margin-left: 5px;
    margin-right: 15px;
}

.dag_spoiler div.dag_spoiler_content {
    /* border: 1px solid black; */
    padding-left: 7%; 
    padding-right: 7%;
    display: none;
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire