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