web-dev-qa-db-fra.com

changer la fonction shortcode du plugin

j'utilise un plugin qui contient ce code et je veux changer l'emplacement des fichiers css, js et template.php afin qu'ils soient situés dans mon répertoire de modèles au lieu d'un plugin sans modifier les fichiers du plugin

public function shortcode($atts, $content = NULL) {

    global $post, $wpdb;

    STATIC $i = 1;



    $timelinr_options = get_option('timelinr_general_options');

    $desing_options = get_option('timelinr_desing_options');

    $pairs = array(

            'orientation' => $timelinr_options['orientation'],

            'startat' => intval($timelinr_options['startat']),

            'arrowkeys' => $timelinr_options['arrowkeys'],

            'autoplay' => $timelinr_options['autoplay'],

            'autoplaydirection' => $timelinr_options['autoplaydirection'],

            'autoplaypause' => $timelinr_options['autoplaypause'],

            'order' => $timelinr_options['order'],

            'containerdiv' => 'timelinr-'.$i,

            'category' => '',

            'dateformat' => $desing_options['dateformat'],

    );

    $atts = shortcode_atts($pairs, $atts );



    if ( strcmp ( $atts['orientation'] , 'horizontal' ) == 0){

        wp_enqueue_style('timelinr-style', JQTL_BASE_URL . '/assets/css/style.css', '', JQTL_CURRENT_VERSION );

    } elseif ( strcmp ( $atts['orientation'] , 'vertical' ) == 0) {

        wp_enqueue_style('timelinr-style_v', JQTL_BASE_URL . '/assets/css/style_v.css', '', JQTL_CURRENT_VERSION );

    }



    ob_start();

    include (JQTL_BASE_PATH . '/includes/template.php');

    $out = ob_get_contents();

    ob_end_clean();



    $i++;

    return $out;

}
1
Amro Shalaby

vous pouvez remplacer le shortcode comme ceci:

add_action("init", function () {


    remove_shortcode("timelinr");

    add_shortcode("timelinr", function ($atts, $content) {

        // call the shortcode of jqueryTimelinrLoad
        $result = $GLOBALS["jqueryTimelinrLoad"]->shortcode($atts, $content);

        // dequeue style
        wp_dequeue_style("timelinr-style");

        // enqueue your style
        wp_enqueue_style("timelinr-style2", "new.css");

        // result of the shortcode
        return $result;
    });

});
3
mmm