*/ private static array $rendered = array(); public static function init(): void { add_filter( 'the_content', array( __CLASS__, 'append_to_content' ), 25 ); } public static function append_to_content( string $content ): string { if ( is_admin() || ! is_singular( 'sg7g_media' ) || ! in_the_loop() || ! is_main_query() ) { return $content; } $post_id = get_the_ID(); if ( $post_id <= 0 ) { return $content; } return $content . self::markup( $post_id ); } private static function markup( int $post_id ): string { if ( $post_id <= 0 || isset( self::$rendered[ $post_id ] ) || ! SG7G_Settings::enabled( 'show_sharing' ) || post_password_required( $post_id ) ) { return ''; } $enabled = array_values( array_filter( self::NETWORKS, static fn( string $network ): bool => SG7G_Settings::enabled( 'share_' . $network ) ) ); if ( empty( $enabled ) ) { return ''; } self::$rendered[ $post_id ] = true; $url = get_permalink( $post_id ); $title = get_the_title( $post_id ); $image = get_the_post_thumbnail_url( $post_id, 'full' ); $description = self::description( $post_id ); $actions = array( 'facebook' => '1', 'x' => '2', 'whatsapp' => '3', 'telegram' => '4', 'linkedin' => '5', 'reddit' => '6', 'pinterest' => '7', 'copy' => '8', ); ob_start(); ?>
post_content ) ), 28, '…' ) : ''; } return trim( wp_strip_all_tags( $excerpt ) ); } private static function label( string $network ): string { $labels = array( 'facebook' => __( 'Share on Facebook', '7sgaleri' ), 'x' => __( 'Share on X', '7sgaleri' ), 'whatsapp' => __( 'Share on WhatsApp', '7sgaleri' ), 'telegram' => __( 'Share on Telegram', '7sgaleri' ), 'linkedin' => __( 'Share on LinkedIn', '7sgaleri' ), 'reddit' => __( 'Share on Reddit', '7sgaleri' ), 'pinterest' => __( 'Share on Pinterest', '7sgaleri' ), ); return $labels[ $network ] ?? __( 'Share', '7sgaleri' ); } private static function icon( string $network ): string { $paths = array( 'facebook' => '', 'x' => '', 'whatsapp' => '', 'telegram' => '', 'linkedin' => '', 'reddit' => '', 'pinterest' => '', 'copy' => '', ); if ( ! isset( $paths[ $network ] ) ) { return ''; } return ''; } }