| @@ -71,13 +71,14 @@ | ||
| 71 | 71 | * @var string |
| 72 | 72 | */ |
| 73 | 73 | public static $tags_product_page_template = 'rtsb_tags_product_page_template'; |
| 74 | 74 | /** |
| 75 | - * Page builder id. | |
| 75 | + * Get template ID based on page type. | |
| 76 | 76 | * |
| 77 | - * @return int | |
| 77 | + * @param string $type Page type (product, archive, etc.). | |
| 78 | + * @return int Template ID or 0. | |
| 78 | 79 | */ |
| 79 | - public static function builder_page_id_by_type( $type ) { | |
| 80 | + public static function builder_page_id_by_type( $type ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity | |
| 80 | 81 | global $post; |
| 81 | 82 | |
| 82 | 83 | if ( ! array_key_exists( $type, self::builder_page_types() ) ) { |
| 83 | 84 | return 0; |
| @@ -178,11 +179,11 @@ | ||
| 178 | 179 | return 0; |
| 179 | 180 | } |
| 180 | 181 | |
| 181 | 182 | /** |
| 182 | - * Page builder id. | |
| 183 | + * Get current page builder ID via filter. | |
| 183 | 184 | * |
| 184 | - * @return init | |
| 185 | + * @return int Template ID or 0. | |
| 185 | 186 | */ |
| 186 | 187 | public static function builder_page_id_by_page() { |
| 187 | 188 | $type = apply_filters( 'rtsb/builder/set/current/page/type', '' ); |
| 188 | 189 | if ( ! $type ) { |
| @@ -193,18 +194,19 @@ | ||
| 193 | 194 | } |
| 194 | 195 | |
| 195 | 196 | /** |
| 196 | 197 | * Page builder Page for. |
| 198 | + * No need translatable Text and textdomain. | |
| 197 | 199 | * |
| 198 | 200 | * @return array |
| 199 | 201 | */ |
| 200 | 202 | public static function builder_page_types() { |
| 201 | 203 | $page_types = [ |
| 202 | - 'shop' => esc_html__( 'Shop', 'shopbuilder' ), | |
| 203 | - 'archive' => esc_html__( 'Category Archive', 'shopbuilder' ), | |
| 204 | - 'product' => esc_html__( 'Product Page', 'shopbuilder' ), | |
| 205 | - 'cart' => esc_html__( 'Cart', 'shopbuilder' ), | |
| 206 | - 'checkout' => esc_html__( 'Checkout', 'shopbuilder' ), | |
| 204 | + 'shop' => 'Shop', | |
| 205 | + 'archive' => 'Category Archive', | |
| 206 | + 'product' => 'Product Page', | |
| 207 | + 'cart' => 'Cart', | |
| 208 | + 'checkout' => 'Checkout', | |
| 207 | 209 | ]; |
| 208 | 210 | |
| 209 | 211 | return apply_filters( 'rtsb/builder/register/page/types', $page_types ); |
| 210 | 212 | } |
| @@ -209,13 +211,13 @@ | ||
| 209 | 211 | return apply_filters( 'rtsb/builder/register/page/types', $page_types ); |
| 210 | 212 | } |
| 211 | 213 | |
| 212 | 214 | /** |
| 213 | - * Option name. | |
| 215 | + * Get option key for template storage. | |
| 214 | 216 | * |
| 215 | - * @param string $type Builder type. | |
| 216 | - * | |
| 217 | - * @return string | |
| 217 | + * @param string $type Template type. | |
| 218 | + * @param bool $default_lang Use default language. | |
| 219 | + * @return string Option key. | |
| 218 | 220 | */ |
| 219 | 221 | public static function option_name( $type, $default_lang = false ) { |
| 220 | 222 | |
| 221 | 223 | $type = str_replace( [ '-', ' ' ], '_', $type ); |
| @@ -233,11 +235,12 @@ | ||
| 233 | 235 | return self::$template_meta . '_default_' . $suffix; |
| 234 | 236 | } |
| 235 | 237 | |
| 236 | 238 | /** |
| 237 | - * @param $post_id | |
| 239 | + * Option name to mark product template as default. | |
| 238 | 240 | * |
| 239 | - * @return string|void | |
| 241 | + * @param int $post_id Template ID. | |
| 242 | + * @return string|null | |
| 240 | 243 | */ |
| 241 | 244 | public static function option_name_for_specific_product_set_default( $post_id ) { |
| 242 | 245 | if ( ! $post_id ) { |
| 243 | 246 | return; |
| @@ -246,11 +249,12 @@ | ||
| 246 | 249 | return 'rtsb_template_specific_product_set_default_' . $post_id; |
| 247 | 250 | } |
| 248 | 251 | |
| 249 | 252 | /** |
| 250 | - * @param $post_id | |
| 253 | + * Check if a specific product template is default. | |
| 251 | 254 | * |
| 252 | - * @return false|mixed|void|null | |
| 255 | + * @param int $post_id Template ID. | |
| 256 | + * @return mixed | |
| 253 | 257 | */ |
| 254 | 258 | public static function get_specific_product_as_default( $post_id ) { |
| 255 | 259 | if ( ! $post_id ) { |
| 256 | 260 | return; |
| @@ -260,11 +264,12 @@ | ||
| 260 | 264 | return TemplateSettings::instance()->get_option( $options ); |
| 261 | 265 | } |
| 262 | 266 | |
| 263 | 267 | /** |
| 264 | - * @param $post_id | |
| 268 | + * Option name for default category template. | |
| 265 | 269 | * |
| 266 | - * @return string|void | |
| 270 | + * @param int $post_id Template ID. | |
| 271 | + * @return string|null | |
| 267 | 272 | */ |
| 268 | 273 | public static function option_name_for_specific_category_set_default( $post_id ) { |
| 269 | 274 | if ( ! $post_id ) { |
| 270 | 275 | return; |
| @@ -273,11 +278,12 @@ | ||
| 273 | 278 | return 'rtsb_template_specific_category_set_default_' . $post_id; |
| 274 | 279 | } |
| 275 | 280 | |
| 276 | 281 | /** |
| 277 | - * @param $post_id | |
| 282 | + * Check if a specific category template is default. | |
| 278 | 283 | * |
| 279 | - * @return false|mixed|void|null | |
| 284 | + * @param int $post_id Template ID. | |
| 285 | + * @return mixed | |
| 280 | 286 | */ |
| 281 | 287 | public static function get_specific_category_as_default( $post_id ) { |
| 282 | 288 | if ( ! $post_id ) { |
| 283 | 289 | return; |
| @@ -282,15 +288,15 @@ | ||
| 282 | 288 | if ( ! $post_id ) { |
| 283 | 289 | return; |
| 284 | 290 | } |
| 285 | 291 | $options = self::option_name_for_specific_category_set_default( $post_id ); |
| 286 | - | |
| 287 | - return TemplateSettings::instance()->get_option( $options ); // get_option( $options ); | |
| 292 | + return TemplateSettings::instance()->get_option( $options ); | |
| 288 | 293 | } |
| 289 | 294 | |
| 290 | 295 | /** |
| 291 | - * @param $template_id | |
| 296 | + * Get meta key by template ID for products. | |
| 292 | 297 | * |
| 298 | + * @param int $template_id Template ID. | |
| 293 | 299 | * @return string |
| 294 | 300 | */ |
| 295 | 301 | public static function option_name_by_template_id( $template_id ) { |
| 296 | 302 | $_suff = null; |
| @@ -301,11 +307,13 @@ | ||
| 301 | 307 | return self::$view_template_for_products_meta . $_suff; |
| 302 | 308 | } |
| 303 | 309 | |
| 304 | 310 | /** |
| 305 | - * @param $template_id | |
| 311 | + * Get option name for the selected product category template. | |
| 306 | 312 | * |
| 307 | - * @return string | |
| 313 | + * @param int|string $template_id Template ID for the category. | |
| 314 | + * | |
| 315 | + * @return string Generated option name. | |
| 308 | 316 | */ |
| 309 | 317 | public static function option_name_product_page_selected_cat( $template_id ) { |
| 310 | 318 | $_suff = null; |
| 311 | 319 | if ( $template_id ) { |
| @@ -315,11 +323,13 @@ | ||
| 315 | 323 | return self::$categories_product_page_template . $_suff; |
| 316 | 324 | } |
| 317 | 325 | |
| 318 | 326 | /** |
| 319 | - * @param $post_id | |
| 327 | + * Get option name for setting a specific product category template as default. | |
| 320 | 328 | * |
| 321 | - * @return string|void | |
| 329 | + * @param int|string $post_id Template or post ID. | |
| 330 | + * | |
| 331 | + * @return string|null Option name or null if post ID is invalid. | |
| 322 | 332 | */ |
| 323 | 333 | public static function option_name_product_page_specific_cat_set_default( $post_id ) { |
| 324 | 334 | if ( ! $post_id ) { |
| 325 | 335 | return; |
| @@ -328,11 +338,13 @@ | ||
| 328 | 338 | return 'rtsb_template_product_page_specific_category_set_default_' . $post_id; |
| 329 | 339 | } |
| 330 | 340 | |
| 331 | 341 | /** |
| 332 | - * @param $template_id | |
| 342 | + * Get option name for the selected product tag template. | |
| 333 | 343 | * |
| 334 | - * @return string | |
| 344 | + * @param int|string $template_id Template ID for the tag. | |
| 345 | + * | |
| 346 | + * @return string Generated option name. | |
| 335 | 347 | */ |
| 336 | 348 | public static function option_name_product_page_selected_tag( $template_id ) { |
| 337 | 349 | $_suff = null; |
| 338 | 350 | if ( $template_id ) { |
| @@ -341,11 +353,13 @@ | ||
| 341 | 353 | |
| 342 | 354 | return self::$tags_product_page_template . $_suff; |
| 343 | 355 | } |
| 344 | 356 | /** |
| 345 | - * @param $post_id | |
| 357 | + * Get option name for setting a specific product tag template as default. | |
| 346 | 358 | * |
| 347 | - * @return string|void | |
| 359 | + * @param int|string $post_id Template or post ID. | |
| 360 | + * | |
| 361 | + * @return string|null Option name or null if post ID is not provided. | |
| 348 | 362 | */ |
| 349 | 363 | public static function option_name_product_page_specific_tag_set_default( $post_id ) { |
| 350 | 364 | if ( ! $post_id ) { |
| 351 | 365 | return; |
| @@ -353,11 +367,13 @@ | ||
| 353 | 367 | |
| 354 | 368 | return 'rtsb_template_product_page_specific_tag_set_default_' . $post_id; |
| 355 | 369 | } |
| 356 | 370 | /** |
| 357 | - * @param $template_id | |
| 371 | + * Get option name for the selected archive (category) template. | |
| 358 | 372 | * |
| 359 | - * @return string | |
| 373 | + * @param int|string $template_id Template ID. | |
| 374 | + * | |
| 375 | + * @return string Generated option name. | |
| 360 | 376 | */ |
| 361 | 377 | public static function archive_option_name_by_template_id( $template_id ) { |
| 362 | 378 | $_suff = null; |
| 363 | 379 | if ( $template_id ) { |
| @@ -367,11 +383,11 @@ | ||
| 367 | 383 | return self::$view_template_for_archive_meta . $_suff; |
| 368 | 384 | } |
| 369 | 385 | |
| 370 | 386 | /** |
| 371 | - * Template builder | |
| 387 | + * Returns meta key used to store builder type. | |
| 372 | 388 | * |
| 373 | - * @var string | |
| 389 | + * @return string | |
| 374 | 390 | */ |
| 375 | 391 | public static function template_type_meta_key() { |
| 376 | 392 | return self::$template_meta . '_type'; |
| 377 | 393 | } |
| @@ -403,11 +419,11 @@ | ||
| 403 | 419 | return $type; |
| 404 | 420 | } |
| 405 | 421 | |
| 406 | 422 | /** |
| 407 | - * Template builder | |
| 423 | + * Check if current page is builder preview. | |
| 408 | 424 | * |
| 409 | - * @var boolean | |
| 425 | + * @return bool | |
| 410 | 426 | */ |
| 411 | 427 | public static function is_builder_preview() { |
| 412 | 428 | return is_singular( self::$post_type_tb ); |
| 413 | 429 | } |
| @@ -412,11 +428,11 @@ | ||
| 412 | 428 | return is_singular( self::$post_type_tb ); |
| 413 | 429 | } |
| 414 | 430 | |
| 415 | 431 | /** |
| 416 | - * Template builder | |
| 432 | + * Check if archive template should load. | |
| 417 | 433 | * |
| 418 | - * @var boolean | |
| 434 | + * @return bool | |
| 419 | 435 | */ |
| 420 | 436 | public static function is_archive() { |
| 421 | 437 | return self::is_page_builder( 'archive', is_product_taxonomy() ); |
| 422 | 438 | } |
| @@ -421,11 +437,11 @@ | ||
| 421 | 437 | return self::is_page_builder( 'archive', is_product_taxonomy() ); |
| 422 | 438 | } |
| 423 | 439 | |
| 424 | 440 | /** |
| 425 | - * Template builder | |
| 441 | + * Check if shop template should load. | |
| 426 | 442 | * |
| 427 | - * @var boolean | |
| 443 | + * @return bool | |
| 428 | 444 | */ |
| 429 | 445 | public static function is_shop() { |
| 430 | 446 | return self::is_page_builder( 'shop', is_shop() ); |
| 431 | 447 | } |
| @@ -430,11 +446,11 @@ | ||
| 430 | 446 | return self::is_page_builder( 'shop', is_shop() ); |
| 431 | 447 | } |
| 432 | 448 | |
| 433 | 449 | /** |
| 434 | - * Template builder | |
| 450 | + * Check if cart template should load. | |
| 435 | 451 | * |
| 436 | - * @var boolean | |
| 452 | + * @return bool | |
| 437 | 453 | */ |
| 438 | 454 | public static function is_cart() { |
| 439 | 455 | return self::is_page_builder( 'cart', is_cart() ); |
| 440 | 456 | } |
| @@ -439,11 +455,11 @@ | ||
| 439 | 455 | return self::is_page_builder( 'cart', is_cart() ); |
| 440 | 456 | } |
| 441 | 457 | |
| 442 | 458 | /** |
| 443 | - * Template builder | |
| 459 | + * Check if checkout template should load. | |
| 444 | 460 | * |
| 445 | - * @var boolean | |
| 461 | + * @return bool | |
| 446 | 462 | */ |
| 447 | 463 | public static function is_checkout() { |
| 448 | 464 | return self::is_page_builder( 'checkout', is_checkout() && ! is_wc_endpoint_url() && ! is_order_received_page() ); |
| 449 | 465 | } |
| @@ -457,10 +473,11 @@ | ||
| 457 | 473 | return self::is_page_builder( 'product', is_product() ); |
| 458 | 474 | } |
| 459 | 475 | |
| 460 | 476 | /** |
| 461 | - * @param $is_quick_view | |
| 477 | + * Check if quick view page template should load. | |
| 462 | 478 | * |
| 479 | + * @param bool $is_quick_view True if quick view. | |
| 463 | 480 | * @return bool |
| 464 | 481 | */ |
| 465 | 482 | public static function is_quick_views_page( $is_quick_view = false ) { |
| 466 | 483 | return rtsb()->has_pro() && self::is_page_builder( 'quick-view', $is_quick_view ); |
| @@ -465,35 +482,38 @@ | ||
| 465 | 482 | public static function is_quick_views_page( $is_quick_view = false ) { |
| 466 | 483 | return rtsb()->has_pro() && self::is_page_builder( 'quick-view', $is_quick_view ); |
| 467 | 484 | } |
| 468 | 485 | |
| 486 | + | |
| 469 | 487 | /** |
| 470 | - * Builder page detector. | |
| 488 | + * Check if a template should replace default WooCommerce page. | |
| 471 | 489 | * |
| 472 | - * @param string $type builder Page type. | |
| 473 | - * @param boolean $is_page page status. | |
| 474 | - * | |
| 475 | - * @return boolean | |
| 490 | + * @param string $type Page type. | |
| 491 | + * @param bool $is_page Current page status. | |
| 492 | + * @param bool $is_require_auth Require login. | |
| 493 | + * @return bool | |
| 476 | 494 | */ |
| 477 | 495 | public static function is_page_builder( $type, $is_page, $is_require_auth = false ) { |
| 478 | - if ( self::builder_type( get_the_ID() ) === $type ) { | |
| 479 | - return true; | |
| 496 | + $current_builder_type = self::builder_type( get_the_ID() ); | |
| 497 | + $post_type = get_post_type( get_the_ID() ); | |
| 498 | + if ( $post_type === self::$post_type_tb ) { | |
| 499 | + if ( $current_builder_type === $type ) { | |
| 500 | + return true; | |
| 501 | + } else { | |
| 502 | + return false; | |
| 503 | + } | |
| 480 | 504 | } |
| 481 | - | |
| 482 | 505 | if ( $is_require_auth && ! is_user_logged_in() ) { |
| 483 | 506 | $type = 'myaccount-auth'; |
| 484 | 507 | } |
| 485 | - | |
| 486 | 508 | $builder_id = self::builder_page_id_by_type( $type ); |
| 487 | 509 | if ( ! $builder_id ) { |
| 488 | 510 | return false; |
| 489 | 511 | } |
| 490 | - | |
| 491 | 512 | $builder_type = self::builder_type( $builder_id ); |
| 492 | 513 | if ( $type === $builder_type && $is_page ) { |
| 493 | 514 | return true; |
| 494 | 515 | } |
| 495 | - | |
| 496 | 516 | return false; |
| 497 | 517 | } |
| 498 | 518 | |
| 499 | 519 | /** |