| @@ -1,6 +1,10 @@ | ||
| 1 | 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | 2 | |
| 3 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 4 | + exit( 0 ); | |
| 5 | +} | |
| 6 | + | |
| 3 | 7 | // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. |
| 4 | 8 | |
| 5 | 9 | /** |
| 6 | 10 | * Social Icons Widget. |
| @@ -52,14 +56,8 @@ | ||
| 52 | 56 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) ); |
| 53 | 57 | add_action( 'admin_print_footer_scripts', array( $this, 'render_admin_js' ) ); |
| 54 | 58 | } |
| 55 | 59 | |
| 56 | - // Enqueue scripts and styles for the display of the widget, on the frontend or in the customizer. | |
| 57 | - if ( is_active_widget( false, $this->id, $this->id_base, true ) || is_customize_preview() ) { | |
| 58 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_icon_scripts' ) ); | |
| 59 | - add_action( 'wp_footer', array( $this, 'include_svg_icons' ), 9999 ); | |
| 60 | - } | |
| 61 | - | |
| 62 | 60 | add_filter( 'widget_types_to_hide_from_legacy_widget_block', array( $this, 'hide_widget_in_block_editor' ) ); |
| 63 | 61 | } |
| 64 | 62 | |
| 65 | 63 | /** |
| @@ -115,18 +113,39 @@ | ||
| 115 | 113 | */ |
| 116 | 114 | public function include_svg_icons() { |
| 117 | 115 | // Define SVG sprite file in Jetpack. |
| 118 | 116 | $svg_icons = dirname( __DIR__ ) . '/theme-tools/social-menu/social-menu.svg'; |
| 119 | - | |
| 117 | + $svg_icons = class_exists( 'Automattic\Jetpack\Classic_Theme_Helper\Main' ) ? JETPACK__PLUGIN_DIR . 'jetpack_vendor/automattic/jetpack-classic-theme-helper/src/social-menu/social-menu.svg' : dirname( __DIR__ ) . '/theme-tools/social-menu/social-menu.svg'; | |
| 120 | 118 | // Define SVG sprite file in WPCOM. |
| 121 | 119 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
| 122 | - $svg_icons = dirname( __DIR__ ) . '/social-menu/social-menu.svg'; | |
| 120 | + $svg_icons = class_exists( 'Automattic\Jetpack\Classic_Theme_Helper\Main' ) ? JETPACK__PLUGIN_DIR . 'jetpack_vendor/automattic/jetpack-classic-theme-helper/src/social-menu/social-menu.svg' : dirname( __DIR__ ) . '/social-menu/social-menu.svg'; | |
| 123 | 121 | } |
| 124 | 122 | |
| 125 | 123 | // If it exists, include it. |
| 126 | 124 | if ( is_file( $svg_icons ) ) { |
| 127 | - require_once $svg_icons; | |
| 125 | + $svg_contents = file_get_contents( $svg_icons ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Only reading a local file. | |
| 128 | 126 | } |
| 127 | + | |
| 128 | + if ( ! empty( $svg_contents ) ) { | |
| 129 | + $allowed_tags = array( | |
| 130 | + 'svg' => array( | |
| 131 | + 'style' => true, | |
| 132 | + 'version' => true, | |
| 133 | + 'xmlns' => true, | |
| 134 | + 'xmlns:xlink' => true, | |
| 135 | + ), | |
| 136 | + 'defs' => array(), | |
| 137 | + 'symbol' => array( | |
| 138 | + 'id' => true, | |
| 139 | + 'viewbox' => true, | |
| 140 | + ), | |
| 141 | + 'path' => array( | |
| 142 | + 'd' => true, | |
| 143 | + 'style' => true, | |
| 144 | + ), | |
| 145 | + ); | |
| 146 | + echo wp_kses( $svg_contents, $allowed_tags ); | |
| 147 | + } | |
| 129 | 148 | } |
| 130 | 149 | |
| 131 | 150 | /** |
| 132 | 151 | * Front-end display of widget. |
| @@ -138,8 +157,12 @@ | ||
| 138 | 157 | */ |
| 139 | 158 | public function widget( $args, $instance ) { |
| 140 | 159 | $instance = wp_parse_args( $instance, $this->defaults ); |
| 141 | 160 | |
| 161 | + // Enqueue front end assets. | |
| 162 | + $this->enqueue_icon_scripts(); | |
| 163 | + add_action( 'wp_footer', array( $this, 'include_svg_icons' ), 9999 ); | |
| 164 | + | |
| 142 | 165 | /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
| 143 | 166 | $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
| 144 | 167 | |
| 145 | 168 | echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| @@ -164,9 +187,9 @@ | ||
| 164 | 187 | <li class="jetpack-social-widget-item"> |
| 165 | 188 | <?php |
| 166 | 189 | printf( |
| 167 | 190 | '<a href="%1$s" %2$s>', |
| 168 | - esc_url( $icon['url'], array( 'http', 'https', 'mailto', 'skype' ) ), | |
| 191 | + esc_url( $icon['url'], array( 'http', 'https', 'mailto', 'sms' ) ), | |
| 169 | 192 | true === $instance['new-tab'] ? |
| 170 | 193 | 'target="_blank" rel="noopener noreferrer"' : |
| 171 | 194 | 'target="_self"' |
| 172 | 195 | ); |
| @@ -181,13 +204,13 @@ | ||
| 181 | 204 | */ |
| 182 | 205 | if ( |
| 183 | 206 | // First Regex. |
| 184 | 207 | ( |
| 185 | - '#' === substr( $url_fragment, 0, 1 ) && '#' === substr( $url_fragment, -1 ) | |
| 208 | + str_starts_with( $url_fragment, '#' ) && str_ends_with( $url_fragment, '#' ) | |
| 186 | 209 | && preg_match( $url_fragment, $icon['url'] ) |
| 187 | 210 | ) |
| 188 | 211 | // Then, regular host name. |
| 189 | - || false !== strpos( $icon['url'], $url_fragment ) | |
| 212 | + || str_contains( $icon['url'], $url_fragment ) | |
| 190 | 213 | ) { |
| 191 | 214 | printf( |
| 192 | 215 | '<span class="screen-reader-text">%1$s</span>%2$s', |
| 193 | 216 | esc_attr( $social_icon['label'] ), |
| @@ -323,19 +346,21 @@ | ||
| 323 | 346 | </button> |
| 324 | 347 | </p> |
| 325 | 348 | |
| 326 | 349 | <?php |
| 327 | - switch ( get_locale() ) { | |
| 350 | + $lang = strtolower( substr( get_locale(), 0, 2 ) ); | |
| 351 | + switch ( $lang ) { | |
| 328 | 352 | case 'es': |
| 329 | - $support = 'https://es.support.wordpress.com/social-media-icons-widget/#iconos-disponibles'; | |
| 353 | + $support = 'https://wordpress.com/es/support/wordpress-editor/blocks/social-icons-block/display-social-profiles/#iconos-sociales-compatibles'; | |
| 330 | 354 | break; |
| 331 | 355 | |
| 332 | - case 'pt-br': | |
| 333 | - $support = 'https://br.support.wordpress.com/widgets/widget-de-icones-sociais/#ícones-disponíveis'; | |
| 356 | + case 'pt': | |
| 357 | + $support = 'https://wordpress.com/pt-br/support/exibir-perfis-de-redes-sociais/#icones-de-redes-sociais-compativeis'; | |
| 334 | 358 | break; |
| 335 | 359 | |
| 336 | 360 | default: |
| 337 | - $support = 'https://en.support.wordpress.com/widgets/social-media-icons-widget/#available-icons'; | |
| 361 | + $support = 'https://wordpress.com/support/wordpress-editor/blocks/social-icons-block/display-social-profiles/#supported-social-icons'; | |
| 362 | + break; | |
| 338 | 363 | } |
| 339 | 364 | ?> |
| 340 | 365 | |
| 341 | 366 | <p> |
| @@ -377,9 +402,9 @@ | ||
| 377 | 402 | '<input class="widefat" id="%1$s" name="%2$s[]" type="text" placeholder="%3$s" value="%4$s"/>', |
| 378 | 403 | esc_attr( $args['url-icon-id'] ), |
| 379 | 404 | esc_attr( $args['url-icon-name'] ), |
| 380 | 405 | esc_attr__( 'Account URL', 'jetpack' ), |
| 381 | - esc_url( $args['url-value'], array( 'http', 'https', 'mailto', 'skype' ) ) | |
| 406 | + esc_url( $args['url-value'], array( 'http', 'https', 'mailto', 'sms' ) ) | |
| 382 | 407 | ); |
| 383 | 408 | ?> |
| 384 | 409 | </p> |
| 385 | 410 | |
| @@ -418,9 +443,9 @@ | ||
| 418 | 443 | // Parse args. |
| 419 | 444 | $args = wp_parse_args( $args, $defaults ); |
| 420 | 445 | |
| 421 | 446 | // Define an icon. |
| 422 | - if ( false === array_key_exists( 'icon', $args ) ) { | |
| 447 | + if ( ! array_key_exists( 'icon', $args ) ) { | |
| 423 | 448 | return esc_html__( 'Please define an SVG icon filename.', 'jetpack' ); |
| 424 | 449 | } |
| 425 | 450 | |
| 426 | 451 | // Set aria hidden. |
| @@ -490,8 +515,13 @@ | ||
| 490 | 515 | 'icon' => 'blogger', |
| 491 | 516 | 'label' => 'Blogger', |
| 492 | 517 | ), |
| 493 | 518 | array( |
| 519 | + 'url' => array( 'bsky.app' ), | |
| 520 | + 'icon' => 'bluesky', | |
| 521 | + 'label' => 'Bluesky', | |
| 522 | + ), | |
| 523 | + array( | |
| 494 | 524 | 'url' => array( 'codepen.io' ), |
| 495 | 525 | 'icon' => 'codepen', |
| 496 | 526 | 'label' => 'CodePen', |
| 497 | 527 | ), |
| @@ -595,8 +625,13 @@ | ||
| 595 | 625 | 'icon' => 'medium', |
| 596 | 626 | 'label' => 'Medium', |
| 597 | 627 | ), |
| 598 | 628 | array( |
| 629 | + 'url' => array( 'nextdoor.com' ), | |
| 630 | + 'icon' => 'nextdoor', | |
| 631 | + 'label' => 'Nextdoor', | |
| 632 | + ), | |
| 633 | + array( | |
| 599 | 634 | 'url' => array( 'patreon.com' ), |
| 600 | 635 | 'icon' => 'patreon', |
| 601 | 636 | 'label' => 'Patreon', |
| 602 | 637 | ), |
| @@ -605,13 +640,8 @@ | ||
| 605 | 640 | 'icon' => 'pinterest', |
| 606 | 641 | 'label' => 'Pinterest', |
| 607 | 642 | ), |
| 608 | 643 | array( |
| 609 | - 'url' => array( 'getpocket.com' ), | |
| 610 | - 'icon' => 'pocket', | |
| 611 | - 'label' => 'Pocket', | |
| 612 | - ), | |
| 613 | - array( | |
| 614 | 644 | 'url' => array( 'ravelry.com' ), |
| 615 | 645 | 'icon' => 'ravelry', |
| 616 | 646 | 'label' => 'Ravelry', |
| 617 | 647 | ), |
| @@ -620,23 +650,18 @@ | ||
| 620 | 650 | 'icon' => 'reddit', |
| 621 | 651 | 'label' => 'Reddit', |
| 622 | 652 | ), |
| 623 | 653 | array( |
| 624 | - 'url' => array( 'skype.com' ), | |
| 625 | - 'icon' => 'skype', | |
| 626 | - 'label' => 'Skype', | |
| 627 | - ), | |
| 628 | - array( | |
| 629 | - 'url' => array( 'skype:' ), | |
| 630 | - 'icon' => 'skype', | |
| 631 | - 'label' => 'Skype', | |
| 632 | - ), | |
| 633 | - array( | |
| 634 | 654 | 'url' => array( 'slideshare.net' ), |
| 635 | 655 | 'icon' => 'slideshare', |
| 636 | 656 | 'label' => 'SlideShare', |
| 637 | 657 | ), |
| 638 | 658 | array( |
| 659 | + 'url' => array( 'sms:' ), | |
| 660 | + 'icon' => 'sms', | |
| 661 | + 'label' => 'SMS', | |
| 662 | + ), | |
| 663 | + array( | |
| 639 | 664 | 'url' => array( 'snapchat.com' ), |
| 640 | 665 | 'icon' => 'snapchat', |
| 641 | 666 | 'label' => 'Snapchat', |
| 642 | 667 | ), |
| @@ -670,8 +695,13 @@ | ||
| 670 | 695 | 'icon' => 'telegram', |
| 671 | 696 | 'label' => 'Telegram', |
| 672 | 697 | ), |
| 673 | 698 | array( |
| 699 | + 'url' => array( 'threads.net' ), | |
| 700 | + 'icon' => 'threads', | |
| 701 | + 'label' => 'Threads', | |
| 702 | + ), | |
| 703 | + array( | |
| 674 | 704 | 'url' => array( 'tiktok.com' ), |
| 675 | 705 | 'icon' => 'tiktok', |
| 676 | 706 | 'label' => 'TikTok', |
| 677 | 707 | ), |
| @@ -685,13 +715,8 @@ | ||
| 685 | 715 | 'icon' => 'twitch', |
| 686 | 716 | 'label' => 'Twitch', |
| 687 | 717 | ), |
| 688 | 718 | array( |
| 689 | - 'url' => array( 'twitter.com' ), | |
| 690 | - 'icon' => 'twitter', | |
| 691 | - 'label' => 'Twitter', | |
| 692 | - ), | |
| 693 | - array( | |
| 694 | 719 | 'url' => array( 'vimeo.com' ), |
| 695 | 720 | 'icon' => 'vimeo', |
| 696 | 721 | 'label' => 'Vimeo', |
| 697 | 722 | ), |
| @@ -720,8 +745,13 @@ | ||
| 720 | 745 | 'icon' => 'yelp', |
| 721 | 746 | 'label' => 'Yelp', |
| 722 | 747 | ), |
| 723 | 748 | array( |
| 749 | + 'url' => array( '#^https?:\/\/(www\.)?(twitter|x)\.com#' ), | |
| 750 | + 'icon' => 'x', | |
| 751 | + 'label' => 'X', | |
| 752 | + ), | |
| 753 | + array( | |
| 724 | 754 | 'url' => array( 'xanga.com' ), |
| 725 | 755 | 'icon' => 'xanga', |
| 726 | 756 | 'label' => 'Xanga', |
| 727 | 757 | ), |
| @@ -761,9 +791,19 @@ | ||
| 761 | 791 | 'label' => __( 'RSS Feed', 'jetpack' ), |
| 762 | 792 | ), |
| 763 | 793 | ); |
| 764 | 794 | |
| 765 | - return $social_links_icons; | |
| 795 | + /** | |
| 796 | + * Filter the list of services matching Social Media Icons available in the Social Icons SVG sprite. | |
| 797 | + * | |
| 798 | + * @since 12.3 | |
| 799 | + * | |
| 800 | + * @param array $social_links_icons Array of social links icons. | |
| 801 | + */ | |
| 802 | + return apply_filters( | |
| 803 | + 'jetpack_social_icons_supported_icons', | |
| 804 | + $social_links_icons | |
| 805 | + ); | |
| 766 | 806 | } |
| 767 | 807 | } // Jetpack_Widget_Social_Icons |
| 768 | 808 | |
| 769 | 809 | /** |