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; } $display = in_array( $attributes['display'] ?? 'inline', [ 'inline', 'popover', 'column' ], true ) ? (string) ( $attributes['display'] ?? 'inline' ) : 'inline'; $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'] : 'inline' === $display; $heading_html = $show_heading ? '' : ''; $wanted = array_filter( array_map( 'trim', explode( ',', strtolower( (string) ( $attributes['channels'] ?? '' ) ) ) ) ); if ( 'column' === $display ) { $wanted = array_merge( [ 'copy' ], array_slice( array_values( array_diff( $wanted, [ 'copy' ] ) ), 0, 2 ) ); } $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' ], ]; $heart = ''; if ( ! empty( $attributes['favourite'] ) && WP_Block_Type_Registry::get_instance()->is_registered( 'aieo/favourite' ) ) { $heart = trim( (string) ( new WP_Block( [ 'blockName' => 'aieo/favourite', 'attrs' => [ 'look' => 'icon' ], 'innerBlocks' => [], 'innerHTML' => '', 'innerContent' => [] ], [ 'postId' => $post_id, 'postType' => (string) get_post_type( $post_id ) ] ) )->render() ); } $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( '