~canonical-sysadmins/wordpress/4.8.3

« back to all changes in this revision

Viewing changes to wp-includes/default-widgets.php

  • Committer: Ryan Finnie
  • Date: 2015-08-31 16:09:47 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: ryan.finnie@canonical.com-20150831160947-1h6rfxby9z1ec62u
Merge WP4.3 from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
                parent::__construct('pages', __('Pages'), $widget_ops);
19
19
        }
20
20
 
 
21
        /**
 
22
         * @param array $args
 
23
         * @param array $instance
 
24
         */
21
25
        public function widget( $args, $instance ) {
22
26
 
23
27
                /**
67
71
                }
68
72
        }
69
73
 
 
74
        /**
 
75
         * @param array $new_instance
 
76
         * @param array $old_instance
 
77
         * @return array
 
78
         */
70
79
        public function update( $new_instance, $old_instance ) {
71
80
                $instance = $old_instance;
72
81
                $instance['title'] = strip_tags($new_instance['title']);
81
90
                return $instance;
82
91
        }
83
92
 
 
93
        /**
 
94
         * @param array $instance
 
95
         */
84
96
        public function form( $instance ) {
85
97
                //Defaults
86
98
                $instance = wp_parse_args( (array) $instance, array( 'sortby' => 'post_title', 'title' => '', 'exclude' => '') );
118
130
                parent::__construct('links', __('Links'), $widget_ops);
119
131
        }
120
132
 
 
133
        /**
 
134
         * @param array $args
 
135
         * @param array $instance
 
136
         */
121
137
        public function widget( $args, $instance ) {
122
 
 
123
138
                $show_description = isset($instance['description']) ? $instance['description'] : false;
124
139
                $show_name = isset($instance['name']) ? $instance['name'] : false;
125
140
                $show_rating = isset($instance['rating']) ? $instance['rating'] : false;
151
166
                ) ) );
152
167
        }
153
168
 
 
169
        /**
 
170
         * @param array $new_instance
 
171
         * @param array $old_instance
 
172
         * @return array
 
173
         */
154
174
        public function update( $new_instance, $old_instance ) {
155
175
                $new_instance = (array) $new_instance;
156
176
                $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0 );
169
189
                return $instance;
170
190
        }
171
191
 
 
192
        /**
 
193
         * @param array $instance
 
194
         */
172
195
        public function form( $instance ) {
173
196
 
174
197
                //Defaults
227
250
                parent::__construct( 'search', _x( 'Search', 'Search widget' ), $widget_ops );
228
251
        }
229
252
 
 
253
        /**
 
254
         * @param array $args
 
255
         * @param array $instance
 
256
         */
230
257
        public function widget( $args, $instance ) {
231
 
 
232
258
                /** This filter is documented in wp-includes/default-widgets.php */
233
259
                $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
234
260
 
243
269
                echo $args['after_widget'];
244
270
        }
245
271
 
 
272
        /**
 
273
         * @param array $instance
 
274
         */
246
275
        public function form( $instance ) {
247
276
                $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
248
277
                $title = $instance['title'];
251
280
<?php
252
281
        }
253
282
 
 
283
        /**
 
284
         * @param array $new_instance
 
285
         * @param array $old_instance
 
286
         * @return array
 
287
         */
254
288
        public function update( $new_instance, $old_instance ) {
255
289
                $instance = $old_instance;
256
290
                $new_instance = wp_parse_args((array) $new_instance, array( 'title' => ''));
272
306
                parent::__construct('archives', __('Archives'), $widget_ops);
273
307
        }
274
308
 
 
309
        /**
 
310
         * @param array $args
 
311
         * @param array $instance
 
312
         */
275
313
        public function widget( $args, $instance ) {
276
314
                $c = ! empty( $instance['count'] ) ? '1' : '0';
277
315
                $d = ! empty( $instance['dropdown'] ) ? '1' : '0';
354
392
                echo $args['after_widget'];
355
393
        }
356
394
 
 
395
        /**
 
396
         * @param array $new_instance
 
397
         * @param array $old_instance
 
398
         * @return array
 
399
         */
357
400
        public function update( $new_instance, $old_instance ) {
358
401
                $instance = $old_instance;
359
402
                $new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
364
407
                return $instance;
365
408
        }
366
409
 
 
410
        /**
 
411
         * @param array $instance
 
412
         */
367
413
        public function form( $instance ) {
368
414
                $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
369
415
                $title = strip_tags($instance['title']);
394
440
                parent::__construct('meta', __('Meta'), $widget_ops);
395
441
        }
396
442
 
 
443
        /**
 
444
         * @param array $args
 
445
         * @param array $instance
 
446
         */
397
447
        public function widget( $args, $instance ) {
398
 
 
399
448
                /** This filter is documented in wp-includes/default-widgets.php */
400
449
                $title = apply_filters( 'widget_title', empty($instance['title']) ? __( 'Meta' ) : $instance['title'], $instance, $this->id_base );
401
450
 
430
479
                echo $args['after_widget'];
431
480
        }
432
481
 
 
482
        /**
 
483
         * @param array $new_instance
 
484
         * @param array $old_instance
 
485
         * @return array
 
486
         */
433
487
        public function update( $new_instance, $old_instance ) {
434
488
                $instance = $old_instance;
435
489
                $instance['title'] = strip_tags($new_instance['title']);
437
491
                return $instance;
438
492
        }
439
493
 
 
494
        /**
 
495
         * @param array $instance
 
496
         */
440
497
        public function form( $instance ) {
441
498
                $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
442
499
                $title = strip_tags($instance['title']);
458
515
                parent::__construct('calendar', __('Calendar'), $widget_ops);
459
516
        }
460
517
 
 
518
        /**
 
519
         * @param array $args
 
520
         * @param array $instance
 
521
         */
461
522
        public function widget( $args, $instance ) {
462
 
 
463
523
                /** This filter is documented in wp-includes/default-widgets.php */
464
524
                $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
465
525
 
473
533
                echo $args['after_widget'];
474
534
        }
475
535
 
 
536
        /**
 
537
         * @param array $new_instance
 
538
         * @param array $old_instance
 
539
         * @return array
 
540
         */
476
541
        public function update( $new_instance, $old_instance ) {
477
542
                $instance = $old_instance;
478
543
                $instance['title'] = strip_tags($new_instance['title']);
480
545
                return $instance;
481
546
        }
482
547
 
 
548
        /**
 
549
         * @param array $instance
 
550
         */
483
551
        public function form( $instance ) {
484
552
                $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
485
553
                $title = strip_tags($instance['title']);
503
571
                parent::__construct('text', __('Text'), $widget_ops, $control_ops);
504
572
        }
505
573
 
 
574
        /**
 
575
         * @param array $args
 
576
         * @param array $instance
 
577
         */
506
578
        public function widget( $args, $instance ) {
507
 
 
508
579
                /** This filter is documented in wp-includes/default-widgets.php */
509
580
                $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
510
581
 
526
597
                echo $args['after_widget'];
527
598
        }
528
599
 
 
600
        /**
 
601
         * @param array $new_instance
 
602
         * @param array $old_instance
 
603
         * @return array
 
604
         */
529
605
        public function update( $new_instance, $old_instance ) {
530
606
                $instance = $old_instance;
531
607
                $instance['title'] = strip_tags($new_instance['title']);
537
613
                return $instance;
538
614
        }
539
615
 
 
616
        /**
 
617
         * @param array $instance
 
618
         */
540
619
        public function form( $instance ) {
541
620
                $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
542
621
                $title = strip_tags($instance['title']);
545
624
                <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
546
625
                <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); ?>" /></p>
547
626
 
548
 
                <textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo $text; ?></textarea>
 
627
                <p><label for="<?php echo $this->get_field_id( 'text' ); ?>"><?php _e( 'Content:' ); ?></label>
 
628
                <textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo $text; ?></textarea></p>
549
629
 
550
630
                <p><input id="<?php echo $this->get_field_id('filter'); ?>" name="<?php echo $this->get_field_name('filter'); ?>" type="checkbox" <?php checked(isset($instance['filter']) ? $instance['filter'] : 0); ?> />&nbsp;<label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs'); ?></label></p>
551
631
<?php
564
644
                parent::__construct('categories', __('Categories'), $widget_ops);
565
645
        }
566
646
 
 
647
        /**
 
648
         * @staticvar bool $first_dropdown
 
649
         *
 
650
         * @param array $args
 
651
         * @param array $instance
 
652
         */
567
653
        public function widget( $args, $instance ) {
 
654
                static $first_dropdown = true;
568
655
 
569
656
                /** This filter is documented in wp-includes/default-widgets.php */
570
657
                $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base );
585
672
                );
586
673
 
587
674
                if ( $d ) {
588
 
                        static $first_dropdown = true;
589
 
 
590
675
                        $dropdown_id = ( $first_dropdown ) ? 'cat' : "{$this->id_base}-dropdown-{$this->number}";
591
676
                        $first_dropdown = false;
592
677
 
644
729
                echo $args['after_widget'];
645
730
        }
646
731
 
 
732
        /**
 
733
         * @param array $new_instance
 
734
         * @param array $old_instance
 
735
         * @return array
 
736
         */
647
737
        public function update( $new_instance, $old_instance ) {
648
738
                $instance = $old_instance;
649
739
                $instance['title'] = strip_tags($new_instance['title']);
654
744
                return $instance;
655
745
        }
656
746
 
 
747
        /**
 
748
         * @param array $instance
 
749
         */
657
750
        public function form( $instance ) {
658
751
                //Defaults
659
752
                $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
695
788
                add_action( 'switch_theme', array($this, 'flush_widget_cache') );
696
789
        }
697
790
 
698
 
        public function widget($args, $instance) {
 
791
        /**
 
792
         * @param array $args
 
793
         * @param array $instance
 
794
         */
 
795
        public function widget( $args, $instance ) {
699
796
                $cache = array();
700
797
                if ( ! $this->is_preview() ) {
701
798
                        $cache = wp_cache_get( 'widget_recent_posts', 'widget' );
773
870
                }
774
871
        }
775
872
 
 
873
        /**
 
874
         * @param array $new_instance
 
875
         * @param array $old_instance
 
876
         * @return array
 
877
         */
776
878
        public function update( $new_instance, $old_instance ) {
777
879
                $instance = $old_instance;
778
880
                $instance['title'] = strip_tags($new_instance['title']);
787
889
                return $instance;
788
890
        }
789
891
 
 
892
        /**
 
893
         * @access public
 
894
         */
790
895
        public function flush_widget_cache() {
791
896
                wp_cache_delete('widget_recent_posts', 'widget');
792
897
        }
793
898
 
 
899
        /**
 
900
         * @param array $instance
 
901
         */
794
902
        public function form( $instance ) {
795
903
                $title     = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
796
904
                $number    = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
828
936
                add_action( 'transition_comment_status', array($this, 'flush_widget_cache') );
829
937
        }
830
938
 
 
939
        /**
 
940
         * @access public
 
941
         */
831
942
        public function recent_comments_style() {
832
 
 
833
943
                /**
834
944
                 * Filter the Recent Comments default widget styles.
835
945
                 *
846
956
<?php
847
957
        }
848
958
 
 
959
        /**
 
960
         * @access public
 
961
         */
849
962
        public function flush_widget_cache() {
850
963
                wp_cache_delete('widget_recent_comments', 'widget');
851
964
        }
852
965
 
 
966
        /**
 
967
         * @global array  $comments
 
968
         * @global object $comment
 
969
         *
 
970
         * @param array $args
 
971
         * @param array $instance
 
972
         */
853
973
        public function widget( $args, $instance ) {
854
974
                global $comments, $comment;
855
975
 
901
1021
                }
902
1022
 
903
1023
                $output .= '<ul id="recentcomments">';
904
 
                if ( $comments ) {
 
1024
                if ( is_array( $comments ) && $comments ) {
905
1025
                        // Prime cache for associated posts. (Prime post term cache if we need it for permalinks.)
906
1026
                        $post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) );
907
1027
                        _prime_post_caches( $post_ids, strpos( get_option( 'permalink_structure' ), '%category%' ), false );
927
1047
                }
928
1048
        }
929
1049
 
 
1050
        /**
 
1051
         * @param array $new_instance
 
1052
         * @param array $old_instance
 
1053
         * @return array
 
1054
         */
930
1055
        public function update( $new_instance, $old_instance ) {
931
1056
                $instance = $old_instance;
932
1057
                $instance['title'] = strip_tags($new_instance['title']);
940
1065
                return $instance;
941
1066
        }
942
1067
 
 
1068
        /**
 
1069
         * @param array $instance
 
1070
         */
943
1071
        public function form( $instance ) {
944
1072
                $title  = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
945
1073
                $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
966
1094
                parent::__construct( 'rss', __('RSS'), $widget_ops, $control_ops );
967
1095
        }
968
1096
 
969
 
        public function widget($args, $instance) {
970
 
 
 
1097
        /**
 
1098
         * @param array $args
 
1099
         * @param array $instance
 
1100
         */
 
1101
        public function widget( $args, $instance ) {
971
1102
                if ( isset($instance['error']) && $instance['error'] )
972
1103
                        return;
973
1104
 
1019
1150
                unset($rss);
1020
1151
        }
1021
1152
 
1022
 
        public function update($new_instance, $old_instance) {
 
1153
        /**
 
1154
         * @param array $new_instance
 
1155
         * @param array $old_instance
 
1156
         * @return array
 
1157
         */
 
1158
        public function update( $new_instance, $old_instance ) {
1023
1159
                $testurl = ( isset( $new_instance['url'] ) && ( !isset( $old_instance['url'] ) || ( $new_instance['url'] != $old_instance['url'] ) ) );
1024
1160
                return wp_widget_rss_process( $new_instance, $testurl );
1025
1161
        }
1026
1162
 
1027
 
        public function form($instance) {
1028
 
 
1029
 
                if ( empty($instance) )
 
1163
        /**
 
1164
         * @param array $instance
 
1165
         */
 
1166
        public function form( $instance ) {
 
1167
                if ( empty( $instance ) ) {
1030
1168
                        $instance = array( 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 );
 
1169
                }
1031
1170
                $instance['number'] = $this->number;
1032
1171
 
1033
1172
                wp_widget_rss_form( $instance );
1261
1400
                parent::__construct('tag_cloud', __('Tag Cloud'), $widget_ops);
1262
1401
        }
1263
1402
 
 
1403
        /**
 
1404
         * @param array $args
 
1405
         * @param array $instance
 
1406
         */
1264
1407
        public function widget( $args, $instance ) {
1265
1408
                $current_taxonomy = $this->_get_current_taxonomy($instance);
1266
1409
                if ( !empty($instance['title']) ) {
1301
1444
                echo $args['after_widget'];
1302
1445
        }
1303
1446
 
 
1447
        /**
 
1448
         * @param array $new_instance
 
1449
         * @param array $old_instance
 
1450
         * @return array
 
1451
         */
1304
1452
        public function update( $new_instance, $old_instance ) {
1305
1453
                $instance = array();
1306
1454
                $instance['title'] = strip_tags(stripslashes($new_instance['title']));
1308
1456
                return $instance;
1309
1457
        }
1310
1458
 
 
1459
        /**
 
1460
         * @param array $instance
 
1461
         */
1311
1462
        public function form( $instance ) {
1312
1463
                $current_taxonomy = $this->_get_current_taxonomy($instance);
1313
1464
?>
1325
1476
        </select></p><?php
1326
1477
        }
1327
1478
 
 
1479
        /**
 
1480
         * @param array $instance
 
1481
         * @return string
 
1482
         */
1328
1483
        public function _get_current_taxonomy($instance) {
1329
1484
                if ( !empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) )
1330
1485
                        return $instance['taxonomy'];
1345
1500
                parent::__construct( 'nav_menu', __('Custom Menu'), $widget_ops );
1346
1501
        }
1347
1502
 
1348
 
        public function widget($args, $instance) {
 
1503
        /**
 
1504
         * @param array $args
 
1505
         * @param array $instance
 
1506
         */
 
1507
        public function widget( $args, $instance ) {
1349
1508
                // Get menu
1350
1509
                $nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false;
1351
1510
 
1384
1543
                echo $args['after_widget'];
1385
1544
        }
1386
1545
 
 
1546
        /**
 
1547
         * @param array $new_instance
 
1548
         * @param array $old_instance
 
1549
         * @return array
 
1550
         */
1387
1551
        public function update( $new_instance, $old_instance ) {
1388
1552
                $instance = array();
1389
1553
                if ( ! empty( $new_instance['title'] ) ) {
1395
1559
                return $instance;
1396
1560
        }
1397
1561
 
 
1562
        /**
 
1563
         * @param array $instance
 
1564
         */
1398
1565
        public function form( $instance ) {
1399
1566
                $title = isset( $instance['title'] ) ? $instance['title'] : '';
1400
1567
                $nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';
1403
1570
                $menus = wp_get_nav_menus();
1404
1571
 
1405
1572
                // If no menus exists, direct the user to go and create some.
1406
 
                if ( !$menus ) {
1407
 
                        echo '<p>'. sprintf( __('No menus have been created yet. <a href="%s">Create some</a>.'), admin_url('nav-menus.php') ) .'</p>';
1408
 
                        return;
1409
 
                }
1410
1573
                ?>
1411
 
                <p>
1412
 
                        <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
1413
 
                        <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr( $title ); ?>" />
1414
 
                </p>
1415
 
                <p>
1416
 
                        <label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label>
1417
 
                        <select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>">
1418
 
                                <option value="0"><?php _e( '&mdash; Select &mdash;' ) ?></option>
1419
 
                <?php
1420
 
                        foreach ( $menus as $menu ) {
1421
 
                                echo '<option value="' . $menu->term_id . '"'
1422
 
                                        . selected( $nav_menu, $menu->term_id, false )
1423
 
                                        . '>'. esc_html( $menu->name ) . '</option>';
 
1574
                <p class="nav-menu-widget-no-menus-message" <?php if ( ! empty( $menus ) ) { echo ' style="display:none" '; } ?>>
 
1575
                        <?php
 
1576
                        if ( isset( $GLOBALS['wp_customize'] ) && $GLOBALS['wp_customize'] instanceof WP_Customize_Manager ) {
 
1577
                                // @todo When expanding a panel, the JS should be smart enough to collapse any existing panels and sections.
 
1578
                                $url = 'javascript: wp.customize.section.each(function( section ){ section.collapse(); }); wp.customize.panel( "nav_menus" ).focus();';
 
1579
                        } else {
 
1580
                                $url = admin_url( 'nav-menus.php' );
1424
1581
                        }
1425
 
                ?>
1426
 
                        </select>
 
1582
                        ?>
 
1583
                        <?php echo sprintf( __( 'No menus have been created yet. <a href="%s">Create some</a>.' ), esc_attr( $url ) ); ?>
1427
1584
                </p>
 
1585
                <div class="nav-menu-widget-form-controls" <?php if ( empty( $menus ) ) { echo ' style="display:none" '; } ?>>
 
1586
                        <p>
 
1587
                                <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ) ?></label>
 
1588
                                <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo esc_attr( $title ); ?>"/>
 
1589
                        </p>
 
1590
                        <p>
 
1591
                                <label for="<?php echo $this->get_field_id( 'nav_menu' ); ?>"><?php _e( 'Select Menu:' ); ?></label>
 
1592
                                <select id="<?php echo $this->get_field_id( 'nav_menu' ); ?>" name="<?php echo $this->get_field_name( 'nav_menu' ); ?>">
 
1593
                                        <option value="0"><?php _e( '&mdash; Select &mdash;' ); ?></option>
 
1594
                                        <?php foreach ( $menus as $menu ) : ?>
 
1595
                                                <option value="<?php echo esc_attr( $menu->term_id ); ?>" <?php selected( $nav_menu, $menu->term_id ); ?>>
 
1596
                                                        <?php echo esc_html( $menu->name ); ?>
 
1597
                                                </option>
 
1598
                                        <?php endforeach; ?>
 
1599
                                </select>
 
1600
                        </p>
 
1601
                </div>
1428
1602
                <?php
1429
1603
        }
1430
1604
}
1475
1649
         */
1476
1650
        do_action( 'widgets_init' );
1477
1651
}
1478
 
 
1479
 
add_action('init', 'wp_widgets_init', 1);