| Conditions | 27 |
| Paths | > 20000 |
| Total Lines | 481 |
| Lines | 108 |
| Ratio | 22.45 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 563 | public function add_my_sites_submenu( $wp_admin_bar ) { |
||
| 564 | $current_user = wp_get_current_user(); |
||
| 565 | |||
| 566 | $blog_name = get_bloginfo( 'name' ); |
||
| 567 | if ( empty( $blog_name ) ) { |
||
| 568 | $blog_name = $this->primary_site_slug; |
||
| 569 | } |
||
| 570 | |||
| 571 | if ( mb_strlen( $blog_name ) > 20 ) { |
||
| 572 | $blog_name = mb_substr( html_entity_decode( $blog_name, ENT_QUOTES ), 0, 20 ) . '…'; |
||
| 573 | } |
||
| 574 | |||
| 575 | $wp_admin_bar->add_menu( array( |
||
| 576 | 'parent' => 'root-default', |
||
| 577 | 'id' => 'blog', |
||
| 578 | 'title' => _n( 'My Site', 'My Sites', $this->user_site_count, 'jetpack' ), |
||
| 579 | 'href' => '#', |
||
| 580 | 'meta' => array( |
||
| 581 | 'class' => 'my-sites mb-trackable', |
||
| 582 | ), |
||
| 583 | ) ); |
||
| 584 | |||
| 585 | if ( $this->user_site_count > 1 ) { |
||
| 586 | $wp_admin_bar->add_menu( array( |
||
| 587 | 'parent' => 'blog', |
||
| 588 | 'id' => 'switch-site', |
||
| 589 | 'title' => esc_html__( 'Switch Site', 'jetpack' ), |
||
| 590 | 'href' => 'https://wordpress.com/sites', |
||
| 591 | ) ); |
||
| 592 | } else { |
||
| 593 | $wp_admin_bar->add_menu( array( |
||
| 594 | 'parent' => 'blog', |
||
| 595 | 'id' => 'new-site', |
||
| 596 | 'title' => esc_html__( '+ Add New WordPress', 'jetpack' ), |
||
| 597 | 'href' => 'https://wordpress.com/start?ref=admin-bar-logged-in', |
||
| 598 | ) ); |
||
| 599 | } |
||
| 600 | |||
| 601 | if ( is_user_member_of_blog( $current_user->ID ) ) { |
||
| 602 | $blavatar = ''; |
||
| 603 | $class = 'current-site'; |
||
| 604 | |||
| 605 | if ( has_site_icon() ) { |
||
| 606 | $src = get_site_icon_url(); |
||
| 607 | $blavatar = '<img class="avatar" src="'. esc_attr( $src ) . '" alt="Current site avatar">'; |
||
| 608 | $class = 'has-blavatar'; |
||
| 609 | } |
||
| 610 | |||
| 611 | $blog_info = '<div class="ab-site-icon">' . $blavatar . '</div>'; |
||
| 612 | $blog_info .= '<span class="ab-site-title">' . esc_html( $blog_name ) . '</span>'; |
||
| 613 | $blog_info .= '<span class="ab-site-description">' . esc_html( $this->primary_site_url ) . '</span>'; |
||
| 614 | |||
| 615 | $wp_admin_bar->add_menu( array( |
||
| 616 | 'parent' => 'blog', |
||
| 617 | 'id' => 'blog-info', |
||
| 618 | 'title' => $blog_info, |
||
| 619 | 'href' => esc_url( trailingslashit( $this->primary_site_url ) ), |
||
| 620 | 'meta' => array( |
||
| 621 | 'class' => $class, |
||
| 622 | ), |
||
| 623 | ) ); |
||
| 624 | } |
||
| 625 | |||
| 626 | // Site Preview |
||
| 627 | if ( is_admin() ) { |
||
| 628 | $wp_admin_bar->add_menu( array( |
||
| 629 | 'parent' => 'blog', |
||
| 630 | 'id' => 'site-view', |
||
| 631 | 'title' => __( 'View Site', 'jetpack' ), |
||
| 632 | 'href' => home_url(), |
||
| 633 | 'meta' => array( |
||
| 634 | 'class' => 'mb-icon', |
||
| 635 | 'target' => '_blank', |
||
| 636 | ), |
||
| 637 | ) ); |
||
| 638 | } |
||
| 639 | |||
| 640 | // Stats |
||
| 641 | View Code Duplication | if ( Jetpack::is_module_active( 'stats' ) ) { |
|
| 642 | $wp_admin_bar->add_menu( array( |
||
| 643 | 'parent' => 'blog', |
||
| 644 | 'id' => 'blog-stats', |
||
| 645 | 'title' => esc_html__( 'Stats', 'jetpack' ), |
||
| 646 | 'href' => 'https://wordpress.com/stats/' . esc_attr( $this->primary_site_slug ), |
||
| 647 | 'meta' => array( |
||
| 648 | 'class' => 'mb-icon', |
||
| 649 | ), |
||
| 650 | ) ); |
||
| 651 | } |
||
| 652 | |||
| 653 | View Code Duplication | if ( current_user_can( 'manage_options' ) ) { |
|
| 654 | $wp_admin_bar->add_menu( array( |
||
| 655 | 'parent' => 'blog', |
||
| 656 | 'id' => 'activity', |
||
| 657 | 'title' => esc_html__( 'Activity', 'jetpack' ), |
||
| 658 | 'href' => 'https://wordpress.com/activity-log/' . esc_attr( $this->primary_site_slug ), |
||
| 659 | 'meta' => array( |
||
| 660 | 'class' => 'mb-icon', |
||
| 661 | ), |
||
| 662 | ) ); |
||
| 663 | } |
||
| 664 | |||
| 665 | // Add Calypso plans link and plan type indicator |
||
| 666 | if ( is_user_member_of_blog( $current_user->ID ) ) { |
||
| 667 | $plans_url = 'https://wordpress.com/plans/' . esc_attr( $this->primary_site_slug ); |
||
| 668 | $label = esc_html__( 'Plan', 'jetpack' ); |
||
| 669 | $plan = Jetpack_Plan::get(); |
||
| 670 | |||
| 671 | $plan_title = $this->create_menu_item_pair( |
||
| 672 | array( |
||
| 673 | 'url' => $plans_url, |
||
| 674 | 'id' => 'wp-admin-bar-plan', |
||
| 675 | 'label' => $label, |
||
| 676 | ), |
||
| 677 | array( |
||
| 678 | 'url' => $plans_url, |
||
| 679 | 'id' => 'wp-admin-bar-plan-badge', |
||
| 680 | 'label' => $plan['product_name_short'] |
||
| 681 | ) |
||
| 682 | ); |
||
| 683 | |||
| 684 | $wp_admin_bar->add_menu( array( |
||
| 685 | 'parent' => 'blog', |
||
| 686 | 'id' => 'plan', |
||
| 687 | 'title' => $plan_title, |
||
| 688 | 'meta' => array( |
||
| 689 | 'class' => 'inline-action', |
||
| 690 | ), |
||
| 691 | ) ); |
||
| 692 | } |
||
| 693 | |||
| 694 | // Publish group |
||
| 695 | $wp_admin_bar->add_group( array( |
||
| 696 | 'parent' => 'blog', |
||
| 697 | 'id' => 'publish', |
||
| 698 | ) ); |
||
| 699 | |||
| 700 | // Publish header |
||
| 701 | $wp_admin_bar->add_menu( array( |
||
| 702 | 'parent' => 'publish', |
||
| 703 | 'id' => 'publish-header', |
||
| 704 | 'title' => esc_html_x( 'Manage', 'admin bar menu group label', 'jetpack' ), |
||
| 705 | 'meta' => array( |
||
| 706 | 'class' => 'ab-submenu-header', |
||
| 707 | ), |
||
| 708 | ) ); |
||
| 709 | |||
| 710 | // Pages |
||
| 711 | $pages_title = $this->create_menu_item_pair( |
||
| 712 | array( |
||
| 713 | 'url' => 'https://wordpress.com/pages/' . esc_attr( $this->primary_site_slug ), |
||
| 714 | 'id' => 'wp-admin-bar-edit-page', |
||
| 715 | 'label' => esc_html__( 'Site Pages', 'jetpack' ), |
||
| 716 | ), |
||
| 717 | array( |
||
| 718 | 'url' => 'https://wordpress.com/page/' . esc_attr( $this->primary_site_slug ), |
||
| 719 | 'id' => 'wp-admin-bar-new-page-badge', |
||
| 720 | 'label' => esc_html_x( 'Add', 'admin bar menu new item label', 'jetpack' ), |
||
| 721 | ) |
||
| 722 | ); |
||
| 723 | |||
| 724 | if ( ! current_user_can( 'edit_pages' ) ) { |
||
| 725 | $pages_title = $this->create_menu_item_anchor( |
||
| 726 | 'ab-item ab-primary mb-icon', |
||
| 727 | 'https://wordpress.com/pages/' . esc_attr( $this->primary_site_slug ), |
||
| 728 | esc_html__( 'Site Pages', 'jetpack' ), |
||
| 729 | 'wp-admin-bar-edit-page' |
||
| 730 | ); |
||
| 731 | } |
||
| 732 | |||
| 733 | $wp_admin_bar->add_menu( array( |
||
| 734 | 'parent' => 'publish', |
||
| 735 | 'id' => 'new-page', |
||
| 736 | 'title' => $pages_title, |
||
| 737 | 'meta' => array( |
||
| 738 | 'class' => 'inline-action', |
||
| 739 | ), |
||
| 740 | ) ); |
||
| 741 | |||
| 742 | // Blog Posts |
||
| 743 | $posts_title = $this->create_menu_item_pair( |
||
| 744 | array( |
||
| 745 | 'url' => 'https://wordpress.com/posts/' . esc_attr( $this->primary_site_slug ), |
||
| 746 | 'id' => 'wp-admin-bar-edit-post', |
||
| 747 | 'label' => esc_html__( 'Blog Posts', 'jetpack' ), |
||
| 748 | ), |
||
| 749 | array( |
||
| 750 | 'url' => 'https://wordpress.com/post/' . esc_attr( $this->primary_site_slug ), |
||
| 751 | 'id' => 'wp-admin-bar-new-post-badge', |
||
| 752 | 'label' => esc_html_x( 'Add', 'admin bar menu new item label', 'jetpack' ), |
||
| 753 | ) |
||
| 754 | ); |
||
| 755 | |||
| 756 | if ( ! current_user_can( 'edit_posts' ) ) { |
||
| 757 | $posts_title = $this->create_menu_item_anchor( |
||
| 758 | 'ab-item ab-primary mb-icon', |
||
| 759 | 'https://wordpress.com/posts/' . esc_attr( $this->primary_site_slug ), |
||
| 760 | esc_html__( 'Blog Posts', 'jetpack' ), |
||
| 761 | 'wp-admin-bar-edit-post' |
||
| 762 | ); |
||
| 763 | } |
||
| 764 | |||
| 765 | $wp_admin_bar->add_menu( array( |
||
| 766 | 'parent' => 'publish', |
||
| 767 | 'id' => 'new-post', |
||
| 768 | 'title' => $posts_title, |
||
| 769 | 'meta' => array( |
||
| 770 | 'class' => 'inline-action mb-trackable', |
||
| 771 | ), |
||
| 772 | ) ); |
||
| 773 | |||
| 774 | // Comments |
||
| 775 | View Code Duplication | if ( current_user_can( 'moderate_comments' ) ) { |
|
| 776 | $wp_admin_bar->add_menu( array( |
||
| 777 | 'parent' => 'publish', |
||
| 778 | 'id' => 'comments', |
||
| 779 | 'title' => __( 'Comments' ), |
||
| 780 | 'href' => 'https://wordpress.com/comments/' . esc_attr( $this->primary_site_slug ), |
||
| 781 | 'meta' => array( |
||
| 782 | 'class' => 'mb-icon', |
||
| 783 | ), |
||
| 784 | ) ); |
||
| 785 | } |
||
| 786 | |||
| 787 | // Testimonials |
||
| 788 | View Code Duplication | if ( Jetpack::is_module_active( 'custom-content-types' ) && get_option( 'jetpack_testimonial' ) ) { |
|
| 789 | $testimonials_title = $this->create_menu_item_pair( |
||
| 790 | array( |
||
| 791 | 'url' => 'https://wordpress.com/types/jetpack-testimonial/' . esc_attr( $this->primary_site_slug ), |
||
| 792 | 'id' => 'wp-admin-bar-edit-testimonial', |
||
| 793 | 'label' => esc_html__( 'Testimonials', 'jetpack' ), |
||
| 794 | ), |
||
| 795 | array( |
||
| 796 | 'url' => 'https://wordpress.com/edit/jetpack-testimonial/' . esc_attr( $this->primary_site_slug ), |
||
| 797 | 'id' => 'wp-admin-bar-new-testimonial', |
||
| 798 | 'label' => esc_html_x( 'Add', 'Button label for adding a new item via the toolbar menu', 'jetpack' ), |
||
| 799 | ) |
||
| 800 | ); |
||
| 801 | |||
| 802 | if ( ! current_user_can( 'edit_pages' ) ) { |
||
| 803 | $testimonials_title = $this->create_menu_item_anchor( |
||
| 804 | 'ab-item ab-primary mb-icon', |
||
| 805 | 'https://wordpress.com/types/jetpack-testimonial/' . esc_attr( $this->primary_site_slug ), |
||
| 806 | esc_html__( 'Testimonials', 'jetpack' ), |
||
| 807 | 'wp-admin-bar-edit-testimonial' |
||
| 808 | ); |
||
| 809 | } |
||
| 810 | |||
| 811 | $wp_admin_bar->add_menu( array( |
||
| 812 | 'parent' => 'publish', |
||
| 813 | 'id' => 'new-jetpack-testimonial', |
||
| 814 | 'title' => $testimonials_title, |
||
| 815 | 'meta' => array( |
||
| 816 | 'class' => 'inline-action', |
||
| 817 | ), |
||
| 818 | ) ); |
||
| 819 | } |
||
| 820 | |||
| 821 | // Portfolio |
||
| 822 | View Code Duplication | if ( Jetpack::is_module_active( 'custom-content-types' ) && get_option( 'jetpack_portfolio' ) ) { |
|
| 823 | $portfolios_title = $this->create_menu_item_pair( |
||
| 824 | array( |
||
| 825 | 'url' => 'https://wordpress.com/types/jetpack-portfolio/' . esc_attr( $this->primary_site_slug ), |
||
| 826 | 'id' => 'wp-admin-bar-edit-portfolio', |
||
| 827 | 'label' => esc_html__( 'Portfolio', 'jetpack' ), |
||
| 828 | ), |
||
| 829 | array( |
||
| 830 | 'url' => 'https://wordpress.com/edit/jetpack-portfolio/' . esc_attr( $this->primary_site_slug ), |
||
| 831 | 'id' => 'wp-admin-bar-new-portfolio', |
||
| 832 | 'label' => esc_html_x( 'Add', 'Button label for adding a new item via the toolbar menu', 'jetpack' ), |
||
| 833 | ) |
||
| 834 | ); |
||
| 835 | |||
| 836 | if ( ! current_user_can( 'edit_pages' ) ) { |
||
| 837 | $portfolios_title = $this->create_menu_item_anchor( |
||
| 838 | 'ab-item ab-primary mb-icon', |
||
| 839 | 'https://wordpress.com/types/jetpack-portfolio/' . esc_attr( $this->primary_site_slug ), |
||
| 840 | esc_html__( 'Portfolio', 'jetpack' ), |
||
| 841 | 'wp-admin-bar-edit-portfolio' |
||
| 842 | ); |
||
| 843 | } |
||
| 844 | |||
| 845 | $wp_admin_bar->add_menu( array( |
||
| 846 | 'parent' => 'publish', |
||
| 847 | 'id' => 'new-jetpack-portfolio', |
||
| 848 | 'title' => $portfolios_title, |
||
| 849 | 'meta' => array( |
||
| 850 | 'class' => 'inline-action', |
||
| 851 | ), |
||
| 852 | ) ); |
||
| 853 | } |
||
| 854 | |||
| 855 | if ( current_user_can( 'edit_theme_options' ) ) { |
||
| 856 | // Look and Feel group |
||
| 857 | $wp_admin_bar->add_group( array( |
||
| 858 | 'parent' => 'blog', |
||
| 859 | 'id' => 'look-and-feel', |
||
| 860 | ) ); |
||
| 861 | |||
| 862 | // Look and Feel header |
||
| 863 | $wp_admin_bar->add_menu( array( |
||
| 864 | 'parent' => 'look-and-feel', |
||
| 865 | 'id' => 'look-and-feel-header', |
||
| 866 | 'title' => esc_html_x( 'Personalize', 'admin bar menu group label', 'jetpack' ), |
||
| 867 | 'meta' => array( |
||
| 868 | 'class' => 'ab-submenu-header', |
||
| 869 | ), |
||
| 870 | ) ); |
||
| 871 | |||
| 872 | if ( is_admin() ) { |
||
| 873 | // In wp-admin the `return` query arg will return to that page after closing the Customizer |
||
| 874 | $customizer_url = add_query_arg( array( 'return' => urlencode( site_url( $_SERVER['REQUEST_URI'] ) ) ), wp_customize_url() ); |
||
| 875 | } else { |
||
| 876 | // On the frontend the `url` query arg will load that page in the Customizer and also return to it after closing |
||
| 877 | // non-home URLs won't work unless we undo domain mapping since the Customizer preview is unmapped to always have HTTPS |
||
| 878 | $current_page = '//' . $this->primary_site_slug . $_SERVER['REQUEST_URI']; |
||
| 879 | $customizer_url = add_query_arg( array( 'url' => urlencode( $current_page ) ), wp_customize_url() ); |
||
| 880 | } |
||
| 881 | |||
| 882 | $theme_title = $this->create_menu_item_pair( |
||
| 883 | array( |
||
| 884 | 'url' => $customizer_url, |
||
| 885 | 'id' => 'wp-admin-bar-cmz', |
||
| 886 | 'label' => esc_html_x( 'Customize', 'admin bar customize item label', 'jetpack' ), |
||
| 887 | ), |
||
| 888 | array( |
||
| 889 | 'url' => 'https://wordpress.com/themes/' . esc_attr( $this->primary_site_slug ), |
||
| 890 | 'id' => 'wp-admin-bar-themes', |
||
| 891 | 'label' => esc_html__( 'Themes', 'jetpack' ), |
||
| 892 | ) |
||
| 893 | ); |
||
| 894 | $meta = array( 'class' => 'mb-icon', 'class' => 'inline-action' ); |
||
| 895 | $href = false; |
||
| 896 | |||
| 897 | $wp_admin_bar->add_menu( array( |
||
| 898 | 'parent' => 'look-and-feel', |
||
| 899 | 'id' => 'themes', |
||
| 900 | 'title' => $theme_title, |
||
| 901 | 'href' => $href, |
||
| 902 | 'meta' => $meta |
||
| 903 | ) ); |
||
| 904 | } |
||
| 905 | |||
| 906 | if ( current_user_can( 'manage_options' ) ) { |
||
| 907 | // Configuration group |
||
| 908 | $wp_admin_bar->add_group( array( |
||
| 909 | 'parent' => 'blog', |
||
| 910 | 'id' => 'configuration', |
||
| 911 | ) ); |
||
| 912 | |||
| 913 | // Configuration header |
||
| 914 | $wp_admin_bar->add_menu( array( |
||
| 915 | 'parent' => 'configuration', |
||
| 916 | 'id' => 'configuration-header', |
||
| 917 | 'title' => esc_html__( 'Configure', 'admin bar menu group label', 'jetpack' ), |
||
| 918 | 'meta' => array( |
||
| 919 | 'class' => 'ab-submenu-header', |
||
| 920 | ), |
||
| 921 | ) ); |
||
| 922 | |||
| 923 | View Code Duplication | if ( Jetpack::is_module_active( 'publicize' ) || Jetpack::is_module_active( 'sharedaddy' ) ) { |
|
| 924 | $wp_admin_bar->add_menu( array( |
||
| 925 | 'parent' => 'configuration', |
||
| 926 | 'id' => 'sharing', |
||
| 927 | 'title' => esc_html__( 'Sharing', 'jetpack' ), |
||
| 928 | 'href' => 'https://wordpress.com/sharing/' . esc_attr( $this->primary_site_slug ), |
||
| 929 | 'meta' => array( |
||
| 930 | 'class' => 'mb-icon', |
||
| 931 | ), |
||
| 932 | ) ); |
||
| 933 | } |
||
| 934 | |||
| 935 | $people_title = $this->create_menu_item_pair( |
||
| 936 | array( |
||
| 937 | 'url' => 'https://wordpress.com/people/team/' . esc_attr( $this->primary_site_slug ), |
||
| 938 | 'id' => 'wp-admin-bar-people', |
||
| 939 | 'label' => esc_html__( 'People', 'jetpack' ), |
||
| 940 | ), |
||
| 941 | array( |
||
| 942 | 'url' => admin_url( 'user-new.php' ), |
||
| 943 | 'id' => 'wp-admin-bar-people-add', |
||
| 944 | 'label' => esc_html_x( 'Add', 'admin bar people item label', 'jetpack' ), |
||
| 945 | ) |
||
| 946 | ); |
||
| 947 | |||
| 948 | $wp_admin_bar->add_menu( array( |
||
| 949 | 'parent' => 'configuration', |
||
| 950 | 'id' => 'users-toolbar', |
||
| 951 | 'title' => $people_title, |
||
| 952 | 'href' => false, |
||
| 953 | 'meta' => array( |
||
| 954 | 'class' => 'inline-action', |
||
| 955 | ), |
||
| 956 | ) ); |
||
| 957 | |||
| 958 | $plugins_title = $this->create_menu_item_pair( |
||
| 959 | array( |
||
| 960 | 'url' => 'https://wordpress.com/plugins/' . esc_attr( $this->primary_site_slug ), |
||
| 961 | 'id' => 'wp-admin-bar-plugins', |
||
| 962 | 'label' => esc_html__( 'Plugins', 'jetpack' ), |
||
| 963 | ), |
||
| 964 | array( |
||
| 965 | 'url' => 'https://wordpress.com/plugins/manage/' . esc_attr( $this->primary_site_slug ), |
||
| 966 | 'id' => 'wp-admin-bar-plugins-add', |
||
| 967 | 'label' => esc_html_x( 'Manage', 'Label for the button on the Masterbar to manage plugins', 'jetpack' ), |
||
| 968 | ) |
||
| 969 | ); |
||
| 970 | |||
| 971 | $wp_admin_bar->add_menu( array( |
||
| 972 | 'parent' => 'configuration', |
||
| 973 | 'id' => 'plugins', |
||
| 974 | 'title' => $plugins_title, |
||
| 975 | 'href' => false, |
||
| 976 | 'meta' => array( |
||
| 977 | 'class' => 'inline-action', |
||
| 978 | ), |
||
| 979 | ) ); |
||
| 980 | |||
| 981 | if ( jetpack_is_atomic_site() ) { |
||
| 982 | $domain_title = $this->create_menu_item_pair( |
||
| 983 | array( |
||
| 984 | 'url' => 'https://wordpress.com/domains/' . esc_attr( $this->primary_site_slug ), |
||
| 985 | 'id' => 'wp-admin-bar-domains', |
||
| 986 | 'label' => esc_html__( 'Domains', 'jetpack' ), |
||
| 987 | ), |
||
| 988 | array( |
||
| 989 | 'url' => 'https://wordpress.com/domains/add/' . esc_attr( $this->primary_site_slug ), |
||
| 990 | 'id' => 'wp-admin-bar-domains-add', |
||
| 991 | 'label' => esc_html_x( 'Add', 'Label for the button on the Masterbar to add a new domain', 'jetpack' ), |
||
| 992 | ) |
||
| 993 | ); |
||
| 994 | $wp_admin_bar->add_menu( array( |
||
| 995 | 'parent' => 'configuration', |
||
| 996 | 'id' => 'domains', |
||
| 997 | 'title' => $domain_title, |
||
| 998 | 'href' => false, |
||
| 999 | 'meta' => array( |
||
| 1000 | 'class' => 'inline-action', |
||
| 1001 | ), |
||
| 1002 | ) ); |
||
| 1003 | } |
||
| 1004 | |||
| 1005 | $wp_admin_bar->add_menu( array( |
||
| 1006 | 'parent' => 'configuration', |
||
| 1007 | 'id' => 'blog-settings', |
||
| 1008 | 'title' => esc_html__( 'Settings', 'jetpack' ), |
||
| 1009 | 'href' => 'https://wordpress.com/settings/general/' . esc_attr( $this->primary_site_slug ), |
||
| 1010 | 'meta' => array( |
||
| 1011 | 'class' => 'mb-icon', |
||
| 1012 | ), |
||
| 1013 | ) ); |
||
| 1014 | |||
| 1015 | if ( ! is_admin() ) { |
||
| 1016 | $wp_admin_bar->add_menu( array( |
||
| 1017 | 'parent' => 'configuration', |
||
| 1018 | 'id' => 'legacy-dashboard', |
||
| 1019 | 'title' => esc_html__( 'Dashboard', 'jetpack' ), |
||
| 1020 | 'href' => admin_url(), |
||
| 1021 | 'meta' => array( |
||
| 1022 | 'class' => 'mb-icon', |
||
| 1023 | ), |
||
| 1024 | ) ); |
||
| 1025 | } |
||
| 1026 | |||
| 1027 | // Restore dashboard menu toggle that is needed on mobile views. |
||
| 1028 | if ( is_admin() ) { |
||
| 1029 | $wp_admin_bar->add_menu( array( |
||
| 1030 | 'id' => 'menu-toggle', |
||
| 1031 | 'title' => '<span class="ab-icon"></span><span class="screen-reader-text">' . esc_html__( 'Menu', 'jetpack' ) . '</span>', |
||
| 1032 | 'href' => '#', |
||
| 1033 | ) ); |
||
| 1034 | } |
||
| 1035 | |||
| 1036 | /** |
||
| 1037 | * Fires when menu items are added to the masterbar "My Sites" menu. |
||
| 1038 | * |
||
| 1039 | * @since 5.4.0 |
||
| 1040 | */ |
||
| 1041 | do_action( 'jetpack_masterbar' ); |
||
| 1042 | } |
||
| 1043 | } |
||
| 1044 | } |
||
| 1045 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: