diff --git a/admin/action-hook.php b/admin/action-hook.php index ec05515d..bbd1f1b0 100644 --- a/admin/action-hook.php +++ b/admin/action-hook.php @@ -3,6 +3,53 @@ * WPT MODULE + ADMIN ACTION HOOK * WPT Module and In Admin */ + +if( ! function_exists( 'wpt_importing_data' ) ){ + + /** + * Importing Table setting from any other place + * Actually there is a action hook at post_metabox.php file + * for saving table's setting/ table post + * and I have added a filter wpto_import_data to do something + * for import data + * + * @param type $wpt_imported_data + * @param type $post_id + */ + function wpt_importing_data( $wpt_imported_data, $post_id ){ + $serialized_data = base64_decode( $wpt_imported_data ); + $is_serialized = is_serialized( $serialized_data ); + $meta_update_array = array(); + if( $is_serialized ){ + + $meta_update_array = unserialize( $serialized_data ); + } + foreach( $meta_update_array as $meta_key => $meta_value ){ + $final_meta_value = isset( $meta_value[0] ) && is_serialized($meta_value[0]) ? unserialize( $meta_value[0] ) : false; + if( $final_meta_value ){ + update_post_meta( $post_id, $meta_key, $final_meta_value ); + } + + } + //add_filter( 'post_updated_messages', 'wpt_post_message_for_import' ); + + } +} +add_action( 'wpto_import_data', 'wpt_importing_data', 10, 2); + + +if( ! function_exists( 'wpt_post_message_for_import' ) ){ + + function wpt_post_message_for_import( $message ){ + + $message['wpt_custom_message'][] = "Hello World"; + return $message; + } +} + + + + if( !function_exists( 'wpt_admin_form_top' ) ){ /** * Docs and Support Link to Our Form Top diff --git a/admin/functions.php b/admin/functions.php index d0bbb542..6cc9d675 100644 --- a/admin/functions.php +++ b/admin/functions.php @@ -40,6 +40,15 @@ function wpt_selected( $keyword, $gotten_value, $default_config = false ){ if( ! function_exists( 'wpt_get_base64_post_meta' ) ){ /** + * Getting Post Meta Value in base64 encoded formate + * Typically I have used it in post_metabox.php file + * for export box. + * + * In future, we can use it any another place. + * + * @since 2.8.7.1 + * @by Saiful + * @date 11.5.2021 */ function wpt_get_base64_post_meta( $post_id ){ if( ! $post_id || ! is_numeric( $post_id ) ) return false; @@ -59,6 +68,34 @@ function wpt_get_base64_post_meta( $post_id ){ } +if( ! function_exists( 'wpt_ajax_get_post_meta_base64' ) ){ + + /** + * Getting base64 Post meta for Export box + * It will generate and handle from admin.js using + * ajax request + * and we will use POST Request + * + * @since 2.8.7.1 + * @by Saiful + * @date 11.5.2021 + */ + function wpt_ajax_get_post_meta_base64(){ + if( isset( $_POST['post_id'] ) && ! empty( $_POST['post_id'] ) && isset( $_POST['action'] ) == 'wpt_set_post_meta' ){ + $post_id = $_POST['post_id']; + if( ! $post_id || ! is_numeric( $post_id ) ) echo ''; + + echo wpt_get_base64_post_meta( $post_id ); + }else{ + echo ''; + } + die(); + } +} +add_action( 'wp_ajax_wpt_set_post_meta', 'wpt_ajax_get_post_meta_base64' ); +add_action( 'wp_ajax_nopriv_wpt_set_post_meta', 'wpt_ajax_get_post_meta_base64' ); + + /** * @todo This function and will remove */ diff --git a/assets/js/admin.js b/assets/js/admin.js index f525eb6f..894d4351 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -557,6 +557,11 @@ $(document).on('change','li.wpt_sortable_peritem.column_keyword_content',function(){ $('.button,button').removeClass('wpt_ajax_update'); }); + + $(document).on('click,change,focus','#wpt-import-textarea',function(){ + $('.button,button').removeClass('wpt_ajax_update'); + }); + //*********************** AJAX Save - AJAX data save $('body').append("

Saving...

"); @@ -596,6 +601,29 @@ $.post(postURL, data, function(response){}).done(function(){ $('.wpt_notify h1').html('Saved Product Table'); $('.wpt_notify').fadeOut(); + }).done(function() { + var post_id = $('#post_ID').val(); + var ajax_url = WPT_DATA_ADMIN.ajax_url; + + $.ajax({ + type: 'POST', + url: ajax_url,// + get_data, + data: { + action: 'wpt_set_post_meta', + post_id: post_id, + }, + complete: function(){ + + }, + success: function(data) { + $('#wpt-export-textarea').html(data); + $('#wpt-import-textarea').html(data); + }, + error: function() { + + }, + }); + }).fail(function(){ $('.wpt_notify h1').html('Unable to Save, Please try again.'); $('.wpt_notify').fadeOut();