| @@ -1,0 +1,494 @@ | ||
| 1 | +<?php | |
| 2 | +namespace ABlocks\Blocks\FrontendDashboard; | |
| 3 | + | |
| 4 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | + exit; | |
| 6 | +} | |
| 7 | + | |
| 8 | +use ABlocks\Classes\BlockBaseAbstract; | |
| 9 | +use ABlocks\Classes\CssGenerator; | |
| 10 | +use ABlocks\Helper; | |
| 11 | +use ABlocks\Controls\Typography; | |
| 12 | +use ABlocks\Controls\TextShadow; | |
| 13 | +use ABlocks\Controls\TextStroke; | |
| 14 | +use ABlocks\Controls\Background; | |
| 15 | +use ABlocks\Controls\Border; | |
| 16 | +use ABlocks\Controls\Dimensions; | |
| 17 | +use ABlocks\Controls\Range; | |
| 18 | +use ABlocks\Controls\Color; | |
| 19 | + | |
| 20 | + | |
| 21 | +class Block extends BlockBaseAbstract { | |
| 22 | + protected $block_name = 'frontend-dashboard'; | |
| 23 | + | |
| 24 | + public function __construct() { | |
| 25 | + parent::__construct(); | |
| 26 | + | |
| 27 | + } | |
| 28 | + | |
| 29 | + public function build_css( $attributes ) { | |
| 30 | + | |
| 31 | + $css_generator = new CssGenerator( $attributes, $this->block_name ); | |
| 32 | + | |
| 33 | + $get_gaps_css = $this->get_wrapper_gap_css( $attributes ); | |
| 34 | + $css_generator->add_class_styles( | |
| 35 | + '{{WRAPPER}}.ablocks-block--frontend-dashboard', | |
| 36 | + $get_gaps_css, | |
| 37 | + $this->get_wrapper_gap_css( $attributes, 'Tablet' ), | |
| 38 | + $this->get_wrapper_gap_css( $attributes, 'Mobile' ), | |
| 39 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_wrapper_gap_css( $attributes, $device ); } ) | |
| 40 | + ); | |
| 41 | + | |
| 42 | + $get_setting_css = $this->get_setting_css( $attributes ); | |
| 43 | + | |
| 44 | + $css_generator->add_class_styles( | |
| 45 | + '{{WRAPPER}} .ablocks-frontend-dashboard-sidebar', | |
| 46 | + $get_setting_css, | |
| 47 | + $this->get_setting_css( $attributes, 'Tablet' ), | |
| 48 | + $this->get_setting_css( $attributes, 'Mobile' ), | |
| 49 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_setting_css( $attributes, $device ); } ) | |
| 50 | + ); | |
| 51 | + | |
| 52 | + $get_user_setting_css = $this->get_user_setting_css( $attributes ); | |
| 53 | + | |
| 54 | + $css_generator->add_class_styles( | |
| 55 | + '{{WRAPPER}} .ablocks-frontend-dashboard-user', | |
| 56 | + $get_user_setting_css, | |
| 57 | + $this->get_user_setting_css( $attributes, 'Tablet' ), | |
| 58 | + $this->get_user_setting_css( $attributes, 'Mobile' ), | |
| 59 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_user_setting_css( $attributes, $device ); } ) | |
| 60 | + ); | |
| 61 | + | |
| 62 | + $get_menu_list_css = $this->get_menu_list_css( $attributes ); | |
| 63 | + | |
| 64 | + $css_generator->add_class_styles( | |
| 65 | + '{{WRAPPER}} .ablocks-frontend-dashboard-menu__item a', | |
| 66 | + $get_menu_list_css, | |
| 67 | + $this->get_menu_list_css( $attributes, 'Tablet' ), | |
| 68 | + $this->get_menu_list_css( $attributes, 'Mobile' ), | |
| 69 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_menu_list_css( $attributes, $device ); } ) | |
| 70 | + ); | |
| 71 | + | |
| 72 | + $get_menu_hover_list_css = $this->get_menu_hover_list_css( $attributes ); | |
| 73 | + | |
| 74 | + $css_generator->add_class_styles( | |
| 75 | + '{{WRAPPER}} .ablocks-frontend-dashboard-menu__item a:hover', | |
| 76 | + $get_menu_hover_list_css, | |
| 77 | + $this->get_menu_hover_list_css( $attributes, 'Tablet' ), | |
| 78 | + $this->get_menu_hover_list_css( $attributes, 'Mobile' ), | |
| 79 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_menu_hover_list_css( $attributes, $device ); } ) | |
| 80 | + ); | |
| 81 | + | |
| 82 | + $get_menu_active_list_css = $this->get_menu_active_list_css( $attributes ); | |
| 83 | + | |
| 84 | + $css_generator->add_class_styles( | |
| 85 | + '{{WRAPPER}} .ablocks-frontend-dashboard-menu__item--current > a', | |
| 86 | + $get_menu_active_list_css, | |
| 87 | + $this->get_menu_active_list_css( $attributes, 'Tablet' ), | |
| 88 | + $this->get_menu_active_list_css( $attributes, 'Mobile' ), | |
| 89 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_menu_active_list_css( $attributes, $device ); } ) | |
| 90 | + ); | |
| 91 | + | |
| 92 | + $get_breadcrumb_css = $this->get_breadcrumb_css( $attributes ); | |
| 93 | + | |
| 94 | + $css_generator->add_class_styles( | |
| 95 | + '{{WRAPPER}} .ablocks-frontend-dashboard-breadcrumb li', | |
| 96 | + $get_breadcrumb_css, | |
| 97 | + $this->get_breadcrumb_css( $attributes, 'Tablet' ), | |
| 98 | + $this->get_breadcrumb_css( $attributes, 'Mobile' ), | |
| 99 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_breadcrumb_css( $attributes, $device ); } ) | |
| 100 | + ); | |
| 101 | + | |
| 102 | + $get_breadcrumb_css = $this->get_breadcrumb_css( $attributes ); | |
| 103 | + | |
| 104 | + $css_generator->add_class_styles( | |
| 105 | + '{{WRAPPER}} .ablocks-frontend-dashboard-breadcrumb li + li::before', | |
| 106 | + $get_breadcrumb_css, | |
| 107 | + $this->get_breadcrumb_css( $attributes, 'Tablet' ), | |
| 108 | + $this->get_breadcrumb_css( $attributes, 'Mobile' ), | |
| 109 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_breadcrumb_css( $attributes, $device ); } ) | |
| 110 | + ); | |
| 111 | + | |
| 112 | + $get_content_css = $this->get_content_css( $attributes ); | |
| 113 | + | |
| 114 | + $css_generator->add_class_styles( | |
| 115 | + '{{WRAPPER}} .ablocks-frontend-dashboard-content', | |
| 116 | + $get_content_css, | |
| 117 | + $this->get_content_css( $attributes, 'Tablet' ), | |
| 118 | + $this->get_content_css( $attributes, 'Mobile' ), | |
| 119 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_css( $attributes, $device ); } ) | |
| 120 | + ); | |
| 121 | + | |
| 122 | + $get_content_hover_css = $this->get_content_hover_css( $attributes ); | |
| 123 | + | |
| 124 | + $css_generator->add_class_styles( | |
| 125 | + '{{WRAPPER}} .ablocks-frontend-dashboard-content:hover', | |
| 126 | + $get_content_hover_css, | |
| 127 | + $this->get_content_hover_css( $attributes, 'Tablet' ), | |
| 128 | + $this->get_content_hover_css( $attributes, 'Mobile' ), | |
| 129 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_content_hover_css( $attributes, $device ); } ) | |
| 130 | + ); | |
| 131 | + | |
| 132 | + return $css_generator->generate_css(); | |
| 133 | + } | |
| 134 | + | |
| 135 | + | |
| 136 | + public function get_setting_css( $attributes, $device = '' ) { | |
| 137 | + $css = []; | |
| 138 | + | |
| 139 | + if ( ! empty( $attributes['sidebarBackground'] ) ) { | |
| 140 | + $css['background'] = Color::get_css( | |
| 141 | + isset( $attributes['sidebarBackground'] ) ? $attributes['sidebarBackground'] : ''); | |
| 142 | + } | |
| 143 | + | |
| 144 | + return array_merge( | |
| 145 | + $css, | |
| 146 | + Border::get_css( $attributes['sidebarBorder'] ?? [], '', $device ) | |
| 147 | + ); | |
| 148 | + } | |
| 149 | + | |
| 150 | + public function get_user_setting_css( $attributes, $device = '' ) { | |
| 151 | + $css = []; | |
| 152 | + | |
| 153 | + if ( ! empty( $attributes['userTextColor'] ) ) { | |
| 154 | + $css['color'] = Color::get_css( | |
| 155 | + isset( $attributes['userTextColor'] ) ? $attributes['userTextColor'] : ''); | |
| 156 | + } | |
| 157 | + if ( ! empty( $attributes['sidebarUserBackground'] ) ) { | |
| 158 | + $css['background'] = Color::get_css( | |
| 159 | + isset( $attributes['sidebarUserBackground'] ) ? $attributes['sidebarUserBackground'] : ''); | |
| 160 | + } | |
| 161 | + $userTypographyGlobal = ! empty( $attributes['userTypographyGlobal'] ) ? $attributes['userTypographyGlobal'] : ''; | |
| 162 | + return array_merge( | |
| 163 | + $css, | |
| 164 | + Border::get_css( $attributes['userSidebarBorder'] ?? [], '', $device ), | |
| 165 | + Typography::get_css( $attributes['userTypography'], '', $device, $userTypographyGlobal ), | |
| 166 | + ); | |
| 167 | + } | |
| 168 | + | |
| 169 | + public function get_menu_list_css( $attributes, $device = '' ) { | |
| 170 | + $css = []; | |
| 171 | + | |
| 172 | + if ( ! empty( $attributes['menuListTextColor'] ) ) { | |
| 173 | + $css['color'] = Color::get_css( | |
| 174 | + isset( $attributes['menuListTextColor'] ) ? $attributes['menuListTextColor'] : ''); | |
| 175 | + } | |
| 176 | + if ( ! empty( $attributes['menuListBackground'] ) ) { | |
| 177 | + $css['background'] = Color::get_css( | |
| 178 | + isset( $attributes['menuListBackground'] ) ? $attributes['menuListBackground'] : ''); | |
| 179 | + } | |
| 180 | + | |
| 181 | + $userTypographyGlobal = ! empty( $attributes['userTypographyGlobal'] ) ? $attributes['userTypographyGlobal'] : ''; | |
| 182 | + | |
| 183 | + return array_merge( | |
| 184 | + $css, | |
| 185 | + Border::get_css( $attributes['menuListBorder'] ?? [], '', $device ), | |
| 186 | + Dimensions::get_css( $attributes['menuListPadding'] ?? [], 'padding', $device ), | |
| 187 | + Typography::get_css( $attributes['menuListTypography'] ?? [], '', $device, $userTypographyGlobal ) | |
| 188 | + ); | |
| 189 | + } | |
| 190 | + | |
| 191 | + public function get_menu_hover_list_css( $attributes, $device = '' ) { | |
| 192 | + $css = []; | |
| 193 | + | |
| 194 | + if ( ! empty( $attributes['menuListHoverTextColor'] ) ) { | |
| 195 | + $css['color'] = Color::get_css( | |
| 196 | + isset( $attributes['menuListHoverTextColor'] ) ? $attributes['menuListHoverTextColor'] : ''); | |
| 197 | + } | |
| 198 | + if ( ! empty( $attributes['menuListHoverBackground'] ) ) { | |
| 199 | + $css['background'] = Color::get_css( | |
| 200 | + isset( $attributes['menuListHoverBackground'] ) ? $attributes['menuListHoverBackground'] : ''); | |
| 201 | + } | |
| 202 | + | |
| 203 | + return array_merge( | |
| 204 | + $css, | |
| 205 | + Border::get_hover_css( $attributes['menuListBorder'] ?? [], '', $device ) | |
| 206 | + ); | |
| 207 | + } | |
| 208 | + | |
| 209 | + public function get_menu_active_list_css( $attributes, $device = '' ) { | |
| 210 | + $css = []; | |
| 211 | + | |
| 212 | + if ( ! empty( $attributes['menuListActiveTextColor'] ) ) { | |
| 213 | + $css['color'] = Color::get_css( | |
| 214 | + isset( $attributes['menuListActiveTextColor'] ) ? $attributes['menuListActiveTextColor'] : ''); | |
| 215 | + } | |
| 216 | + if ( ! empty( $attributes['menuListActiveBackground'] ) ) { | |
| 217 | + $css['background'] = Color::get_css( | |
| 218 | + isset( $attributes['menuListActiveBackground'] ) ? $attributes['menuListActiveBackground'] : ''); | |
| 219 | + } | |
| 220 | + | |
| 221 | + return $css; | |
| 222 | + } | |
| 223 | + public function get_content_css( $attributes, $device = '' ) { | |
| 224 | + $css = []; | |
| 225 | + | |
| 226 | + if ( ! empty( $attributes['contentBackground'] ) ) { | |
| 227 | + $css['background'] = Color::get_css( | |
| 228 | + isset( $attributes['contentBackground'] ) ? $attributes['contentBackground'] : ''); | |
| 229 | + } | |
| 230 | + | |
| 231 | + return array_merge( | |
| 232 | + $css, | |
| 233 | + Border::get_css( $attributes['contentBorder'] ?? [], '', $device ), | |
| 234 | + Dimensions::get_css( $attributes['contentPadding'] ?? [], 'padding', $device ), | |
| 235 | + ); | |
| 236 | + } | |
| 237 | + public function get_content_hover_css( $attributes, $device = '' ) { | |
| 238 | + | |
| 239 | + return array_merge( | |
| 240 | + Border::get_hover_css( $attributes['contentBorder'] ?? [], '', $device ), | |
| 241 | + ); | |
| 242 | + } | |
| 243 | + | |
| 244 | + public function get_breadcrumb_css( $attributes, $device = '' ) { | |
| 245 | + $css = []; | |
| 246 | + | |
| 247 | + if ( ! empty( $attributes['breadcrumbColor'] ) ) { | |
| 248 | + $css['color'] = Color::get_css( | |
| 249 | + isset( $attributes['breadcrumbColor'] ) ? $attributes['breadcrumbColor'] : ''); | |
| 250 | + } | |
| 251 | + $breadcrumbtTypographyGlobal = ! empty( $attributes['breadcrumbtTypographyGlobal'] ) ? $attributes['breadcrumbtTypographyGlobal'] : ''; | |
| 252 | + | |
| 253 | + return array_merge( | |
| 254 | + $css, | |
| 255 | + Typography::get_css( $attributes['breadcrumbtTypography'] ?? [], '', $device, $breadcrumbtTypographyGlobal ) | |
| 256 | + ); | |
| 257 | + } | |
| 258 | + public function get_wrapper_gap_css( $attributes, $device = '' ) { | |
| 259 | + $css = []; | |
| 260 | + | |
| 261 | + $css['display'] = 'flex'; | |
| 262 | + if ( $device === 'Tablet' ) { | |
| 263 | + $css['flex-direction'] = 'column'; | |
| 264 | + } elseif ( $device === 'Mobile' ) { | |
| 265 | + $css['flex-direction'] = 'column'; | |
| 266 | + } else { | |
| 267 | + $css['flex-direction'] = 'row'; | |
| 268 | + } | |
| 269 | + | |
| 270 | + if ( ! empty( $attributes['bothGap'] ) ) { | |
| 271 | + $css['gap'] = $attributes['bothGap'] . 'px'; | |
| 272 | + } | |
| 273 | + return array_merge( | |
| 274 | + $css | |
| 275 | + ); | |
| 276 | + } | |
| 277 | + | |
| 278 | + // * Render the block content. | |
| 279 | + public function render_block_content( $attributes, $content, $block_instance ) { | |
| 280 | + | |
| 281 | + global $wp; | |
| 282 | + global $wpdb; | |
| 283 | + | |
| 284 | + $dashboard_page = isset( $attributes['dashboard_page'] ) && ! empty( $attributes['dashboard_page'] ) ? $attributes['dashboard_page'] : 'root'; | |
| 285 | + | |
| 286 | + $dashboard_pages = json_decode( get_option( ABLOCKS_FRONTEND_DASHBOARD_SUB_PAGES_SETTINGS_NAME, '{}' ), true ); | |
| 287 | + // print_r($dashboard_pages); | |
| 288 | + $breadcrumbs = []; | |
| 289 | + $breadcrumbs[] = [ | |
| 290 | + 'label' => __( 'Dashboard', 'ablocks' ), | |
| 291 | + 'url' => $this->get_frontend_dashboard_endpoint_url( '' ), | |
| 292 | + ]; | |
| 293 | + | |
| 294 | + $current_page_slug = get_query_var( 'ablocks_dashboard_page', 'root' ); | |
| 295 | + $current_sub_page_slug = get_query_var( 'ablocks_dashboard_sub_page' ); | |
| 296 | + | |
| 297 | + if ( $current_page_slug !== 'root' ) { | |
| 298 | + $current_slug = empty( $current_sub_page_slug ) ? $current_page_slug : $current_sub_page_slug; | |
| 299 | + // var_dump($current_slug); | |
| 300 | + // Find the current page in the dashboard_pages array | |
| 301 | + foreach ( $dashboard_pages as $page ) { | |
| 302 | + if ( isset( $page['slug'] ) && $page['slug'] === $current_slug ) { | |
| 303 | + $breadcrumbs[] = [ | |
| 304 | + 'label' => $page['label'], | |
| 305 | + 'url' => isset( $page['permalink'] ) ? $page['permalink'] : $this->get_frontend_dashboard_endpoint_url( $page['slug'] ), | |
| 306 | + ]; | |
| 307 | + break; | |
| 308 | + } | |
| 309 | + | |
| 310 | + if ( is_array( $page['children'] ?? '' ) ) { | |
| 311 | + if ( | |
| 312 | + isset( $page['slug'] ) && | |
| 313 | + $page['slug'] === $current_page_slug | |
| 314 | + ) { | |
| 315 | + $breadcrumbs[] = [ | |
| 316 | + 'label' => $page['label'], | |
| 317 | + 'url' => isset( $page['permalink'] ) ? $page['permalink'] : $this->get_frontend_dashboard_endpoint_url( $page['slug'] ), | |
| 318 | + ]; | |
| 319 | + } | |
| 320 | + | |
| 321 | + foreach ( $page['children'] as $sub_page ) { | |
| 322 | + // print_r([$sub_page['slug'], $current_slug]); | |
| 323 | + if ( isset( $sub_page['slug'] ) && $sub_page['slug'] === $current_slug ) { | |
| 324 | + $breadcrumbs[] = [ | |
| 325 | + 'label' => $sub_page['label'], | |
| 326 | + 'url' => isset( $sub_page['permalink'] ) ? $sub_page['permalink'] : $this->get_frontend_dashboard_endpoint_url( $sub_page['slug'] ), | |
| 327 | + ]; | |
| 328 | + break; | |
| 329 | + } | |
| 330 | + } | |
| 331 | + }//end if | |
| 332 | + }//end foreach | |
| 333 | + }//end if | |
| 334 | + ?> | |
| 335 | + <div class="ablocks-frontend-dashboard-sidebar"> | |
| 336 | + <div class="ablocks-frontend-dashboard-user"> | |
| 337 | + <div id="ablocks-frontend-dashboard-user-avatar"> | |
| 338 | + <?php echo get_avatar( get_current_user_id(), 96, '', wp_get_current_user()->display_name, [ 'loading' => 'lazy' ] ); ?> | |
| 339 | + <span class="ablocks-frontend-dashboard-user__label"><?php echo esc_html( wp_get_current_user()->display_name ); ?></span> | |
| 340 | + </div> | |
| 341 | + </div> | |
| 342 | + <ul class="ablocks-frontend-dashboard-menu"> | |
| 343 | + <?php | |
| 344 | + foreach ( $dashboard_pages as $menu ) : | |
| 345 | + // print_r($menu); | |
| 346 | + $endpoint = $menu['slug'] ?? $menu['link']; | |
| 347 | + // print_r($endpoint); | |
| 348 | + $menu['permalink'] = $menu['permalink'] ?? $menu['link'] ?? null; | |
| 349 | + if ( $endpoint === 'root' ) { | |
| 350 | + $menu['label'] = __( 'Dashboard', 'ablocks' ); | |
| 351 | + $menu['slug'] = ''; | |
| 352 | + $menu['priority'] = 0; | |
| 353 | + } ?> | |
| 354 | + <?php | |
| 355 | + $is_parent_current = ( get_query_var( 'ablocks_dashboard_page' ) === $endpoint || ( get_query_var( 'ablocks_dashboard_page' ) === '' && 'index' === $endpoint ) ) && empty( get_query_var( 'ablocks_dashboard_sub_page' ) ); | |
| 356 | + ?> | |
| 357 | + <li class="ablocks-frontend-dashboard-menu__item ablocks-frontend-dashboard-menu__item--<?php echo esc_attr( $endpoint ); ?> <?php echo esc_attr( $menu['class_name'] ?? '' ); ?> <?php echo $is_parent_current ? 'ablocks-frontend-dashboard-menu__item--current' : ''; ?>"> | |
| 358 | + <a href="<?php echo esc_url( isset( $menu['permalink'] ) ? $menu['permalink'] : $this->get_frontend_dashboard_endpoint_url( $endpoint ) ); ?>"> | |
| 359 | + <i class="<?php if ( ! empty( $menu['icon'] ) ) { | |
| 360 | + echo esc_html( $menu['icon'] );} ?>"></i> | |
| 361 | + <span class="ablocks-frontend-dashboard-menu__item-label"><?php echo esc_html( $menu['label'] ); ?></span> | |
| 362 | + </a> | |
| 363 | + | |
| 364 | + <?php if ( ! empty( $menu['children'] ) ) : ?> | |
| 365 | + <ul class="ablocks-frontend-dashboard-menu__submenu"> | |
| 366 | + <?php foreach ( $menu['children'] as $child ) : ?> | |
| 367 | + <?php | |
| 368 | + $child['permalink'] = $child['permalink'] ?? $child['link'] ?? null; | |
| 369 | + $is_current_child = get_query_var( 'ablocks_dashboard_sub_page' ) === ( $child['slug'] ?? null ); | |
| 370 | + ?> | |
| 371 | + <li class="<?php echo esc_attr( $child['class_name'] ?? '' ); ?> <?php echo $is_current_child ? 'ablocks-frontend-dashboard-menu__item--current' : ''; ?>"><a href="<?php echo esc_url( isset( $child['permalink'] ) ? $child['permalink'] : $this->get_frontend_dashboard_endpoint_url( $endpoint . '/' . ( $child['slug'] ?? '' ) ) ); ?>"> | |
| 372 | + <i class="<?php if ( ! empty( $child['icon'] ) ) { | |
| 373 | + echo esc_html( $child['icon'] );} ?>"></i> | |
| 374 | + <?php echo esc_html( $child['label'] ); ?> | |
| 375 | + </a></li> | |
| 376 | + <?php endforeach; ?> | |
| 377 | + </ul> | |
| 378 | + <?php endif; ?> | |
| 379 | + </li> | |
| 380 | + <?php endforeach; ?> | |
| 381 | + </ul> | |
| 382 | + | |
| 383 | + </div> | |
| 384 | + <div class="ablocks-frontend-dashboard-content"> | |
| 385 | + <!-- Breadcrumb --> | |
| 386 | + <ul class="ablocks-frontend-dashboard-breadcrumb"> | |
| 387 | + <?php foreach ( $breadcrumbs as $crumb ) : | |
| 388 | + ?> | |
| 389 | + <li> | |
| 390 | + <?php echo esc_html( $crumb['label'] ); ?> | |
| 391 | + </li> | |
| 392 | + <?php endforeach; ?> | |
| 393 | + </ul> | |
| 394 | + <?php | |
| 395 | + if ( Helper::is_gutenberg_editor() ) { | |
| 396 | + self::render_dashboard_page_by_slug( $dashboard_page ); | |
| 397 | + // Show Notice for empty pages | |
| 398 | + if ( ! is_array( $dashboard_pages ) || ! count( $dashboard_pages ) ) { | |
| 399 | + echo 'Dashboard Page is empty. You haven\'t created any dashboard pages.'; | |
| 400 | + } | |
| 401 | + } else { | |
| 402 | + $is_resolved = false; | |
| 403 | + if ( ! empty( $wp->query_vars ) ) { | |
| 404 | + if ( isset( $wp->query_vars['ablocks_dashboard_page'] ) && | |
| 405 | + isset( $wp->query_vars['ablocks_dashboard_sub_page'] ) | |
| 406 | + ) { | |
| 407 | + self::render_dashboard_page_by_slug( | |
| 408 | + get_query_var( | |
| 409 | + 'ablocks_dashboard_sub_page' | |
| 410 | + ) | |
| 411 | + ); | |
| 412 | + } else { | |
| 413 | + self::render_dashboard_page_by_slug( | |
| 414 | + get_query_var( | |
| 415 | + 'ablocks_dashboard_page' | |
| 416 | + ) | |
| 417 | + ); | |
| 418 | + | |
| 419 | + } | |
| 420 | + $is_resolved = true; | |
| 421 | + }//end if | |
| 422 | + if ( ! $is_resolved ) { | |
| 423 | + // Render root | |
| 424 | + self::render_dashboard_page_by_slug( 'root' ); | |
| 425 | + } | |
| 426 | + }//end if | |
| 427 | + ?> | |
| 428 | + </div> | |
| 429 | + <?php | |
| 430 | + } | |
| 431 | + | |
| 432 | + public static function get_endpoint_url( $endpoint, $value = '', $permalink = '' ) { | |
| 433 | + global $wp_query; | |
| 434 | + if ( ! $permalink ) { | |
| 435 | + $permalink = get_permalink(); | |
| 436 | + } | |
| 437 | + | |
| 438 | + // Map endpoint to options. | |
| 439 | + $query_vars = $wp_query->query_vars; | |
| 440 | + $endpoint = ! empty( $query_vars[ $endpoint ] ) ? $query_vars[ $endpoint ] : $endpoint; | |
| 441 | + | |
| 442 | + if ( get_option( 'permalink_structure' ) ) { | |
| 443 | + if ( strstr( $permalink, '?' ) ) { | |
| 444 | + $query_string = '?' . wp_parse_url( $permalink, PHP_URL_QUERY ); | |
| 445 | + $permalink = current( explode( '?', $permalink ) ); | |
| 446 | + } else { | |
| 447 | + $query_string = ''; | |
| 448 | + } | |
| 449 | + $url = trailingslashit( $permalink ); | |
| 450 | + | |
| 451 | + if ( $value ) { | |
| 452 | + $url .= trailingslashit( $endpoint ) . user_trailingslashit( $value ); | |
| 453 | + } else { | |
| 454 | + $url .= user_trailingslashit( $endpoint ); | |
| 455 | + } | |
| 456 | + | |
| 457 | + $url .= $query_string; | |
| 458 | + } else { | |
| 459 | + $url = add_query_arg( $endpoint, $value, $permalink ); | |
| 460 | + } | |
| 461 | + | |
| 462 | + return apply_filters( 'ablocks/get_endpoint_url', $url, $endpoint, $value, $permalink ); | |
| 463 | + } | |
| 464 | + | |
| 465 | + public static function render_dashboard_page_by_slug( $slug ) { | |
| 466 | + global $wpdb; | |
| 467 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 468 | + $page = $wpdb->get_row( $wpdb->prepare( | |
| 469 | + "SELECT post_content FROM $wpdb->posts WHERE post_name = %s AND post_type = 'page'", | |
| 470 | + basename( $slug ) | |
| 471 | + ) ); | |
| 472 | + | |
| 473 | + if ( $page ) { | |
| 474 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 475 | + echo apply_filters( 'the_content', $page->post_content ); | |
| 476 | + return; | |
| 477 | + } | |
| 478 | + } | |
| 479 | + | |
| 480 | + public static function get_frontend_dashboard_endpoint_url( $endpoint ) { | |
| 481 | + if ( 'index' === $endpoint ) { | |
| 482 | + return Helper::get_page_permalink( 'frontend_dashboard_page' ); | |
| 483 | + } | |
| 484 | + | |
| 485 | + if ( 'logout' === $endpoint ) { | |
| 486 | + return Helper::get_logout_url(); | |
| 487 | + } | |
| 488 | + | |
| 489 | + return self::get_endpoint_url( $endpoint, '', Helper::get_page_permalink( 'frontend_dashboard_page' ) ); | |
| 490 | + } | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | +} | |