| @@ -23,8 +23,14 @@ | ||
| 23 | 23 | * @return string |
| 24 | 24 | */ |
| 25 | 25 | function wpbm_ics_import_shortcode( $attr ) { |
| 26 | 26 | |
| 27 | + if ( ( function_exists( 'wpbc_is_on_edit_page' ) ) && ( wpbc_is_on_edit_page() ) ) { | |
| 28 | + return wpbc_get_preview_for_shortcode( 'booking-manager-import', $attr ); //FixIn: 9.9.0.39 | |
| 29 | + } | |
| 30 | + | |
| 31 | + if ( wpbm_block_shortcodes_if_unpublished() ) { return ''; } // FixIn: 2.1.15.1. | |
| 32 | + | |
| 27 | 33 | ob_start(); |
| 28 | 34 | |
| 29 | 35 | $import_status = wpbm_ics_import_start( $attr ); |
| 30 | 36 | |
| @@ -63,9 +69,15 @@ | ||
| 63 | 69 | * |
| 64 | 70 | * @param array $attr |
| 65 | 71 | */ |
| 66 | 72 | function wpbm_ics_listing_shortcode( $attr ) { |
| 67 | - | |
| 73 | + | |
| 74 | + if ( ( function_exists( 'wpbc_is_on_edit_page' ) ) && ( wpbc_is_on_edit_page() ) ) { | |
| 75 | + return wpbc_get_preview_for_shortcode( 'booking-manager-listing', $attr ); //FixIn: 9.9.0.39 | |
| 76 | + } | |
| 77 | + | |
| 78 | + if ( wpbm_block_shortcodes_if_unpublished() ) { return ''; } // FixIn: 2.1.15.1. | |
| 79 | + | |
| 68 | 80 | $listing = wpbm_ics_get_listing( $attr ); |
| 69 | 81 | |
| 70 | 82 | return $listing; |
| 71 | 83 | |
| @@ -74,10 +86,17 @@ | ||
| 74 | 86 | |
| 75 | 87 | |
| 76 | 88 | //FixIn: 2.0.22.1 |
| 77 | 89 | // [booking-manager-delete resource_id=5] |
| 90 | +// [booking-manager-delete resource_id=5 action='delete'] | |
| 78 | 91 | function wpbm_ics_delete_shortcode( $attr ) { |
| 79 | 92 | |
| 93 | + if ( ( function_exists( 'wpbc_is_on_edit_page' ) ) && ( wpbc_is_on_edit_page() ) ) { | |
| 94 | + return wpbc_get_preview_for_shortcode( 'booking-manager-delete', $attr ); //FixIn: 9.9.0.39 | |
| 95 | + } | |
| 96 | + | |
| 97 | + if ( wpbm_block_shortcodes_if_unpublished() ) { return ''; } // FixIn: 2.1.15.1. | |
| 98 | + | |
| 80 | 99 | ob_start(); |
| 81 | 100 | |
| 82 | 101 | if ( ! isset( $attr['resource_id'] ) ) { |
| 83 | 102 | $attr['resource_id'] = 1; |
| @@ -82,21 +101,48 @@ | ||
| 82 | 101 | if ( ! isset( $attr['resource_id'] ) ) { |
| 83 | 102 | $attr['resource_id'] = 1; |
| 84 | 103 | } |
| 85 | 104 | |
| 105 | + if ( ! isset( $attr['action'] ) ) { | |
| 106 | + $attr['action'] = 'trash'; | |
| 107 | + } | |
| 108 | + | |
| 86 | 109 | global $wpdb; |
| 87 | 110 | $is_trash = 1; |
| 88 | - $resource_id = $attr['resource_id']; | |
| 89 | - $my_sql = "UPDATE {$wpdb->prefix}booking AS bk SET bk.trash = {$is_trash} WHERE sync_gid != '' AND trash != 1 AND booking_type = {$resource_id}"; | |
| 111 | + $resource_id = intval( $attr['resource_id'] ); //FixIn: | |
| 90 | 112 | |
| 91 | - if ( false === $wpdb->query( $my_sql ) ){ | |
| 92 | - ?> <script type="text/javascript"> | |
| 93 | - var my_message = '<?php echo html_entity_decode( esc_js( get_debuge_error('Error during trash booking in DB' ,__FILE__,__LINE__) ),ENT_QUOTES) ; ?>'; | |
| 113 | + if ( 'trash' == $attr['action'] ) { | |
| 114 | + | |
| 115 | + $my_sql = "UPDATE {$wpdb->prefix}booking AS bk SET bk.trash = {$is_trash} WHERE sync_gid != '' AND trash != 1 AND booking_type = {$resource_id}"; | |
| 116 | + | |
| 117 | + if ( false === $wpdb->query( $my_sql ) ) { | |
| 118 | + ?> | |
| 119 | + <script type="text/javascript"> | |
| 120 | + var my_message = '<?php echo html_entity_decode( esc_js( get_debuge_error( 'Error during trash booking in DB', __FILE__, __LINE__ ) ), ENT_QUOTES ); ?>'; | |
| 94 | 121 | wpbc_admin_show_message( my_message, 'error', 30000 ); |
| 95 | - </script> <?php | |
| 122 | + </script> <?php | |
| 123 | + } | |
| 96 | 124 | } |
| 97 | 125 | |
| 126 | + if ( 'delete' == $attr['action'] ) { | |
| 98 | 127 | |
| 128 | + $bookings_obj_arr = $wpdb->get_results( "SELECT booking_id as ID FROM {$wpdb->prefix}booking WHERE sync_gid != '' AND trash != 1 AND booking_type = {$resource_id} LIMIT 0, 1000" ); | |
| 129 | + | |
| 130 | + $id_arr = array(); | |
| 131 | + foreach ( $bookings_obj_arr as $booking_obj ) { | |
| 132 | + $id_arr[] = $booking_obj->ID; | |
| 133 | + } | |
| 134 | + $string_id = implode( ',', $id_arr ); | |
| 135 | + | |
| 136 | + if ( $string_id != '' ) { | |
| 137 | + | |
| 138 | + // D E L E T E Dates | |
| 139 | + if ( false === $wpdb->query( "DELETE FROM {$wpdb->prefix}bookingdates WHERE booking_id IN ({$string_id})" ) ) { ?> <script type="text/javascript"> var my_message = '<?php echo html_entity_decode( esc_js( get_debuge_error( 'Error during deleting booking in DB', __FILE__, __LINE__ ) ), ENT_QUOTES ); ?>'; wpbc_admin_show_message( my_message, 'error', 30000 ); </script> <?php die(); } | |
| 140 | + // D E L E T E Bookings | |
| 141 | + if ( false === $wpdb->query( "DELETE FROM {$wpdb->prefix}booking WHERE booking_id IN ({$string_id})" ) ){ ?> <script type="text/javascript"> var my_message = '<?php echo html_entity_decode( esc_js( get_debuge_error( 'Error during deleting booking in DB', __FILE__, __LINE__ ) ), ENT_QUOTES ); ?>'; wpbc_admin_show_message( my_message, 'error', 30000 ); </script> <?php die(); } | |
| 142 | + } | |
| 143 | + } | |
| 144 | + | |
| 99 | 145 | $echo_results = ob_get_contents(); |
| 100 | 146 | |
| 101 | 147 | ob_end_clean(); |
| 102 | 148 | |
| @@ -102,4 +148,45 @@ | ||
| 102 | 148 | |
| 103 | 149 | return ''; |
| 104 | 150 | } |
| 105 | 151 | add_shortcode( 'booking-manager-delete', 'wpbm_ics_delete_shortcode' ); |
| 152 | + | |
| 153 | + | |
| 154 | +/** | |
| 155 | + * Return true if shortcode should NOT run for the current post context. | |
| 156 | + * Allowed statuses are filterable via 'wpbm_shortcode_allowed_statuses' (default: ['publish']). | |
| 157 | + * | |
| 158 | + * @return bool | |
| 159 | + */ | |
| 160 | +function wpbm_block_shortcodes_if_unpublished() { | |
| 161 | + | |
| 162 | + // FixIn: 2.1.15.1. | |
| 163 | + $post = get_post(); | |
| 164 | + if ( ! $post ) { | |
| 165 | + return true; // no post context -> suppress. | |
| 166 | + } | |
| 167 | + | |
| 168 | + // e.g. add 'private'. | |
| 169 | + $allowed_statuses = apply_filters( 'wpbm_shortcode_allowed_statuses', array( 'publish' ) ); | |
| 170 | + | |
| 171 | + // Do not execute the shortcode. | |
| 172 | + if ( ! in_array( $post->post_status, $allowed_statuses, true ) ) { | |
| 173 | + return true; | |
| 174 | + } | |
| 175 | + | |
| 176 | + // Optional: allow front-end preview for editors. | |
| 177 | + /* | |
| 178 | + if ( is_preview() && current_user_can( 'edit_post', $post->ID ) ) { | |
| 179 | + return false; // allow | |
| 180 | + } | |
| 181 | + */ | |
| 182 | + | |
| 183 | + // Optional: suppress in REST/admin universally. | |
| 184 | + /* | |
| 185 | + if ( is_admin() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) { | |
| 186 | + return true; | |
| 187 | + } | |
| 188 | + */ | |
| 189 | + | |
| 190 | + // Execute the shortcode normally. | |
| 191 | + return false; | |
| 192 | +} | |