Skip to content

Commit

Permalink
complete expoert import
Browse files Browse the repository at this point in the history
  • Loading branch information
codersaiful committed May 10, 2021
1 parent 14dacf7 commit 41c2f67
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 0 deletions.
47 changes: 47 additions & 0 deletions admin/action-hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions admin/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
*/
Expand Down
28 changes: 28 additions & 0 deletions assets/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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("<div class='wpt_notify'><h1>Saving...</h1></div>");
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 41c2f67

Please sign in to comment.