Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Masterbar often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Masterbar, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
27 | class Masterbar { |
||
28 | /** |
||
29 | * Use for testing changes made to remotely enqueued scripts and styles on your sandbox. |
||
30 | * If not set it will default to loading the ones from WordPress.com. |
||
31 | * |
||
32 | * @var string $sandbox_url |
||
33 | */ |
||
34 | private $sandbox_url = ''; |
||
35 | |||
36 | /** |
||
37 | * Current locale. |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | private $locale; |
||
42 | |||
43 | /** |
||
44 | * Current User ID. |
||
45 | * |
||
46 | * @var int |
||
47 | */ |
||
48 | private $user_id; |
||
49 | /** |
||
50 | * WordPress.com user data of the connected user. |
||
51 | * |
||
52 | * @var array |
||
53 | */ |
||
54 | private $user_data; |
||
55 | /** |
||
56 | * WordPress.com username for the connected user. |
||
57 | * |
||
58 | * @var string |
||
59 | */ |
||
60 | private $user_login; |
||
61 | /** |
||
62 | * WordPress.com email address for the connected user. |
||
63 | * |
||
64 | * @var string |
||
65 | */ |
||
66 | private $user_email; |
||
67 | /** |
||
68 | * WordPress.com display name for the connected user. |
||
69 | * |
||
70 | * @var string |
||
71 | */ |
||
72 | private $display_name; |
||
73 | /** |
||
74 | * Site URL sanitized for usage in WordPress.com slugs. |
||
75 | * |
||
76 | * @var string |
||
77 | */ |
||
78 | private $primary_site_slug; |
||
79 | /** |
||
80 | * Text direction (ltr or rtl) based on connected WordPress.com user's interface settings. |
||
81 | * |
||
82 | * @var string |
||
83 | */ |
||
84 | private $user_text_direction; |
||
85 | /** |
||
86 | * Number of sites owned by connected WordPress.com user. |
||
87 | * |
||
88 | * @var int |
||
89 | */ |
||
90 | private $user_site_count; |
||
91 | |||
92 | /** |
||
93 | * Constructor |
||
94 | */ |
||
95 | public function __construct() { |
||
101 | |||
102 | /** |
||
103 | * Initialize our masterbar. |
||
104 | */ |
||
105 | public function init() { |
||
179 | |||
180 | /** |
||
181 | * Log out from WordPress.com when logging out of the local site. |
||
182 | * |
||
183 | * @param string $redirect_to The redirect destination URL. |
||
184 | * @param string $requested_redirect_to The requested redirect destination URL passed as a parameter. |
||
185 | * @param WP_User $user The WP_User object for the user that's logging out. |
||
186 | */ |
||
187 | public function maybe_logout_user_from_wpcom( $redirect_to, $requested_redirect_to, $user ) { |
||
226 | |||
227 | /** |
||
228 | * Adds CSS classes to admin body tag. |
||
229 | * |
||
230 | * @since 5.1 |
||
231 | * |
||
232 | * @param string $admin_body_classes CSS classes that will be added. |
||
233 | * |
||
234 | * @return string |
||
235 | */ |
||
236 | public function admin_body_class( $admin_body_classes ) { |
||
239 | |||
240 | /** |
||
241 | * Remove the default Admin Bar CSS. |
||
242 | */ |
||
243 | public function remove_core_styles() { |
||
252 | |||
253 | /** |
||
254 | * Check if the user settings are for an RTL language or not. |
||
255 | */ |
||
256 | public function is_rtl() { |
||
259 | |||
260 | /** |
||
261 | * Enqueue our own CSS and JS to display our custom admin bar. |
||
262 | */ |
||
263 | public function add_styles_and_scripts() { |
||
307 | |||
308 | /** |
||
309 | * Get base URL where our CSS and JS will come from. |
||
310 | * |
||
311 | * @param string $file File path for a static resource. |
||
312 | */ |
||
313 | private function wpcom_static_url( $file ) { |
||
324 | |||
325 | /** |
||
326 | * Remove the default admin bar items and replace it with our own admin bar. |
||
327 | */ |
||
328 | public function replace_core_masterbar() { |
||
338 | |||
339 | /** |
||
340 | * Remove all existing toolbar entries from core Masterbar |
||
341 | * |
||
342 | * @param WP_Admin_Bar $wp_admin_bar Admin Bar instance. |
||
343 | */ |
||
344 | public function clear_core_masterbar( $wp_admin_bar ) { |
||
349 | |||
350 | /** |
||
351 | * Add entries corresponding to WordPress.com Masterbar |
||
352 | * |
||
353 | * @param WP_Admin_Bar $wp_admin_bar Admin Bar instance. |
||
354 | */ |
||
355 | public function build_wpcom_masterbar( $wp_admin_bar ) { |
||
381 | |||
382 | /** |
||
383 | * Get WordPress.com current locale name. |
||
384 | */ |
||
385 | public function get_locale() { |
||
403 | |||
404 | /** |
||
405 | * Add the Notifications menu item. |
||
406 | * |
||
407 | * @param WP_Admin_Bar $wp_admin_bar Admin Bar instance. |
||
408 | */ |
||
409 | public function add_notifications( $wp_admin_bar ) { |
||
432 | |||
433 | /** |
||
434 | * Add the "Reader" menu item in the root default group. |
||
435 | * |
||
436 | * @param WP_Admin_Bar $wp_admin_bar Admin Bar instance. |
||
437 | */ |
||
438 | public function add_reader_submenu( $wp_admin_bar ) { |
||
530 | |||
531 | /** |
||
532 | * Merge 2 menu items together into 2 link tags. |
||
533 | * |
||
534 | * @param array $primary Array of menu information. |
||
535 | * @param array $secondary Array of menu information. |
||
536 | */ |
||
537 | public function create_menu_item_pair( $primary, $secondary ) { |
||
546 | |||
547 | /** |
||
548 | * Create a link tag based on information about a menu item. |
||
549 | * |
||
550 | * @param string $class Menu item CSS class. |
||
551 | * @param string $url URL you go to when clicking on the menu item. |
||
552 | * @param string $label Menu item title. |
||
553 | * @param string $id Menu item slug. |
||
554 | */ |
||
555 | public function create_menu_item_anchor( $class, $url, $label, $id ) { |
||
558 | |||
559 | /** |
||
560 | * Add Secondary groups for submenu items. |
||
561 | * |
||
562 | * @param WP_Admin_Bar $wp_admin_bar Admin Bar instance. |
||
563 | */ |
||
564 | public function wpcom_adminbar_add_secondary_groups( $wp_admin_bar ) { |
||
593 | |||
594 | /** |
||
595 | * Add User info menu item. |
||
596 | * |
||
597 | * @param WP_Admin_Bar $wp_admin_bar Admin Bar instance. |
||
598 | */ |
||
599 | public function add_me_submenu( $wp_admin_bar ) { |
||
777 | |||
778 | /** |
||
779 | * Add Write Menu item. |
||
780 | * |
||
781 | * @param WP_Admin_Bar $wp_admin_bar Admin Bar instance. |
||
782 | */ |
||
783 | public function add_write_button( $wp_admin_bar ) { |
||
811 | |||
812 | /** |
||
813 | * Add the "My Site" menu item in the root default group. |
||
814 | * |
||
815 | * @param WP_Admin_Bar $wp_admin_bar Admin Bar instance. |
||
816 | */ |
||
817 | public function add_my_sites_submenu( $wp_admin_bar ) { |
||
818 | $current_user = wp_get_current_user(); |
||
819 | |||
820 | $blog_name = get_bloginfo( 'name' ); |
||
821 | if ( empty( $blog_name ) ) { |
||
822 | $blog_name = $this->primary_site_slug; |
||
823 | } |
||
824 | |||
825 | if ( mb_strlen( $blog_name ) > 20 ) { |
||
826 | $blog_name = mb_substr( html_entity_decode( $blog_name, ENT_QUOTES ), 0, 20 ) . '…'; |
||
827 | } |
||
828 | |||
829 | $wp_admin_bar->add_menu( |
||
830 | array( |
||
831 | 'parent' => 'root-default', |
||
832 | 'id' => 'blog', |
||
833 | 'title' => _n( 'My Site', 'My Sites', $this->user_site_count, 'jetpack' ), |
||
834 | 'href' => 'https://wordpress.com/sites/' . $this->primary_site_url, |
||
835 | 'meta' => array( |
||
836 | 'class' => 'my-sites mb-trackable', |
||
837 | ), |
||
838 | ) |
||
839 | ); |
||
840 | |||
841 | /** This filter is documented in modules/masterbar.php */ |
||
842 | if ( apply_filters( 'jetpack_load_admin_menu_class', false ) ) { |
||
843 | return; |
||
844 | } |
||
845 | |||
846 | if ( $this->user_site_count > 1 ) { |
||
847 | $wp_admin_bar->add_menu( |
||
848 | array( |
||
849 | 'parent' => 'blog', |
||
850 | 'id' => 'switch-site', |
||
851 | 'title' => esc_html__( 'Switch Site', 'jetpack' ), |
||
852 | 'href' => Redirect::get_url( 'calypso-sites' ), |
||
853 | ) |
||
854 | ); |
||
855 | } else { |
||
856 | $wp_admin_bar->add_menu( |
||
857 | array( |
||
858 | 'parent' => 'blog', |
||
859 | 'id' => 'new-site', |
||
860 | 'title' => esc_html__( '+ Add New WordPress', 'jetpack' ), |
||
861 | 'href' => Redirect::get_url( 'calypso-start', array( 'query' => 'ref=admin-bar-logged-in' ) ), |
||
862 | ) |
||
863 | ); |
||
864 | } |
||
865 | |||
866 | if ( is_user_member_of_blog( $current_user->ID ) ) { |
||
867 | $blavatar = ''; |
||
868 | $class = 'current-site'; |
||
869 | |||
870 | if ( has_site_icon() ) { |
||
871 | $src = get_site_icon_url(); |
||
872 | $blavatar = '<img class="avatar" src="' . esc_attr( $src ) . '" alt="Current site avatar">'; |
||
873 | $class = 'has-blavatar'; |
||
874 | } |
||
875 | |||
876 | $blog_info = '<div class="ab-site-icon">' . $blavatar . '</div>'; |
||
877 | $blog_info .= '<span class="ab-site-title">' . esc_html( $blog_name ) . '</span>'; |
||
878 | $blog_info .= '<span class="ab-site-description">' . esc_html( $this->primary_site_url ) . '</span>'; |
||
879 | |||
880 | $wp_admin_bar->add_menu( |
||
881 | array( |
||
882 | 'parent' => 'blog', |
||
883 | 'id' => 'blog-info', |
||
884 | 'title' => $blog_info, |
||
885 | 'href' => esc_url( trailingslashit( $this->primary_site_url ) ), |
||
886 | 'meta' => array( |
||
887 | 'class' => $class, |
||
888 | ), |
||
889 | ) |
||
890 | ); |
||
891 | } |
||
892 | |||
893 | // Site Preview. |
||
894 | if ( is_admin() ) { |
||
895 | $wp_admin_bar->add_menu( |
||
896 | array( |
||
897 | 'parent' => 'blog', |
||
898 | 'id' => 'site-view', |
||
899 | 'title' => __( 'View Site', 'jetpack' ), |
||
900 | 'href' => home_url(), |
||
901 | 'meta' => array( |
||
902 | 'class' => 'mb-icon', |
||
903 | 'target' => '_blank', |
||
904 | ), |
||
905 | ) |
||
906 | ); |
||
907 | } |
||
908 | |||
909 | $this->add_my_home_submenu_item( $wp_admin_bar ); |
||
910 | |||
911 | // Stats. |
||
912 | View Code Duplication | if ( Jetpack::is_module_active( 'stats' ) && current_user_can( 'view_stats' ) ) { |
|
913 | $wp_admin_bar->add_menu( |
||
914 | array( |
||
915 | 'parent' => 'blog', |
||
916 | 'id' => 'blog-stats', |
||
917 | 'title' => esc_html__( 'Stats', 'jetpack' ), |
||
918 | 'href' => Redirect::get_url( 'calypso-stats' ), |
||
919 | 'meta' => array( |
||
920 | 'class' => 'mb-icon', |
||
921 | ), |
||
922 | ) |
||
923 | ); |
||
924 | } |
||
925 | |||
926 | if ( current_user_can( 'manage_options' ) ) { |
||
927 | $wp_admin_bar->add_menu( |
||
928 | array( |
||
929 | 'parent' => 'blog', |
||
930 | 'id' => 'activity', |
||
931 | 'title' => esc_html__( 'Activity', 'jetpack' ), |
||
932 | 'href' => Redirect::get_url( 'calypso-activity-log' ), |
||
933 | 'meta' => array( |
||
934 | 'class' => 'mb-icon', |
||
935 | ), |
||
936 | ) |
||
937 | ); |
||
938 | } |
||
939 | |||
940 | // Add Calypso plans link and plan type indicator. |
||
941 | if ( is_user_member_of_blog( $current_user->ID ) && current_user_can( 'manage_options' ) ) { |
||
942 | $plans_url = Redirect::get_url( 'calypso-plans' ); |
||
943 | $label = esc_html__( 'Plan', 'jetpack' ); |
||
944 | $plan = Jetpack_Plan::get(); |
||
945 | |||
946 | $plan_title = $this->create_menu_item_pair( |
||
947 | array( |
||
948 | 'url' => $plans_url, |
||
949 | 'id' => 'wp-admin-bar-plan', |
||
950 | 'label' => $label, |
||
951 | ), |
||
952 | array( |
||
953 | 'url' => $plans_url, |
||
954 | 'id' => 'wp-admin-bar-plan-badge', |
||
955 | 'label' => ! empty( $plan['product_name_short'] ) ? $plan['product_name_short'] : esc_html__( 'Free', 'jetpack' ), |
||
956 | ) |
||
957 | ); |
||
958 | |||
959 | $wp_admin_bar->add_menu( |
||
960 | array( |
||
961 | 'parent' => 'blog', |
||
962 | 'id' => 'plan', |
||
963 | 'title' => $plan_title, |
||
964 | 'meta' => array( |
||
965 | 'class' => 'inline-action', |
||
966 | ), |
||
967 | ) |
||
968 | ); |
||
969 | } |
||
970 | |||
971 | // Publish group. |
||
972 | $wp_admin_bar->add_group( |
||
973 | array( |
||
974 | 'parent' => 'blog', |
||
975 | 'id' => 'publish', |
||
976 | ) |
||
977 | ); |
||
978 | |||
979 | // Publish header. |
||
980 | $wp_admin_bar->add_menu( |
||
981 | array( |
||
982 | 'parent' => 'publish', |
||
983 | 'id' => 'publish-header', |
||
984 | 'title' => esc_html_x( 'Manage', 'admin bar menu group label', 'jetpack' ), |
||
985 | 'meta' => array( |
||
986 | 'class' => 'ab-submenu-header', |
||
987 | ), |
||
988 | ) |
||
989 | ); |
||
990 | |||
991 | // Pages. |
||
992 | $pages_title = $this->create_menu_item_pair( |
||
993 | array( |
||
994 | 'url' => Redirect::get_url( 'calypso-edit-pages' ), |
||
995 | 'id' => 'wp-admin-bar-edit-page', |
||
996 | 'label' => esc_html__( 'Site Pages', 'jetpack' ), |
||
997 | ), |
||
998 | array( |
||
999 | 'url' => Redirect::get_url( 'calypso-edit-page' ), |
||
1000 | 'id' => 'wp-admin-bar-new-page-badge', |
||
1001 | 'label' => esc_html_x( 'Add', 'admin bar menu new item label', 'jetpack' ), |
||
1002 | ) |
||
1003 | ); |
||
1004 | |||
1005 | if ( ! current_user_can( 'edit_pages' ) ) { |
||
1006 | $pages_title = $this->create_menu_item_anchor( |
||
1007 | 'ab-item ab-primary mb-icon', |
||
1008 | Redirect::get_url( 'calypso-edit-pages' ), |
||
1009 | esc_html__( 'Site Pages', 'jetpack' ), |
||
1010 | 'wp-admin-bar-edit-page' |
||
1011 | ); |
||
1012 | } |
||
1013 | |||
1014 | $wp_admin_bar->add_menu( |
||
1015 | array( |
||
1016 | 'parent' => 'publish', |
||
1017 | 'id' => 'new-page', |
||
1018 | 'title' => $pages_title, |
||
1019 | 'meta' => array( |
||
1020 | 'class' => 'inline-action', |
||
1021 | ), |
||
1022 | ) |
||
1023 | ); |
||
1024 | |||
1025 | // Blog Posts. |
||
1026 | $posts_title = $this->create_menu_item_pair( |
||
1027 | array( |
||
1028 | 'url' => Redirect::get_url( 'calypso-edit-posts' ), |
||
1029 | 'id' => 'wp-admin-bar-edit-post', |
||
1030 | 'label' => esc_html__( 'Blog Posts', 'jetpack' ), |
||
1031 | ), |
||
1032 | array( |
||
1033 | 'url' => Redirect::get_url( 'calypso-edit-post' ), |
||
1034 | 'id' => 'wp-admin-bar-new-post-badge', |
||
1035 | 'label' => esc_html_x( 'Add', 'admin bar menu new item label', 'jetpack' ), |
||
1036 | ) |
||
1037 | ); |
||
1038 | |||
1039 | if ( ! current_user_can( 'edit_posts' ) ) { |
||
1040 | $posts_title = $this->create_menu_item_anchor( |
||
1041 | 'ab-item ab-primary mb-icon', |
||
1042 | Redirect::get_url( 'calypso-edit-posts' ), |
||
1043 | esc_html__( 'Blog Posts', 'jetpack' ), |
||
1044 | 'wp-admin-bar-edit-post' |
||
1045 | ); |
||
1046 | } |
||
1047 | |||
1048 | $wp_admin_bar->add_menu( |
||
1049 | array( |
||
1050 | 'parent' => 'publish', |
||
1051 | 'id' => 'new-post', |
||
1052 | 'title' => $posts_title, |
||
1053 | 'meta' => array( |
||
1054 | 'class' => 'inline-action mb-trackable', |
||
1055 | ), |
||
1056 | ) |
||
1057 | ); |
||
1058 | |||
1059 | // Comments. |
||
1060 | if ( current_user_can( 'moderate_comments' ) ) { |
||
1061 | $wp_admin_bar->add_menu( |
||
1062 | array( |
||
1063 | 'parent' => 'publish', |
||
1064 | 'id' => 'comments', |
||
1065 | 'title' => __( 'Comments', 'jetpack' ), |
||
1066 | 'href' => Redirect::get_url( 'calypso-comments' ), |
||
1067 | 'meta' => array( |
||
1068 | 'class' => 'mb-icon', |
||
1069 | ), |
||
1070 | ) |
||
1071 | ); |
||
1072 | } |
||
1073 | |||
1074 | // Testimonials. |
||
1075 | View Code Duplication | if ( Jetpack::is_module_active( 'custom-content-types' ) && get_option( 'jetpack_testimonial' ) ) { |
|
1076 | $testimonials_title = $this->create_menu_item_pair( |
||
1077 | array( |
||
1078 | 'url' => Redirect::get_url( 'calypso-list-jetpack-testimonial' ), |
||
1079 | 'id' => 'wp-admin-bar-edit-testimonial', |
||
1080 | 'label' => esc_html__( 'Testimonials', 'jetpack' ), |
||
1081 | ), |
||
1082 | array( |
||
1083 | 'url' => Redirect::get_url( 'calypso-edit-jetpack-testimonial' ), |
||
1084 | 'id' => 'wp-admin-bar-new-testimonial', |
||
1085 | 'label' => esc_html_x( 'Add', 'Button label for adding a new item via the toolbar menu', 'jetpack' ), |
||
1086 | ) |
||
1087 | ); |
||
1088 | |||
1089 | if ( ! current_user_can( 'edit_pages' ) ) { |
||
1090 | $testimonials_title = $this->create_menu_item_anchor( |
||
1091 | 'ab-item ab-primary mb-icon', |
||
1092 | Redirect::get_url( 'calypso-list-jetpack-testimonial' ), |
||
1093 | esc_html__( 'Testimonials', 'jetpack' ), |
||
1094 | 'wp-admin-bar-edit-testimonial' |
||
1095 | ); |
||
1096 | } |
||
1097 | |||
1098 | $wp_admin_bar->add_menu( |
||
1099 | array( |
||
1100 | 'parent' => 'publish', |
||
1101 | 'id' => 'new-jetpack-testimonial', |
||
1102 | 'title' => $testimonials_title, |
||
1103 | 'meta' => array( |
||
1104 | 'class' => 'inline-action', |
||
1105 | ), |
||
1106 | ) |
||
1107 | ); |
||
1108 | } |
||
1109 | |||
1110 | // Portfolio. |
||
1111 | View Code Duplication | if ( Jetpack::is_module_active( 'custom-content-types' ) && get_option( 'jetpack_portfolio' ) ) { |
|
1112 | $portfolios_title = $this->create_menu_item_pair( |
||
1113 | array( |
||
1114 | 'url' => Redirect::get_url( 'calypso-list-jetpack-portfolio' ), |
||
1115 | 'id' => 'wp-admin-bar-edit-portfolio', |
||
1116 | 'label' => esc_html__( 'Portfolio', 'jetpack' ), |
||
1117 | ), |
||
1118 | array( |
||
1119 | 'url' => Redirect::get_url( 'calypso-edit-jetpack-portfolio' ), |
||
1120 | 'id' => 'wp-admin-bar-new-portfolio', |
||
1121 | 'label' => esc_html_x( 'Add', 'Button label for adding a new item via the toolbar menu', 'jetpack' ), |
||
1122 | ) |
||
1123 | ); |
||
1124 | |||
1125 | if ( ! current_user_can( 'edit_pages' ) ) { |
||
1126 | $portfolios_title = $this->create_menu_item_anchor( |
||
1127 | 'ab-item ab-primary mb-icon', |
||
1128 | Redirect::get_url( 'calypso-list-jetpack-portfolio' ), |
||
1129 | esc_html__( 'Portfolio', 'jetpack' ), |
||
1130 | 'wp-admin-bar-edit-portfolio' |
||
1131 | ); |
||
1132 | } |
||
1133 | |||
1134 | $wp_admin_bar->add_menu( |
||
1135 | array( |
||
1136 | 'parent' => 'publish', |
||
1137 | 'id' => 'new-jetpack-portfolio', |
||
1138 | 'title' => $portfolios_title, |
||
1139 | 'meta' => array( |
||
1140 | 'class' => 'inline-action', |
||
1141 | ), |
||
1142 | ) |
||
1143 | ); |
||
1144 | } |
||
1145 | |||
1146 | if ( current_user_can( 'edit_theme_options' ) ) { |
||
1147 | // Look and Feel group. |
||
1148 | $wp_admin_bar->add_group( |
||
1149 | array( |
||
1150 | 'parent' => 'blog', |
||
1151 | 'id' => 'look-and-feel', |
||
1152 | ) |
||
1153 | ); |
||
1154 | |||
1155 | // Look and Feel header. |
||
1156 | $wp_admin_bar->add_menu( |
||
1157 | array( |
||
1158 | 'parent' => 'look-and-feel', |
||
1159 | 'id' => 'look-and-feel-header', |
||
1160 | 'title' => esc_html_x( 'Personalize', 'admin bar menu group label', 'jetpack' ), |
||
1161 | 'meta' => array( |
||
1162 | 'class' => 'ab-submenu-header', |
||
1163 | ), |
||
1164 | ) |
||
1165 | ); |
||
1166 | |||
1167 | if ( is_admin() ) { |
||
1168 | // In wp-admin the `return` query arg will return to that page after closing the Customizer. |
||
1169 | $customizer_url = add_query_arg( |
||
1170 | array( |
||
1171 | 'return' => rawurlencode( site_url( $_SERVER['REQUEST_URI'] ) ), |
||
1172 | ), |
||
1173 | wp_customize_url() |
||
1174 | ); |
||
1175 | } else { |
||
1176 | /* |
||
1177 | * On the frontend the `url` query arg will load that page in the Customizer |
||
1178 | * and also return to it after closing |
||
1179 | * non-home URLs won't work unless we undo domain mapping |
||
1180 | * since the Customizer preview is unmapped to always have HTTPS. |
||
1181 | */ |
||
1182 | $current_page = '//' . $this->primary_site_slug . $_SERVER['REQUEST_URI']; |
||
1183 | $customizer_url = add_query_arg( array( 'url' => rawurlencode( $current_page ) ), wp_customize_url() ); |
||
1184 | } |
||
1185 | |||
1186 | $theme_title = $this->create_menu_item_pair( |
||
1187 | array( |
||
1188 | 'url' => $customizer_url, |
||
1189 | 'id' => 'wp-admin-bar-cmz', |
||
1190 | 'label' => esc_html_x( 'Customize', 'admin bar customize item label', 'jetpack' ), |
||
1191 | ), |
||
1192 | array( |
||
1193 | 'url' => Redirect::get_url( 'calypso-themes' ), |
||
1194 | 'id' => 'wp-admin-bar-themes', |
||
1195 | 'label' => esc_html__( 'Themes', 'jetpack' ), |
||
1196 | ) |
||
1197 | ); |
||
1198 | $meta = array( |
||
1199 | 'class' => 'mb-icon', |
||
1200 | 'class' => 'inline-action', |
||
1201 | ); |
||
1202 | $href = false; |
||
1203 | |||
1204 | $wp_admin_bar->add_menu( |
||
1205 | array( |
||
1206 | 'parent' => 'look-and-feel', |
||
1207 | 'id' => 'themes', |
||
1208 | 'title' => $theme_title, |
||
1209 | 'href' => $href, |
||
1210 | 'meta' => $meta, |
||
1211 | ) |
||
1212 | ); |
||
1213 | } |
||
1214 | |||
1215 | if ( current_user_can( 'manage_options' ) ) { |
||
1216 | // Configuration group. |
||
1217 | $wp_admin_bar->add_group( |
||
1218 | array( |
||
1219 | 'parent' => 'blog', |
||
1220 | 'id' => 'configuration', |
||
1221 | ) |
||
1222 | ); |
||
1223 | |||
1224 | // Configuration header. |
||
1225 | $wp_admin_bar->add_menu( |
||
1226 | array( |
||
1227 | 'parent' => 'configuration', |
||
1228 | 'id' => 'configuration-header', |
||
1229 | 'title' => esc_html_x( 'Configure', 'admin bar menu group label', 'jetpack' ), |
||
1230 | 'meta' => array( |
||
1231 | 'class' => 'ab-submenu-header', |
||
1232 | ), |
||
1233 | ) |
||
1234 | ); |
||
1235 | |||
1236 | View Code Duplication | if ( Jetpack::is_module_active( 'publicize' ) || Jetpack::is_module_active( 'sharedaddy' ) ) { |
|
1237 | $wp_admin_bar->add_menu( |
||
1238 | array( |
||
1239 | 'parent' => 'configuration', |
||
1240 | 'id' => 'sharing', |
||
1241 | 'title' => esc_html__( 'Sharing', 'jetpack' ), |
||
1242 | 'href' => Redirect::get_url( 'calypso-sharing' ), |
||
1243 | 'meta' => array( |
||
1244 | 'class' => 'mb-icon', |
||
1245 | ), |
||
1246 | ) |
||
1247 | ); |
||
1248 | } |
||
1249 | |||
1250 | $people_title = $this->create_menu_item_pair( |
||
1251 | array( |
||
1252 | 'url' => Redirect::get_url( 'calypso-people-team' ), |
||
1253 | 'id' => 'wp-admin-bar-people', |
||
1254 | 'label' => esc_html__( 'People', 'jetpack' ), |
||
1255 | ), |
||
1256 | array( |
||
1257 | 'url' => admin_url( 'user-new.php' ), |
||
1258 | 'id' => 'wp-admin-bar-people-add', |
||
1259 | 'label' => esc_html_x( 'Add', 'admin bar people item label', 'jetpack' ), |
||
1260 | ) |
||
1261 | ); |
||
1262 | |||
1263 | $wp_admin_bar->add_menu( |
||
1264 | array( |
||
1265 | 'parent' => 'configuration', |
||
1266 | 'id' => 'users-toolbar', |
||
1267 | 'title' => $people_title, |
||
1268 | 'href' => false, |
||
1269 | 'meta' => array( |
||
1270 | 'class' => 'inline-action', |
||
1271 | ), |
||
1272 | ) |
||
1273 | ); |
||
1274 | |||
1275 | $plugins_title = $this->create_menu_item_pair( |
||
1276 | array( |
||
1277 | 'url' => Redirect::get_url( 'calypso-plugins' ), |
||
1278 | 'id' => 'wp-admin-bar-plugins', |
||
1279 | 'label' => esc_html__( 'Plugins', 'jetpack' ), |
||
1280 | ), |
||
1281 | array( |
||
1282 | 'url' => Redirect::get_url( 'calypso-plugins-manage' ), |
||
1283 | 'id' => 'wp-admin-bar-plugins-add', |
||
1284 | 'label' => esc_html_x( 'Manage', 'Label for the button on the Masterbar to manage plugins', 'jetpack' ), |
||
1285 | ) |
||
1286 | ); |
||
1287 | |||
1288 | $wp_admin_bar->add_menu( |
||
1289 | array( |
||
1290 | 'parent' => 'configuration', |
||
1291 | 'id' => 'plugins', |
||
1292 | 'title' => $plugins_title, |
||
1293 | 'href' => false, |
||
1294 | 'meta' => array( |
||
1295 | 'class' => 'inline-action', |
||
1296 | ), |
||
1297 | ) |
||
1298 | ); |
||
1299 | |||
1300 | if ( jetpack_is_atomic_site() ) { |
||
1301 | $domain_title = $this->create_menu_item_pair( |
||
1302 | array( |
||
1303 | 'url' => Redirect::get_url( 'calypso-domains' ), |
||
1304 | 'id' => 'wp-admin-bar-domains', |
||
1305 | 'label' => esc_html__( 'Domains', 'jetpack' ), |
||
1306 | ), |
||
1307 | array( |
||
1308 | 'url' => Redirect::get_url( 'calypso-domains-add' ), |
||
1309 | 'id' => 'wp-admin-bar-domains-add', |
||
1310 | 'label' => esc_html_x( 'Add', 'Label for the button on the Masterbar to add a new domain', 'jetpack' ), |
||
1311 | ) |
||
1312 | ); |
||
1313 | $wp_admin_bar->add_menu( |
||
1314 | array( |
||
1315 | 'parent' => 'configuration', |
||
1316 | 'id' => 'domains', |
||
1317 | 'title' => $domain_title, |
||
1318 | 'href' => false, |
||
1319 | 'meta' => array( |
||
1320 | 'class' => 'inline-action', |
||
1321 | ), |
||
1322 | ) |
||
1323 | ); |
||
1324 | } |
||
1325 | |||
1326 | $wp_admin_bar->add_menu( |
||
1327 | array( |
||
1328 | 'parent' => 'configuration', |
||
1329 | 'id' => 'blog-settings', |
||
1330 | 'title' => esc_html__( 'Settings', 'jetpack' ), |
||
1331 | 'href' => Redirect::get_url( 'calypso-settings-general' ), |
||
1332 | 'meta' => array( |
||
1333 | 'class' => 'mb-icon', |
||
1334 | ), |
||
1335 | ) |
||
1336 | ); |
||
1337 | |||
1338 | if ( ! is_admin() ) { |
||
1339 | $wp_admin_bar->add_menu( |
||
1340 | array( |
||
1341 | 'parent' => 'configuration', |
||
1342 | 'id' => 'legacy-dashboard', |
||
1343 | 'title' => esc_html__( 'Dashboard', 'jetpack' ), |
||
1344 | 'href' => admin_url(), |
||
1345 | 'meta' => array( |
||
1346 | 'class' => 'mb-icon', |
||
1347 | ), |
||
1348 | ) |
||
1349 | ); |
||
1350 | } |
||
1351 | |||
1352 | // Restore dashboard menu toggle that is needed on mobile views. |
||
1353 | if ( is_admin() ) { |
||
1354 | $wp_admin_bar->add_menu( |
||
1355 | array( |
||
1356 | 'id' => 'menu-toggle', |
||
1357 | 'title' => '<span class="ab-icon"></span><span class="screen-reader-text">' . esc_html__( 'Menu', 'jetpack' ) . '</span>', |
||
1358 | 'href' => '#', |
||
1359 | ) |
||
1360 | ); |
||
1361 | } |
||
1362 | |||
1363 | /** |
||
1364 | * Fires when menu items are added to the masterbar "My Sites" menu. |
||
1365 | * |
||
1366 | * @since 5.4.0 |
||
1367 | */ |
||
1368 | do_action( 'jetpack_masterbar' ); |
||
1369 | } |
||
1370 | } |
||
1371 | |||
1372 | /** |
||
1373 | * Adds "My Home" submenu item to sites that are eligible. |
||
1374 | * |
||
1375 | * @param WP_Admin_Bar $wp_admin_bar Admin Bar instance. |
||
1376 | * @return void |
||
1377 | */ |
||
1378 | private function add_my_home_submenu_item( &$wp_admin_bar ) { |
||
1395 | } |
||
1396 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..