Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

canvas save in WP post WordPress

  • SOLVED

https://kinder.com.tw/%E5%81%A5%E9%81%94%E8%A6%AA%E5%AD%90%E7%87%9F%E9%A4%8A%E6%99%82%E5%85%89%E4%B8%80/
this is my event site
i use canvas plugin for photo frame
and USP plugin for summit post
wish can user upload the file with photo frame
when send or summit bottom click then
the frame photo can be save in WP post

Answers (4)

2017-10-02

Cesar Contreras answers:

you want to add the photo when registering a new user?

Maybe you can solve your problem using this plugin:
https://www.advancedcustomfields.com/

2017-10-02

Bob answers:

may be this answer from wpquestions.com site can help you.

https://wpquestions.com/Save_canvas_in_wp_upload/19678

2017-10-04

Arnav Joy answers:

can you please describe more about your requirement ?

2017-10-03

Mohamed Ahmed answers:

Hello,

If you want to convert canvas to image URL and save it to WordPress post, You can depend on this codes

jQuery
<script>
jQuery(document).ready(function($) {
/* Variables */
var canvas = $('#canvas')[0],
ctx = canvas.getContext('2d'),
photo_frame = $('.photo_frames_loading');

/* Convert canvas data to image url */
var dataURL = canvas.toDataURL('image/png');
/* Add canvas image url to photo frame div in data-url tag */
photo_frame.attr('data-url',dataURL);


/* Use Ajax to pass canvas image url to PHP function */
var imageURL = photo_frame.attr('data-url');

// This does the ajax request
$.ajax({
url: ajaxurl,
data: {
'action':'save_canvas_in_wp_post',
'imageURL' : imageURL
},
success:function(data) {
// This outputs the result of the ajax request
console.log(data);
},
error: function(errorThrown){
console.log(errorThrown);
}
});

});
</script>

#PHP to functions.php file
function save_canvas_in_wp_post() {
global $post;
if ( isset($_REQUEST) ) {

$imageURL = $_REQUEST['imageURL'];

// Save image URL to post meta field
add_post_meta( $post->ID, 'user_photo_frame', $imageURL );

}
die();
}

add_action( 'wp_ajax_save_canvas_in_wp_post', 'save_canvas_in_wp_post' );

// If you want to also use the function for non-logged in users remove slashes from next line
// add_action( 'wp_ajax_nopriv_save_canvas_in_wp_post', 'save_canvas_in_wp_post' );

/* Localize ajax script */
function enqueue_ajax_script() {
wp_register_script('ajax-script', esc_url(get_template_directory_uri()));
wp_enqueue_script('ajax-script');
wp_localize_script( 'ajax-script', 'ajaxurl', admin_url( 'admin-ajax.php' ) );
}

add_action('wp_enqueue_scripts', 'enqueue_ajax_script');

If you need anything else please tell us