Conditions | 23 |
Paths | > 20000 |
Total Lines | 432 |
Code Lines | 281 |
Lines | 108 |
Ratio | 25 % |
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 |
||
492 | public function add_my_sites_submenu( $wp_admin_bar ) { |
||
493 | $current_user = wp_get_current_user(); |
||
494 | |||
495 | $blog_name = get_bloginfo( 'name' ); |
||
496 | if ( empty( $blog_name ) ) { |
||
497 | $blog_name = $this->primary_site_slug; |
||
498 | } |
||
499 | |||
500 | if ( mb_strlen( $blog_name ) > 20 ) { |
||
501 | $blog_name = mb_substr( html_entity_decode( $blog_name, ENT_QUOTES ), 0, 20 ) . '…'; |
||
502 | } |
||
503 | |||
504 | $wp_admin_bar->add_menu( array( |
||
505 | 'parent' => 'root-default', |
||
506 | 'id' => 'blog', |
||
507 | 'title' => __( 'My Sites', 'jetpack' ), |
||
508 | 'href' => '#', |
||
509 | 'meta' => array( |
||
510 | 'class' => 'my-sites', |
||
511 | ), |
||
512 | ) ); |
||
513 | |||
514 | $wp_admin_bar->add_menu( array( |
||
515 | 'parent' => 'blog', |
||
516 | 'id' => 'switch-site', |
||
517 | 'title' => __( 'Switch Site', 'jetpack' ), |
||
518 | 'href' => 'https://wordpress.com/sites', |
||
519 | ) ); |
||
520 | |||
521 | if ( is_user_member_of_blog( $current_user->ID ) ) { |
||
522 | $blavatar = ''; |
||
523 | $class = 'current-site'; |
||
524 | |||
525 | if ( has_site_icon() ) { |
||
526 | $src = get_site_icon_url(); |
||
527 | $blavatar = '<img class="avatar" src="'. esc_attr( $src ) . '" alt="Current site avatar">'; |
||
528 | $class = 'has-blavatar'; |
||
529 | } |
||
530 | |||
531 | $site_link = str_replace( '::', '/', $this->primary_site_slug ); |
||
532 | $blog_info = '<div class="ab-site-icon">' . $blavatar . '</div>'; |
||
533 | $blog_info .= '<span class="ab-site-title">' . esc_html( $blog_name ) . '</span>'; |
||
534 | $blog_info .= '<span class="ab-site-description">' . esc_html( $site_link ) . '</span>'; |
||
535 | |||
536 | $wp_admin_bar->add_menu( array( |
||
537 | 'parent' => 'blog', |
||
538 | 'id' => 'blog-info', |
||
539 | 'title' => $blog_info, |
||
540 | 'href' => esc_url( trailingslashit( $this->primary_site_slug ) ), |
||
541 | 'meta' => array( |
||
542 | 'class' => $class, |
||
543 | ), |
||
544 | ) ); |
||
545 | |||
546 | } |
||
547 | |||
548 | // Stats |
||
549 | View Code Duplication | if ( Jetpack::is_module_active( 'stats' ) ) { |
|
550 | $wp_admin_bar->add_menu( array( |
||
551 | 'parent' => 'blog', |
||
552 | 'id' => 'blog-stats', |
||
553 | 'title' => __( 'Stats', 'jetpack' ), |
||
554 | 'href' => 'https://wordpress.com/stats/' . esc_attr( $this->primary_site_slug ), |
||
555 | 'meta' => array( |
||
556 | 'class' => 'mb-icon', |
||
557 | ), |
||
558 | ) ); |
||
559 | } |
||
560 | |||
561 | // Add Calypso plans link and plan type indicator |
||
562 | if ( is_user_member_of_blog( $current_user->ID ) ) { |
||
563 | $plans_url = 'https://wordpress.com/plans/' . esc_attr( $this->primary_site_slug ); |
||
564 | $label = __( 'Plan', 'jetpack' ); |
||
565 | $plan = Jetpack::get_active_plan(); |
||
566 | |||
567 | $plan_title = $this->create_menu_item_pair( |
||
568 | array( |
||
569 | 'url' => $plans_url, |
||
570 | 'id' => 'wp-admin-bar-plan', |
||
571 | 'label' => $label, |
||
572 | ), |
||
573 | array( |
||
574 | 'url' => $plans_url, |
||
575 | 'id' => 'wp-admin-bar-plan-badge', |
||
576 | 'label' => $plan['product_name_short'] |
||
577 | ) |
||
578 | ); |
||
579 | |||
580 | $wp_admin_bar->add_menu( array( |
||
581 | 'parent' => 'blog', |
||
582 | 'id' => 'plan', |
||
583 | 'title' => $plan_title, |
||
584 | 'meta' => array( |
||
585 | 'class' => 'inline-action', |
||
586 | ), |
||
587 | ) ); |
||
588 | } |
||
589 | |||
590 | // Publish group |
||
591 | $wp_admin_bar->add_group( array( |
||
592 | 'parent' => 'blog', |
||
593 | 'id' => 'publish', |
||
594 | ) ); |
||
595 | |||
596 | // Publish header |
||
597 | $wp_admin_bar->add_menu( array( |
||
598 | 'parent' => 'publish', |
||
599 | 'id' => 'publish-header', |
||
600 | 'title' => _x( 'Publish', 'admin bar menu group label', 'jetpack' ), |
||
601 | 'meta' => array( |
||
602 | 'class' => 'ab-submenu-header', |
||
603 | ), |
||
604 | ) ); |
||
605 | |||
606 | // Blog Posts |
||
607 | $posts_title = $this->create_menu_item_pair( |
||
608 | array( |
||
609 | 'url' => 'https://wordpress.com/posts/' . esc_attr( $this->primary_site_slug ), |
||
610 | 'id' => 'wp-admin-bar-edit-post', |
||
611 | 'label' => __( 'Blog Posts', 'jetpack' ), |
||
612 | ), |
||
613 | array( |
||
614 | 'url' => 'https://wordpress.com/post/' . esc_attr( $this->primary_site_slug ), |
||
615 | 'id' => 'wp-admin-bar-new-post', |
||
616 | 'label' => _x( 'Add', 'admin bar menu new item label', 'jetpack' ), |
||
617 | ) |
||
618 | ); |
||
619 | |||
620 | if ( ! current_user_can( 'edit_posts' ) ) { |
||
621 | $posts_title = $this->create_menu_item_anchor( |
||
622 | 'ab-item ab-primary mb-icon', |
||
623 | 'https://wordpress.com/posts/' . esc_attr( $this->primary_site_slug ), |
||
624 | __( 'Blog Posts', 'jetpack' ), |
||
625 | 'wp-admin-bar-edit-post' |
||
626 | ); |
||
627 | } |
||
628 | |||
629 | $wp_admin_bar->add_menu( array( |
||
630 | 'parent' => 'publish', |
||
631 | 'id' => 'new-post', |
||
632 | 'title' => $posts_title, |
||
633 | 'meta' => array( |
||
634 | 'class' => 'inline-action', |
||
635 | ), |
||
636 | ) ); |
||
637 | |||
638 | // Pages |
||
639 | $pages_title = $this->create_menu_item_pair( |
||
640 | array( |
||
641 | 'url' => 'https://wordpress.com/pages/' . esc_attr( $this->primary_site_slug ), |
||
642 | 'id' => 'wp-admin-bar-edit-page', |
||
643 | 'label' => __( 'Pages', 'jetpack' ), |
||
644 | ), |
||
645 | array( |
||
646 | 'url' => 'https://wordpress.com/page/' . esc_attr( $this->primary_site_slug ), |
||
647 | 'id' => 'wp-admin-bar-new-page', |
||
648 | 'label' => _x( 'Add', 'admin bar menu new item label', 'jetpack' ), |
||
649 | ) |
||
650 | ); |
||
651 | |||
652 | if ( ! current_user_can( 'edit_pages' ) ) { |
||
653 | $pages_title = $this->create_menu_item_anchor( |
||
654 | 'ab-item ab-primary mb-icon', |
||
655 | 'https://wordpress.com/pages/' . esc_attr( $this->primary_site_slug ), |
||
656 | __( 'Pages', 'jetpack' ), |
||
657 | 'wp-admin-bar-edit-page' |
||
658 | ); |
||
659 | } |
||
660 | |||
661 | $wp_admin_bar->add_menu( array( |
||
662 | 'parent' => 'publish', |
||
663 | 'id' => 'new-page', |
||
664 | 'title' => $pages_title, |
||
665 | 'meta' => array( |
||
666 | 'class' => 'inline-action', |
||
667 | ), |
||
668 | ) ); |
||
669 | |||
670 | // Testimonials |
||
671 | View Code Duplication | if ( Jetpack::is_module_active( 'custom-content-types' ) && get_option( 'jetpack_testimonial' ) ) { |
|
672 | $testimonials_title = $this->create_menu_item_pair( |
||
673 | array( |
||
674 | 'url' => 'https://wordpress.com/types/jetpack-testimonial/' . esc_attr( $this->primary_site_slug ), |
||
675 | 'id' => 'wp-admin-bar-edit-testimonial', |
||
676 | 'label' => __( 'Testimonials', 'jetpack' ), |
||
677 | ), |
||
678 | array( |
||
679 | 'url' => 'https://wordpress.com/edit/jetpack-testimonial/' . esc_attr( $this->primary_site_slug ), |
||
680 | 'id' => 'wp-admin-bar-new-testimonial', |
||
681 | 'label' => _x( 'Add', 'admin bar menu new item label', 'jetpack' ), |
||
682 | ) |
||
683 | ); |
||
684 | |||
685 | if ( ! current_user_can( 'edit_pages' ) ) { |
||
686 | $testimonials_title = $this->create_menu_item_anchor( |
||
687 | 'ab-item ab-primary mb-icon', |
||
688 | 'https://wordpress.com/types/jetpack-testimonial/' . esc_attr( $this->primary_site_slug ), |
||
689 | __( 'Testimonials', 'jetpack' ), |
||
690 | 'wp-admin-bar-edit-testimonial' |
||
691 | ); |
||
692 | } |
||
693 | |||
694 | $wp_admin_bar->add_menu( array( |
||
695 | 'parent' => 'publish', |
||
696 | 'id' => 'new-jetpack-testimonial', |
||
697 | 'title' => $testimonials_title, |
||
698 | 'meta' => array( |
||
699 | 'class' => 'inline-action', |
||
700 | ), |
||
701 | ) ); |
||
702 | } |
||
703 | |||
704 | // Portfolio |
||
705 | View Code Duplication | if ( Jetpack::is_module_active( 'custom-content-types' ) && get_option( 'jetpack_portfolio' ) ) { |
|
706 | $portfolios_title = $this->create_menu_item_pair( |
||
707 | array( |
||
708 | 'url' => 'https://wordpress.com/types/jetpack-portfolio/' . esc_attr( $this->primary_site_slug ), |
||
709 | 'id' => 'wp-admin-bar-edit-portfolio', |
||
710 | 'label' => __( 'Portfolio', 'jetpack' ), |
||
711 | ), |
||
712 | array( |
||
713 | 'url' => 'https://wordpress.com/edit/jetpack-portfolio/' . esc_attr( $this->primary_site_slug ), |
||
714 | 'id' => 'wp-admin-bar-new-portfolio', |
||
715 | 'label' => _x( 'Add', 'admin bar menu new item label', 'jetpack' ), |
||
716 | ) |
||
717 | ); |
||
718 | |||
719 | if ( ! current_user_can( 'edit_pages' ) ) { |
||
720 | $portfolios_title = $this->create_menu_item_anchor( |
||
721 | 'ab-item ab-primary mb-icon', |
||
722 | 'https://wordpress.com/types/jetpack-portfolio/' . esc_attr( $this->primary_site_slug ), |
||
723 | __( 'Portfolio', 'jetpack' ), |
||
724 | 'wp-admin-bar-edit-portfolio' |
||
725 | ); |
||
726 | } |
||
727 | |||
728 | $wp_admin_bar->add_menu( array( |
||
729 | 'parent' => 'publish', |
||
730 | 'id' => 'new-jetpack-portfolio', |
||
731 | 'title' => $portfolios_title, |
||
732 | 'meta' => array( |
||
733 | 'class' => 'inline-action', |
||
734 | ), |
||
735 | ) ); |
||
736 | } |
||
737 | |||
738 | if ( current_user_can( 'edit_theme_options' ) ) { |
||
739 | // Look and Feel group |
||
740 | $wp_admin_bar->add_group( array( |
||
741 | 'parent' => 'blog', |
||
742 | 'id' => 'look-and-feel', |
||
743 | ) ); |
||
744 | |||
745 | // Look and Feel header |
||
746 | $wp_admin_bar->add_menu( array( |
||
747 | 'parent' => 'look-and-feel', |
||
748 | 'id' => 'look-and-feel-header', |
||
749 | 'title' => _x( 'Personalize', 'admin bar menu group label', 'jetpack' ), |
||
750 | 'meta' => array( |
||
751 | 'class' => 'ab-submenu-header', |
||
752 | ), |
||
753 | ) ); |
||
754 | |||
755 | if ( is_admin() ) { |
||
756 | // In wp-admin the `return` query arg will return to that page after closing the Customizer |
||
757 | $customizer_url = add_query_arg( array( 'return' => urlencode( site_url( $_SERVER['REQUEST_URI'] ) ) ), wp_customize_url() ); |
||
758 | } else { |
||
759 | // On the frontend the `url` query arg will load that page in the Customizer and also return to it after closing |
||
760 | // non-home URLs won't work unless we undo domain mapping since the Customizer preview is unmapped to always have HTTPS |
||
761 | $current_page = '//' . $this->primary_site_slug . $_SERVER['REQUEST_URI']; |
||
762 | $customizer_url = add_query_arg( array( 'url' => urlencode( $current_page ) ), wp_customize_url() ); |
||
763 | } |
||
764 | |||
765 | $theme_title = $this->create_menu_item_pair( |
||
766 | array( |
||
767 | 'url' => 'https://wordpress.com/design/' . esc_attr( $this->primary_site_slug ), |
||
768 | 'id' => 'wp-admin-bar-themes', |
||
769 | 'label' => __( 'Themes', 'jetpack' ), |
||
770 | ), |
||
771 | array( |
||
772 | 'url' => $customizer_url, |
||
773 | 'id' => 'wp-admin-bar-cmz', |
||
774 | 'label' => _x( 'Customize', 'admin bar customize item label', 'jetpack' ), |
||
775 | ) |
||
776 | ); |
||
777 | $meta = array( 'class' => 'mb-icon', 'class' => 'inline-action' ); |
||
778 | $href = false; |
||
779 | |||
780 | $wp_admin_bar->add_menu( array( |
||
781 | 'parent' => 'look-and-feel', |
||
782 | 'id' => 'themes', |
||
783 | 'title' => $theme_title, |
||
784 | 'href' => $href, |
||
785 | 'meta' => $meta |
||
786 | ) ); |
||
787 | |||
788 | View Code Duplication | if ( current_theme_supports( 'menus' ) ) { |
|
789 | $wp_admin_bar->add_menu( array( |
||
790 | 'parent' => 'look-and-feel', |
||
791 | 'id' => 'menus', |
||
792 | 'title' => __( 'Menus', 'jetpack' ), |
||
793 | 'href' => 'https://wordpress.com/menus/' . esc_attr( $this->primary_site_slug ), |
||
794 | 'meta' => array( |
||
795 | 'class' => 'mb-icon', |
||
796 | ), |
||
797 | ) ); |
||
798 | } |
||
799 | } |
||
800 | |||
801 | if ( current_user_can( 'manage_options' ) ) { |
||
802 | // Configuration group |
||
803 | $wp_admin_bar->add_group( array( |
||
804 | 'parent' => 'blog', |
||
805 | 'id' => 'configuration', |
||
806 | ) ); |
||
807 | |||
808 | // Configuration header |
||
809 | $wp_admin_bar->add_menu( array( |
||
810 | 'parent' => 'configuration', |
||
811 | 'id' => 'configuration-header', |
||
812 | 'title' => __( 'Configure', 'admin bar menu group label', 'jetpack' ), |
||
813 | 'meta' => array( |
||
814 | 'class' => 'ab-submenu-header', |
||
815 | ), |
||
816 | ) ); |
||
817 | |||
818 | View Code Duplication | if ( Jetpack::is_module_active( 'publicize' ) || Jetpack::is_module_active( 'sharedaddy' ) ) { |
|
819 | $wp_admin_bar->add_menu( array( |
||
820 | 'parent' => 'configuration', |
||
821 | 'id' => 'sharing', |
||
822 | 'title' => __( 'Sharing', 'jetpack' ), |
||
823 | 'href' => 'https://wordpress.com/sharing/' . esc_attr( $this->primary_site_slug ), |
||
824 | 'meta' => array( |
||
825 | 'class' => 'mb-icon', |
||
826 | ), |
||
827 | ) ); |
||
828 | } |
||
829 | |||
830 | $people_title = $this->create_menu_item_pair( |
||
831 | array( |
||
832 | 'url' => 'https://wordpress.com/people/team/' . esc_attr( $this->primary_site_slug ), |
||
833 | 'id' => 'wp-admin-bar-people', |
||
834 | 'label' => __( 'People', 'jetpack' ), |
||
835 | ), |
||
836 | array( |
||
837 | 'url' => '//' . esc_attr( $this->primary_site_slug ) . '/wp-admin/user-new.php', |
||
838 | 'id' => 'wp-admin-bar-people-add', |
||
839 | 'label' => _x( 'Add', 'admin bar people item label', 'jetpack' ), |
||
840 | ) |
||
841 | ); |
||
842 | |||
843 | $wp_admin_bar->add_menu( array( |
||
844 | 'parent' => 'configuration', |
||
845 | 'id' => 'users-toolbar', |
||
846 | 'title' => $people_title, |
||
847 | 'href' => false, |
||
848 | 'meta' => array( |
||
849 | 'class' => 'inline-action', |
||
850 | ), |
||
851 | ) ); |
||
852 | |||
853 | $plugins_title = $this->create_menu_item_pair( |
||
854 | array( |
||
855 | 'url' => 'https://wordpress.com/plugins/' . esc_attr( $this->primary_site_slug ), |
||
856 | 'id' => 'wp-admin-bar-plugins', |
||
857 | 'label' => __( 'Plugins', 'jetpack' ), |
||
858 | ), |
||
859 | array( |
||
860 | 'url' => 'https://wordpress.com/plugins/browse/' . esc_attr( $this->primary_site_slug ), |
||
861 | 'id' => 'wp-admin-bar-plugins-add', |
||
862 | 'label' => _x( 'Add', 'Label for the button on the Masterbar to add a new plugin', 'jetpack' ), |
||
863 | ) |
||
864 | ); |
||
865 | |||
866 | $wp_admin_bar->add_menu( array( |
||
867 | 'parent' => 'configuration', |
||
868 | 'id' => 'plugins', |
||
869 | 'title' => $plugins_title, |
||
870 | 'href' => false, |
||
871 | 'meta' => array( |
||
872 | 'class' => 'inline-action', |
||
873 | ), |
||
874 | ) ); |
||
875 | |||
876 | if ( $this->is_automated_transfer_site() ) { |
||
877 | $domain_title = $this->create_menu_item_pair( |
||
878 | array( |
||
879 | 'url' => 'https://wordpress.com/domains/' . esc_attr( $this->primary_site_slug ), |
||
880 | 'id' => 'wp-admin-bar-domains', |
||
881 | 'label' => __( 'Domains', 'jetpack' ), |
||
882 | ), |
||
883 | array( |
||
884 | 'url' => 'https://wordpress.com/domains/add/' . esc_attr( $this->primary_site_slug ), |
||
885 | 'id' => 'wp-admin-bar-domains-add', |
||
886 | 'label' => _x( 'Add', 'Label for the button on the Masterbar to add a new domain', 'jetpack' ), |
||
887 | ) |
||
888 | ); |
||
889 | $wp_admin_bar->add_menu( array( |
||
890 | 'parent' => 'configuration', |
||
891 | 'id' => 'domains', |
||
892 | 'title' => $domain_title, |
||
893 | 'href' => false, |
||
894 | 'meta' => array( |
||
895 | 'class' => 'inline-action', |
||
896 | ), |
||
897 | ) ); |
||
898 | } |
||
899 | |||
900 | |||
901 | $wp_admin_bar->add_menu( array( |
||
902 | 'parent' => 'configuration', |
||
903 | 'id' => 'blog-settings', |
||
904 | 'title' => __( 'Settings', 'jetpack' ), |
||
905 | 'href' => 'https://wordpress.com/settings/general/' . esc_attr( $this->primary_site_slug ), |
||
906 | 'meta' => array( |
||
907 | 'class' => 'mb-icon', |
||
908 | ), |
||
909 | ) ); |
||
910 | |||
911 | View Code Duplication | if ( $this->is_automated_transfer_site() ) { |
|
912 | $wp_admin_bar->add_menu( array( |
||
913 | 'parent' => 'configuration', |
||
914 | 'id' => 'legacy-dashboard', |
||
915 | 'title' => __( 'WP Admin', 'jetpack' ), |
||
916 | 'href' => '//' . esc_attr( $this->primary_site_slug ) . '/wp-admin/', |
||
917 | 'meta' => array( |
||
918 | 'class' => 'mb-icon', |
||
919 | ), |
||
920 | ) ); |
||
921 | } |
||
922 | } |
||
923 | } |
||
924 | } |
||
925 |