web-dev-qa-db-fra.com

Les attributs par défaut des codes courts

J'utilise cette construction pour implémenter mon propre shortcode:

function column_with_icon($atts, $content = null) {
    extract(shortcode_atts(array(
        'icon' => 'onebit_03'
    ), $atts));

    return '<div class="column3">
    <img class="features-icon" alt="icon" src="' . get_bloginfo("template_url") . '/images/icons/' . $icon . '.png"/>
                            <div class="feature-content">' . $content . $icon . '</div>';
}

add_shortcode('column-icon', 'column_with_icon');

Quand j'essaie d'ajouter un contenu comme celui-ci:

[column-icon icon="onebit_13"]
<h3>What is Lorem ipsum?</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
<a href="#" class="main-theme-link">Learn more</a></div>
[/column-icon]

La valeur par défaut de l'attribut 'icon' n'est pas remplacée et elle est égale à 'onebit_03', pas 'onebit_13'. Que puis-je faire à ce sujet?

UPDATE Voici le code que j'utilise pour récupérer et présenter les données:

function skible_load_special_offer_section() {
    $content = get_option("prc_speciall_offer_text", true);
    if (get_option("prc_show_special_offer_section")) {
        echo stripslashes(do_shortcode('<!--Start Special offer (in border) content-->
                    <div class="border-top"></div>
                    <div class="border-middle">
                        <div class="special-offer-area">
                            <div class="special-offer-image-left">
                                <img alt="image" src="' . get_bloginfo("template_url") . ' /colors/magic_night/special-offer-image.png"/>
                            </div>
                            <div class="special-offer-content-right">' . $content . '</div>
            <div class = "clear"></div>
            </div>
            </div>
            <div class = "border-bottom"></div>
            <!--End Special offer (in border) content-->'));
    }
}
1
Sergei Basharov

Je n'ai aucune idée de ce qui ne va pas dans votre configuration. Clairement, le shortcode est correctement enregistré, mais dans certains cas, quelque chose l'empêche d'être analysé correctement.

C'est le code de test qui reproduit approximativement la façon dont le shortcode est analysé pour l'exécution:

$content = get_option("prc_speciall_offer_text", true);
$pattern = '/'.get_shortcode_regex().'/s';
preg_replace_callback( $pattern, 'var_dump', $content );

La sortie du tableau doit correspondre à ce qui suit, conformément à la spécification get_shortcode_regex():

1/6 - Un [ou] supplémentaire pour permettre l'échappement de codes courts avec un double [[]]

2 - Le nom du shortcode

3 - La liste d'arguments shortcode

4 - La fermeture automatique /

5 - Le contenu d'un shortcode quand il enveloppe du contenu.

C'est ce que ça laisse pour moi:

array
  0 => string '[column-icon icon="onebit_13"]
<h3>What is Lorem ipsum?</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
<a href="#" class="main-theme-link">Learn more</a></div>
[/column-icon]' (length=389)
  1 => string '' (length=0)
  2 => string 'column-icon' (length=11)
  3 => string ' icon="onebit_13"' (length=17)
  4 => string '' (length=0)
  5 => string '
<h3>What is Lorem ipsum?</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
<a href="#" class="main-theme-link">Learn more</a></div>
' (length=345)
  6 => string '' (length=0)
1
Rarst