0 ) { $meta_nofollow = get_post_meta( $box_id, '_affistyle_nofollow', true ); $meta_sponsored = get_post_meta( $box_id, '_affistyle_sponsored', true ); $rel_parts = array(); if ( '' === $meta_nofollow || '1' === (string) $meta_nofollow ) { $rel_parts[] = 'nofollow'; } if ( '' === $meta_sponsored || '1' === (string) $meta_sponsored ) { $rel_parts[] = 'sponsored'; } $rel_parts[] = 'noopener'; $default_rel = implode( ' ', $rel_parts ); } $rel = apply_filters( 'affistyle_link_rel_tags', $default_rel, $box_id ); return sanitize_text_field( trim( (string) $rel ) ); } /** * Retrieve Link Target Attribute (e.g. '_blank' or '_self'). * * @param int $box_id Affiliate Box ID. * @return string */ public static function get_link_target( $box_id = 0 ) { $box_id = absint( $box_id ); $default_target = '_blank'; if ( $box_id > 0 ) { $meta_new_tab = get_post_meta( $box_id, '_affistyle_new_tab', true ); if ( '0' === (string) $meta_new_tab ) { $default_target = '_self'; } } $target = apply_filters( 'affistyle_link_target', $default_target, $box_id ); $allowed_targets = array( '_blank', '_self', '_parent', '_top' ); if ( ! in_array( $target, $allowed_targets, true ) ) { $target = '_blank'; } return $target; } /** * Retrieve Formatted Link Attributes String. * * @param int $box_id Affiliate Box ID. * @return string */ public static function get_link_attributes_string( $box_id = 0 ) { $box_id = absint( $box_id ); $target = self::get_link_target( $box_id ); $rel = self::get_rel_attributes( $box_id ); $attr = sprintf( 'target="%s" rel="%s"', esc_attr( $target ), esc_attr( $rel ) ); return apply_filters( 'affistyle_link_attributes_string', $attr, $box_id ); } /** * Get Default FTC Disclosure Text. * * @return string */ public static function get_default_disclosure_text() { return __( 'We may earn an affiliate commission at no extra cost to you when you purchase through links on our site.', 'affistyle' ); } /** * Retrieve FTC Affiliate Disclosure Text with Filter Override. * * @param int $box_id Affiliate Box ID. * @return string */ public static function get_disclosure_text( $box_id = 0 ) { $box_id = absint( $box_id ); $default = self::get_default_disclosure_text(); if ( $box_id > 0 ) { $custom_disclosure = get_post_meta( $box_id, '_affistyle_disclosure_text', true ); if ( ! empty( $custom_disclosure ) ) { $default = $custom_disclosure; } } $text = apply_filters( 'affistyle_ftc_disclosure_text', $default, $box_id ); return sanitize_text_field( (string) $text ); } /** * Alias for get_disclosure_text. * * @param int $box_id Affiliate Box ID. * @return string */ public static function get_ftc_disclosure( $box_id = 0 ) { return self::get_disclosure_text( $box_id ); } /** * Check if FTC Micro-Disclosure is enabled. * * @param int $box_id Affiliate Box ID. * @return bool */ public static function is_disclosure_enabled( $box_id = 0 ) { $box_id = absint( $box_id ); $default = true; if ( $box_id > 0 ) { $meta_show = get_post_meta( $box_id, '_affistyle_show_disclosure', true ); if ( '0' === (string) $meta_show ) { $default = false; } } $enabled = apply_filters( 'affistyle_is_ftc_enabled', $default, $box_id ); return (bool) $enabled; } /** * Alias for is_disclosure_enabled. * * @param int $box_id Affiliate Box ID. * @return bool */ public static function is_ftc_enabled( $box_id = 0 ) { return self::is_disclosure_enabled( $box_id ); } /** * Render FTC Disclosure Component (Returns HTML String). * * @param int $box_id Affiliate Box ID. * @return string */ public static function render_disclosure( $box_id = 0 ) { if ( ! self::is_disclosure_enabled( $box_id ) ) { return ''; } $text = self::get_disclosure_text( $box_id ); if ( empty( $text ) ) { return ''; } return '
' . esc_html( $text ) . '
'; } /** * Echo FTC Disclosure Component (Hook callback). * * @param int $box_id Affiliate Box ID. */ public static function render_ftc_disclosure( $box_id = 0 ) { $html = self::render_disclosure( $box_id ); if ( ! empty( $html ) ) { echo wp_kses_post( $html ); } } } new AffiStyle_Compliance();