Skip to content

Commit

Permalink
Merge pull request #96 from codersaiful/2.8.7
Browse files Browse the repository at this point in the history
2.8.7
  • Loading branch information
codersaiful authored May 12, 2021
2 parents 880e0c5 + 9c92e9d commit 59ae96f
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 6 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
61 changes: 61 additions & 0 deletions admin/functions.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php



if( !function_exists( 'wpt_admin_body_class' ) ){
/**
* set class for Admin Body tag
Expand Down Expand Up @@ -34,6 +37,64 @@ 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;

$meta = get_post_meta($post_id);
unset($meta['_edit_lock']);
unset($meta['_edit_last']);

$meta = array_map('array_filter', $meta);
$meta = array_filter($meta);

$serialize_meta = serialize($meta);
$base64_meta = base64_encode($serialize_meta);

return $base64_meta;
}
}


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
72 changes: 67 additions & 5 deletions admin/post_metabox.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,50 @@ function wpt_shortcode_metabox_render(){
function wpt_export_import_metabox_render(){
global $post;
$post_id = $post->ID;
//update_post_meta($post_id, $meta_key, $post_id);
//var_dump( get_post_meta($post_id));
// The following code has Transferred to admin/functions.php
// $meta = get_post_meta($post_id);
// unset($meta['_edit_lock']);
// unset($meta['_edit_last']);
//
// $meta = array_map('array_filter', $meta);
// $meta = array_filter($meta);
//
// $serialize_meta = serialize($meta);
// $base64_meta = base64_encode($serialize_meta);

$base64_meta = wpt_get_base64_post_meta( $post_id );

$post_title = preg_replace( '/[#$%^&*()+=\-\[\]\';,.\/{}|":<>?~\\\\]/',"$1", $post->post_title );
?>
<div class="wpt-export-import-wrapper">
<textarea id="wpt-export-textarea" class="wpt-export-textarea ua-input"></textarea>
</div>
<form class="wpt-export-import" action="" method="post">
<div class="wpt-export-import-wrapper">
<div class="wpt-export-area">
<label for="wpt-export-textarea">Export Box</label>
<textarea
id="wpt-export-textarea"
class="wpt-export-textarea ua-input"
onclick="this.focus();this.select()"
readonly="readonly"
><?php echo esc_html( $base64_meta ); ?></textarea>
</div>
<div class="wpt-import-area">

<label for="wpt-import-textarea">Import Box</label>
<textarea
name="wpt-import-data"
id="wpt-import-textarea"
class="wpt-import-textarea ua-input"
></textarea>
<div class="wpt-export-button-wrapper">
<button type="submit" name="wpt_import_button" class="button-primary button-primary primary button wpt-import-button">Import Table Data</button>
</div>
</div>
</div>




</form>
<?php
}
}
Expand All @@ -141,6 +178,7 @@ function wpt_shortcode_configuration_metabox_render(){

if( !function_exists( 'wpt_shortcode_configuration_metabox_save_meta' ) ){
function wpt_shortcode_configuration_metabox_save_meta( $post_id, $post ) { // save the data

/*
* We need to verify this came from our screen and with proper authorization,
* because the save_post action can be triggered at other times.
Expand All @@ -156,6 +194,30 @@ function wpt_shortcode_configuration_metabox_save_meta( $post_id, $post ) { // s
return;
}

/**
* Importing Data Here
*
* @since 2.8.7.1
* @by Saiful
* @date 10.5.2021
*/

if( isset( $_POST['wpt-import-data'] ) && ! empty( $_POST['wpt-import-data'] ) ){
$wpt_import_data = $_POST['wpt-import-data'];

/**
* Do something, when something importing on Import Box
*
* @Hooked wpt_importing_data admin/action-hook.php 10 (top side of this file)
*
* @since 2.8.7.1
* @by Saiful Islam
* @Date 10.5.2021
*/
do_action( 'wpto_import_data', $wpt_import_data, $post_id );
return;
}

/**
* @Hook Filter: wpto_on_save_global_post
* To change/Modify $_POST
Expand Down
1 change: 1 addition & 0 deletions assets/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,7 @@ a.button {}
/* Notice Style for UltraAddons | END*/

/* Export Import Features start */
.wpt-import-textarea,
.wpt-export-textarea{
width: 100%;
min-height: 100px;
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
3 changes: 2 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ You can easily show specific category products. While creating new table click o

== Changelog ==

= 2.8.6 =
= 2.8.7 =
* Product Table Preview added
* Export/Import Features Added

= 2.8.6 =
* Illegal Offset issue fixed
Expand Down

0 comments on commit 59ae96f

Please sign in to comment.