| @@ -8,11 +8,13 @@ | ||
| 8 | 8 | namespace RadiusTheme\SB\Controllers\Builder; |
| 9 | 9 | |
| 10 | 10 | defined( 'ABSPATH' ) || exit(); |
| 11 | 11 | |
| 12 | -use RadiusTheme\SB\Traits\SingletonTrait; | |
| 12 | +use RadiusTheme\SB\Models\TemplateSettings; | |
| 13 | +use WP_Query; | |
| 13 | 14 | use RadiusTheme\SB\Helpers\Fns; |
| 14 | 15 | use RadiusTheme\SB\Helpers\BuilderFns; |
| 16 | +use RadiusTheme\SB\Traits\SingletonTrait; | |
| 15 | 17 | |
| 16 | 18 | /** |
| 17 | 19 | * Builder Custom post type |
| 18 | 20 | */ |
| @@ -32,19 +34,53 @@ | ||
| 32 | 34 | add_filter( 'manage_edit-' . BuilderFns::$post_type_tb . '_columns', [ $this, 'add_new_columns' ] ); |
| 33 | 35 | add_action( 'manage_' . BuilderFns::$post_type_tb . '_posts_custom_column', [ $this, 'custom_columns' ], 10, 2 ); |
| 34 | 36 | add_filter( 'manage_edit-' . BuilderFns::$post_type_tb . '_sortable_columns', [ $this, 'register_sortable_columns' ] ); |
| 35 | 37 | add_action( 'pre_get_posts', [ $this, 'sortable_columns_query' ] ); |
| 36 | - add_filter( 'template_include', [ $this, 'builder_template' ], 99 ); | |
| 38 | + // Priority 99999 ensures ShopBuilder wins over Elementor Pro Theme Builder, | |
| 39 | + // which also filters `template_include` at 99. | |
| 40 | + add_filter( 'template_include', [ $this, 'builder_template' ], 99999 ); | |
| 41 | + add_filter( 'template_redirect', [ $this, 'restrict_preview_access' ], 99 ); | |
| 37 | 42 | |
| 38 | 43 | add_filter( 'parse_query', [ $this, 'query_filter' ] ); |
| 39 | - // add filter for search | |
| 44 | + // Add filter for search. | |
| 40 | 45 | add_action( 'restrict_manage_posts', [ $this, 'add_filter' ] ); |
| 46 | + // Post Content Remove For Elementor Builder. | |
| 47 | + add_action( 'save_post_' . BuilderFns::$post_type_tb, [ $this, 'on_save_post' ], 10, 2 ); | |
| 48 | + } | |
| 41 | 49 | |
| 42 | - add_action( 'in_admin_header', [ $this, 'remove_all_notices' ], 1000 ); | |
| 43 | - | |
| 50 | + /** | |
| 51 | + * Hook into post save to clear post content for specific post type and editor. | |
| 52 | + * | |
| 53 | + * This method checks if the post is being updated (not newly created), | |
| 54 | + * and if the post type matches the target type defined in BuilderFns::$post_type_tb. | |
| 55 | + * If the post is edited with Elementor, it clears the post_content directly | |
| 56 | + * from the database and clears the post cache. | |
| 57 | + * | |
| 58 | + * @param int $post_ID ID of the post being saved. | |
| 59 | + * @param WP_Post $post Post object. | |
| 60 | + * | |
| 61 | + * @return void | |
| 62 | + */ | |
| 63 | + public function on_save_post( $post_ID, $post ) { | |
| 64 | + // Only proceed on update and specific post type. | |
| 65 | + if ( BuilderFns::$post_type_tb !== $post->post_type ) { | |
| 66 | + return; | |
| 67 | + } | |
| 68 | + if ( 'elementor' !== Fns::page_edit_with( $post_ID ) ) { | |
| 69 | + return; | |
| 70 | + } | |
| 71 | + global $wpdb; | |
| 72 | + // Directly update the post_content to empty. | |
| 73 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery | |
| 74 | + $wpdb->update( | |
| 75 | + $wpdb->posts, | |
| 76 | + [ 'post_content' => '' ], | |
| 77 | + [ 'ID' => $post_ID ] | |
| 78 | + ); | |
| 79 | + // Clear cache so changes reflect properly. | |
| 80 | + clean_post_cache( $post_ID ); | |
| 44 | 81 | } |
| 45 | 82 | |
| 46 | - | |
| 47 | 83 | /** |
| 48 | 84 | * Public function add_filter. |
| 49 | 85 | * Added search filter for type of template |
| 50 | 86 | * |
| @@ -53,14 +89,14 @@ | ||
| 53 | 89 | public function add_filter() { |
| 54 | 90 | |
| 55 | 91 | global $typenow; |
| 56 | 92 | |
| 57 | - if ( $typenow != BuilderFns::$post_type_tb ) { | |
| 93 | + if ( BuilderFns::$post_type_tb != $typenow ) { | |
| 58 | 94 | return; |
| 59 | 95 | } |
| 60 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended. No need nonce. | |
| 61 | - $selected = isset( $_GET['type'] ) ? sanitize_key( $_GET['type'] ) : ''; | |
| 62 | - $builder_page_types = BuilderFns::builder_page_types(); | |
| 96 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 97 | + $selected = isset( $_GET['type'] ) ? sanitize_key( $_GET['type'] ) : ''; | |
| 98 | + $builder_page_types = BuilderFns::builder_page_types(); | |
| 63 | 99 | ?> |
| 64 | 100 | <select name="template_type" id="type"> |
| 65 | 101 | <option value="all" <?php selected( 'all', $selected ); ?>><?php esc_html_e( 'Template Type ', 'shopbuilder' ); ?></option> |
| 66 | 102 | <?php foreach ( $builder_page_types as $key => $value ) { ?> |
| @@ -67,9 +103,8 @@ | ||
| 67 | 103 | <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $key, $selected ); ?>><?php echo esc_html( $value ); ?></option> |
| 68 | 104 | <?php } ?> |
| 69 | 105 | </select> |
| 70 | 106 | <?php |
| 71 | - | |
| 72 | 107 | } |
| 73 | 108 | |
| 74 | 109 | /** |
| 75 | 110 | * Post type function |
| @@ -130,20 +165,19 @@ | ||
| 130 | 165 | 'feeds' => false, |
| 131 | 166 | ], |
| 132 | 167 | 'query_var' => true, |
| 133 | 168 | 'publicly_queryable' => true, |
| 134 | - 'capability_type' => 'product', | |
| 169 | + // 'capability_type' => 'product', Will Remove this line in the future. | |
| 135 | 170 | 'show_in_rest' => true, |
| 136 | 171 | 'rest_base' => BuilderFns::$post_type_tb, |
| 137 | 172 | ]; |
| 138 | 173 | |
| 139 | - $tb_args = apply_filters( 'rtsb_register_template_builder_args', $tb_args ); | |
| 174 | + $tb_args = apply_filters( 'rtsb/builder/template_args', $tb_args ); | |
| 140 | 175 | |
| 141 | 176 | register_post_type( BuilderFns::$post_type_tb, $tb_args ); |
| 142 | 177 | |
| 143 | 178 | // Flash rewrite rules. |
| 144 | 179 | $this->flush_rewrite_rules(); |
| 145 | - | |
| 146 | 180 | } |
| 147 | 181 | |
| 148 | 182 | /** |
| 149 | 183 | * Flush rewrite |
| @@ -187,17 +221,18 @@ | ||
| 187 | 221 | * @param string $post_id Post id. |
| 188 | 222 | * |
| 189 | 223 | * @return void |
| 190 | 224 | */ |
| 191 | - public function custom_columns( $column, $post_id ) { | |
| 192 | - $post_id = absint( $post_id ); | |
| 193 | - $types = BuilderFns::builder_page_types(); | |
| 194 | - $type = BuilderFns::builder_type( $post_id ) ? BuilderFns::builder_type( $post_id ) : array_key_first( $types ); | |
| 225 | + public function custom_columns( $column, $post_id ) { // phpcs:ignore Generic.Metrics.NestingLevel.TooHigh | |
| 226 | + $post_id = absint( $post_id ); | |
| 227 | + $types = BuilderFns::builder_page_types(); | |
| 228 | + $template_type = BuilderFns::builder_type( $post_id ) ? BuilderFns::builder_type( $post_id ) : array_key_first( $types ); | |
| 195 | 229 | |
| 196 | 230 | switch ( $column ) { |
| 197 | 231 | case 'type': |
| 198 | - $the_type = ! empty( $types[ $type ] ) ? esc_html( ucwords( $types[ $type ] ) ) : ''; | |
| 199 | - echo apply_filters( 'rtsb/columns/template/types/text', $the_type, $type, $post_id ); | |
| 232 | + $the_type = ! empty( $types[ $template_type ] ) ? '<b>' . esc_html( ucwords( $types[ $template_type ] ) ) . '</b>' : ''; | |
| 233 | + $the_type = $this->template_type_suffix( $the_type, $template_type, $post_id ); | |
| 234 | + Fns::print_html( apply_filters( 'rtsb/columns/template/types/text', $the_type, $template_type, $post_id ) ); | |
| 200 | 235 | break; |
| 201 | 236 | case 'edit_with': |
| 202 | 237 | $edit_by = Fns::page_edit_with( $post_id ); |
| 203 | 238 | echo esc_html( ucfirst( $edit_by ) ); |
| @@ -202,31 +237,83 @@ | ||
| 202 | 237 | $edit_by = Fns::page_edit_with( $post_id ); |
| 203 | 238 | echo esc_html( ucfirst( $edit_by ) ); |
| 204 | 239 | break; |
| 205 | 240 | case 'set_default': |
| 206 | - $is_set_default = absint( BuilderFns::builder_page_id_by_type( $type ) ); | |
| 207 | - $is_published = 'publish' === get_post_status( $post_id ); | |
| 208 | - $page_type_for = $type; | |
| 209 | - if ( 'product' === $type ) { | |
| 210 | - $product_ids = apply_filters( 'rtsb/product/page/builder/selected/products', [], $post_id ); | |
| 211 | - $set_default = BuilderFns::get_specific_product_as_default( $post_id ); | |
| 212 | - if ( ! empty( $product_ids ) && $set_default ) { | |
| 213 | - $is_set_default = $post_id; | |
| 214 | - $page_type_for = 'template-' . $post_id . '-specific-products'; | |
| 241 | + $singleton_types = apply_filters( | |
| 242 | + 'rtsb/builder/singleton_types', | |
| 243 | + array_keys( BuilderFns::builder_page_types() ) | |
| 244 | + ); | |
| 245 | + if ( in_array( $template_type, $singleton_types, true ) ) { | |
| 246 | + $is_set_default = absint( BuilderFns::builder_page_id_by_type( $template_type ) ); | |
| 247 | + } else { | |
| 248 | + // Pool type: read per-post meta flag — multiple templates of the same type can be enabled simultaneously. | |
| 249 | + $is_set_default = 'on' === get_post_meta( $post_id, '_rtsb_tb_enabled_in_pool', true ) ? $post_id : 0; | |
| 250 | + } | |
| 251 | + $is_published = 'publish' === get_post_status( $post_id ); | |
| 252 | + $page_type_for = $template_type; | |
| 253 | + if ( 'product' === $template_type ) { | |
| 254 | + $product_page_for = get_post_meta( $post_id, '_is_product_page_template_for', true ); | |
| 255 | + switch ( $product_page_for ) { | |
| 256 | + case 'specific_products': | |
| 257 | + $page_type_for = 'template-' . $post_id . '-specific-products'; | |
| 258 | + $set_default = BuilderFns::get_specific_product_as_default( $post_id ); | |
| 259 | + if ( $set_default ) { | |
| 260 | + $is_set_default = $post_id; | |
| 261 | + } | |
| 262 | + if ( ! $set_default && $is_set_default === $post_id ) { | |
| 263 | + $is_set_default = ''; | |
| 264 | + } | |
| 265 | + break; | |
| 266 | + case 'product_cats': | |
| 267 | + $page_type_for = 'product-page-template-' . $post_id . '-specific-category'; | |
| 268 | + $set_default_option_name = BuilderFns::option_name_product_page_specific_cat_set_default( $post_id ); | |
| 269 | + $pp_cat_set_default = TemplateSettings::instance()->get_option( $set_default_option_name ); | |
| 270 | + if ( $pp_cat_set_default ) { | |
| 271 | + $is_set_default = $post_id; | |
| 272 | + } | |
| 273 | + break; | |
| 274 | + case 'product_tags': | |
| 275 | + $page_type_for = 'product-page-template-' . $post_id . '-specific-tag'; | |
| 276 | + $set_default_option_name = BuilderFns::option_name_product_page_specific_tag_set_default( $post_id ); | |
| 277 | + $pp_tag_set_default = TemplateSettings::instance()->get_option( $set_default_option_name ); | |
| 278 | + if ( $pp_tag_set_default ) { | |
| 279 | + $is_set_default = $post_id; | |
| 280 | + } | |
| 281 | + break; | |
| 282 | + case 'product_brands': | |
| 283 | + $page_type_for = 'product-page-template-' . $post_id . '-specific-brand'; | |
| 284 | + $set_default_option_name = BuilderFns::option_name_product_page_specific_brand_set_default( $post_id ); | |
| 285 | + $pp_brand_set_default = TemplateSettings::instance()->get_option( $set_default_option_name ); | |
| 286 | + if ( $pp_brand_set_default ) { | |
| 287 | + $is_set_default = $post_id; | |
| 288 | + } | |
| 289 | + break; | |
| 290 | + default: | |
| 291 | + break; | |
| 215 | 292 | } |
| 216 | - } elseif ( 'archive' === $type ) { | |
| 217 | - $categories_name = apply_filters( 'rtsb/archive/page/builder/selected/categories', [], $post_id ); | |
| 293 | + } elseif ( 'archive' === $template_type ) { | |
| 294 | + $categories_name = apply_filters( 'rtsb/template/builder/selected/categories', [], $post_id, $template_type ); | |
| 218 | 295 | $set_default = BuilderFns::get_specific_category_as_default( $post_id ); |
| 219 | 296 | if ( ! empty( $categories_name ) && $set_default ) { |
| 220 | 297 | $is_set_default = $post_id; |
| 221 | 298 | $page_type_for = 'template-' . $post_id . '-specific-category'; |
| 299 | + } else { | |
| 300 | + $option_name = BuilderFns::option_name( $template_type ); | |
| 301 | + $is_set_default = TemplateSettings::instance()->get_option( $option_name ); | |
| 302 | + $set_default = $is_set_default; | |
| 222 | 303 | } |
| 304 | + if ( ! $set_default && $is_set_default === $post_id ) { | |
| 305 | + $is_set_default = ''; | |
| 306 | + } | |
| 223 | 307 | } |
| 308 | + | |
| 309 | + $is_set_default = apply_filters( 'rtsb/builder/columns/set_default', $is_set_default, $post_id, $template_type ); | |
| 310 | + $page_type_for = apply_filters( 'rtsb/builder/columns/page_type_for', $page_type_for, $post_id, $template_type ); | |
| 224 | 311 | ?> |
| 225 | 312 | <span class="rtsb-switch-wrapper page-type-<?php echo esc_attr( $page_type_for ); ?>" <?php echo ! $is_published ? 'style="pointer-events: none;"' : null; ?> title="<?php esc_html_e( 'Only publish post can set default ', 'shopbuilder' ); ?>"> |
| 226 | 313 | <label class="rtsb-switch"> |
| 227 | - <?php do_action( 'rtsb/set/default/column/extra/field', $post_id, $type, $is_set_default, $is_published ); ?> | |
| 228 | - <div class="rtsb_template_type" data-template_type="<?php echo esc_attr( $type ); ?>" style='display:none;'></div> | |
| 314 | + <?php do_action( 'rtsb/set/default/column/extra/field', $post_id, $template_type, $is_set_default, $is_published ); ?> | |
| 315 | + <div class="rtsb_template_type" data-template_type="<?php echo esc_attr( $template_type ); ?>" style='display:none;'></div> | |
| 229 | 316 | <input disabled="disabled" value="<?php echo absint( $post_id ); ?>" class="rtsb_set_default" name="set_default" type="checkbox" <?php echo esc_attr( $post_id === $is_set_default ? 'checked' : '' ); ?> > |
| 230 | 317 | <span class="rtsb-slider rtsb-round "> |
| 231 | 318 | <span class="rtsb-loader"></span> |
| 232 | 319 | </span> |
| @@ -237,8 +324,211 @@ | ||
| 237 | 324 | } |
| 238 | 325 | } |
| 239 | 326 | |
| 240 | 327 | /** |
| 328 | + * Appends template sub-type suffix and selected item details to the type column text. | |
| 329 | + * | |
| 330 | + * For product templates: shows "Template For Selected Products/Categories/Tags" | |
| 331 | + * with linked item names below. | |
| 332 | + * For archive templates: shows "Template For Selected Category" with linked names. | |
| 333 | + * | |
| 334 | + * @param string $the_type The current type column HTML. | |
| 335 | + * @param string $template_type The template type slug. | |
| 336 | + * @param int $post_id The builder post ID. | |
| 337 | + * | |
| 338 | + * @return string | |
| 339 | + */ | |
| 340 | + private function template_type_suffix( $the_type, $template_type, $post_id ) { | |
| 341 | + if ( 'product' === $template_type ) { | |
| 342 | + $the_type = $this->product_template_type_suffix( $the_type, $post_id ); | |
| 343 | + } elseif ( 'archive' === $template_type ) { | |
| 344 | + $the_type = $this->archive_template_type_suffix( $the_type, $post_id ); | |
| 345 | + } | |
| 346 | + | |
| 347 | + return $the_type; | |
| 348 | + } | |
| 349 | + | |
| 350 | + /** | |
| 351 | + * Appends product template sub-type suffix with linked product/category/tag names. | |
| 352 | + * | |
| 353 | + * @param string $the_type The current type column HTML. | |
| 354 | + * @param int $post_id The builder post ID. | |
| 355 | + * | |
| 356 | + * @return string | |
| 357 | + */ | |
| 358 | + private function product_template_type_suffix( $the_type, $post_id ) { | |
| 359 | + $product_page_for = get_post_meta( $post_id, '_is_product_page_template_for', true ); | |
| 360 | + $has_pro = rtsb()->has_pro(); | |
| 361 | + $pro_label = ! $has_pro ? ' <span class="rtsb-pro-label" style="color:#fff;background:#ff5722;padding:1px 6px;border-radius:3px;font-size:11px;font-weight:600;">' . esc_html__( 'Pro', 'shopbuilder' ) . '</span>' : ''; | |
| 362 | + | |
| 363 | + switch ( $product_page_for ) { | |
| 364 | + case 'specific_products': | |
| 365 | + $the_type .= ' - ' . esc_html__( 'Template For Selected Products', 'shopbuilder' ) . $pro_label; | |
| 366 | + if ( $has_pro ) { | |
| 367 | + $the_type .= $this->get_selected_products_html( $post_id ); | |
| 368 | + } | |
| 369 | + break; | |
| 370 | + case 'product_cats': | |
| 371 | + $the_type .= ' - ' . esc_html__( 'Template For Selected Categories', 'shopbuilder' ) . $pro_label; | |
| 372 | + if ( $has_pro ) { | |
| 373 | + $the_type .= $this->get_selected_terms_html( $post_id, 'product_cat' ); | |
| 374 | + } | |
| 375 | + break; | |
| 376 | + case 'product_tags': | |
| 377 | + $the_type .= ' - ' . esc_html__( 'Template For Selected Tags', 'shopbuilder' ) . $pro_label; | |
| 378 | + if ( $has_pro ) { | |
| 379 | + $the_type .= $this->get_selected_terms_html( $post_id, 'product_tag' ); | |
| 380 | + } | |
| 381 | + break; | |
| 382 | + } | |
| 383 | + | |
| 384 | + return $the_type; | |
| 385 | + } | |
| 386 | + | |
| 387 | + /** | |
| 388 | + * Appends archive template sub-type suffix with linked category names. | |
| 389 | + * | |
| 390 | + * @param string $the_type The current type column HTML. | |
| 391 | + * @param int $post_id The builder post ID. | |
| 392 | + * | |
| 393 | + * @return string | |
| 394 | + */ | |
| 395 | + private function archive_template_type_suffix( $the_type, $post_id ) { | |
| 396 | + $option_name = BuilderFns::archive_option_name_by_template_id( $post_id ); | |
| 397 | + $categories = TemplateSettings::instance()->get_option( $option_name ); | |
| 398 | + | |
| 399 | + if ( ! empty( $categories ) && is_array( $categories ) ) { | |
| 400 | + $has_pro = rtsb()->has_pro(); | |
| 401 | + $pro_label = ! $has_pro ? ' <span class="rtsb-pro-label" style="color:#fff;background:#ff5722;padding:1px 6px;border-radius:3px;font-size:11px;font-weight:600;">' . esc_html__( 'Pro', 'shopbuilder' ) . '</span>' : ''; | |
| 402 | + $the_type .= ' - ' . esc_html__( 'Template For Selected Category', 'shopbuilder' ) . $pro_label; | |
| 403 | + $the_type .= $this->get_selected_archive_categories_html( $categories ); | |
| 404 | + } | |
| 405 | + | |
| 406 | + return $the_type; | |
| 407 | + } | |
| 408 | + | |
| 409 | + /** | |
| 410 | + * Gets HTML list of selected archive category names with links. | |
| 411 | + * | |
| 412 | + * @param array $category_slugs Array of term slugs. | |
| 413 | + * | |
| 414 | + * @return string | |
| 415 | + */ | |
| 416 | + private function get_selected_archive_categories_html( $category_slugs ) { | |
| 417 | + if ( empty( $category_slugs ) || ! is_array( $category_slugs ) ) { | |
| 418 | + return ''; | |
| 419 | + } | |
| 420 | + | |
| 421 | + $links = []; | |
| 422 | + | |
| 423 | + foreach ( $category_slugs as $cat_slug ) { | |
| 424 | + $term = get_term_by( 'slug', $cat_slug, 'product_cat' ); | |
| 425 | + | |
| 426 | + if ( is_wp_error( $term ) || ! $term ) { | |
| 427 | + continue; | |
| 428 | + } | |
| 429 | + | |
| 430 | + $term_link = get_term_link( $term ); | |
| 431 | + | |
| 432 | + if ( is_wp_error( $term_link ) ) { | |
| 433 | + continue; | |
| 434 | + } | |
| 435 | + | |
| 436 | + $links[] = '<a href="' . esc_url( $term_link ) . '" target="_blank">' | |
| 437 | + . esc_html( $term->name ) . '</a>'; | |
| 438 | + } | |
| 439 | + | |
| 440 | + if ( empty( $links ) ) { | |
| 441 | + return ''; | |
| 442 | + } | |
| 443 | + | |
| 444 | + return '<br><small>' . implode( ', ', $links ) . '</small>'; | |
| 445 | + } | |
| 446 | + | |
| 447 | + /** | |
| 448 | + * Gets HTML list of selected product names with links to their detail pages. | |
| 449 | + * | |
| 450 | + * @param int $post_id The builder post ID. | |
| 451 | + * | |
| 452 | + * @return string | |
| 453 | + */ | |
| 454 | + private function get_selected_products_html( $post_id ) { | |
| 455 | + $option_name = BuilderFns::option_name_by_template_id( $post_id ); | |
| 456 | + $product_ids = TemplateSettings::instance()->get_option( $option_name ); | |
| 457 | + | |
| 458 | + if ( empty( $product_ids ) || ! is_array( $product_ids ) ) { | |
| 459 | + return ''; | |
| 460 | + } | |
| 461 | + | |
| 462 | + $links = []; | |
| 463 | + | |
| 464 | + foreach ( $product_ids as $product_id ) { | |
| 465 | + $product_id = absint( $product_id ); | |
| 466 | + $product = wc_get_product( $product_id ); | |
| 467 | + | |
| 468 | + if ( ! $product ) { | |
| 469 | + continue; | |
| 470 | + } | |
| 471 | + | |
| 472 | + $links[] = '<a href="' . esc_url( get_permalink( $product_id ) ) . '" target="_blank">' | |
| 473 | + . esc_html( $product->get_name() ) . '</a>'; | |
| 474 | + } | |
| 475 | + | |
| 476 | + if ( empty( $links ) ) { | |
| 477 | + return ''; | |
| 478 | + } | |
| 479 | + | |
| 480 | + return '<br><small>' . implode( ', ', $links ) . '</small>'; | |
| 481 | + } | |
| 482 | + | |
| 483 | + /** | |
| 484 | + * Gets HTML list of selected term names with links. | |
| 485 | + * | |
| 486 | + * @param int $post_id The builder post ID. | |
| 487 | + * @param string $taxonomy The taxonomy slug. | |
| 488 | + * | |
| 489 | + * @return string | |
| 490 | + */ | |
| 491 | + private function get_selected_terms_html( $post_id, $taxonomy ) { | |
| 492 | + if ( 'product_cat' === $taxonomy ) { | |
| 493 | + $option_name = BuilderFns::option_name_product_page_selected_cat( $post_id ); | |
| 494 | + } else { | |
| 495 | + $option_name = BuilderFns::option_name_product_page_selected_tag( $post_id ); | |
| 496 | + } | |
| 497 | + | |
| 498 | + $term_ids = TemplateSettings::instance()->get_option( $option_name ); | |
| 499 | + | |
| 500 | + if ( empty( $term_ids ) || ! is_array( $term_ids ) ) { | |
| 501 | + return ''; | |
| 502 | + } | |
| 503 | + | |
| 504 | + $links = []; | |
| 505 | + | |
| 506 | + foreach ( $term_ids as $term_id ) { | |
| 507 | + $term = get_term( absint( $term_id ), $taxonomy ); | |
| 508 | + | |
| 509 | + if ( is_wp_error( $term ) || ! $term ) { | |
| 510 | + continue; | |
| 511 | + } | |
| 512 | + | |
| 513 | + $term_link = get_term_link( $term ); | |
| 514 | + | |
| 515 | + if ( is_wp_error( $term_link ) ) { | |
| 516 | + continue; | |
| 517 | + } | |
| 518 | + | |
| 519 | + $links[] = '<a href="' . esc_url( $term_link ) . '" target="_blank">' | |
| 520 | + . esc_html( $term->name ) . '</a>'; | |
| 521 | + } | |
| 522 | + | |
| 523 | + if ( empty( $links ) ) { | |
| 524 | + return ''; | |
| 525 | + } | |
| 526 | + | |
| 527 | + return '<br><small>' . implode( ', ', $links ) . '</small>'; | |
| 528 | + } | |
| 529 | + | |
| 530 | + /** | |
| 241 | 531 | * Register sortable columns |
| 242 | 532 | * |
| 243 | 533 | * @param [type] $columns column list. |
| 244 | 534 | * |
| @@ -281,22 +571,23 @@ | ||
| 281 | 571 | |
| 282 | 572 | /** |
| 283 | 573 | * Manage Template filter by template type |
| 284 | 574 | * |
| 285 | - * @param \WP_Query $query WordPress main query. | |
| 575 | + * @param WP_Query $query WordPress main query. | |
| 286 | 576 | * |
| 287 | 577 | * @return void |
| 288 | 578 | */ |
| 289 | - public function query_filter( \WP_Query $query ) { | |
| 579 | + public function query_filter( WP_Query $query ) { | |
| 290 | 580 | |
| 291 | 581 | if ( ! is_admin() || ! $this->is_current_screen() || ! empty( $query->query_vars['meta_key'] ) ) { |
| 292 | 582 | return; |
| 293 | 583 | } |
| 584 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 294 | 585 | $type = isset( $_GET['template_type'] ) ? sanitize_key( $_GET['template_type'] ) : ''; |
| 295 | 586 | |
| 296 | 587 | if ( '' != $type && 'all' != $type ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 297 | 588 | $query->query_vars['meta_key'] = BuilderFns::template_type_meta_key(); // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key |
| 298 | - $query->query_vars['meta_value'] = $type; | |
| 589 | + $query->query_vars['meta_value'] = $type; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value | |
| 299 | 590 | $query->query_vars['meta_compare'] = '='; |
| 300 | 591 | } |
| 301 | 592 | } |
| 302 | 593 | |
| @@ -308,9 +599,9 @@ | ||
| 308 | 599 | * @return string |
| 309 | 600 | */ |
| 310 | 601 | public function builder_template( $template ) { |
| 311 | 602 | $builder_page_id = BuilderFns::is_builder_preview() ? get_the_ID() : BuilderFns::builder_page_id_by_page(); |
| 312 | - if ( $builder_page_id ) { | |
| 603 | + if ( defined( 'ELEMENTOR_VERSION' ) && $builder_page_id ) { // Elementor Check. | |
| 313 | 604 | $page_template = get_post_meta( $builder_page_id, '_wp_page_template', true ); |
| 314 | 605 | $new_template = RTSB_ABSPATH . 'page-templates/builder-template.php'; |
| 315 | 606 | if ( 'elementor_canvas' === $page_template ) { |
| 316 | 607 | $new_template = RTSB_ABSPATH . 'page-templates/elementor-canvas.php'; |
| @@ -325,8 +616,25 @@ | ||
| 325 | 616 | return $template; |
| 326 | 617 | } |
| 327 | 618 | |
| 328 | 619 | /** |
| 620 | + * Restrict the preview access. | |
| 621 | + * | |
| 622 | + * @return void | |
| 623 | + */ | |
| 624 | + public function restrict_preview_access() { | |
| 625 | + if ( ! apply_filters( 'rtsb/builder/preview/access', true ) ) { | |
| 626 | + return; | |
| 627 | + } | |
| 628 | + | |
| 629 | + if ( is_singular( 'rtsb_builder' ) ) { | |
| 630 | + if ( ! is_user_logged_in() ) { | |
| 631 | + wp_safe_redirect( home_url() ); | |
| 632 | + } | |
| 633 | + } | |
| 634 | + } | |
| 635 | + | |
| 636 | + /** | |
| 329 | 637 | * Add/Remove edit link in dashboard. |
| 330 | 638 | * |
| 331 | 639 | * Add or remove an edit link to the post/page action links on the post/pages list table. |
| 332 | 640 | * |
| @@ -339,22 +647,14 @@ | ||
| 339 | 647 | * @return array An updated array of row action links. |
| 340 | 648 | */ |
| 341 | 649 | public function filter_post_row_actions( $actions ) { |
| 342 | 650 | if ( $this->is_current_screen() ) { |
| 343 | - // unset( $actions['view'] ); | |
| 344 | 651 | unset( $actions['inline hide-if-no-js'] ); |
| 652 | + | |
| 653 | + if ( isset( $actions['view'] ) ) { | |
| 654 | + $actions['view'] = str_replace( __( 'View', 'shopbuilder' ), __( 'Preview', 'shopbuilder' ), $actions['view'] ); | |
| 655 | + } | |
| 345 | 656 | } |
| 346 | 657 | |
| 347 | 658 | return $actions; |
| 348 | - } | |
| 349 | - | |
| 350 | - /** | |
| 351 | - * Remove admin notices | |
| 352 | - */ | |
| 353 | - public function remove_all_notices() { | |
| 354 | - $screen = get_current_screen(); | |
| 355 | - if ( 'edit-rtsb_builder' === $screen->id ) { | |
| 356 | - remove_all_actions( 'admin_notices' ); | |
| 357 | - remove_all_actions( 'all_admin_notices' ); | |
| 358 | - } | |
| 359 | 659 | } |
| 360 | 660 | } |