| @@ -8,9 +8,8 @@ | ||
| 8 | 8 | namespace RadiusTheme\SB\Controllers\Builder; |
| 9 | 9 | |
| 10 | 10 | defined( 'ABSPATH' ) || exit(); |
| 11 | 11 | |
| 12 | -use RadiusTheme\SB\Models\TemplateSettings; | |
| 13 | 12 | use WP_Query; |
| 14 | 13 | use RadiusTheme\SB\Helpers\Fns; |
| 15 | 14 | use RadiusTheme\SB\Helpers\BuilderFns; |
| 16 | 15 | use RadiusTheme\SB\Traits\SingletonTrait; |
| @@ -35,9 +34,8 @@ | ||
| 35 | 34 | add_action( 'manage_' . BuilderFns::$post_type_tb . '_posts_custom_column', [ $this, 'custom_columns' ], 10, 2 ); |
| 36 | 35 | add_filter( 'manage_edit-' . BuilderFns::$post_type_tb . '_sortable_columns', [ $this, 'register_sortable_columns' ] ); |
| 37 | 36 | add_action( 'pre_get_posts', [ $this, 'sortable_columns_query' ] ); |
| 38 | 37 | add_filter( 'template_include', [ $this, 'builder_template' ], 99 ); |
| 39 | - add_filter( 'template_redirect', [ $this, 'restrict_preview_access' ], 99 ); | |
| 40 | 38 | |
| 41 | 39 | add_filter( 'parse_query', [ $this, 'query_filter' ] ); |
| 42 | 40 | // add filter for search. |
| 43 | 41 | add_action( 'restrict_manage_posts', [ $this, 'add_filter' ] ); |
| @@ -42,8 +40,9 @@ | ||
| 42 | 40 | // add filter for search. |
| 43 | 41 | add_action( 'restrict_manage_posts', [ $this, 'add_filter' ] ); |
| 44 | 42 | |
| 45 | 43 | add_action( 'in_admin_header', [ $this, 'remove_all_notices' ], 1000 ); |
| 44 | + | |
| 46 | 45 | } |
| 47 | 46 | |
| 48 | 47 | |
| 49 | 48 | /** |
| @@ -69,8 +68,9 @@ | ||
| 69 | 68 | <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $key, $selected ); ?>><?php echo esc_html( $value ); ?></option> |
| 70 | 69 | <?php } ?> |
| 71 | 70 | </select> |
| 72 | 71 | <?php |
| 72 | + | |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
| 76 | 76 | * Post type function |
| @@ -130,9 +130,9 @@ | ||
| 130 | 130 | 'with_front' => true, |
| 131 | 131 | 'feeds' => false, |
| 132 | 132 | ], |
| 133 | 133 | 'query_var' => true, |
| 134 | - 'publicly_queryable' => true, | |
| 134 | + 'publicly_queryable' => apply_filters( 'rtsb/builder/args/publicly_queryable', true ), | |
| 135 | 135 | 'capability_type' => 'product', |
| 136 | 136 | 'show_in_rest' => true, |
| 137 | 137 | 'rest_base' => BuilderFns::$post_type_tb, |
| 138 | 138 | ]; |
| @@ -142,8 +142,9 @@ | ||
| 142 | 142 | register_post_type( BuilderFns::$post_type_tb, $tb_args ); |
| 143 | 143 | |
| 144 | 144 | // Flash rewrite rules. |
| 145 | 145 | $this->flush_rewrite_rules(); |
| 146 | + | |
| 146 | 147 | } |
| 147 | 148 | |
| 148 | 149 | /** |
| 149 | 150 | * Flush rewrite |
| @@ -188,16 +189,16 @@ | ||
| 188 | 189 | * |
| 189 | 190 | * @return void |
| 190 | 191 | */ |
| 191 | 192 | public function custom_columns( $column, $post_id ) { |
| 192 | - $post_id = absint( $post_id ); | |
| 193 | - $types = BuilderFns::builder_page_types(); | |
| 194 | - $template_type = BuilderFns::builder_type( $post_id ) ? BuilderFns::builder_type( $post_id ) : array_key_first( $types ); | |
| 193 | + $post_id = absint( $post_id ); | |
| 194 | + $types = BuilderFns::builder_page_types(); | |
| 195 | + $type = BuilderFns::builder_type( $post_id ) ? BuilderFns::builder_type( $post_id ) : array_key_first( $types ); | |
| 195 | 196 | |
| 196 | 197 | switch ( $column ) { |
| 197 | 198 | case 'type': |
| 198 | - $the_type = ! empty( $types[ $template_type ] ) ? '<b>' . esc_html( ucwords( $types[ $template_type ] ) ) . '</b>' : ''; | |
| 199 | - Fns::print_html( apply_filters( 'rtsb/columns/template/types/text', $the_type, $template_type, $post_id ) ); | |
| 199 | + $the_type = ! empty( $types[ $type ] ) ? esc_html( ucwords( $types[ $type ] ) ) : ''; | |
| 200 | + Fns::print_html( apply_filters( 'rtsb/columns/template/types/text', $the_type, $type, $post_id ) ); | |
| 200 | 201 | break; |
| 201 | 202 | case 'edit_with': |
| 202 | 203 | $edit_by = Fns::page_edit_with( $post_id ); |
| 203 | 204 | echo esc_html( ucfirst( $edit_by ) ); |
| @@ -202,42 +203,20 @@ | ||
| 202 | 203 | $edit_by = Fns::page_edit_with( $post_id ); |
| 203 | 204 | echo esc_html( ucfirst( $edit_by ) ); |
| 204 | 205 | break; |
| 205 | 206 | case 'set_default': |
| 206 | - $is_set_default = absint( BuilderFns::builder_page_id_by_type( $template_type ) ); | |
| 207 | + $is_set_default = absint( BuilderFns::builder_page_id_by_type( $type ) ); | |
| 207 | 208 | $is_published = 'publish' === get_post_status( $post_id ); |
| 208 | - $page_type_for = $template_type; | |
| 209 | - if ( 'product' === $template_type ) { | |
| 210 | - $product_page_for = get_post_meta( $post_id, '_is_product_page_template_for', true ); | |
| 211 | - switch ( $product_page_for ) { | |
| 212 | - case 'specific_products': | |
| 213 | - $page_type_for = 'template-' . $post_id . '-specific-products'; | |
| 214 | - $set_default = BuilderFns::get_specific_product_as_default( $post_id ); | |
| 215 | - if ( $set_default ) { | |
| 216 | - $is_set_default = $post_id; | |
| 217 | - } | |
| 218 | - break; | |
| 219 | - case 'product_cats': | |
| 220 | - $page_type_for = 'product-page-template-' . $post_id . '-specific-category'; | |
| 221 | - $set_default_option_name = BuilderFns::option_name_product_page_specific_cat_set_default( $post_id ); | |
| 222 | - $pp_cat_set_default = TemplateSettings::instance()->get_option( $set_default_option_name ); | |
| 223 | - if ( $pp_cat_set_default ) { | |
| 224 | - $is_set_default = $post_id; | |
| 225 | - } | |
| 226 | - break; | |
| 227 | - case 'product_tags': | |
| 228 | - $page_type_for = 'product-page-template-' . $post_id . '-specific-tag'; | |
| 229 | - $set_default_option_name = BuilderFns::option_name_product_page_specific_tag_set_default( $post_id ); | |
| 230 | - $pp_tag_set_default = TemplateSettings::instance()->get_option( $set_default_option_name ); | |
| 231 | - if ( $pp_tag_set_default ) { | |
| 232 | - $is_set_default = $post_id; | |
| 233 | - } | |
| 234 | - break; | |
| 235 | - default: | |
| 236 | - break; | |
| 209 | + $page_type_for = $type; | |
| 210 | + if ( 'product' === $type ) { | |
| 211 | + $product_ids = apply_filters( 'rtsb/product/page/builder/selected/products', [], $post_id ); | |
| 212 | + $set_default = BuilderFns::get_specific_product_as_default( $post_id ); | |
| 213 | + if ( ! empty( $product_ids ) && $set_default ) { | |
| 214 | + $is_set_default = $post_id; | |
| 215 | + $page_type_for = 'template-' . $post_id . '-specific-products'; | |
| 237 | 216 | } |
| 238 | - } elseif ( 'archive' === $template_type ) { | |
| 239 | - $categories_name = apply_filters( 'rtsb/template/builder/selected/categories', [], $post_id, $template_type ); | |
| 217 | + } elseif ( 'archive' === $type ) { | |
| 218 | + $categories_name = apply_filters( 'rtsb/archive/page/builder/selected/categories', [], $post_id ); | |
| 240 | 219 | $set_default = BuilderFns::get_specific_category_as_default( $post_id ); |
| 241 | 220 | if ( ! empty( $categories_name ) && $set_default ) { |
| 242 | 221 | $is_set_default = $post_id; |
| 243 | 222 | $page_type_for = 'template-' . $post_id . '-specific-category'; |
| @@ -245,10 +224,10 @@ | ||
| 245 | 224 | } |
| 246 | 225 | ?> |
| 247 | 226 | <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' ); ?>"> |
| 248 | 227 | <label class="rtsb-switch"> |
| 249 | - <?php do_action( 'rtsb/set/default/column/extra/field', $post_id, $template_type, $is_set_default, $is_published ); ?> | |
| 250 | - <div class="rtsb_template_type" data-template_type="<?php echo esc_attr( $template_type ); ?>" style='display:none;'></div> | |
| 228 | + <?php do_action( 'rtsb/set/default/column/extra/field', $post_id, $type, $is_set_default, $is_published ); ?> | |
| 229 | + <div class="rtsb_template_type" data-template_type="<?php echo esc_attr( $type ); ?>" style='display:none;'></div> | |
| 251 | 230 | <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' : '' ); ?> > |
| 252 | 231 | <span class="rtsb-slider rtsb-round "> |
| 253 | 232 | <span class="rtsb-loader"></span> |
| 254 | 233 | </span> |
| @@ -348,25 +327,8 @@ | ||
| 348 | 327 | return $template; |
| 349 | 328 | } |
| 350 | 329 | |
| 351 | 330 | /** |
| 352 | - * Restrict the preview access. | |
| 353 | - * | |
| 354 | - * @return void | |
| 355 | - */ | |
| 356 | - public function restrict_preview_access() { | |
| 357 | - if ( ! apply_filters( 'rtsb/builder/preview/access', true ) ) { | |
| 358 | - return; | |
| 359 | - } | |
| 360 | - | |
| 361 | - if ( is_singular( 'rtsb_builder' ) ) { | |
| 362 | - if ( ! is_user_logged_in() ) { | |
| 363 | - wp_safe_redirect( home_url() ); | |
| 364 | - } | |
| 365 | - } | |
| 366 | - } | |
| 367 | - | |
| 368 | - /** | |
| 369 | 331 | * Add/Remove edit link in dashboard. |
| 370 | 332 | * |
| 371 | 333 | * Add or remove an edit link to the post/page action links on the post/pages list table. |
| 372 | 334 | * |
| @@ -381,12 +343,8 @@ | ||
| 381 | 343 | public function filter_post_row_actions( $actions ) { |
| 382 | 344 | if ( $this->is_current_screen() ) { |
| 383 | 345 | // unset( $actions['view'] ); |
| 384 | 346 | unset( $actions['inline hide-if-no-js'] ); |
| 385 | - | |
| 386 | - if ( isset( $actions['view'] ) ) { | |
| 387 | - $actions['view'] = str_replace( __( 'View', 'shopbuilder' ), __( 'Preview', 'shopbuilder' ), $actions['view'] ); | |
| 388 | - } | |
| 389 | 347 | } |
| 390 | 348 | |
| 391 | 349 | return $actions; |
| 392 | 350 | } |