| Conditions | 18 |
| Paths | 17280 |
| Total Lines | 396 |
| Code Lines | 258 |
| Lines | 68 |
| Ratio | 17.17 % |
| 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 | View Code Duplication | 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 | View Code Duplication | 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 | // Portfolio |
||
| 671 | $portfolios_title = $this->create_menu_item_pair( |
||
| 672 | array( |
||
| 673 | 'url' => 'https://wordpress.com/types/jetpack-portfolio/' . esc_attr( $this->primary_site_slug ), |
||
| 674 | 'id' => 'wp-admin-bar-edit-portfolio', |
||
| 675 | 'label' => __( 'Portfolio', 'jetpack' ), |
||
| 676 | ), |
||
| 677 | array( |
||
| 678 | 'url' => 'https://wordpress.com/edit/jetpack-portfolio/' . esc_attr( $this->primary_site_slug ), |
||
| 679 | 'id' => 'wp-admin-bar-new-portfolio', |
||
| 680 | 'label' => _x( 'Add', 'admin bar menu new item label', 'jetpack' ), |
||
| 681 | ) |
||
| 682 | ); |
||
| 683 | |||
| 684 | View Code Duplication | if ( ! current_user_can( 'edit_pages' ) ) { |
|
| 685 | $portfolios_title = $this->create_menu_item_anchor( |
||
| 686 | 'ab-item ab-primary mb-icon', |
||
| 687 | 'https://wordpress.com/types/jetpack-portfolio/' . esc_attr( $this->primary_site_slug ), |
||
| 688 | __( 'Portfolio', 'jetpack' ), |
||
| 689 | 'wp-admin-bar-edit-portfolio' |
||
| 690 | ); |
||
| 691 | } |
||
| 692 | |||
| 693 | $wp_admin_bar->add_menu( array( |
||
| 694 | 'parent' => 'publish', |
||
| 695 | 'id' => 'new-jetpack-portfolio', |
||
| 696 | 'title' => $portfolios_title, |
||
| 697 | 'meta' => array( |
||
| 698 | 'class' => 'inline-action', |
||
| 699 | ), |
||
| 700 | ) ); |
||
| 701 | |||
| 702 | if ( current_user_can( 'edit_theme_options' ) ) { |
||
| 703 | // Look and Feel group |
||
| 704 | $wp_admin_bar->add_group( array( |
||
| 705 | 'parent' => 'blog', |
||
| 706 | 'id' => 'look-and-feel', |
||
| 707 | ) ); |
||
| 708 | |||
| 709 | // Look and Feel header |
||
| 710 | $wp_admin_bar->add_menu( array( |
||
| 711 | 'parent' => 'look-and-feel', |
||
| 712 | 'id' => 'look-and-feel-header', |
||
| 713 | 'title' => _x( 'Personalize', 'admin bar menu group label', 'jetpack' ), |
||
| 714 | 'meta' => array( |
||
| 715 | 'class' => 'ab-submenu-header', |
||
| 716 | ), |
||
| 717 | ) ); |
||
| 718 | |||
| 719 | if ( is_admin() ) { |
||
| 720 | // In wp-admin the `return` query arg will return to that page after closing the Customizer |
||
| 721 | $customizer_url = add_query_arg( array( 'return' => urlencode( site_url( $_SERVER['REQUEST_URI'] ) ) ), wp_customize_url() ); |
||
| 722 | } else { |
||
| 723 | // On the frontend the `url` query arg will load that page in the Customizer and also return to it after closing |
||
| 724 | // non-home URLs won't work unless we undo domain mapping since the Customizer preview is unmapped to always have HTTPS |
||
| 725 | $current_page = '//' . $this->primary_site_slug . $_SERVER['REQUEST_URI']; |
||
| 726 | $customizer_url = add_query_arg( array( 'url' => urlencode( $current_page ) ), wp_customize_url() ); |
||
| 727 | } |
||
| 728 | |||
| 729 | $theme_title = $this->create_menu_item_pair( |
||
| 730 | array( |
||
| 731 | 'url' => 'https://wordpress.com/design/' . esc_attr( $this->primary_site_slug ), |
||
| 732 | 'id' => 'wp-admin-bar-themes', |
||
| 733 | 'label' => __( 'Themes', 'jetpack' ), |
||
| 734 | ), |
||
| 735 | array( |
||
| 736 | 'url' => $customizer_url, |
||
| 737 | 'id' => 'wp-admin-bar-cmz', |
||
| 738 | 'label' => _x( 'Customize', 'admin bar customize item label', 'jetpack' ), |
||
| 739 | ) |
||
| 740 | ); |
||
| 741 | $meta = array( 'class' => 'mb-icon', 'class' => 'inline-action' ); |
||
| 742 | $href = false; |
||
| 743 | |||
| 744 | $wp_admin_bar->add_menu( array( |
||
| 745 | 'parent' => 'look-and-feel', |
||
| 746 | 'id' => 'themes', |
||
| 747 | 'title' => $theme_title, |
||
| 748 | 'href' => $href, |
||
| 749 | 'meta' => $meta |
||
| 750 | ) ); |
||
| 751 | |||
| 752 | View Code Duplication | if ( current_theme_supports( 'menus' ) ) { |
|
| 753 | $wp_admin_bar->add_menu( array( |
||
| 754 | 'parent' => 'look-and-feel', |
||
| 755 | 'id' => 'menus', |
||
| 756 | 'title' => __( 'Menus', 'jetpack' ), |
||
| 757 | 'href' => 'https://wordpress.com/menus/' . esc_attr( $this->primary_site_slug ), |
||
| 758 | 'meta' => array( |
||
| 759 | 'class' => 'mb-icon', |
||
| 760 | ), |
||
| 761 | ) ); |
||
| 762 | } |
||
| 763 | } |
||
| 764 | |||
| 765 | if ( current_user_can( 'manage_options' ) ) { |
||
| 766 | // Configuration group |
||
| 767 | $wp_admin_bar->add_group( array( |
||
| 768 | 'parent' => 'blog', |
||
| 769 | 'id' => 'configuration', |
||
| 770 | ) ); |
||
| 771 | |||
| 772 | // Configuration header |
||
| 773 | $wp_admin_bar->add_menu( array( |
||
| 774 | 'parent' => 'configuration', |
||
| 775 | 'id' => 'configuration-header', |
||
| 776 | 'title' => __( 'Configure', 'admin bar menu group label', 'jetpack' ), |
||
| 777 | 'meta' => array( |
||
| 778 | 'class' => 'ab-submenu-header', |
||
| 779 | ), |
||
| 780 | ) ); |
||
| 781 | |||
| 782 | View Code Duplication | if ( Jetpack::is_module_active( 'publicize' ) || Jetpack::is_module_active( 'sharedaddy' ) ) { |
|
| 783 | $wp_admin_bar->add_menu( array( |
||
| 784 | 'parent' => 'configuration', |
||
| 785 | 'id' => 'sharing', |
||
| 786 | 'title' => __( 'Sharing', 'jetpack' ), |
||
| 787 | 'href' => 'https://wordpress.com/sharing/' . esc_attr( $this->primary_site_slug ), |
||
| 788 | 'meta' => array( |
||
| 789 | 'class' => 'mb-icon', |
||
| 790 | ), |
||
| 791 | ) ); |
||
| 792 | } |
||
| 793 | |||
| 794 | $people_title = $this->create_menu_item_pair( |
||
| 795 | array( |
||
| 796 | 'url' => 'https://wordpress.com/people/team/' . esc_attr( $this->primary_site_slug ), |
||
| 797 | 'id' => 'wp-admin-bar-people', |
||
| 798 | 'label' => __( 'People', 'jetpack' ), |
||
| 799 | ), |
||
| 800 | array( |
||
| 801 | 'url' => '//' . esc_attr( $this->primary_site_slug ) . '/wp-admin/user-new.php', |
||
| 802 | 'id' => 'wp-admin-bar-people-add', |
||
| 803 | 'label' => _x( 'Add', 'admin bar people item label', 'jetpack' ), |
||
| 804 | ) |
||
| 805 | ); |
||
| 806 | |||
| 807 | $wp_admin_bar->add_menu( array( |
||
| 808 | 'parent' => 'configuration', |
||
| 809 | 'id' => 'users-toolbar', |
||
| 810 | 'title' => $people_title, |
||
| 811 | 'href' => false, |
||
| 812 | 'meta' => array( |
||
| 813 | 'class' => 'inline-action', |
||
| 814 | ), |
||
| 815 | ) ); |
||
| 816 | |||
| 817 | $plugins_title = $this->create_menu_item_pair( |
||
| 818 | array( |
||
| 819 | 'url' => 'https://wordpress.com/plugins/' . esc_attr( $this->primary_site_slug ), |
||
| 820 | 'id' => 'wp-admin-bar-plugins', |
||
| 821 | 'label' => __( 'Plugins', 'jetpack' ), |
||
| 822 | ), |
||
| 823 | array( |
||
| 824 | 'url' => 'https://wordpress.com/plugins/browse/' . esc_attr( $this->primary_site_slug ), |
||
| 825 | 'id' => 'wp-admin-bar-plugins-add', |
||
| 826 | 'label' => _x( 'Add', 'Label for the button on the Masterbar to add a new plugin', 'jetpack' ), |
||
| 827 | ) |
||
| 828 | ); |
||
| 829 | |||
| 830 | $wp_admin_bar->add_menu( array( |
||
| 831 | 'parent' => 'configuration', |
||
| 832 | 'id' => 'plugins', |
||
| 833 | 'title' => $plugins_title, |
||
| 834 | 'href' => false, |
||
| 835 | 'meta' => array( |
||
| 836 | 'class' => 'inline-action', |
||
| 837 | ), |
||
| 838 | ) ); |
||
| 839 | |||
| 840 | if ( $this->is_automated_transfer_site() ) { |
||
| 841 | $domain_title = $this->create_menu_item_pair( |
||
| 842 | array( |
||
| 843 | 'url' => 'https://wordpress.com/domains/' . esc_attr( $this->primary_site_slug ), |
||
| 844 | 'id' => 'wp-admin-bar-domains', |
||
| 845 | 'label' => __( 'Domains', 'jetpack' ), |
||
| 846 | ), |
||
| 847 | array( |
||
| 848 | 'url' => 'https://wordpress.com/domains/add/' . esc_attr( $this->primary_site_slug ), |
||
| 849 | 'id' => 'wp-admin-bar-domains-add', |
||
| 850 | 'label' => _x( 'Add', 'Label for the button on the Masterbar to add a new domain', 'jetpack' ), |
||
| 851 | ) |
||
| 852 | ); |
||
| 853 | $wp_admin_bar->add_menu( array( |
||
| 854 | 'parent' => 'configuration', |
||
| 855 | 'id' => 'domains', |
||
| 856 | 'title' => $domain_title, |
||
| 857 | 'href' => false, |
||
| 858 | 'meta' => array( |
||
| 859 | 'class' => 'inline-action', |
||
| 860 | ), |
||
| 861 | ) ); |
||
| 862 | } |
||
| 863 | |||
| 864 | |||
| 865 | $wp_admin_bar->add_menu( array( |
||
| 866 | 'parent' => 'configuration', |
||
| 867 | 'id' => 'blog-settings', |
||
| 868 | 'title' => __( 'Settings', 'jetpack' ), |
||
| 869 | 'href' => 'https://wordpress.com/settings/general/' . esc_attr( $this->primary_site_slug ), |
||
| 870 | 'meta' => array( |
||
| 871 | 'class' => 'mb-icon', |
||
| 872 | ), |
||
| 873 | ) ); |
||
| 874 | |||
| 875 | View Code Duplication | if ( $this->is_automated_transfer_site() ) { |
|
| 876 | $wp_admin_bar->add_menu( array( |
||
| 877 | 'parent' => 'configuration', |
||
| 878 | 'id' => 'legacy-dashboard', |
||
| 879 | 'title' => __( 'WP Admin', 'jetpack' ), |
||
| 880 | 'href' => '//' . esc_attr( $this->primary_site_slug ) . '/wp-admin/', |
||
| 881 | 'meta' => array( |
||
| 882 | 'class' => 'mb-icon', |
||
| 883 | ), |
||
| 884 | ) ); |
||
| 885 | } |
||
| 886 | } |
||
| 887 | } |
||
| 888 | } |
||
| 889 |