simplereach / sranalytics_wordpress

www.simplereach.com
1 stars 2 forks source link

apply_filters for values in $javascript_array #11

Closed matthewpizza closed 9 years ago

matthewpizza commented 9 years ago

Create filters for values sent to SimpleReach: sranalytics_title, sranalytics_url, sranalytics_date, sranalytics_channels, sranalytics_tags, and sranalytics_authors.

Allows sites with unconventional setups to send the correct data. For example, when using Co-Authors Plus for post attribution, the following filter could be used to send author data:

<?php

/**
 * SimpleReach Analytics and Co-Authors Plus
 *
 * @uses get_coauthors
 * @param array $authors
 * @return array $authors
 */
add_filter( 'sranalytics_authors', function( $authors ) {
    if ( ! function_exists( 'get_coauthors') ) return $authors;

    $authors = array();
    $coauthors = get_coauthors( get_the_ID() );

    foreach ( $coauthors as $coauthor ) {
        $authors[] = $coauthor->display_name;
    }

    return $authors;
} );
andremalan commented 9 years ago

thanks @matthewspencer. Taking a look now.

andremalan commented 9 years ago

This is great (and was kind of fun to play with). Merging now and will submit changes to WP VIP @matthewspencer

matthewpizza commented 9 years ago

@andremalan Thank you!