null, 'type' => 'text', 'icon' => null, 'text' => null, 'track' => null, 'target' => '_blank', 'width' => null, 'obf' => null, 'fsize' => null, 'color' => null, 'align' => null, ), $atts ); // If URL or text is empty, return nothing. if ( empty( $atts['url'] ) || empty( $atts['text'] ) ) { return; } // Add AMP CSS if not already added. if ( empty( AffiAI::$call_amp ) ) { add_action( 'amp_post_template_css', array( 'Afx', 'affiai_amp_css' ), 11 ); AffiAI::$call_amp = 1; } // Sanitize URL. if (class_exists('Afx') && method_exists('Afx', 'affiai_sanitize_url')) { $atts['url'] = AffiAI::affiai_sanitize_url($atts['url']); } // Get site URL. $site = wp_parse_url( $atts['url'], PHP_URL_HOST ); // If tracking is enabled and site URL is available, get custom affiliate link. if ( $atts['track'] == 1 && $site ) { $custm_res = AffiAI::get_custm_afx( $site, 'direct' ); if ( ! empty( $custm_res ) ) { if (substr( $custm_res[0]['url_track'], 0, 7 ) === '%%URL%%') { $atts['url'] = str_replace( '%%URL%%', $atts['url'], $custm_res[0]['url_track'] ); } elseif ( strpos( $custm_res[0]['url_track'], '%%URL%%' ) ) { $atts['url'] = str_replace( '%%URL%%', urlencode( $atts['url'] ), $custm_res[0]['url_track'] ); } } } // Set button type if specified. if ( $atts['type'] == 'button' ) { $type = 'button btnafx'; } else { $type = 'linkafx'; } // Set style attributes if specified. $st = 0; if ( ! empty( $atts['width'] ) && $atts['width'] > 100 && $atts['type'] == 'button' ) { $width = 'width:' . intval( $atts['width'] ) . 'px;'; $st++; } else { $width = ''; } if ( ! empty( $atts['fsize'] ) && $atts['fsize'] > 10 ) { $fsize = 'font-size:' . intval( $atts['fsize'] ) . 'px;'; $st++; } else { $fsize = ''; } if ( ! empty( $atts['color'] ) && $atts['type'] == 'button' ) { $color = 'background-color:' . $atts['color'] . ' !important;'; $st++; } else { $color = ''; } if ( $st > 0 ) { $style = ' style="' . $width . $fsize . $color . '"'; } else { $style = ''; } // Set icon if specified. if ( ! empty( $atts['icon'] ) ) { $icon = ' '; } else { $icon = ''; } // Set URL attribute with obfuscation if specified. if ( ! empty( $atts['obf'] ) && ! ( ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) || ( function_exists( 'amp_is_request' ) && amp_is_request() ) || ( function_exists( 'ampforwp_is_amp_endpoint' ) && ampforwp_is_amp_endpoint() ) ) ) { $url = 'data-afxshop="' . esc_attr( base64_encode( $atts['url'] ) ) . '"'; } else { $url = 'href="' . esc_url( $atts['url'] ) . '"'; } // Set alignment if specified. if ( ! empty( $atts['align'] ) ) { $output = '
'; } else { $output = ''; } // Generate shortcode output. $output .= '' . esc_html( $icon ) . esc_html( $atts['text'] ) . ''; // Close alignment div if specified. if ( ! empty( $atts['align'] ) ) { $output .= '
'; } return $output; } add_shortcode( 'affiai_link', 'affiai_link_shortcode' );