Issue with ad duplication on archives

Home Forums AdRotate for WordPress Adverts and Banners Issue with ad duplication on archives

  • #134594

    Ryan Smith
    Badges:

    Following up on an issue I raised via email earlier, I’m suggesting we introduce a couple hooks in the adrotate_group function so developers can alter the values of the $session_page and $selected ads array that are eventually used to render creatives on pages.

    Kinda like this:

    
    /* adrotate_group function code line 159 */
    if ( $ads ) {
    foreach ( $ads as $ad ) {
    $selected[ $ad->id ] = $ad;
    if ( $adrotate_config['duplicate_adverts_filter'] == 'Y' ) {
    $session_page = apply_filters( 'adrotate_session-page', 'adrotate-post-' . get_the_ID() );
    $selected     = adrotate_filter_duplicates( $selected, $ad->id, $session_page );
    }
    $selected = adrotate_filter_show_everyone( $selected, $ad );
    $selected = adrotate_filter_schedule( $selected, $ad );
    if ( $adrotate_config['enable_advertisers'] == 'Y' AND ( $ad->crate > 0 OR $ad->irate > 0 ) ) {
    $selected = adrotate_filter_budget( $selected, $ad );
    }
    if ( $adrotate_config['enable_geo'] > 0 AND $group->geo == 1 ) {
    $selected = adrotate_filter_location( $selected, $ad );
    }
    }
    $selected = apply_filters( 'adrotate_selected-ads', $selected, $session_page );
    /* Rest of code goes here... */
    }
    

    Without this, the $session_page variable is incorrectly populated using get_the_ID() which may return the ID of the first post in a loop on an archive page like the front page, custom post type archives, taxonomy / date archives etc. instead of the ID of the page you’re actually on. This pub sub approach keeps everything clean and organized I think, lemme know your thoughts.

    #134596

    Arnan de Gans
    Badges:

    But that doesn’t fix the original issue you raised.
    However, the version 5.8.14 fixes that already. So there is no need for these filters.

    #134604

    Ryan Smith
    Badges:

    this line:
    $session_page = apply_filters( 'adrotate_session-page', 'adrotate-post-' . get_the_ID() );

    would allow developers to implement something like:

    add_filter('adrotate_session-page', function($id) {
    if(is_front_page()){return 'adrotate-post-front';}
    return $id;
    });

    anywhere in their code (custom theme or plugin), which would allow the ads to be added to the correct array associated with the $session_page .

    If this has already been addressed in 5.8.14 then that’s awesome!

    #135413

    Arnan de Gans
    Badges:

    The next version of AdRotate Pro improves session handling for WordPress.
    This filter while perhaps fixing your use case, does not solve the issue you raised for common users.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

You may be interested in