Automattic /
jetpack
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | class Jetpack_Widget_Social_Icons extends WP_Widget { |
||
| 3 | /** |
||
| 4 | * @var array Default widget options. |
||
| 5 | */ |
||
| 6 | protected $defaults; |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Widget constructor. |
||
| 10 | */ |
||
| 11 | public function __construct() { |
||
| 12 | $widget_ops = array( |
||
| 13 | 'classname' => 'jetpack_widget_social_icons', |
||
| 14 | 'description' => __( 'Add social-media icons to your site.', 'jetpack' ), |
||
| 15 | 'customize_selective_refresh' => true, |
||
| 16 | ); |
||
| 17 | |||
| 18 | parent::__construct( |
||
| 19 | 'jetpack_widget_social_icons', |
||
| 20 | /** This filter is documented in modules/widgets/facebook-likebox.php */ |
||
| 21 | apply_filters( 'jetpack_widget_name', __( 'Social Icons', 'jetpack' ) ), |
||
| 22 | $widget_ops |
||
| 23 | ); |
||
| 24 | |||
| 25 | $this->defaults = array( |
||
| 26 | 'title' => __( 'Follow Us', 'jetpack' ), |
||
| 27 | 'icon-size' => 'medium', |
||
| 28 | 'new-tab' => false, |
||
| 29 | 'icons' => array( |
||
| 30 | array( |
||
| 31 | 'url' => '', |
||
| 32 | ), |
||
| 33 | ), |
||
| 34 | ); |
||
| 35 | |||
| 36 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) ); |
||
| 37 | add_action( 'admin_print_footer_scripts', array( $this, 'render_admin_js' ) ); |
||
| 38 | add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_icon_scripts' ) ); |
||
| 39 | add_action( 'wp_footer', array( $this, 'include_svg_icons' ), 9999 ); |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Script & styles for admin widget form. |
||
| 44 | */ |
||
| 45 | public function enqueue_admin_scripts( $hook ) { |
||
| 46 | global $wp_customize; |
||
| 47 | |||
| 48 | if ( isset( $wp_customize ) || 'widgets.php' === $hook ) { |
||
| 49 | wp_enqueue_script( 'jetpack-widget-social-icons-script', plugins_url( 'social-icons/social-icons-admin.js', __FILE__ ), array( 'jquery-ui-sortable' ), '20170506' ); |
||
| 50 | wp_enqueue_style( 'jetpack-widget-social-icons-admin', plugins_url( 'social-icons/social-icons-admin.css', __FILE__ ), array(), '20170506' ); |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Styles for front-end widget. |
||
| 56 | */ |
||
| 57 | public function enqueue_icon_scripts() { |
||
| 58 | wp_enqueue_style( 'jetpack-widget-social-icons-styles', plugins_url( 'social-icons/social-icons.css', __FILE__ ), array(), '20170506' ); |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * JavaScript for admin widget form. |
||
| 63 | */ |
||
| 64 | public function render_admin_js() { |
||
| 65 | global $wp_customize; |
||
| 66 | global $pagenow; |
||
| 67 | |||
| 68 | if ( ! isset( $wp_customize ) && 'widgets.php' !== $pagenow ) { |
||
| 69 | return; |
||
| 70 | } |
||
| 71 | ?> |
||
| 72 | <script type="text/html" id="tmpl-jetpack-widget-social-icons-template"> |
||
| 73 | <?php self::render_icons_template(); ?> |
||
| 74 | </script> |
||
| 75 | <?php |
||
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Add SVG definitions to the footer. |
||
| 80 | */ |
||
| 81 | public function include_svg_icons() { |
||
| 82 | if ( ! is_active_widget( false, $this->id, $this->id_base, true ) ) { |
||
| 83 | return; |
||
| 84 | } |
||
| 85 | |||
| 86 | // Define SVG sprite file in Jetpack |
||
| 87 | $svg_icons = dirname( dirname( __FILE__ ) ) . '/theme-tools/social-menu/social-menu.svg'; |
||
| 88 | |||
| 89 | // Define SVG sprite file in WPCOM |
||
| 90 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
||
| 91 | $svg_icons = dirname( dirname( __FILE__ ) ) . '/social-menu/social-menu.svg'; |
||
| 92 | } |
||
| 93 | |||
| 94 | // If it exists, include it. |
||
| 95 | if ( is_file( $svg_icons ) ) { |
||
| 96 | require_once( $svg_icons ); |
||
| 97 | } |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Front-end display of widget. |
||
| 102 | * |
||
| 103 | * @see WP_Widget::widget() |
||
| 104 | * |
||
| 105 | * @param array $args Widget arguments. |
||
| 106 | * @param array $instance Saved values from database. |
||
| 107 | */ |
||
| 108 | public function widget( $args, $instance ) { |
||
| 109 | $instance = wp_parse_args( $instance, $this->defaults ); |
||
| 110 | |||
| 111 | /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
||
| 112 | $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
||
| 113 | |||
| 114 | echo $args['before_widget']; |
||
| 115 | |||
| 116 | if ( ! empty( $title ) ) { |
||
| 117 | echo $args['before_title'] . esc_html( $title ) . $args['after_title']; |
||
| 118 | } |
||
| 119 | |||
| 120 | if ( ! empty( $instance['icons'] ) ) : |
||
| 121 | |||
| 122 | // Get supported social icons. |
||
| 123 | $social_icons = $this->get_supported_icons(); |
||
| 124 | $default_icon = $this->get_svg_icon( array( 'icon' => 'chain' ) ); |
||
| 125 | |||
| 126 | // Set target attribute for the link |
||
| 127 | if ( true === $instance['new-tab'] ) { |
||
| 128 | $target = '_blank'; |
||
| 129 | } else { |
||
| 130 | $target = '_self'; |
||
| 131 | } |
||
| 132 | ?> |
||
| 133 | |||
| 134 | <ul class="jetpack-social-widget-list size-<?php echo esc_attr( $instance['icon-size'] ); ?>"> |
||
| 135 | |||
| 136 | <?php foreach ( $instance['icons'] as $icon ) : ?> |
||
| 137 | |||
| 138 | <?php if ( ! empty( $icon['url'] ) ) : ?> |
||
| 139 | <li class="jetpack-social-widget-item"> |
||
| 140 | <a href="<?php echo esc_url( $icon['url'], array( 'http', 'https', 'mailto', 'skype' ) ); ?>" target="<?php echo $target; ?>"> |
||
| 141 | <?php |
||
| 142 | $found_icon = false; |
||
| 143 | |||
| 144 | foreach( $social_icons as $social_icon ) { |
||
| 145 | if ( false !== stripos( $icon['url'], $social_icon['url'] ) ) { |
||
| 146 | echo '<span class="screen-reader-text">' . esc_attr( $social_icon['label'] ) . '</span>'; |
||
| 147 | echo $this->get_svg_icon( array( 'icon' => esc_attr( $social_icon['icon'] ) ) ); |
||
| 148 | $found_icon = true; |
||
| 149 | break; |
||
| 150 | } |
||
| 151 | } |
||
| 152 | |||
| 153 | if ( ! $found_icon ) { |
||
| 154 | echo $default_icon; |
||
| 155 | } |
||
| 156 | ?> |
||
| 157 | </a> |
||
| 158 | </li> |
||
| 159 | <?php endif; ?> |
||
| 160 | |||
| 161 | <?php endforeach; ?> |
||
| 162 | |||
| 163 | </ul> |
||
| 164 | |||
| 165 | <?php |
||
| 166 | endif; |
||
| 167 | |||
| 168 | echo $args['after_widget']; |
||
| 169 | |||
| 170 | /** This action is documented in modules/widgets/gravatar-profile.php */ |
||
| 171 | do_action( 'jetpack_stats_extra', 'widget_view', 'social_icons' ); |
||
| 172 | } |
||
| 173 | |||
| 174 | /** |
||
| 175 | * Sanitize widget form values as they are saved. |
||
| 176 | * |
||
| 177 | * @see WP_Widget::update() |
||
| 178 | * |
||
| 179 | * @param array $new_instance Values just sent to be saved. |
||
| 180 | * @param array $old_instance Previously saved values from database. |
||
| 181 | * |
||
| 182 | * @return array Updated safe values to be saved. |
||
| 183 | */ |
||
| 184 | public function update( $new_instance, $old_instance ) { |
||
| 185 | $instance['title'] = sanitize_text_field( $new_instance['title'] ); |
||
|
0 ignored issues
–
show
|
|||
| 186 | $instance['icon-size'] = $this->defaults['icon-size']; |
||
| 187 | |||
| 188 | if ( in_array( $new_instance['icon-size'], array( 'small', 'medium', 'large' ) ) ) { |
||
| 189 | $instance['icon-size'] = $new_instance['icon-size']; |
||
| 190 | } |
||
| 191 | |||
| 192 | $instance['new-tab'] = isset( $new_instance['new-tab'] ) ? (bool) $new_instance['new-tab'] : false; |
||
| 193 | $icon_count = count( $new_instance['url-icons'] ); |
||
|
0 ignored issues
–
show
$icon_count is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 194 | $instance['icons'] = array(); |
||
| 195 | |||
| 196 | foreach( $new_instance['url-icons'] as $url ) { |
||
| 197 | $url = filter_var( $url, FILTER_SANITIZE_URL ); |
||
| 198 | |||
| 199 | if ( ! empty( $url ) ) { |
||
| 200 | $instance['icons'][] = array( |
||
| 201 | 'url' => $url, |
||
| 202 | ); |
||
| 203 | } |
||
| 204 | } |
||
| 205 | |||
| 206 | return $instance; |
||
| 207 | } |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Back-end widget form. |
||
| 211 | * |
||
| 212 | * @see WP_Widget::form() |
||
| 213 | * |
||
| 214 | * @param array $instance Previously saved values from database. |
||
| 215 | * |
||
| 216 | * @return string|void |
||
| 217 | */ |
||
| 218 | public function form( $instance ) { |
||
| 219 | $instance = wp_parse_args( $instance, $this->defaults ); |
||
| 220 | $title = sanitize_text_field( $instance['title'] ); |
||
| 221 | $sizes = array( |
||
| 222 | 'small' => __( 'Small', 'jetpack' ), |
||
| 223 | 'medium' => __( 'Medium', 'jetpack' ), |
||
| 224 | 'large' => __( 'Large', 'jetpack' ), |
||
| 225 | ); |
||
| 226 | $new_tab = isset( $instance['new-tab'] ) ? (bool) $instance['new-tab'] : false; |
||
| 227 | ?> |
||
| 228 | |||
| 229 | <p> |
||
| 230 | <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'jetpack' ); ?></label> |
||
| 231 | <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /> |
||
| 232 | </p> |
||
| 233 | |||
| 234 | <p> |
||
| 235 | <label for="<?php echo $this->get_field_id( 'icon-size' ); ?>"><?php esc_html_e( 'Size:', 'jetpack' ); ?></label> |
||
| 236 | <select class="widefat" name="<?php echo $this->get_field_name( 'icon-size' ); ?>"> |
||
| 237 | <?php foreach ( $sizes as $value => $label ) : ?> |
||
| 238 | <option value="<?php echo esc_attr( $value ); ?>" <?php selected( $value, $instance['icon-size'] ); ?>><?php echo esc_attr( $label ); ?></option> |
||
| 239 | <?php endforeach; ?> |
||
| 240 | </select> |
||
| 241 | </p> |
||
| 242 | |||
| 243 | <div class="jetpack-social-icons-widget-list" |
||
| 244 | data-url-icon-id="<?php echo $this->get_field_id( 'url-icons' ); ?>" |
||
| 245 | data-url-icon-name="<?php echo $this->get_field_name( 'url-icons' ); ?>" |
||
| 246 | > |
||
| 247 | |||
| 248 | <?php |
||
| 249 | foreach ( $instance['icons'] as $icon ) { |
||
| 250 | self::render_icons_template( array( |
||
| 251 | 'url-icon-id' => $this->get_field_id( 'url-icons' ), |
||
| 252 | 'url-icon-name' => $this->get_field_name( 'url-icons' ), |
||
| 253 | 'url-value' => $icon['url'], |
||
| 254 | ) ); |
||
| 255 | } |
||
| 256 | ?> |
||
| 257 | |||
| 258 | </div> |
||
| 259 | |||
| 260 | <p class="jetpack-social-icons-widget add-button"> |
||
| 261 | <button type="button" class="button jetpack-social-icons-add-button"> |
||
| 262 | <?php esc_html_e( 'Add an icon', 'jetpack' ); ?> |
||
| 263 | </button> |
||
| 264 | </p> |
||
| 265 | |||
| 266 | <?php |
||
| 267 | switch ( get_locale() ) { |
||
| 268 | case 'es': |
||
| 269 | $support = 'https://es.support.wordpress.com/social-media-icons-widget/#iconos-disponibles'; |
||
| 270 | break; |
||
| 271 | |||
| 272 | case 'pt-br': |
||
| 273 | $support = 'https://br.support.wordpress.com/widgets/widget-de-icones-sociais/#ícones-disponíveis'; |
||
| 274 | break; |
||
| 275 | |||
| 276 | default: |
||
| 277 | $support = 'https://en.support.wordpress.com/widgets/social-media-icons-widget/#available-icons'; |
||
| 278 | } |
||
| 279 | ?> |
||
| 280 | |||
| 281 | <p> |
||
| 282 | <em><a href="<?php echo esc_url( $support ); ?>" target="_blank"> |
||
| 283 | <?php esc_html_e( 'View available icons', 'jetpack' ); ?> |
||
| 284 | </a></em> |
||
| 285 | </p> |
||
| 286 | |||
| 287 | <p> |
||
| 288 | <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id( 'new-tab' ); ?>" name="<?php echo $this->get_field_name( 'new-tab' ); ?>" <?php checked( $new_tab ); ?> /> |
||
| 289 | <label for="<?php echo $this->get_field_id( 'new-tab' ); ?>"><?php esc_html_e( 'Open link in a new tab', 'jetpack' ); ?></label> |
||
| 290 | </p> |
||
| 291 | |||
| 292 | <?php |
||
| 293 | } |
||
| 294 | |||
| 295 | /** |
||
| 296 | * Generates template to add icons. |
||
| 297 | * |
||
| 298 | * @param array $args Template arguments |
||
| 299 | */ |
||
| 300 | static function render_icons_template( $args = array() ) { |
||
| 301 | $defaults = array( |
||
| 302 | 'url-icon-id' => '', |
||
| 303 | 'url-icon-name' => '', |
||
| 304 | 'url-value' => '', |
||
| 305 | ); |
||
| 306 | |||
| 307 | $args = wp_parse_args( $args, $defaults ); |
||
| 308 | ?> |
||
| 309 | |||
| 310 | <div class="jetpack-social-icons-widget-item"> |
||
| 311 | <div class="jetpack-social-icons-widget-item-wrapper"> |
||
| 312 | <div class="handle"></div> |
||
| 313 | |||
| 314 | <p class="jetpack-widget-social-icons-url"> |
||
| 315 | <?php |
||
| 316 | printf( '<input class="widefat id="%1$s" name="%2$s[]" type="text" placeholder="%3$s" value="%4$s"/>', |
||
| 317 | esc_attr( $args['url-icon-id'] ), |
||
| 318 | esc_attr( $args['url-icon-name'] ), |
||
| 319 | esc_attr__( 'Account URL', 'jetpack' ), |
||
| 320 | esc_url( $args['url-value'], array( 'http', 'https', 'mailto', 'skype' ) ) |
||
| 321 | ); |
||
| 322 | ?> |
||
| 323 | </p> |
||
| 324 | |||
| 325 | <p class="jetpack-widget-social-icons-remove-item"> |
||
| 326 | <a class="jetpack-widget-social-icons-remove-item-button" href="javascript:;"> |
||
| 327 | <?php esc_html_e( 'Remove', 'jetpack' ); ?> |
||
| 328 | </a> |
||
| 329 | </p> |
||
| 330 | </div> |
||
| 331 | </div> |
||
| 332 | |||
| 333 | <?php |
||
| 334 | } |
||
| 335 | |||
| 336 | /** |
||
| 337 | * Return SVG markup. |
||
| 338 | * |
||
| 339 | * @param array $args { |
||
| 340 | * Parameters needed to display an SVG. |
||
| 341 | * |
||
| 342 | * @type string $icon Required SVG icon filename. |
||
| 343 | * } |
||
| 344 | * @return string SVG markup. |
||
| 345 | */ |
||
| 346 | public function get_svg_icon( $args = array() ) { |
||
| 347 | // Make sure $args are an array. |
||
| 348 | if ( empty( $args ) ) { |
||
| 349 | return esc_html__( 'Please define default parameters in the form of an array.', 'jetpack' ); |
||
| 350 | } |
||
| 351 | |||
| 352 | // Set defaults. |
||
| 353 | $defaults = array( |
||
| 354 | 'icon' => '', |
||
| 355 | ); |
||
| 356 | |||
| 357 | // Parse args. |
||
| 358 | $args = wp_parse_args( $args, $defaults ); |
||
| 359 | |||
| 360 | // Define an icon. |
||
| 361 | if ( false === array_key_exists( 'icon', $args ) ) { |
||
| 362 | return esc_html__( 'Please define an SVG icon filename.', 'jetpack' ); |
||
| 363 | } |
||
| 364 | |||
| 365 | // Set aria hidden. |
||
| 366 | $aria_hidden = ' aria-hidden="true"'; |
||
| 367 | |||
| 368 | // Begin SVG markup. |
||
| 369 | $svg = '<svg class="icon icon-' . esc_attr( $args['icon'] ) . '"' . $aria_hidden . ' role="img">'; |
||
| 370 | |||
| 371 | /* |
||
| 372 | * Display the icon. |
||
| 373 | * |
||
| 374 | * The whitespace around `<use>` is intentional - it is a work around to a keyboard navigation bug in Safari 10. |
||
| 375 | * |
||
| 376 | * See https://core.trac.wordpress.org/ticket/38387. |
||
| 377 | */ |
||
| 378 | $svg .= ' <use href="#icon-' . esc_html( $args['icon'] ) . '" xlink:href="#icon-' . esc_html( $args['icon'] ) . '"></use> '; |
||
| 379 | |||
| 380 | $svg .= '</svg>'; |
||
| 381 | |||
| 382 | return $svg; |
||
| 383 | } |
||
| 384 | |||
| 385 | /** |
||
| 386 | * Returns an array of supported social links (URL, icon, and label). |
||
| 387 | * |
||
| 388 | * @return array $social_links_icons |
||
| 389 | */ |
||
| 390 | public function get_supported_icons() { |
||
| 391 | $social_links_icons = array( |
||
| 392 | array( |
||
| 393 | 'url' => '500px.com', |
||
| 394 | 'icon' => '500px', |
||
| 395 | 'label' => '500px', |
||
| 396 | ), |
||
| 397 | array( |
||
| 398 | 'url' => 'amazon.cn', |
||
| 399 | 'icon' => 'amazon', |
||
| 400 | 'label' => 'Amazon', |
||
| 401 | ), |
||
| 402 | array( |
||
| 403 | 'url' => 'amazon.in', |
||
| 404 | 'icon' => 'amazon', |
||
| 405 | 'label' => 'Amazon', |
||
| 406 | ), |
||
| 407 | array( |
||
| 408 | 'url' => 'amazon.fr', |
||
| 409 | 'icon' => 'amazon', |
||
| 410 | 'label' => 'Amazon', |
||
| 411 | ), |
||
| 412 | array( |
||
| 413 | 'url' => 'amazon.de', |
||
| 414 | 'icon' => 'amazon', |
||
| 415 | 'label' => 'Amazon', |
||
| 416 | ), |
||
| 417 | array( |
||
| 418 | 'url' => 'amazon.it', |
||
| 419 | 'icon' => 'amazon', |
||
| 420 | 'label' => 'Amazon', |
||
| 421 | ), |
||
| 422 | array( |
||
| 423 | 'url' => 'amazon.nl', |
||
| 424 | 'icon' => 'amazon', |
||
| 425 | 'label' => 'Amazon', |
||
| 426 | ), |
||
| 427 | array( |
||
| 428 | 'url' => 'amazon.es', |
||
| 429 | 'icon' => 'amazon', |
||
| 430 | 'label' => 'Amazon', |
||
| 431 | ), |
||
| 432 | array( |
||
| 433 | 'url' => 'amazon.co', |
||
| 434 | 'icon' => 'amazon', |
||
| 435 | 'label' => 'Amazon', |
||
| 436 | ), |
||
| 437 | array( |
||
| 438 | 'url' => 'amazon.ca', |
||
| 439 | 'icon' => 'amazon', |
||
| 440 | 'label' => 'Amazon', |
||
| 441 | ), |
||
| 442 | array( |
||
| 443 | 'url' => 'amazon.com', |
||
| 444 | 'icon' => 'amazon', |
||
| 445 | 'label' => 'Amazon', |
||
| 446 | ), |
||
| 447 | array( |
||
| 448 | 'url' => 'apple.com', |
||
| 449 | 'icon' => 'apple', |
||
| 450 | 'label' => 'Apple', |
||
| 451 | ), |
||
| 452 | array( |
||
| 453 | 'url' => 'itunes.com', |
||
| 454 | 'icon' => 'apple', |
||
| 455 | 'label' => 'iTunes', |
||
| 456 | ), |
||
| 457 | array( |
||
| 458 | 'url' => 'bandcamp.com', |
||
| 459 | 'icon' => 'bandcamp', |
||
| 460 | 'label' => 'Bandcamp', |
||
| 461 | ), |
||
| 462 | array( |
||
| 463 | 'url' => 'behance.net', |
||
| 464 | 'icon' => 'behance', |
||
| 465 | 'label' => 'Behance', |
||
| 466 | ), |
||
| 467 | array( |
||
| 468 | 'url' => 'codepen.io', |
||
| 469 | 'icon' => 'codepen', |
||
| 470 | 'label' => 'CodePen', |
||
| 471 | ), |
||
| 472 | array( |
||
| 473 | 'url' => 'deviantart.com', |
||
| 474 | 'icon' => 'deviantart', |
||
| 475 | 'label' => 'DeviantArt', |
||
| 476 | ), |
||
| 477 | array( |
||
| 478 | 'url' => 'digg.com', |
||
| 479 | 'icon' => 'digg', |
||
| 480 | 'label' => 'Digg', |
||
| 481 | ), |
||
| 482 | array( |
||
| 483 | 'url' => 'dribbble.com', |
||
| 484 | 'icon' => 'dribbble', |
||
| 485 | 'label' => 'Dribbble', |
||
| 486 | ), |
||
| 487 | array( |
||
| 488 | 'url' => 'dropbox.com', |
||
| 489 | 'icon' => 'dropbox', |
||
| 490 | 'label' => 'Dropbox', |
||
| 491 | ), |
||
| 492 | array( |
||
| 493 | 'url' => 'etsy.com', |
||
| 494 | 'icon' => 'etsy', |
||
| 495 | 'label' => 'Etsy', |
||
| 496 | ), |
||
| 497 | array( |
||
| 498 | 'url' => 'facebook.com', |
||
| 499 | 'icon' => 'facebook', |
||
| 500 | 'label' => 'Facebook', |
||
| 501 | ), |
||
| 502 | array( |
||
| 503 | 'url' => '/feed/', |
||
| 504 | 'icon' => 'feed', |
||
| 505 | 'label' => __( 'RSS Feed', 'jetpack' ), |
||
| 506 | ), |
||
| 507 | array( |
||
| 508 | 'url' => 'flickr.com', |
||
| 509 | 'icon' => 'flickr', |
||
| 510 | 'label' => 'Flickr', |
||
| 511 | ), |
||
| 512 | array( |
||
| 513 | 'url' => 'foursquare.com', |
||
| 514 | 'icon' => 'foursquare', |
||
| 515 | 'label' => 'Foursquare', |
||
| 516 | ), |
||
| 517 | array( |
||
| 518 | 'url' => 'goodreads.com', |
||
| 519 | 'icon' => 'goodreads', |
||
| 520 | 'label' => 'Goodreads', |
||
| 521 | ), |
||
| 522 | array( |
||
| 523 | 'url' => 'google.com/+', |
||
| 524 | 'icon' => 'google-plus', |
||
| 525 | 'label' => 'Google +', |
||
| 526 | ), |
||
| 527 | array( |
||
| 528 | 'url' => 'plus.google.com', |
||
| 529 | 'icon' => 'google-plus', |
||
| 530 | 'label' => 'Google +', |
||
| 531 | ), |
||
| 532 | array( |
||
| 533 | 'url' => 'google.com', |
||
| 534 | 'icon' => 'google', |
||
| 535 | 'label' => 'Google', |
||
| 536 | ), |
||
| 537 | array( |
||
| 538 | 'url' => 'github.com', |
||
| 539 | 'icon' => 'github', |
||
| 540 | 'label' => 'GitHub', |
||
| 541 | ), |
||
| 542 | array( |
||
| 543 | 'url' => 'instagram.com', |
||
| 544 | 'icon' => 'instagram', |
||
| 545 | 'label' => 'Instagram', |
||
| 546 | ), |
||
| 547 | array( |
||
| 548 | 'url' => 'linkedin.com', |
||
| 549 | 'icon' => 'linkedin', |
||
| 550 | 'label' => 'LinkedIn', |
||
| 551 | ), |
||
| 552 | array( |
||
| 553 | 'url' => 'mailto:', |
||
| 554 | 'icon' => 'mail', |
||
| 555 | 'label' => __( 'Email', 'jetpack' ), |
||
| 556 | ), |
||
| 557 | array( |
||
| 558 | 'url' => 'meetup.com', |
||
| 559 | 'icon' => 'meetup', |
||
| 560 | 'label' => 'Meetup', |
||
| 561 | ), |
||
| 562 | array( |
||
| 563 | 'url' => 'medium.com', |
||
| 564 | 'icon' => 'medium', |
||
| 565 | 'label' => 'Medium', |
||
| 566 | ), |
||
| 567 | array( |
||
| 568 | 'url' => 'pinterest.com', |
||
| 569 | 'icon' => 'pinterest', |
||
| 570 | 'label' => 'Pinterest', |
||
| 571 | ), |
||
| 572 | array( |
||
| 573 | 'url' => 'getpocket.com', |
||
| 574 | 'icon' => 'pocket', |
||
| 575 | 'label' => 'Pocket', |
||
| 576 | ), |
||
| 577 | array( |
||
| 578 | 'url' => 'reddit.com', |
||
| 579 | 'icon' => 'reddit', |
||
| 580 | 'label' => 'Reddit', |
||
| 581 | ), |
||
| 582 | array( |
||
| 583 | 'url' => 'skype.com', |
||
| 584 | 'icon' => 'skype', |
||
| 585 | 'label' => 'Skype', |
||
| 586 | ), |
||
| 587 | array( |
||
| 588 | 'url' => 'skype:', |
||
| 589 | 'icon' => 'skype', |
||
| 590 | 'label' => 'Skype', |
||
| 591 | ), |
||
| 592 | array( |
||
| 593 | 'url' => 'slideshare.net', |
||
| 594 | 'icon' => 'slideshare', |
||
| 595 | 'label' => 'SlideShare', |
||
| 596 | ), |
||
| 597 | array( |
||
| 598 | 'url' => 'snapchat.com', |
||
| 599 | 'icon' => 'snapchat', |
||
| 600 | 'label' => 'Snapchat', |
||
| 601 | ), |
||
| 602 | array( |
||
| 603 | 'url' => 'soundcloud.com', |
||
| 604 | 'icon' => 'soundcloud', |
||
| 605 | 'label' => 'SoundCloud', |
||
| 606 | ), |
||
| 607 | array( |
||
| 608 | 'url' => 'spotify.com', |
||
| 609 | 'icon' => 'spotify', |
||
| 610 | 'label' => 'Spotify', |
||
| 611 | ), |
||
| 612 | array( |
||
| 613 | 'url' => 'stumbleupon.com', |
||
| 614 | 'icon' => 'stumbleupon', |
||
| 615 | 'label' => 'StumbleUpon', |
||
| 616 | ), |
||
| 617 | array( |
||
| 618 | 'url' => 'tumblr.com', |
||
| 619 | 'icon' => 'tumblr', |
||
| 620 | 'label' => 'Tumblr', |
||
| 621 | ), |
||
| 622 | array( |
||
| 623 | 'url' => 'twitch.tv', |
||
| 624 | 'icon' => 'twitch', |
||
| 625 | 'label' => 'Twitch', |
||
| 626 | ), |
||
| 627 | array( |
||
| 628 | 'url' => 'twitter.com', |
||
| 629 | 'icon' => 'twitter', |
||
| 630 | 'label' => 'Twitter', |
||
| 631 | ), |
||
| 632 | array( |
||
| 633 | 'url' => 'vimeo.com', |
||
| 634 | 'icon' => 'vimeo', |
||
| 635 | 'label' => 'Vimeo', |
||
| 636 | ), |
||
| 637 | array( |
||
| 638 | 'url' => 'vk.com', |
||
| 639 | 'icon' => 'vk', |
||
| 640 | 'label' => 'VK', |
||
| 641 | ), |
||
| 642 | array( |
||
| 643 | 'url' => 'wordpress.com', |
||
| 644 | 'icon' => 'wordpress', |
||
| 645 | 'label' => 'WordPress.com', |
||
| 646 | ), |
||
| 647 | array( |
||
| 648 | 'url' => 'wordpress.org', |
||
| 649 | 'icon' => 'wordpress', |
||
| 650 | 'label' => 'WordPress', |
||
| 651 | ), |
||
| 652 | array( |
||
| 653 | 'url' => 'yelp.com', |
||
| 654 | 'icon' => 'yelp', |
||
| 655 | 'label' => 'Yelp', |
||
| 656 | ), |
||
| 657 | array( |
||
| 658 | 'url' => 'youtube.com', |
||
| 659 | 'icon' => 'youtube', |
||
| 660 | 'label' => 'YouTube', |
||
| 661 | ), |
||
| 662 | ); |
||
| 663 | |||
| 664 | return $social_links_icons; |
||
| 665 | } |
||
| 666 | } // Jetpack_Widget_Social_Icons |
||
| 667 | |||
| 668 | /** |
||
| 669 | * Register and load the widget. |
||
| 670 | * |
||
| 671 | * @access public |
||
| 672 | * @return void |
||
| 673 | */ |
||
| 674 | function jetpack_widget_social_icons_load() { |
||
| 675 | register_widget( 'Jetpack_Widget_Social_Icons' ); |
||
| 676 | } |
||
| 677 | add_action( 'widgets_init', 'jetpack_widget_social_icons_load' ); |
||
| 678 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.