| @@ -10,8 +10,10 @@ | ||
| 10 | 10 | /** |
| 11 | 11 | * Get info about the current page view. |
| 12 | 12 | */ |
| 13 | 13 | public function get_current_view() { |
| 14 | + global $wp_the_query; | |
| 15 | + | |
| 14 | 16 | $data = []; |
| 15 | 17 | $actions = []; |
| 16 | 18 | $intro = __( 'Currently Viewing', 'fl-assistant' ); |
| 17 | 19 | $type = ''; |
| @@ -16,10 +18,9 @@ | ||
| 16 | 18 | $intro = __( 'Currently Viewing', 'fl-assistant' ); |
| 17 | 19 | $type = ''; |
| 18 | 20 | $name = __( 'Untitled', 'fl-assistant' ); |
| 19 | 21 | |
| 20 | - $obj = get_queried_object(); | |
| 21 | - $data['queried_object'] = $obj; | |
| 22 | + $obj = get_queried_object(); | |
| 22 | 23 | |
| 23 | 24 | if ( is_admin() ) { |
| 24 | 25 | |
| 25 | 26 | $intro = __( 'Currently Viewing Admin Page', 'fl-assistant' ); |
| @@ -61,8 +62,9 @@ | ||
| 61 | 62 | $type = $labels->singular_name; |
| 62 | 63 | $name = $obj->name; |
| 63 | 64 | |
| 64 | 65 | $actions[] = [ |
| 66 | + 'handle' => 'edit', | |
| 65 | 67 | 'label' => $labels->edit_item, |
| 66 | 68 | 'href' => get_edit_term_link( $obj->term_id, $obj->taxonomy, null ), |
| 67 | 69 | 'capability' => 'manage_categories', |
| 68 | 70 | ]; |
| @@ -75,21 +77,18 @@ | ||
| 75 | 77 | $intro = sprintf( esc_html__( 'Currently Viewing %s', 'fl-assistant' ), $post_type ); |
| 76 | 78 | $type = $post_type; |
| 77 | 79 | $name = $obj->post_title; |
| 78 | 80 | |
| 79 | - if ( is_attachment() ) { | |
| 80 | - $meta = wp_get_attachment_metadata( $obj->ID ); | |
| 81 | - $name = basename( $meta['file'] ); | |
| 82 | - } | |
| 83 | - | |
| 84 | 81 | $actions[] = [ |
| 82 | + 'handle' => 'edit', | |
| 85 | 83 | 'label' => $labels->edit_item, |
| 86 | 84 | 'href' => get_edit_post_link( $obj->ID, '' ), |
| 85 | + 'target' => '_blank', | |
| 86 | + 'rel' => 'noopener', | |
| 87 | 87 | 'capability' => 'edit_pages', |
| 88 | 88 | ]; |
| 89 | 89 | |
| 90 | 90 | // Add Beaver Builder edit link |
| 91 | - global $wp_the_query; | |
| 92 | 91 | if ( class_exists( '\FLBuilderModel' ) ) { |
| 93 | 92 | if ( \FLBuilderModel::is_post_editable() && is_object( $wp_the_query->post ) ) { |
| 94 | 93 | |
| 95 | 94 | $enabled = get_post_meta( $wp_the_query->post->ID, '_fl_builder_enabled', true ); |
| @@ -94,8 +93,9 @@ | ||
| 94 | 93 | |
| 95 | 94 | $enabled = get_post_meta( $wp_the_query->post->ID, '_fl_builder_enabled', true ); |
| 96 | 95 | |
| 97 | 96 | $actions[] = [ |
| 97 | + 'handle' => 'fl-builder', | |
| 98 | 98 | 'label' => \FLBuilderModel::get_branding(), |
| 99 | 99 | 'href' => \FLBuilderModel::get_edit_url( $wp_the_query->post->ID ), |
| 100 | 100 | 'capability' => 'edit_pages', |
| 101 | 101 | 'isEnabled' => $enabled, |
| @@ -117,8 +117,9 @@ | ||
| 117 | 117 | |
| 118 | 118 | $data['intro'] = $intro; |
| 119 | 119 | $data['name'] = $name; |
| 120 | 120 | $data['type'] = $type; |
| 121 | + | |
| 121 | 122 | $data['actions'] = $this->filter_actions_by_capability( $actions ); |
| 122 | 123 | |
| 123 | 124 | $theme = wp_get_theme(); |
| 124 | 125 | $data['theme'] = [ |
| @@ -127,17 +128,36 @@ | ||
| 127 | 128 | 'screenshot' => $theme->get_screenshot(), |
| 128 | 129 | 'version' => $theme->get( 'Version' ), |
| 129 | 130 | ]; |
| 130 | 131 | |
| 131 | - $default_icon = plugins_url('img/icon-128x128.jpg', FL_ASSISTANT_FILE ); | |
| 132 | + $default_icon = plugins_url( 'img/icon-128x128.jpg', FL_ASSISTANT_FILE ); | |
| 132 | 133 | $data['site'] = [ |
| 133 | - 'test' => $default_icon, | |
| 134 | - 'icon' => get_site_icon_url( 120, $default_icon ), | |
| 135 | - 'title' => get_bloginfo('name'), | |
| 136 | - 'description' => get_bloginfo('description'), | |
| 137 | - 'homeURL' => home_url(), | |
| 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(), | |
| 138 | 139 | ]; |
| 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 | + | |
| 140 | 160 | return $data; |
| 141 | 161 | } |
| 142 | 162 | |
| 143 | 163 | /** |
| @@ -183,8 +203,10 @@ | ||
| 183 | 203 | |
| 184 | 204 | $urls['dashboard'] = admin_url(); |
| 185 | 205 | |
| 186 | 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' ); | |
| 187 | 209 | |
| 188 | 210 | $url = static::get_customize_url(); |
| 189 | 211 | if ( $url ) { |
| 190 | 212 | $urls['customize'] = $url; |
| @@ -190,9 +212,9 @@ | ||
| 190 | 212 | $urls['customize'] = $url; |
| 191 | 213 | } |
| 192 | 214 | |
| 193 | 215 | if ( current_user_can( 'switch_themes' ) ) { |
| 194 | - $urls['switchThemes'] = ''; | |
| 216 | + $urls['switchThemes'] = admin_url( 'themes.php' ); | |
| 195 | 217 | } |
| 196 | 218 | |
| 197 | 219 | // Your User Profile |
| 198 | 220 | $user_id = get_current_user_id(); |
| @@ -233,6 +255,18 @@ | ||
| 233 | 255 | $customize_url = add_query_arg( [ 'changeset_uuid' => $wp_customize->changeset_uuid() ], $customize_url ); |
| 234 | 256 | } |
| 235 | 257 | |
| 236 | 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; | |
| 237 | 271 | } |
| 238 | 272 | } |