Pregunta

I have a select field wittin a Wordpress plugin that happily returns 'true' and 'false' values when selected. It is outputted like so:-

$wpautop_value = $this->opt('textbox_wpautop');

What I want to do is to add the Wordpress filter 'wpautop' to a text field '$text' only if the value returned is 'true' so something like:-

$text = (!$text && !$title) ? '<p><strong>TextBox</strong> &raquo; Add Content!</p>' : sprintf('<div class="hentry">%s</div>', do_shortcode( $wpautop_value=='true' ($text) ) );

I know the logic for where I have added '$wpautop_value=='true'' instead of the actual desired function 'wpautop' is incorrect so its just placed there for explanation purposes. The code should actually read like so if 'true'

$text = (!$text && !$title) ? '<p><strong>TextBox</strong> &raquo; Add Content!</p>' : sprintf('<div class="hentry">%s</div>', do_shortcode( wpautop ($text) ) );

... and if false no 'wpautop is added:-

$text = (!$text && !$title) ? '<p><strong>TextBox</strong> &raquo; Add Content!</p>' : sprintf('<div class="hentry">%s</div>', do_shortcode( ($text) ) );

Thanks for the input!

Glennyboy

¿Fue útil?

Solución

I hope I understood you right, but the easiest way to get that result is using a shorthand if/else-statement (which is already being used in that line of code).

do_shortcode( $wpautop_value == 'true' ? wpautop($text) : $text )

or the full line of code:

$text = (!$text && !$title) ? '<p><strong>TextBox</strong> &raquo; Add Content!</p>' : sprintf('<div class="hentry">%s</div>', do_shortcode( $wpautop_value == 'true' ? wpautop($text) : $text ) );
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top