How can we help?

If you are looking for support for our PokaTheme, this is the place!

Home Forums PokaTheme support External affiliate link

Viewing 11 post (of 11 total)
  • Author
    Posts
  • #18733
    Gilberto
    Participant

    Hi,
    I have the same need/problem. I don’t want to cloak our links anymore, apparently this is now against Google’s best practices and having all those affiliate links in .pho files that are “noindex”, the links marked as “nofollow” and having redirect to the actual merchants website is being picked up as “too many redirects” and “too many noindex” pages on Search Console.

    I added the code to the functions.php file in the child theme but that on it’s does nothing. I used ChatGPT to guide me in applying this, and I did the following:

    – Added a ACF plugin (i used the one from WP Engine).
    – Created a new Field Group with field type “URL”.

    Up to this point, the new ACF field DOES appear in the Affiliate review posts editor. I can specify the URL I want, but it won’t pick it up and use it in place of the affiliate link as the theme normally does (poka_affiliate_button).

    After hours of searching in all the files, I found that the poka_affiliate_button function is indeed defined in the helpers-affiliates.php file found at PokaTheme: helpers-affiliates.php (inc/core/helpers-affiliates.php)

    I edited the file replacing all the instances of the poka-affiliate-button function for the newly created ACF, as follows but it’s not working. now the button won’t even show. Here’s the code:

    <?php
    /**
    * There goes all the affiliate helpers
    */

    /**
    * Affiliate thumb
    *
    * @return string
    */
    if ( ! function_exists( ‘poka_affiliate_thumb’ ) ) {
    function poka_affiliate_thumb( $review_id, $atts, $extra_classes = ” ) {
    $html = ”;
    $style = ”;
    $el_type = ‘div’;
    $el_atts = ”;
    $el_aff_link = ”;
    $geotag = ”;
    $classes = ‘review-logo’;

    $background_color = poka_get_field( ‘affiliate_background_color’, $review_id );

    if ( in_array( ‘centered’, $atts, true ) ) {
    $classes .= ‘ review-logo–centered’;
    }

    if ( in_array( ’rounded’, $atts, true ) ) {
    $classes .= ‘ review-logo–rounded’;
    }

    if ( in_array( ‘boxed’, $atts, true ) ) {
    $classes .= ‘ review-logo–boxed’;
    }

    if ( in_array( ‘post’, $atts, true ) ) {
    $classes .= ‘ link-on-img–affiliates’;
    }

    if ( in_array( ‘link-on-img’, $atts, true ) ) {
    $classes .= ‘ link-on-img’;
    }

    if ( in_array( ‘link-absolute’, $atts, true ) ) {
    $classes .= ‘ link-absolute’;
    }

    if ( $extra_classes ) {
    $classes .= ‘ ‘ . $extra_classes;
    }

    if ( $background_color ) {
    $style .= ‘background-color: ‘ . $background_color . ‘;’;
    }

    if ( in_array( ‘link_affiliate’, $atts, true ) ) {
    $el_type = ‘a’;
    $el_atts = poka_affiliate_link_atts( $review_id );
    $el_aff_link = ‘href=”‘ . poka_affiliate_link( $review_id ) . ‘”‘;
    }

    if ( in_array( ‘link_review’, $atts, true ) ) {
    $el_type = ‘a’;
    $el_aff_link = ‘href=”‘ . poka_review_single_link_url( $review_id ) . ‘”‘;
    }

    if ( POKA_GEOLOCATION_ENABLED && pokageo_check_post_enabled( $review_id ) ) {
    if ( POKA_GEOLOCATION_AJAX_MODE_ENABLED ) {
    $geotag = ‘<div class=”pokageo-flag-circle jsPokaGeoFlagCircle” data-review-id=”‘ . $review_id . ‘”></div>’;
    } else {
    $geotag = ‘<div class=”pokageo-flag-circle”>’;
    $geotag .= ‘' . pokageo_detect_country_name() . '‘;

    if ( pokageo_is_country_allowed_for_post( $review_id ) ) {
    $geotag .= ‘<div class=”pokageo-status-icon pokageo-status-icon-allowed icon poka-bx-check”></div>’;
    } else {
    $geotag .= ‘<div class=”pokageo-status-icon pokageo-status-icon-disallowed icon poka-close”></div>’;
    }
    $geotag .= ‘</div>’;
    }
    }

    //$html .= ‘<div class=”single-affiliate-img”>’;
    $html .= ‘<‘ . $el_type . ‘ ‘ . $el_atts . ‘ ‘ . $el_aff_link . ‘ class=”‘ . $classes . ‘” ‘ . ( $style ? ‘style=”‘ . $style . ‘”‘ : ” ) . ‘>’;
    $html .= $geotag;
    $html .= get_the_post_thumbnail( $review_id, ‘affiliate-thumb’ );
    $html .= ‘</’ . $el_type . ‘>’;
    //$html .= ‘</div>’;

    return $html;
    }
    }

    /**
    * Get affiliate link attributes
    *
    * @param [id] $review_id
    * @return void
    */
    if ( ! function_exists( ‘poka_affiliate_link_atts’ ) ) {
    function poka_affiliate_link_atts( $review_id ) {
    return apply_filters( ‘poka_affiliate_link_atts’, ‘target=”_blank” rel=”nofollow”‘ );
    }
    }

    /**
    * Get affiliate link
    *
    * @param [id] $review_id
    * @return void
    */
    if ( ! function_exists( ‘poka_affiliate_link’ ) ) {
    function poka_affiliate_link( $review_id ) {
    $base = get_theme_mod( ‘general-affiliate-redirect-link-folder’ ) ? get_theme_mod( ‘general-affiliate-redirect-link-folder’ ) : ‘go’;

    if ( ” !== $review_id ) {
    $affiliate_link_id = poka_get_field( ‘direct-affiliate-link’, $review_id );
    $url = trailingslashit( get_home_url() );
    $link = $url . $base . ‘/’ . poka_get_field( ‘affiliate_key’, $affiliate_link_id );
    } else {
    $link = ‘#’;
    }

    return apply_filters( ‘poka_affiliate_link’, $link );
    }
    }

    /**
    * Get review single link url
    *
    * @param [id] $review_id
    * @return void
    */
    if ( ! function_exists( ‘poka_review_single_link_url’ ) ) {
    function poka_review_single_link_url( $review_id ) {
    return apply_filters( ‘poka_affiliate_link’, get_permalink( $review_id ) );
    }
    }
    /**
    * Get review single link html
    *
    * @param [id] $review_id
    * @return void
    */
    if ( ! function_exists( ‘poka_review_single_link’ ) ) {
    function poka_review_single_link( $review_id ) {
    // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
    $link = ‘<span>’ . poka_get_translation( ‘Review’ ) . ‘</span>‘;

    // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
    return apply_filters( ‘poka_review_single_button_html’, $link );
    }
    }

    /**
    * Get affiliate bonus
    *
    * @param [type] $review_id
    * @return void
    */
    if ( ! function_exists( ‘poka_affiliate_bonus’ ) ) {
    function poka_affiliate_bonus( $review_id ) {
    $html = ‘<div class=”review-bonus”>’;
    $html .= force_balance_tags( apply_filters( ‘poka_affiliate_bonus_text’, poka_get_field( ‘affiliate_bonus’, $review_id ) ) );
    $html .= ‘</div>’;

    return $html;
    }
    }

    /**
    * Get affiliate terms with tooltip
    *
    * @param [type] $review_id
    * @return void
    */
    if ( ! function_exists( ‘poka_affiliate_terms’ ) ) {
    function poka_affiliate_terms( $review_id, $wrapper_class = false, $tooltip_override = false ) {
    $html = ”;
    if ( poka_get_field( ‘affiliate_terms’, $review_id ) ) {
    if ( ( get_theme_mod( ‘terms-and-conditions-functionality’, poka_get_css_defaults( ‘terms-and-conditions-functionality’ ) ) && get_theme_mod( ‘terms-and-conditions-tooltip’, poka_get_css_defaults( ‘terms-and-conditions-tooltip’ ) ) ) || ( $tooltip_override && get_theme_mod( ‘terms-and-conditions-functionality’, poka_get_css_defaults( ‘terms-and-conditions-functionality’ ) ) ) ) {

    if ( $wrapper_class ) {
    $html .= ‘<div class=”‘ . $wrapper_class . ‘”>’;
    }
    $html .= ‘<div class=”tooltip”>’;
    $html .= ‘<span class=”tooltip-label”>’ . get_theme_mod( ‘terms-and-conditions-text’, poka_get_css_defaults( ‘terms-and-conditions-text’ ) ) . ‘</span>’;
    $html .= ‘<span class=”tooltip-text”>’;
    $html .= wp_kses_post( nl2br( poka_get_field( ‘affiliate_terms’, $review_id ) ) );
    $html .= ‘</span>’;
    $html .= ‘</div>’;
    if ( $wrapper_class ) {
    $html .= ‘</div>’;
    }
    }
    }
    return $html;
    }
    }

    if ( ! function_exists( ‘poka_affiliate_terms_text’ ) ) {
    function poka_affiliate_terms_text( $review_id, $wrapper_class = false, $terms_override = false ) {
    $html = ”;
    if ( poka_get_field( ‘affiliate_terms’, $review_id ) ) {
    if ( ( get_theme_mod( ‘terms-and-conditions-functionality’, poka_get_css_defaults( ‘terms-and-conditions-functionality’ ) ) && ! get_theme_mod( ‘terms-and-conditions-tooltip’, poka_get_css_defaults( ‘terms-and-conditions-tooltip’ ) ) ) || ( $terms_override && get_theme_mod( ‘terms-and-conditions-functionality’, poka_get_css_defaults( ‘terms-and-conditions-functionality’ ) ) ) ) {
    if ( $wrapper_class ) {
    $html .= ‘<div class=”‘ . $wrapper_class . ‘”>’;
    }
    $html .= wp_kses_post( nl2br( poka_get_field( ‘affiliate_terms’, $review_id ) ) );

    if ( $wrapper_class ) {
    $html .= ‘</div>’;
    }
    }
    }
    return $html;
    }
    }

    /**
    * Allow onclick attribute
    */

    add_filter( ‘wp_kses_allowed_html’, ‘return_allowed_a_tags’, 10, 2 );
    if ( ! function_exists( ‘return_allowed_a_tags’ ) ) {
    function return_allowed_a_tags( $allowed_tags, $context ) {
    if ( ‘post’ !== $context ) {
    return $allowed_tags;
    }
    $allowed_tags[‘a’][‘onclick’] = true;
    return $allowed_tags;
    }
    }

    /**
    * Return affiliate button
    */
    if ( ! function_exists( ‘poka_affiliate_button’ ) ) {
    function poka_affiliate_button( $review_id, $classes = ” ) {
    $affiliate_link = poka_get_field( ‘direct-affiliate-link’, $review_id );
    if ( ! $affiliate_link ) {
    $btn = ”;
    return apply_filters( ‘poka_affiliate_button’, $btn );
    }
    $onclick_event = poka_get_field( ‘affiliate_onclick_event’, $affiliate_link );
    $onclick = ”;
    if ( $onclick_event ) {
    $onclick = ‘onclick=”‘ . esc_html( $onclick_event ) . ‘”‘;
    }
    $classes = apply_filters( ‘poka_affiliate_button_classes’, ‘btn btn-primary ‘ . $classes );

    $btn = ‘‘ . poka_get_translation( ‘Play Now’ ) . ‘‘;
    return apply_filters( ‘poka_affiliate_button’, $btn );
    }
    }

    /**
    * Return review single button
    */
    if ( ! function_exists( ‘poka_review_single_button’ ) ) {
    function poka_review_single_button( $review_id, $classes = ” ) {
    $classes = apply_filters( ‘poka_review_single_button_classes’, ‘btn ‘ . $classes );
    $btn = ‘‘ . poka_get_translation( ‘Review’ ) . ‘‘;

    return apply_filters( ‘poka_review_single_button’, $btn );
    }
    }

    /**
    * Return affiliate tag element
    */
    if ( ! function_exists( ‘poka_affiliate_tag’ ) ) {
    function poka_affiliate_tag( $review_id ) {

    if ( ! empty( poka_get_field( ‘affiliate_tag’, $review_id ) ) ) {

    $tag_color = ( poka_get_field( ‘affiliate_tag_color’, $review_id ) ? ‘style=”background-color:’ . poka_get_field( ‘affiliate_tag_color’, $review_id ) . ‘;”‘ : ” );

    $tag = ‘<span class=”review-badge” ‘ . $tag_color . ‘> ‘ . poka_get_field( ‘affiliate_tag’, $review_id ) . ‘ </span>’;

    return apply_filters( ‘poka_affiliate_tag’, $tag );

    }

    }
    }
    /**
    * Return affiliate rating number
    */
    if ( ! function_exists( ‘poka_affiliate_rating_number’ ) ) {
    function poka_affiliate_rating_number( $review_id ) {

    $rating_num = (float) poka_get_field( ‘affiliate_rating’, $review_id );

    // TODO – How will we handle the old field “allow_user_rating_in_reviews” ? – For now just use affiliate_rating field (pokafield_affiliate_rating)

    return $rating_num;
    }
    }

    /**
    * Return affiliate rating
    */
    if ( ! function_exists( ‘poka_affiliate_rating’ ) ) {
    function poka_affiliate_rating( $review_id, $atts = array() ) {

    $html = ”;
    $count = 0;
    $rating_num = poka_affiliate_rating_number( $review_id );
    $rating_icons = poka_affiliate_rating_icons();
    $half_icon = apply_filters( ‘poka_affiliate_rating_half_icon’, true );

    if ( $rating_num ) {

    if ( in_array( ‘rating_num’, $atts ) ) {
    $html .= ‘<div class=”review-rating”>’;
    $html .= ‘<span>‘ . $rating_num . ‘/5</span>’;
    }

    $html .= ‘<div class=”rating”>’;

    $rest = 5 – $rating_num;

    while ( $count < floor( $rating_num ) ) {
    $html .= $rating_icons[‘full_star’];
    $count++;
    }

    if ( $rest > 0 ) {

    $count = 0;

    while ( $count < $rest ) {

    $dec = $rating_num – floor( $rating_num );

    if ( $half_icon ) {

    if ( 0.7 > $dec && 0.3 < $dec && is_float( $rest ) && 0 == $count ) {
    $html .= $rating_icons[‘half_star’];
    } elseif ( 0.7 <= $dec && is_float( $rest ) && 0 == $count ) {
    $html .= $rating_icons[‘full_star’];
    } else {
    $html .= $rating_icons[’empty_star’];
    }
    } else {

    if ( $dec >= 0.6 && is_float( $rest ) && 0 == $count ) {
    $html .= $rating_icons[‘full_star’];
    } else {
    $html .= $rating_icons[’empty_star’];
    }
    }

    $count++;
    }
    }

    $html .= ‘</div>’;
    $html .= ‘<!–/.rating–>’;

    if ( in_array( ‘rating_num’, $atts ) ) {
    $html .= ‘</div>’;
    $html .= ‘<!–/. review -rating–>’;
    }
    }

    return apply_filters( ‘poka_affiliate_rating_html’, $html );
    }
    }

    /**
    * Rating icons
    */
    if ( ! function_exists( ‘poka_affiliate_rating_icons’ ) ) {
    function poka_affiliate_rating_icons() {

    $rating_icons = array(
    ‘full_star’ => ‘<span class=”icon poka-star”></span>’,
    ‘half_star’ => ‘<span class=”icon poka-star-half-o”></span>’,
    ’empty_star’ => ‘<span class=”icon poka-star-o”></span>’,
    );

    return apply_filters( ‘poka_affiliate_rating_icons’, $rating_icons );

    }
    }

    /**
    * Affiliate redirect
    * Not completed / needs work!
    */
    if ( ! function_exists( ‘poka_affiliate_redirect’ ) ) {
    function poka_affiliate_redirect() {
    global $wpdb;

    $request = $_SERVER[‘REQUEST_URI’];
    if ( ! isset( $_SERVER[‘REQUEST_URI’] ) ) {
    $request = substr( $_SERVER[‘PHP_SELF’], 1 );
    if ( isset( $_SERVER[‘QUERY_STRING’] ) && ” != $_SERVER[‘QUERY_STRING’] ) {
    $request .= ‘?’ . $_SERVER[‘QUERY_STRING’]; }
    }

    $urlparts = explode( ‘/’, $request );

    $folder = get_theme_mod( ‘general-affiliate-redirect-link-folder’ ) ? get_theme_mod( ‘general-affiliate-redirect-link-folder’ ) : ‘go’;

    if ( count( $urlparts ) – 2 >= 0 ) {
    if ( array_key_exists( count( $urlparts ) – 2, $urlparts ) ) {
    if ( $urlparts[ count( $urlparts ) – 2 ] === $folder ) {

    $is_mobile = false;
    $casino_param = explode( ‘?’, $urlparts[ count( $urlparts ) – 1 ] );
    $casino_name = $casino_param[0];

    if ( ‘$mobile’ === $casino_param[ count( $casino_param ) – 1 ] ) {
    $is_mobile = true;
    }
    // @codingStandardsIgnoreStart
    $querystr = “SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_value = ‘” . $casino_name . “‘ AND wpostmeta.meta_key = ‘pokafield_affiliate_key’ AND wposts.post_type = ‘affiliate_links’ AND wposts.post_status = ‘publish'”;
    $pageposts = $wpdb->get_results( $querystr, OBJECT );

    if ( $pageposts ) {
    global $post;

    foreach ( $pageposts as $post ) :
    setup_postdata( $post );

    if ( $is_mobile && poka_get_field( ‘affiliate_link_mobile’, $post->ID ) ) {
    $siteurl = poka_get_field( ‘affiliate_link_mobile’, $post->ID );
    } else {
    $siteurl = poka_get_field( ‘affiliate_link’, $post->ID );
    }

    if ( $siteurl ) {
    header( ‘X-Robots-Tag: noindex, nofollow’, true );
    wp_redirect( $siteurl, 301 );
    exit;
    }

    break;
    endforeach;
    }
    // @codingStandardsIgnoreEnd
    }
    }
    }

    }
    add_action( ‘init’, ‘poka_affiliate_redirect’ );
    }

    /**
    * Affiliates ajax search with autocomplete
    */
    if ( ! function_exists( ‘poka_affiliates_search_autocomplete’ ) ) {
    function poka_affiliates_search_autocomplete() {
    // Check for nonce security

    if ( isset( $_POST[‘nonce’] ) && ! wp_verify_nonce( $_POST[‘nonce’], ‘ajax-nonce’ ) ) {
    die( ‘Busted!’ );
    }

    $args = array(
    ‘post_status’ => ‘publish’,
    ‘post_type’ => ‘affiliates’,
    ‘posts_per_page’ => 20,
    ‘orderby’ => ‘post_title’,
    ‘order’ => ‘ASC’,
    ‘no_found_rows’ => true,
    ‘update_post_meta_cache’ => false,
    ‘update_post_term_cache’ => false,
    );

    if ( isset( $_POST[‘keyword’] ) && $_POST[‘keyword’] ) {
    $args[‘s’] = $_POST[‘keyword’];
    }

    if ( isset( $_POST[‘exclude’] ) && $_POST[‘exclude’] ) {
    $args[‘post__not_in’] = array( (int) $_POST[‘exclude’] );
    }

    $query = new WP_Query( $args );

    if ( $query->have_posts() ) {
    $results = array();
    while ( $query->have_posts() ) {
    $query->the_post();
    $results[] = array(
    ‘id’ => get_the_ID(),
    ‘title’ => get_the_title(),
    ‘content’ => get_the_content(),
    );
    }
    wp_reset_postdata();
    wp_send_json_success( $results );
    } else {
    wp_send_json_error( ‘No results found’ );
    }
    }
    add_action( ‘wp_ajax_poka_affiliates_search_autocomplete’, ‘poka_affiliates_search_autocomplete’ );
    add_action( ‘wp_ajax_nopriv_poka_affiliates_search_autocomplete’, ‘poka_affiliates_search_autocomplete’ );
    }

    can anybody from the support team/ or savvy user shed some light into this? It would be super useful to be able to add the casino link directly in the review edit page as opposed to having to to add a separate entry under ‘links’ every time and then choose from the drop down list and allowing us to linkout directly without pointing to an internal page.

    Thanks for the help in advance!

Viewing 11 post (of 11 total)
  • You must be logged in to reply to this topic.