Plugin Filters

Formatting Outputs

This version of Spanish Quote of the Day includes several filters that give you the possibility to modify completely both of the behaviour as the output format of the plugin.

Spanish Quote of the Day works via different filtered outputs depending on its operational mode so,

  • All the plugin outputs can have the same format and structure.
  • You can just change one of the outputs, Widget or Shortcode modes.
  • You can change all of the outputs.
  • You can use the plugin $options for modifying dinamicaly the output.
  • Or even, you can also modify the format output depending on the $post thus, you can use the ID, the post content or categories of the post that is been displayed to choose a special filter among all of your custom filters.

The standard output format

After installation and activation, the quote standard output format to screen is this:

<div id="cool-quote">
    <span class="quote-text"> the quote </span>
    <span class="author-tag">

        <span class="quote-author-link-separator"></span> 
        <span class="quote-author-link"> anchor to author's archive page ( as the <span class="author-name">author_name</span> ) </span>

    </span>

    <span class="quote-credits"> anchor to quote's website source ( with the $provider_name element ) </span>
</div>

In a basic installation, as default, both of widget and shorcode outputs are formatted via the same function that convert the object response and adds a minimun styling via these four simple classes: .cool-quote, .quote-text, .author-tag, .quote-author-link-separator, .quote-author-link, .quote-credits.

Plugin filters

Spanish Quote of the Day has three filters,

  • widget_quotes for the output via Widget,
  • post_outputs for the output via shortcode,
  • raw_quotes for the raw json object response from the oembed call called to Todopensamientos.com .

All of these three filters has the same structure:

apply_filters( 'namefilter', string $response, WP_post $post, array $options );

All filters receive the $response that is the complete content of the quote, the $post that’s the current WP displayed post, and $options that’s the parameters plugin.

The default filter cook_quotes

As default, Spanish Quote of the day uses a default filter cook_quotes, that basically just transforms the oEmbed response json object in HTML formatted code. See the advanced filters section for futher information.

Filter use basic examples

For example, if you want to modify the output for shortcodes inserted into your posts and always include an HTML <blockquote></blockquote>, you can add this function at the beginning of the single.php template of your theme:

<?php
function add_blockquote ( $response, $post, $options ) {
    $out      = '<blockquote>';
    $out     .= $response;
    $out     .= '</blockquote>';
    return $out;

}
add_filter ( 'post_quotes', 'add_blockquote', 10, 3 );
?>

As we’ve said, these filters allow you to control very accuratelly the style of output depending on parameters related even with the $post so that, another example could be to change the format just for pages and leaving the standard output for posts. In this case, you should include a function like this in the functions.php file of your theme:

<?php
function only_in_pages ( $response, $post, $options ) {

    if ( $post->post_type != 'page' ) return $response;

    $out      = '<div style="display:block; float:right;">';
    $out     .= $response;
    $out     .= '</div>';
    return $out;

}
add_filter ( 'post_quotes', 'only_in_pages', 10, 3 ); 
?>

Filter use advanced examples

The above examples simply work attached to the basic filters and after the default filter cook_quotes so they just add some HTML code to the quote however, if you need a more accurate control of the output, you can even disconnect this default filter function in that way,

remove_filter ( 'post_quotes', array ('sqod_widget', 'cook_quotes'), 1 );

That’s possible but then, remember that the functions will be directly receiving the oEmbed json object response because the most important task of the filter cook_quotes is precisely convertting the json array into HTML text so, if you disconnect this filter, then you have to deal directly the json array (see the oEmbed call section below for further information).

For example, if in the shortcode mode you want to change a) the order of the elements of the output, b) add some text and finally, and c) change completely the classes of HTML code, you could write a function like this.

<?php
// removing the default filter
function reorder_quote ( $response, $post, $options ) {

    // after removing the default filter, $response is not a string, is an object 
    // See The Oembed Call section below for more information of the json object $response

    // changing classes 
    $out     = '<div id="my-quote-style">';

    // first, the author
    $out    .= 'This quote belongs to: ';
    $out    .= '<span class="my-quote-author-link"><a href="' . $response->author_url . '" title="' . __( 'Notable quotes of', 'spanish-quotes-of-the-day' ) . ' ' . $response->author_name . ' | ' . $response->provider_name . '" target="_blank" >' . $response->author_name . '</a></span>';

    // then, the quote
    $out    .= 'The quote: '; 
    $out    .= '<span class="my-quote-text">'. $response->html . '</span>';

    // and finally, the provider
    $out    .= 'Provided by: ';
    $out    .= ' <span class="my-quote-credits"><a href="' . $response->provider_url . '" target="_blank" title="' . __( 'Theme classified notable quotes in spanish', 'spanish-quotes-of-the-day' ) . ' | ' . $response->provider_name . '">'. __('Notable Quotes in Spanish', 'spanish-quotes-of-the-day') . '</a></span>';

    $out    .= '</div><!-- end #my-quote-style -->';

    return $out;

}
remove_filter ( 'post_quotes', array ('sqod_widget', 'cook_quotes'), 1 );
add_filter ( 'post_quotes', 'reorder_quote', 10, 3 ); 
?>

Now, this new function reorder_quote substitutes the default function cook_quotes in all Widget outputs.

Asynchronous Mode

Remember that if your Spanish Quote of the Day plugin is working in asynchronous mode, some filters are unavailable. See the documentation about Asynchronous Mode for further information.

Install Now

DemoDownload NowWordPress plugin pageImprove your themes, install now Spanish Quote of the Day.