| @@ -1,276 +1,272 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | - | |
| 4 | -namespace FL\Assistant\Data; | |
| 5 | - | |
| 6 | - | |
| 7 | -class Site { | |
| 8 | - | |
| 9 | - | |
| 10 | - /** | |
| 11 | - * Get info about the current page view. | |
| 12 | - */ | |
| 13 | - public function get_current_view() { | |
| 14 | - global $wp_the_query; | |
| 15 | - | |
| 16 | - $data = []; | |
| 17 | - $actions = []; | |
| 18 | - $intro = __( 'Currently Viewing', 'assistant' ); | |
| 19 | - $type = ''; | |
| 20 | - $type_name = ''; | |
| 21 | - $name = __( 'Untitled', 'assistant' ); | |
| 22 | - | |
| 23 | - $obj = get_queried_object(); | |
| 24 | - | |
| 25 | - if ( is_admin() ) { | |
| 26 | - | |
| 27 | - $intro = __( 'Currently Viewing Admin Page', 'assistant' ); | |
| 28 | - $type = __( 'Admin Page', 'assistant' ); | |
| 29 | - $screen = get_current_screen(); | |
| 30 | - $name = $screen->id; | |
| 31 | - | |
| 32 | - } else { | |
| 33 | - | |
| 34 | - if ( is_404() ) { | |
| 35 | - $name = __( 'Page Not Found', 'assistant' ); | |
| 36 | - $type = __( '404', 'assistant' ); | |
| 37 | - | |
| 38 | - } elseif ( is_search() ) { | |
| 39 | - | |
| 40 | - $intro = __( 'Currently Viewing Search Results For', 'assistant' ); | |
| 41 | - $type = __( 'Search Results For:', 'assistant' ); | |
| 42 | - $name = get_search_query(); | |
| 43 | - | |
| 44 | - } elseif ( is_date() ) { | |
| 45 | - | |
| 46 | - $intro = __( 'Currently Viewing Date Archive', 'assistant' ); | |
| 47 | - $type = __( 'Date Archive', 'assistant' ); | |
| 48 | - $name = get_the_date(); | |
| 49 | - | |
| 50 | - } elseif ( is_post_type_archive() ) { | |
| 51 | - | |
| 52 | - $post_type = get_post_type_object( 'post' ); | |
| 53 | - $intro = __( 'Currently Viewing Post Type Archive', 'assistant' ); | |
| 54 | - $type = __( 'Post Type Archive', 'assistant' ); | |
| 55 | - $name = $post_type->labels->singular_name; | |
| 56 | - $type_name = $post_type->name; | |
| 57 | - | |
| 58 | - } elseif ( is_tax() || is_category() || is_tag() ) { | |
| 59 | - | |
| 60 | - $tax = get_taxonomy( $obj->taxonomy ); | |
| 61 | - $labels = $tax->labels; | |
| 62 | - | |
| 63 | - $intro = sprintf( esc_html__( 'Currently Viewing %s', 'assistant' ), $labels->singular_name ); | |
| 64 | - $type = $labels->singular_name; | |
| 65 | - $name = $obj->name; | |
| 66 | - | |
| 67 | - $actions[] = [ | |
| 68 | - 'handle' => 'edit', | |
| 69 | - 'label' => $labels->edit_item, | |
| 70 | - 'href' => get_edit_term_link( $obj->term_id, $obj->taxonomy, null ), | |
| 71 | - 'capability' => 'manage_categories', | |
| 72 | - ]; | |
| 73 | - | |
| 74 | - } elseif ( is_singular() || is_attachment() ) { | |
| 75 | - | |
| 76 | - $post_type = get_post_type_object( get_post_type() ); | |
| 77 | - $type_name = $post_type->name; | |
| 78 | - $labels = $post_type->labels; | |
| 79 | - $post_type = $labels->singular_name; | |
| 80 | - $intro = sprintf( esc_html__( 'Currently Viewing %s', 'assistant' ), $post_type ); | |
| 81 | - $type = $post_type; | |
| 82 | - $name = $obj->post_title; | |
| 83 | - | |
| 84 | - $actions[] = [ | |
| 85 | - 'handle' => 'edit', | |
| 86 | - 'label' => $labels->edit_item, | |
| 87 | - 'href' => get_edit_post_link( $obj->ID, '' ), | |
| 88 | - 'target' => '_blank', | |
| 89 | - 'rel' => 'noopener', | |
| 90 | - 'capability' => 'edit_pages', | |
| 91 | - ]; | |
| 92 | - | |
| 93 | - // Add Beaver Builder edit link | |
| 94 | - if ( class_exists( '\FLBuilderModel' ) ) { | |
| 95 | - if ( \FLBuilderModel::is_post_editable() && is_object( $wp_the_query->post ) ) { | |
| 96 | - | |
| 97 | - $enabled = get_post_meta( $wp_the_query->post->ID, '_fl_builder_enabled', true ); | |
| 98 | - | |
| 99 | - $actions[] = [ | |
| 100 | - 'handle' => 'fl-builder', | |
| 101 | - 'label' => \FLBuilderModel::get_branding(), | |
| 102 | - 'href' => \FLBuilderModel::get_edit_url( $wp_the_query->post->ID ), | |
| 103 | - 'capability' => 'edit_pages', | |
| 104 | - 'isEnabled' => $enabled, | |
| 105 | - ]; | |
| 106 | - } | |
| 107 | - } | |
| 108 | - } elseif ( is_author() ) { | |
| 109 | - | |
| 110 | - $intro = __( 'Currently Viewing Author', 'assistant' ); | |
| 111 | - $type = __( 'Author Archive', 'assistant' ); | |
| 112 | - $name = wp_get_current_user()->display_name; | |
| 113 | - | |
| 114 | - } elseif ( is_front_page() ) { | |
| 115 | - $intro = __( 'Currently Viewing Post Archive', 'assistant' ); | |
| 116 | - $type = __( 'Post Archive', 'assistant' ); | |
| 117 | - $name = __( 'Latest Posts', 'assistant' ); | |
| 118 | - } | |
| 119 | - } | |
| 120 | - | |
| 121 | - $data['intro'] = $intro; | |
| 122 | - $data['name'] = $name; | |
| 123 | - $data['type'] = $type; | |
| 124 | - $data['type_name'] = $type_name; | |
| 125 | - | |
| 126 | - $data['actions'] = $this->filter_actions_by_capability( $actions ); | |
| 127 | - | |
| 128 | - $theme = wp_get_theme(); | |
| 129 | - $data['theme'] = [ | |
| 130 | - 'name' => $theme->get( 'Name' ), | |
| 131 | - 'team' => $theme->get( 'Author' ), | |
| 132 | - 'screenshot' => $theme->get_screenshot(), | |
| 133 | - 'version' => $theme->get( 'Version' ), | |
| 134 | - ]; | |
| 135 | - | |
| 136 | - $default_icon = plugins_url( 'img/icon-128x128.jpg', FL_ASSISTANT_FILE ); | |
| 137 | - $data['site'] = [ | |
| 138 | - 'defaultIcon' => $default_icon, | |
| 139 | - 'icon' => get_site_icon_url( 120, $default_icon ), | |
| 140 | - 'title' => get_bloginfo( 'name' ), | |
| 141 | - 'description' => get_bloginfo( 'description' ), | |
| 142 | - 'homeURL' => home_url(), | |
| 143 | - ]; | |
| 144 | - | |
| 145 | - $data['isAdmin'] = is_admin(); | |
| 146 | - $data['is404'] = is_404(); | |
| 147 | - $data['isSearch'] = is_search(); | |
| 148 | - $data['isDate'] = is_date(); | |
| 149 | - $data['isPostTypeArchive'] = is_post_type_archive(); | |
| 150 | - $data['isSingular'] = is_singular(); | |
| 151 | - $data['isSingle'] = is_single(); | |
| 152 | - $data['isPage'] = is_page(); | |
| 153 | - $data['isAttachment'] = is_attachment(); | |
| 154 | - $data['isCategory'] = is_tax(); | |
| 155 | - $data['isCategory'] = is_category(); | |
| 156 | - $data['isTag'] = is_tag(); | |
| 157 | - $data['isAuthor'] = is_author(); | |
| 158 | - $data['isFrontPage'] = is_front_page(); | |
| 159 | - | |
| 160 | - if ( is_singular() ) { | |
| 161 | - $data['id'] = $obj->ID; | |
| 162 | - } | |
| 163 | - | |
| 164 | - return $data; | |
| 165 | - } | |
| 166 | - | |
| 167 | - /** | |
| 168 | - * Filter an array of actions by their capability | |
| 169 | - */ | |
| 170 | - public function filter_actions_by_capability( $actions = [], $exclude_unset = true ) { | |
| 171 | - | |
| 172 | - foreach ( $actions as $i => $action ) { | |
| 173 | - $defaults = [ | |
| 174 | - 'label' => '', | |
| 175 | - 'capability' => '', | |
| 176 | - ]; | |
| 177 | - $action = wp_parse_args( $action, $defaults ); | |
| 178 | - $cap = $action['capability']; | |
| 179 | - | |
| 180 | - // Remove actions without a capability set | |
| 181 | - if ( $exclude_unset && ( '' === $cap || empty( $cap ) ) ) { | |
| 182 | - unset( $actions[ $i ] ); | |
| 183 | - } | |
| 184 | - // Test capability | |
| 185 | - if ( is_string( $cap ) && ! current_user_can( $cap ) ) { | |
| 186 | - unset( $actions[ $i ] ); | |
| 187 | - } | |
| 188 | - | |
| 189 | - // Test array of capabilities | |
| 190 | - if ( is_array( $cap ) ) { | |
| 191 | - foreach ( $cap as $single_cap ) { | |
| 192 | - if ( ! current_user_can( $single_cap ) ) { | |
| 193 | - unset( $actions[ $i ] ); | |
| 194 | - } | |
| 195 | - } | |
| 196 | - } | |
| 197 | - } | |
| 198 | - | |
| 199 | - return $actions; | |
| 200 | - } | |
| 201 | - | |
| 202 | - /** | |
| 203 | - * Get an action set for allowed admin links. | |
| 204 | - */ | |
| 205 | - public function get_admin_urls() { | |
| 206 | - $urls = []; | |
| 207 | - | |
| 208 | - $urls['dashboard'] = admin_url(); | |
| 209 | - | |
| 210 | - $urls['createPost'] = admin_url( 'post-new.php' ); | |
| 211 | - $urls['editPost'] = admin_url( 'post.php?action=edit&post=' ); | |
| 212 | - $urls['customizeBase'] = admin_url( 'customize.php' ); | |
| 213 | - | |
| 214 | - $url = static::get_customize_url(); | |
| 215 | - if ( $url ) { | |
| 216 | - $urls['customize'] = $url; | |
| 217 | - } | |
| 218 | - | |
| 219 | - if ( current_user_can( 'switch_themes' ) ) { | |
| 220 | - $urls['switchThemes'] = admin_url( 'themes.php' ); | |
| 221 | - } | |
| 222 | - | |
| 223 | - // Your User Profile | |
| 224 | - $user_id = get_current_user_id(); | |
| 225 | - if ( current_user_can( 'read' ) ) { | |
| 226 | - $urls['userProfile'] = get_edit_profile_url( $user_id ); | |
| 227 | - } | |
| 228 | - | |
| 229 | - if ( current_user_can( 'create_users' ) ) { | |
| 230 | - $urls['createUser'] = admin_url( 'user-new.php' ); | |
| 231 | - } | |
| 232 | - | |
| 233 | - return $urls; | |
| 234 | - } | |
| 235 | - | |
| 236 | - /** | |
| 237 | - * Get customize url | |
| 238 | - */ | |
| 239 | - public function get_customize_url() { | |
| 240 | - global $wp_customize; | |
| 241 | - | |
| 242 | - // Don't show for users who can't access the customizer or when in the admin. | |
| 243 | - if ( ! current_user_can( 'customize' ) || is_admin() ) { | |
| 244 | - return; | |
| 245 | - } | |
| 246 | - | |
| 247 | - // Don't show if the user cannot edit a given customize_changeset post currently being previewed. | |
| 248 | - if ( is_customize_preview() && $wp_customize->changeset_post_id() && ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->edit_post, $wp_customize->changeset_post_id() ) ) { | |
| 249 | - return; | |
| 250 | - } | |
| 251 | - | |
| 252 | - $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; | |
| 253 | - if ( is_customize_preview() && $wp_customize->changeset_uuid() ) { | |
| 254 | - $current_url = remove_query_arg( 'customize_changeset_uuid', $current_url ); | |
| 255 | - } | |
| 256 | - | |
| 257 | - $customize_url = add_query_arg( 'url', urlencode( $current_url ), wp_customize_url() ); | |
| 258 | - if ( is_customize_preview() ) { | |
| 259 | - $customize_url = add_query_arg( [ 'changeset_uuid' => $wp_customize->changeset_uuid() ], $customize_url ); | |
| 260 | - } | |
| 261 | - | |
| 262 | - return $customize_url; | |
| 263 | - } | |
| 264 | - | |
| 265 | - /** | |
| 266 | - * Check if the site is on localhost or not. | |
| 267 | - */ | |
| 268 | - public function is_local() { | |
| 269 | - $ips = [ '127.0.0.1', '::1' ]; | |
| 270 | - $domain = '.local'; | |
| 271 | - if ( isset( $_SERVER['REMOTE_ADDR'] ) && ! in_array( $_SERVER['REMOTE_ADDR'], $ips, true ) ) { | |
| 272 | - return substr_compare( $_SERVER['SERVER_NAME'], $domain, -strlen( $domain ) ) === 0; | |
| 273 | - } | |
| 274 | - return true; | |
| 275 | - } | |
| 276 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | + | |
| 4 | +namespace FL\Assistant\Data; | |
| 5 | + | |
| 6 | + | |
| 7 | +class Site { | |
| 8 | + | |
| 9 | + | |
| 10 | + /** | |
| 11 | + * Get info about the current page view. | |
| 12 | + */ | |
| 13 | + public function get_current_view() { | |
| 14 | + global $wp_the_query; | |
| 15 | + | |
| 16 | + $data = []; | |
| 17 | + $actions = []; | |
| 18 | + $intro = __( 'Currently Viewing', 'fl-assistant' ); | |
| 19 | + $type = ''; | |
| 20 | + $name = __( 'Untitled', 'fl-assistant' ); | |
| 21 | + | |
| 22 | + $obj = get_queried_object(); | |
| 23 | + | |
| 24 | + if ( is_admin() ) { | |
| 25 | + | |
| 26 | + $intro = __( 'Currently Viewing Admin Page', 'fl-assistant' ); | |
| 27 | + $type = __( 'Admin Page', 'fl-assistant' ); | |
| 28 | + $screen = get_current_screen(); | |
| 29 | + $name = $screen->id; | |
| 30 | + | |
| 31 | + } else { | |
| 32 | + | |
| 33 | + if ( is_404() ) { | |
| 34 | + $name = __( 'Page Not Found', 'fl-assistant' ); | |
| 35 | + $type = __( '404', 'fl-assistant' ); | |
| 36 | + | |
| 37 | + } elseif ( is_search() ) { | |
| 38 | + | |
| 39 | + $intro = __( 'Currently Viewing Search Results For', 'fl-assistant' ); | |
| 40 | + $type = __( 'Search Results For:', 'fl-assistant' ); | |
| 41 | + $name = get_search_query(); | |
| 42 | + | |
| 43 | + } elseif ( is_date() ) { | |
| 44 | + | |
| 45 | + $intro = __( 'Currently Viewing Date Archive', 'fl-assistant' ); | |
| 46 | + $type = __( 'Date Archive', 'fl-assistant' ); | |
| 47 | + $name = get_the_date(); | |
| 48 | + | |
| 49 | + } elseif ( is_post_type_archive() ) { | |
| 50 | + | |
| 51 | + $post_type = get_post_type_object( 'post' ); | |
| 52 | + $intro = __( 'Currently Viewing Post Type Archive', 'fl-assistant' ); | |
| 53 | + $type = __( 'Post Type Archive', 'fl-assistant' ); | |
| 54 | + $name = $post_type->labels->singular_name; | |
| 55 | + | |
| 56 | + } elseif ( is_tax() || is_category() || is_tag() ) { | |
| 57 | + | |
| 58 | + $tax = get_taxonomy( $obj->taxonomy ); | |
| 59 | + $labels = $tax->labels; | |
| 60 | + | |
| 61 | + $intro = sprintf( esc_html__( 'Currently Viewing %s', 'fl-assistant' ), $labels->singular_name ); | |
| 62 | + $type = $labels->singular_name; | |
| 63 | + $name = $obj->name; | |
| 64 | + | |
| 65 | + $actions[] = [ | |
| 66 | + 'handle' => 'edit', | |
| 67 | + 'label' => $labels->edit_item, | |
| 68 | + 'href' => get_edit_term_link( $obj->term_id, $obj->taxonomy, null ), | |
| 69 | + 'capability' => 'manage_categories', | |
| 70 | + ]; | |
| 71 | + | |
| 72 | + } elseif ( is_singular() || is_attachment() ) { | |
| 73 | + | |
| 74 | + $post_type = get_post_type_object( get_post_type() ); | |
| 75 | + $labels = $post_type->labels; | |
| 76 | + $post_type = $labels->singular_name; | |
| 77 | + $intro = sprintf( esc_html__( 'Currently Viewing %s', 'fl-assistant' ), $post_type ); | |
| 78 | + $type = $post_type; | |
| 79 | + $name = $obj->post_title; | |
| 80 | + | |
| 81 | + $actions[] = [ | |
| 82 | + 'handle' => 'edit', | |
| 83 | + 'label' => $labels->edit_item, | |
| 84 | + 'href' => get_edit_post_link( $obj->ID, '' ), | |
| 85 | + 'target' => '_blank', | |
| 86 | + 'rel' => 'noopener', | |
| 87 | + 'capability' => 'edit_pages', | |
| 88 | + ]; | |
| 89 | + | |
| 90 | + // Add Beaver Builder edit link | |
| 91 | + if ( class_exists( '\FLBuilderModel' ) ) { | |
| 92 | + if ( \FLBuilderModel::is_post_editable() && is_object( $wp_the_query->post ) ) { | |
| 93 | + | |
| 94 | + $enabled = get_post_meta( $wp_the_query->post->ID, '_fl_builder_enabled', true ); | |
| 95 | + | |
| 96 | + $actions[] = [ | |
| 97 | + 'handle' => 'fl-builder', | |
| 98 | + 'label' => \FLBuilderModel::get_branding(), | |
| 99 | + 'href' => \FLBuilderModel::get_edit_url( $wp_the_query->post->ID ), | |
| 100 | + 'capability' => 'edit_pages', | |
| 101 | + 'isEnabled' => $enabled, | |
| 102 | + ]; | |
| 103 | + } | |
| 104 | + } | |
| 105 | + } elseif ( is_author() ) { | |
| 106 | + | |
| 107 | + $intro = __( 'Currently Viewing Author', 'fl-assistant' ); | |
| 108 | + $type = __( 'Author Archive', 'fl-assistant' ); | |
| 109 | + $name = wp_get_current_user()->display_name; | |
| 110 | + | |
| 111 | + } elseif ( is_front_page() ) { | |
| 112 | + $intro = __( 'Currently Viewing Post Archive', 'fl-assistant' ); | |
| 113 | + $type = __( 'Post Archive', 'fl-assistant' ); | |
| 114 | + $name = __( 'Latest Posts', 'fl-assistant' ); | |
| 115 | + } | |
| 116 | + } | |
| 117 | + | |
| 118 | + $data['intro'] = $intro; | |
| 119 | + $data['name'] = $name; | |
| 120 | + $data['type'] = $type; | |
| 121 | + | |
| 122 | + $data['actions'] = $this->filter_actions_by_capability( $actions ); | |
| 123 | + | |
| 124 | + $theme = wp_get_theme(); | |
| 125 | + $data['theme'] = [ | |
| 126 | + 'name' => $theme->get( 'Name' ), | |
| 127 | + 'team' => $theme->get( 'Author' ), | |
| 128 | + 'screenshot' => $theme->get_screenshot(), | |
| 129 | + 'version' => $theme->get( 'Version' ), | |
| 130 | + ]; | |
| 131 | + | |
| 132 | + $default_icon = plugins_url( 'img/icon-128x128.jpg', FL_ASSISTANT_FILE ); | |
| 133 | + $data['site'] = [ | |
| 134 | + 'defaultIcon' => $default_icon, | |
| 135 | + 'icon' => get_site_icon_url( 120, $default_icon ), | |
| 136 | + 'title' => get_bloginfo( 'name' ), | |
| 137 | + 'description' => get_bloginfo( 'description' ), | |
| 138 | + 'homeURL' => home_url(), | |
| 139 | + ]; | |
| 140 | + | |
| 141 | + $data['isAdmin'] = is_admin(); | |
| 142 | + $data['is404'] = is_404(); | |
| 143 | + $data['isSearch'] = is_search(); | |
| 144 | + $data['isDate'] = is_date(); | |
| 145 | + $data['isPostTypeArchive'] = is_post_type_archive(); | |
| 146 | + $data['isSingular'] = is_singular(); | |
| 147 | + $data['isSingle'] = is_single(); | |
| 148 | + $data['isPage'] = is_page(); | |
| 149 | + $data['isAttachment'] = is_attachment(); | |
| 150 | + $data['isCategory'] = is_tax(); | |
| 151 | + $data['isCategory'] = is_category(); | |
| 152 | + $data['isTag'] = is_tag(); | |
| 153 | + $data['isAuthor'] = is_author(); | |
| 154 | + $data['isFrontPage'] = is_front_page(); | |
| 155 | + | |
| 156 | + if ( is_singular() ) { | |
| 157 | + $data['id'] = $obj->ID; | |
| 158 | + } | |
| 159 | + | |
| 160 | + return $data; | |
| 161 | + } | |
| 162 | + | |
| 163 | + /** | |
| 164 | + * Filter an array of actions by their capability | |
| 165 | + */ | |
| 166 | + public function filter_actions_by_capability( $actions = [], $exclude_unset = true ) { | |
| 167 | + | |
| 168 | + foreach ( $actions as $i => $action ) { | |
| 169 | + $defaults = [ | |
| 170 | + 'label' => '', | |
| 171 | + 'capability' => '', | |
| 172 | + ]; | |
| 173 | + $action = wp_parse_args( $action, $defaults ); | |
| 174 | + $cap = $action['capability']; | |
| 175 | + | |
| 176 | + // Remove actions without a capability set | |
| 177 | + if ( $exclude_unset && ( '' === $cap || empty( $cap ) ) ) { | |
| 178 | + unset( $actions[ $i ] ); | |
| 179 | + } | |
| 180 | + // Test capability | |
| 181 | + if ( is_string( $cap ) && ! current_user_can( $cap ) ) { | |
| 182 | + unset( $actions[ $i ] ); | |
| 183 | + } | |
| 184 | + | |
| 185 | + // Test array of capabilities | |
| 186 | + if ( is_array( $cap ) ) { | |
| 187 | + foreach ( $cap as $single_cap ) { | |
| 188 | + if ( ! current_user_can( $single_cap ) ) { | |
| 189 | + unset( $actions[ $i ] ); | |
| 190 | + } | |
| 191 | + } | |
| 192 | + } | |
| 193 | + } | |
| 194 | + | |
| 195 | + return $actions; | |
| 196 | + } | |
| 197 | + | |
| 198 | + /** | |
| 199 | + * Get an action set for allowed admin links. | |
| 200 | + */ | |
| 201 | + public function get_admin_urls() { | |
| 202 | + $urls = []; | |
| 203 | + | |
| 204 | + $urls['dashboard'] = admin_url(); | |
| 205 | + | |
| 206 | + $urls['createPost'] = admin_url( 'post-new.php' ); | |
| 207 | + $urls['editPost'] = admin_url( 'post.php?action=edit&post=' ); | |
| 208 | + $urls['customizeBase'] = admin_url( 'customize.php' ); | |
| 209 | + | |
| 210 | + $url = static::get_customize_url(); | |
| 211 | + if ( $url ) { | |
| 212 | + $urls['customize'] = $url; | |
| 213 | + } | |
| 214 | + | |
| 215 | + if ( current_user_can( 'switch_themes' ) ) { | |
| 216 | + $urls['switchThemes'] = admin_url( 'themes.php' ); | |
| 217 | + } | |
| 218 | + | |
| 219 | + // Your User Profile | |
| 220 | + $user_id = get_current_user_id(); | |
| 221 | + if ( current_user_can( 'read' ) ) { | |
| 222 | + $urls['userProfile'] = get_edit_profile_url( $user_id ); | |
| 223 | + } | |
| 224 | + | |
| 225 | + if ( current_user_can( 'create_users' ) ) { | |
| 226 | + $urls['createUser'] = admin_url( 'user-new.php' ); | |
| 227 | + } | |
| 228 | + | |
| 229 | + return $urls; | |
| 230 | + } | |
| 231 | + | |
| 232 | + /** | |
| 233 | + * Get customize url | |
| 234 | + */ | |
| 235 | + public function get_customize_url() { | |
| 236 | + global $wp_customize; | |
| 237 | + | |
| 238 | + // Don't show for users who can't access the customizer or when in the admin. | |
| 239 | + if ( ! current_user_can( 'customize' ) || is_admin() ) { | |
| 240 | + return; | |
| 241 | + } | |
| 242 | + | |
| 243 | + // Don't show if the user cannot edit a given customize_changeset post currently being previewed. | |
| 244 | + if ( is_customize_preview() && $wp_customize->changeset_post_id() && ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->edit_post, $wp_customize->changeset_post_id() ) ) { | |
| 245 | + return; | |
| 246 | + } | |
| 247 | + | |
| 248 | + $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; | |
| 249 | + if ( is_customize_preview() && $wp_customize->changeset_uuid() ) { | |
| 250 | + $current_url = remove_query_arg( 'customize_changeset_uuid', $current_url ); | |
| 251 | + } | |
| 252 | + | |
| 253 | + $customize_url = add_query_arg( 'url', urlencode( $current_url ), wp_customize_url() ); | |
| 254 | + if ( is_customize_preview() ) { | |
| 255 | + $customize_url = add_query_arg( [ 'changeset_uuid' => $wp_customize->changeset_uuid() ], $customize_url ); | |
| 256 | + } | |
| 257 | + | |
| 258 | + return $customize_url; | |
| 259 | + } | |
| 260 | + | |
| 261 | + /** | |
| 262 | + * Check if the site is on localhost or not. | |
| 263 | + */ | |
| 264 | + public function is_local() { | |
| 265 | + $ips = [ '127.0.0.1', '::1' ]; | |
| 266 | + $domain = '.local'; | |
| 267 | + if ( ! in_array( $_SERVER['REMOTE_ADDR'], $ips, true ) ) { | |
| 268 | + return substr_compare( $_SERVER['SERVER_NAME'], $domain, -strlen( $domain ) ) === 0; | |
| 269 | + } | |
| 270 | + return true; | |
| 271 | + } | |
| 272 | +} | |