display label. * * @var array */ const PLATFORMS = array( 'facebook' => 'Facebook', 'twitter' => 'X (Twitter)', 'instagram' => 'Instagram', 'linkedin' => 'LinkedIn', 'youtube' => 'YouTube', 'github' => 'GitHub', ); function __construct() { $this->defaults = array_merge( array( 'title' => __( 'Follow Us', 'advance-widget-pack' ), 'open_in_new_tab' => '1', ), array_fill_keys( array_keys( self::PLATFORMS ), '' ) ); $widget_ops = array( 'classname' => 'awp_social_links awp_widget', 'description' => __( 'Widget to display a row of links to your social profiles.', 'advance-widget-pack' ), ); $control_ops = array( 'id_base' => 'awp_social_links', 'width' => 200, 'height' => 250, ); parent::__construct( 'awp_social_links', __( 'AWP Social Links', 'advance-widget-pack' ), $widget_ops, $control_ops ); } public function widget( $args, $instance ) { $instance = wp_parse_args( (array) $instance, $this->defaults ); $title = apply_filters( 'widget_title', $instance['title'] ); $new_tab = ! empty( $instance['open_in_new_tab'] ); $links = self::get_links( $instance ); if ( ! $links ) { return; } echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- sidebar-provided wrapper markup, trusted per WP core convention. if ( ! empty( $title ) ) { echo $args['before_title'] . esc_html( $title ) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- title text is esc_html()'d; before/after_title are sidebar-provided wrapper markup. } self::render_links( $links, $new_tab ); echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- sidebar-provided wrapper markup, trusted per WP core convention. } /** * Builds the validated link list from raw instance/attribute data. * * @param array $data Instance or block-attribute values keyed by platform. * @return array Map of platform => array( 'url' => ..., 'label' => ... ). */ public static function get_links( $data ) { $links = array(); foreach ( self::PLATFORMS as $key => $label ) { if ( ! empty( $data[ $key ] ) ) { $url = esc_url( $data[ $key ] ); if ( $url ) { $links[ $key ] = array( 'url' => $url, 'label' => $label, ); } } } return $links; } /** * Renders the social links