context['postId'] ?? get_the_ID() ); if ( $post_id <= 0 ) { return; } $url = (string) get_permalink( $post_id ); $title = (string) get_the_title( $post_id ); if ( '' === $url ) { return; } $heading = trim( (string) ( $attributes['heading'] ?? '' ) ); $heading = '' === $heading ? _x( 'Share', 'the share box: its button and its heading', 'ai-eshop-optimizer' ) : $heading; $show_heading = isset( $attributes['showHeading'] ) ? (bool) $attributes['showHeading'] : 'popover' !== ( $attributes['display'] ?? 'inline' ); $heading_html = $show_heading ? '' : ''; $wanted = array_filter( array_map( 'trim', explode( ',', strtolower( (string) ( $attributes['channels'] ?? '' ) ) ) ) ); $url_e = rawurlencode( $url ); $title_e = rawurlencode( $title ); $channels = [ 'facebook' => [ __( 'Share on Facebook', 'ai-eshop-optimizer' ), 'https://www.facebook.com/sharer/sharer.php?u=' . $url_e, 'facebook' ], 'x' => [ __( 'Share on X', 'ai-eshop-optimizer' ), 'https://twitter.com/intent/tweet?url=' . $url_e . '&text=' . $title_e, 'x-social' ], 'pinterest' => [ __( 'Pin on Pinterest', 'ai-eshop-optimizer' ), 'https://pinterest.com/pin/create/button/?url=' . $url_e . '&description=' . $title_e, 'pinterest' ], 'whatsapp' => [ __( 'Share on WhatsApp', 'ai-eshop-optimizer' ), 'https://api.whatsapp.com/send?text=' . $title_e . '%20' . $url_e, 'whatsapp' ], 'email' => [ __( 'Share by email', 'ai-eshop-optimizer' ), 'mailto:?subject=' . $title_e . '&body=' . $url_e, 'mail' ], ]; $items = ''; foreach ( $wanted as $key ) { if ( 'copy' === $key ) { $items .= sprintf( '
', esc_attr__( 'Copy link', 'ai-eshop-optimizer' ), rooster_icon( 'link', [ 'width' => 20, 'height' => 20 ] ) ); continue; } if ( ! isset( $channels[ $key ] ) ) { continue; } [ $label, $href, $icon ] = $channels[ $key ]; $item = sprintf( '