lundi 5 octobre 2015

WordPress Plugin - Obtain output content without conflicts

I'm writing a WordPress plugin that obtain the HTML contents

i found 2 ways to obtain the final output:

// first way

function __myplugin_callback($buffer) {
    return $buffer;
}

function __myplugin_buffer_start() { ob_start("callback"); }

function __myplugin__buffer_end() { ob_end_flush(); }

add_action('wp_head', 'buffer_start');
add_action('wp_footer', 'buffer_end');

That works when i have only my plugin active, when i have more plugins active, like SEO Yoast, i get conflicts between plugins and mine is not working properly.

// second way
ob_start();

add_action('shutdown', function() {
$final = '';
$levels = ob_get_level();

for ($i = 0; $i < $levels; $i++)
{
    $final .= ob_get_clean();
}

echo apply_filters('final_output', $final);
}, 0);

// call the filter

add_filter('final_output', function($output)
{
     return str_replace(.., .., $output);
});

This works better than the first way but i have also conflicts with plugins like Visual Composer

There is a safe way, to obtain the final html output without conflicts with other plugins?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire