| Conditions | 29 |
| Paths | > 20000 |
| Total Lines | 549 |
| Lines | 94 |
| Ratio | 17.12 % |
| 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 // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
||
| 803 | public function add_my_sites_submenu( $wp_admin_bar ) { |
||
| 804 | $current_user = wp_get_current_user(); |
||
| 805 | |||
| 806 | $blog_name = get_bloginfo( 'name' ); |
||
| 807 | if ( empty( $blog_name ) ) { |
||
| 808 | $blog_name = $this->primary_site_slug; |
||
| 809 | } |
||
| 810 | |||
| 811 | if ( mb_strlen( $blog_name ) > 20 ) { |
||
| 812 | $blog_name = mb_substr( html_entity_decode( $blog_name, ENT_QUOTES ), 0, 20 ) . '…'; |
||
| 813 | } |
||
| 814 | |||
| 815 | $wp_admin_bar->add_menu( |
||
| 816 | array( |
||
| 817 | 'parent' => 'root-default', |
||
| 818 | 'id' => 'blog', |
||
| 819 | 'title' => _n( 'My Site', 'My Sites', $this->user_site_count, 'jetpack' ), |
||
| 820 | 'href' => '#', |
||
| 821 | 'meta' => array( |
||
| 822 | 'class' => 'my-sites mb-trackable', |
||
| 823 | ), |
||
| 824 | ) |
||
| 825 | ); |
||
| 826 | |||
| 827 | if ( $this->user_site_count > 1 ) { |
||
| 828 | $wp_admin_bar->add_menu( |
||
| 829 | array( |
||
| 830 | 'parent' => 'blog', |
||
| 831 | 'id' => 'switch-site', |
||
| 832 | 'title' => esc_html__( 'Switch Site', 'jetpack' ), |
||
| 833 | 'href' => Redirect::get_url( 'calypso-sites' ), |
||
| 834 | ) |
||
| 835 | ); |
||
| 836 | } else { |
||
| 837 | $wp_admin_bar->add_menu( |
||
| 838 | array( |
||
| 839 | 'parent' => 'blog', |
||
| 840 | 'id' => 'new-site', |
||
| 841 | 'title' => esc_html__( '+ Add New WordPress', 'jetpack' ), |
||
| 842 | 'href' => Redirect::get_url( 'calypso-start', array( 'query' => 'ref=admin-bar-logged-in' ) ), |
||
| 843 | ) |
||
| 844 | ); |
||
| 845 | } |
||
| 846 | |||
| 847 | if ( is_user_member_of_blog( $current_user->ID ) ) { |
||
| 848 | $blavatar = ''; |
||
| 849 | $class = 'current-site'; |
||
| 850 | |||
| 851 | if ( has_site_icon() ) { |
||
| 852 | $src = get_site_icon_url(); |
||
| 853 | $blavatar = '<img class="avatar" src="' . esc_attr( $src ) . '" alt="Current site avatar">'; |
||
| 854 | $class = 'has-blavatar'; |
||
| 855 | } |
||
| 856 | |||
| 857 | $blog_info = '<div class="ab-site-icon">' . $blavatar . '</div>'; |
||
| 858 | $blog_info .= '<span class="ab-site-title">' . esc_html( $blog_name ) . '</span>'; |
||
| 859 | $blog_info .= '<span class="ab-site-description">' . esc_html( $this->primary_site_url ) . '</span>'; |
||
| 860 | |||
| 861 | $wp_admin_bar->add_menu( |
||
| 862 | array( |
||
| 863 | 'parent' => 'blog', |
||
| 864 | 'id' => 'blog-info', |
||
| 865 | 'title' => $blog_info, |
||
| 866 | 'href' => esc_url( trailingslashit( $this->primary_site_url ) ), |
||
| 867 | 'meta' => array( |
||
| 868 | 'class' => $class, |
||
| 869 | ), |
||
| 870 | ) |
||
| 871 | ); |
||
| 872 | } |
||
| 873 | |||
| 874 | // Site Preview. |
||
| 875 | if ( is_admin() ) { |
||
| 876 | $wp_admin_bar->add_menu( |
||
| 877 | array( |
||
| 878 | 'parent' => 'blog', |
||
| 879 | 'id' => 'site-view', |
||
| 880 | 'title' => __( 'View Site', 'jetpack' ), |
||
| 881 | 'href' => home_url(), |
||
| 882 | 'meta' => array( |
||
| 883 | 'class' => 'mb-icon', |
||
| 884 | 'target' => '_blank', |
||
| 885 | ), |
||
| 886 | ) |
||
| 887 | ); |
||
| 888 | } |
||
| 889 | |||
| 890 | $this->add_my_home_submenu_item( $wp_admin_bar ); |
||
| 891 | |||
| 892 | // Stats. |
||
| 893 | View Code Duplication | if ( Jetpack::is_module_active( 'stats' ) && current_user_can( 'view_stats' ) ) { |
|
| 894 | $wp_admin_bar->add_menu( |
||
| 895 | array( |
||
| 896 | 'parent' => 'blog', |
||
| 897 | 'id' => 'blog-stats', |
||
| 898 | 'title' => esc_html__( 'Stats', 'jetpack' ), |
||
| 899 | 'href' => Redirect::get_url( 'calypso-stats' ), |
||
| 900 | 'meta' => array( |
||
| 901 | 'class' => 'mb-icon', |
||
| 902 | ), |
||
| 903 | ) |
||
| 904 | ); |
||
| 905 | } |
||
| 906 | |||
| 907 | if ( current_user_can( 'manage_options' ) ) { |
||
| 908 | $wp_admin_bar->add_menu( |
||
| 909 | array( |
||
| 910 | 'parent' => 'blog', |
||
| 911 | 'id' => 'activity', |
||
| 912 | 'title' => esc_html__( 'Activity', 'jetpack' ), |
||
| 913 | 'href' => Redirect::get_url( 'calypso-activity-log' ), |
||
| 914 | 'meta' => array( |
||
| 915 | 'class' => 'mb-icon', |
||
| 916 | ), |
||
| 917 | ) |
||
| 918 | ); |
||
| 919 | } |
||
| 920 | |||
| 921 | // Add Calypso plans link and plan type indicator. |
||
| 922 | if ( is_user_member_of_blog( $current_user->ID ) && current_user_can( 'manage_options' ) ) { |
||
| 923 | $plans_url = Redirect::get_url( 'calypso-plans' ); |
||
| 924 | $label = esc_html__( 'Plan', 'jetpack' ); |
||
| 925 | $plan = Jetpack_Plan::get(); |
||
| 926 | |||
| 927 | $plan_title = $this->create_menu_item_pair( |
||
| 928 | array( |
||
| 929 | 'url' => $plans_url, |
||
| 930 | 'id' => 'wp-admin-bar-plan', |
||
| 931 | 'label' => $label, |
||
| 932 | ), |
||
| 933 | array( |
||
| 934 | 'url' => $plans_url, |
||
| 935 | 'id' => 'wp-admin-bar-plan-badge', |
||
| 936 | 'label' => $plan['product_name_short'], |
||
| 937 | ) |
||
| 938 | ); |
||
| 939 | |||
| 940 | $wp_admin_bar->add_menu( |
||
| 941 | array( |
||
| 942 | 'parent' => 'blog', |
||
| 943 | 'id' => 'plan', |
||
| 944 | 'title' => $plan_title, |
||
| 945 | 'meta' => array( |
||
| 946 | 'class' => 'inline-action', |
||
| 947 | ), |
||
| 948 | ) |
||
| 949 | ); |
||
| 950 | } |
||
| 951 | |||
| 952 | // Publish group. |
||
| 953 | $wp_admin_bar->add_group( |
||
| 954 | array( |
||
| 955 | 'parent' => 'blog', |
||
| 956 | 'id' => 'publish', |
||
| 957 | ) |
||
| 958 | ); |
||
| 959 | |||
| 960 | // Publish header. |
||
| 961 | $wp_admin_bar->add_menu( |
||
| 962 | array( |
||
| 963 | 'parent' => 'publish', |
||
| 964 | 'id' => 'publish-header', |
||
| 965 | 'title' => esc_html_x( 'Manage', 'admin bar menu group label', 'jetpack' ), |
||
| 966 | 'meta' => array( |
||
| 967 | 'class' => 'ab-submenu-header', |
||
| 968 | ), |
||
| 969 | ) |
||
| 970 | ); |
||
| 971 | |||
| 972 | // Pages. |
||
| 973 | $pages_title = $this->create_menu_item_pair( |
||
| 974 | array( |
||
| 975 | 'url' => Redirect::get_url( 'calypso-edit-pages' ), |
||
| 976 | 'id' => 'wp-admin-bar-edit-page', |
||
| 977 | 'label' => esc_html__( 'Site Pages', 'jetpack' ), |
||
| 978 | ), |
||
| 979 | array( |
||
| 980 | 'url' => Redirect::get_url( 'calypso-edit-page' ), |
||
| 981 | 'id' => 'wp-admin-bar-new-page-badge', |
||
| 982 | 'label' => esc_html_x( 'Add', 'admin bar menu new item label', 'jetpack' ), |
||
| 983 | ) |
||
| 984 | ); |
||
| 985 | |||
| 986 | if ( ! current_user_can( 'edit_pages' ) ) { |
||
| 987 | $pages_title = $this->create_menu_item_anchor( |
||
| 988 | 'ab-item ab-primary mb-icon', |
||
| 989 | Redirect::get_url( 'calypso-edit-pages' ), |
||
| 990 | esc_html__( 'Site Pages', 'jetpack' ), |
||
| 991 | 'wp-admin-bar-edit-page' |
||
| 992 | ); |
||
| 993 | } |
||
| 994 | |||
| 995 | $wp_admin_bar->add_menu( |
||
| 996 | array( |
||
| 997 | 'parent' => 'publish', |
||
| 998 | 'id' => 'new-page', |
||
| 999 | 'title' => $pages_title, |
||
| 1000 | 'meta' => array( |
||
| 1001 | 'class' => 'inline-action', |
||
| 1002 | ), |
||
| 1003 | ) |
||
| 1004 | ); |
||
| 1005 | |||
| 1006 | // Blog Posts. |
||
| 1007 | $posts_title = $this->create_menu_item_pair( |
||
| 1008 | array( |
||
| 1009 | 'url' => Redirect::get_url( 'calypso-edit-posts' ), |
||
| 1010 | 'id' => 'wp-admin-bar-edit-post', |
||
| 1011 | 'label' => esc_html__( 'Blog Posts', 'jetpack' ), |
||
| 1012 | ), |
||
| 1013 | array( |
||
| 1014 | 'url' => Redirect::get_url( 'calypso-edit-post' ), |
||
| 1015 | 'id' => 'wp-admin-bar-new-post-badge', |
||
| 1016 | 'label' => esc_html_x( 'Add', 'admin bar menu new item label', 'jetpack' ), |
||
| 1017 | ) |
||
| 1018 | ); |
||
| 1019 | |||
| 1020 | if ( ! current_user_can( 'edit_posts' ) ) { |
||
| 1021 | $posts_title = $this->create_menu_item_anchor( |
||
| 1022 | 'ab-item ab-primary mb-icon', |
||
| 1023 | Redirect::get_url( 'calypso-edit-posts' ), |
||
| 1024 | esc_html__( 'Blog Posts', 'jetpack' ), |
||
| 1025 | 'wp-admin-bar-edit-post' |
||
| 1026 | ); |
||
| 1027 | } |
||
| 1028 | |||
| 1029 | $wp_admin_bar->add_menu( |
||
| 1030 | array( |
||
| 1031 | 'parent' => 'publish', |
||
| 1032 | 'id' => 'new-post', |
||
| 1033 | 'title' => $posts_title, |
||
| 1034 | 'meta' => array( |
||
| 1035 | 'class' => 'inline-action mb-trackable', |
||
| 1036 | ), |
||
| 1037 | ) |
||
| 1038 | ); |
||
| 1039 | |||
| 1040 | // Comments. |
||
| 1041 | if ( current_user_can( 'moderate_comments' ) ) { |
||
| 1042 | $wp_admin_bar->add_menu( |
||
| 1043 | array( |
||
| 1044 | 'parent' => 'publish', |
||
| 1045 | 'id' => 'comments', |
||
| 1046 | 'title' => __( 'Comments', 'jetpack' ), |
||
| 1047 | 'href' => Redirect::get_url( 'calypso-comments' ), |
||
| 1048 | 'meta' => array( |
||
| 1049 | 'class' => 'mb-icon', |
||
| 1050 | ), |
||
| 1051 | ) |
||
| 1052 | ); |
||
| 1053 | } |
||
| 1054 | |||
| 1055 | // Testimonials. |
||
| 1056 | View Code Duplication | if ( Jetpack::is_module_active( 'custom-content-types' ) && get_option( 'jetpack_testimonial' ) ) { |
|
| 1057 | $testimonials_title = $this->create_menu_item_pair( |
||
| 1058 | array( |
||
| 1059 | 'url' => Redirect::get_url( 'calypso-list-jetpack-testimonial' ), |
||
| 1060 | 'id' => 'wp-admin-bar-edit-testimonial', |
||
| 1061 | 'label' => esc_html__( 'Testimonials', 'jetpack' ), |
||
| 1062 | ), |
||
| 1063 | array( |
||
| 1064 | 'url' => Redirect::get_url( 'calypso-edit-jetpack-testimonial' ), |
||
| 1065 | 'id' => 'wp-admin-bar-new-testimonial', |
||
| 1066 | 'label' => esc_html_x( 'Add', 'Button label for adding a new item via the toolbar menu', 'jetpack' ), |
||
| 1067 | ) |
||
| 1068 | ); |
||
| 1069 | |||
| 1070 | if ( ! current_user_can( 'edit_pages' ) ) { |
||
| 1071 | $testimonials_title = $this->create_menu_item_anchor( |
||
| 1072 | 'ab-item ab-primary mb-icon', |
||
| 1073 | Redirect::get_url( 'calypso-list-jetpack-testimonial' ), |
||
| 1074 | esc_html__( 'Testimonials', 'jetpack' ), |
||
| 1075 | 'wp-admin-bar-edit-testimonial' |
||
| 1076 | ); |
||
| 1077 | } |
||
| 1078 | |||
| 1079 | $wp_admin_bar->add_menu( |
||
| 1080 | array( |
||
| 1081 | 'parent' => 'publish', |
||
| 1082 | 'id' => 'new-jetpack-testimonial', |
||
| 1083 | 'title' => $testimonials_title, |
||
| 1084 | 'meta' => array( |
||
| 1085 | 'class' => 'inline-action', |
||
| 1086 | ), |
||
| 1087 | ) |
||
| 1088 | ); |
||
| 1089 | } |
||
| 1090 | |||
| 1091 | // Portfolio. |
||
| 1092 | View Code Duplication | if ( Jetpack::is_module_active( 'custom-content-types' ) && get_option( 'jetpack_portfolio' ) ) { |
|
| 1093 | $portfolios_title = $this->create_menu_item_pair( |
||
| 1094 | array( |
||
| 1095 | 'url' => Redirect::get_url( 'calypso-list-jetpack-portfolio' ), |
||
| 1096 | 'id' => 'wp-admin-bar-edit-portfolio', |
||
| 1097 | 'label' => esc_html__( 'Portfolio', 'jetpack' ), |
||
| 1098 | ), |
||
| 1099 | array( |
||
| 1100 | 'url' => Redirect::get_url( 'calypso-edit-jetpack-portfolio' ), |
||
| 1101 | 'id' => 'wp-admin-bar-new-portfolio', |
||
| 1102 | 'label' => esc_html_x( 'Add', 'Button label for adding a new item via the toolbar menu', 'jetpack' ), |
||
| 1103 | ) |
||
| 1104 | ); |
||
| 1105 | |||
| 1106 | if ( ! current_user_can( 'edit_pages' ) ) { |
||
| 1107 | $portfolios_title = $this->create_menu_item_anchor( |
||
| 1108 | 'ab-item ab-primary mb-icon', |
||
| 1109 | Redirect::get_url( 'calypso-list-jetpack-portfolio' ), |
||
| 1110 | esc_html__( 'Portfolio', 'jetpack' ), |
||
| 1111 | 'wp-admin-bar-edit-portfolio' |
||
| 1112 | ); |
||
| 1113 | } |
||
| 1114 | |||
| 1115 | $wp_admin_bar->add_menu( |
||
| 1116 | array( |
||
| 1117 | 'parent' => 'publish', |
||
| 1118 | 'id' => 'new-jetpack-portfolio', |
||
| 1119 | 'title' => $portfolios_title, |
||
| 1120 | 'meta' => array( |
||
| 1121 | 'class' => 'inline-action', |
||
| 1122 | ), |
||
| 1123 | ) |
||
| 1124 | ); |
||
| 1125 | } |
||
| 1126 | |||
| 1127 | if ( current_user_can( 'edit_theme_options' ) ) { |
||
| 1128 | // Look and Feel group. |
||
| 1129 | $wp_admin_bar->add_group( |
||
| 1130 | array( |
||
| 1131 | 'parent' => 'blog', |
||
| 1132 | 'id' => 'look-and-feel', |
||
| 1133 | ) |
||
| 1134 | ); |
||
| 1135 | |||
| 1136 | // Look and Feel header. |
||
| 1137 | $wp_admin_bar->add_menu( |
||
| 1138 | array( |
||
| 1139 | 'parent' => 'look-and-feel', |
||
| 1140 | 'id' => 'look-and-feel-header', |
||
| 1141 | 'title' => esc_html_x( 'Personalize', 'admin bar menu group label', 'jetpack' ), |
||
| 1142 | 'meta' => array( |
||
| 1143 | 'class' => 'ab-submenu-header', |
||
| 1144 | ), |
||
| 1145 | ) |
||
| 1146 | ); |
||
| 1147 | |||
| 1148 | if ( is_admin() ) { |
||
| 1149 | // In wp-admin the `return` query arg will return to that page after closing the Customizer. |
||
| 1150 | $customizer_url = add_query_arg( |
||
| 1151 | array( |
||
| 1152 | 'return' => rawurlencode( site_url( $_SERVER['REQUEST_URI'] ) ), |
||
| 1153 | ), |
||
| 1154 | wp_customize_url() |
||
| 1155 | ); |
||
| 1156 | } else { |
||
| 1157 | /* |
||
| 1158 | * On the frontend the `url` query arg will load that page in the Customizer |
||
| 1159 | * and also return to it after closing |
||
| 1160 | * non-home URLs won't work unless we undo domain mapping |
||
| 1161 | * since the Customizer preview is unmapped to always have HTTPS. |
||
| 1162 | */ |
||
| 1163 | $current_page = '//' . $this->primary_site_slug . $_SERVER['REQUEST_URI']; |
||
| 1164 | $customizer_url = add_query_arg( array( 'url' => rawurlencode( $current_page ) ), wp_customize_url() ); |
||
| 1165 | } |
||
| 1166 | |||
| 1167 | $theme_title = $this->create_menu_item_pair( |
||
| 1168 | array( |
||
| 1169 | 'url' => $customizer_url, |
||
| 1170 | 'id' => 'wp-admin-bar-cmz', |
||
| 1171 | 'label' => esc_html_x( 'Customize', 'admin bar customize item label', 'jetpack' ), |
||
| 1172 | ), |
||
| 1173 | array( |
||
| 1174 | 'url' => Redirect::get_url( 'calypso-themes' ), |
||
| 1175 | 'id' => 'wp-admin-bar-themes', |
||
| 1176 | 'label' => esc_html__( 'Themes', 'jetpack' ), |
||
| 1177 | ) |
||
| 1178 | ); |
||
| 1179 | $meta = array( |
||
| 1180 | 'class' => 'mb-icon', |
||
| 1181 | 'class' => 'inline-action', |
||
| 1182 | ); |
||
| 1183 | $href = false; |
||
| 1184 | |||
| 1185 | $wp_admin_bar->add_menu( |
||
| 1186 | array( |
||
| 1187 | 'parent' => 'look-and-feel', |
||
| 1188 | 'id' => 'themes', |
||
| 1189 | 'title' => $theme_title, |
||
| 1190 | 'href' => $href, |
||
| 1191 | 'meta' => $meta, |
||
| 1192 | ) |
||
| 1193 | ); |
||
| 1194 | } |
||
| 1195 | |||
| 1196 | if ( current_user_can( 'manage_options' ) ) { |
||
| 1197 | // Configuration group. |
||
| 1198 | $wp_admin_bar->add_group( |
||
| 1199 | array( |
||
| 1200 | 'parent' => 'blog', |
||
| 1201 | 'id' => 'configuration', |
||
| 1202 | ) |
||
| 1203 | ); |
||
| 1204 | |||
| 1205 | // Configuration header. |
||
| 1206 | $wp_admin_bar->add_menu( |
||
| 1207 | array( |
||
| 1208 | 'parent' => 'configuration', |
||
| 1209 | 'id' => 'configuration-header', |
||
| 1210 | 'title' => esc_html_x( 'Configure', 'admin bar menu group label', 'jetpack' ), |
||
| 1211 | 'meta' => array( |
||
| 1212 | 'class' => 'ab-submenu-header', |
||
| 1213 | ), |
||
| 1214 | ) |
||
| 1215 | ); |
||
| 1216 | |||
| 1217 | View Code Duplication | if ( Jetpack::is_module_active( 'publicize' ) || Jetpack::is_module_active( 'sharedaddy' ) ) { |
|
| 1218 | $wp_admin_bar->add_menu( |
||
| 1219 | array( |
||
| 1220 | 'parent' => 'configuration', |
||
| 1221 | 'id' => 'sharing', |
||
| 1222 | 'title' => esc_html__( 'Sharing', 'jetpack' ), |
||
| 1223 | 'href' => Redirect::get_url( 'calypso-sharing' ), |
||
| 1224 | 'meta' => array( |
||
| 1225 | 'class' => 'mb-icon', |
||
| 1226 | ), |
||
| 1227 | ) |
||
| 1228 | ); |
||
| 1229 | } |
||
| 1230 | |||
| 1231 | $people_title = $this->create_menu_item_pair( |
||
| 1232 | array( |
||
| 1233 | 'url' => Redirect::get_url( 'calypso-people-team' ), |
||
| 1234 | 'id' => 'wp-admin-bar-people', |
||
| 1235 | 'label' => esc_html__( 'People', 'jetpack' ), |
||
| 1236 | ), |
||
| 1237 | array( |
||
| 1238 | 'url' => admin_url( 'user-new.php' ), |
||
| 1239 | 'id' => 'wp-admin-bar-people-add', |
||
| 1240 | 'label' => esc_html_x( 'Add', 'admin bar people item label', 'jetpack' ), |
||
| 1241 | ) |
||
| 1242 | ); |
||
| 1243 | |||
| 1244 | $wp_admin_bar->add_menu( |
||
| 1245 | array( |
||
| 1246 | 'parent' => 'configuration', |
||
| 1247 | 'id' => 'users-toolbar', |
||
| 1248 | 'title' => $people_title, |
||
| 1249 | 'href' => false, |
||
| 1250 | 'meta' => array( |
||
| 1251 | 'class' => 'inline-action', |
||
| 1252 | ), |
||
| 1253 | ) |
||
| 1254 | ); |
||
| 1255 | |||
| 1256 | $plugins_title = $this->create_menu_item_pair( |
||
| 1257 | array( |
||
| 1258 | 'url' => Redirect::get_url( 'calypso-plugins' ), |
||
| 1259 | 'id' => 'wp-admin-bar-plugins', |
||
| 1260 | 'label' => esc_html__( 'Plugins', 'jetpack' ), |
||
| 1261 | ), |
||
| 1262 | array( |
||
| 1263 | 'url' => Redirect::get_url( 'calypso-plugins-manage' ), |
||
| 1264 | 'id' => 'wp-admin-bar-plugins-add', |
||
| 1265 | 'label' => esc_html_x( 'Manage', 'Label for the button on the Masterbar to manage plugins', 'jetpack' ), |
||
| 1266 | ) |
||
| 1267 | ); |
||
| 1268 | |||
| 1269 | $wp_admin_bar->add_menu( |
||
| 1270 | array( |
||
| 1271 | 'parent' => 'configuration', |
||
| 1272 | 'id' => 'plugins', |
||
| 1273 | 'title' => $plugins_title, |
||
| 1274 | 'href' => false, |
||
| 1275 | 'meta' => array( |
||
| 1276 | 'class' => 'inline-action', |
||
| 1277 | ), |
||
| 1278 | ) |
||
| 1279 | ); |
||
| 1280 | |||
| 1281 | if ( jetpack_is_atomic_site() ) { |
||
| 1282 | $domain_title = $this->create_menu_item_pair( |
||
| 1283 | array( |
||
| 1284 | 'url' => Redirect::get_url( 'calypso-domains' ), |
||
| 1285 | 'id' => 'wp-admin-bar-domains', |
||
| 1286 | 'label' => esc_html__( 'Domains', 'jetpack' ), |
||
| 1287 | ), |
||
| 1288 | array( |
||
| 1289 | 'url' => Redirect::get_url( 'calypso-domains-add' ), |
||
| 1290 | 'id' => 'wp-admin-bar-domains-add', |
||
| 1291 | 'label' => esc_html_x( 'Add', 'Label for the button on the Masterbar to add a new domain', 'jetpack' ), |
||
| 1292 | ) |
||
| 1293 | ); |
||
| 1294 | $wp_admin_bar->add_menu( |
||
| 1295 | array( |
||
| 1296 | 'parent' => 'configuration', |
||
| 1297 | 'id' => 'domains', |
||
| 1298 | 'title' => $domain_title, |
||
| 1299 | 'href' => false, |
||
| 1300 | 'meta' => array( |
||
| 1301 | 'class' => 'inline-action', |
||
| 1302 | ), |
||
| 1303 | ) |
||
| 1304 | ); |
||
| 1305 | } |
||
| 1306 | |||
| 1307 | $wp_admin_bar->add_menu( |
||
| 1308 | array( |
||
| 1309 | 'parent' => 'configuration', |
||
| 1310 | 'id' => 'blog-settings', |
||
| 1311 | 'title' => esc_html__( 'Settings', 'jetpack' ), |
||
| 1312 | 'href' => Redirect::get_url( 'calypso-settings-general' ), |
||
| 1313 | 'meta' => array( |
||
| 1314 | 'class' => 'mb-icon', |
||
| 1315 | ), |
||
| 1316 | ) |
||
| 1317 | ); |
||
| 1318 | |||
| 1319 | if ( ! is_admin() ) { |
||
| 1320 | $wp_admin_bar->add_menu( |
||
| 1321 | array( |
||
| 1322 | 'parent' => 'configuration', |
||
| 1323 | 'id' => 'legacy-dashboard', |
||
| 1324 | 'title' => esc_html__( 'Dashboard', 'jetpack' ), |
||
| 1325 | 'href' => admin_url(), |
||
| 1326 | 'meta' => array( |
||
| 1327 | 'class' => 'mb-icon', |
||
| 1328 | ), |
||
| 1329 | ) |
||
| 1330 | ); |
||
| 1331 | } |
||
| 1332 | |||
| 1333 | // Restore dashboard menu toggle that is needed on mobile views. |
||
| 1334 | if ( is_admin() ) { |
||
| 1335 | $wp_admin_bar->add_menu( |
||
| 1336 | array( |
||
| 1337 | 'id' => 'menu-toggle', |
||
| 1338 | 'title' => '<span class="ab-icon"></span><span class="screen-reader-text">' . esc_html__( 'Menu', 'jetpack' ) . '</span>', |
||
| 1339 | 'href' => '#', |
||
| 1340 | ) |
||
| 1341 | ); |
||
| 1342 | } |
||
| 1343 | |||
| 1344 | /** |
||
| 1345 | * Fires when menu items are added to the masterbar "My Sites" menu. |
||
| 1346 | * |
||
| 1347 | * @since 5.4.0 |
||
| 1348 | */ |
||
| 1349 | do_action( 'jetpack_masterbar' ); |
||
| 1350 | } |
||
| 1351 | } |
||
| 1352 | |||
| 1377 |
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: