When using javascript to dynamically add a textarea, how can I render it as a tinyMCE editor (in wordpress)?
tinymce.remove(); tinymce.init(); This works well!
tinymce.remove(); tinymce.init(); This works well!
I hadn’t run your code, but my educated guess is that the fault in your code flow is that nonces are user specific. While anonymous nonce is possible, it is useless for its purpose because it would be same for all anonymous users. So there is likely mismatch somewhere and you are trying to use … Read more
File Upload via Ajax is a bit tricky, but manageable. Add some additional form fields (nonce and ajax_action) to your form in suite_export_import_menu(): function suite_export_import_menu(){ ?> <h2>Suite Report Export/Import </h2> <div id=”export_import_form”> <p id=”custom_ajax_call_process”>Uploading…</p> <p id=”custom_ajax_call_result”></p> <form action=”<?php echo admin_url(‘admin-ajax.php’); ?>” method=”post” enctype=”multipart/form-data” target=”upload_target”> <input type=”hidden” name=”action” value=”export_vacancy”> <input type=”hidden” name=”subaction” value=”imp_vacancy”> <input type=”file” name=”file_source” … Read more
What a type you work with response If you work with json $.post( ajaxurl , data , function(res){ // your code },’json’); Remove wp_die() and replace with die()
Attempting to answer this question directly: if the data you are returning is exactly the same each time, you can send cache control / expires headers with your AJAX response so that the browser knows not to request again for a while. // ask the browser to cache this response, to reduce requests $expires = … Read more
Your problem probably starts with your callback: public function handleAjax( $action ) To send a JSON error or success, you just have to call wp_send_json_success( array( /* Data */ ) ); wp_send_json_error( array( /* Data */ ) ); The response will be like: { success : true, data : [ // Some data as key/value … Read more
The error is most likely correct (and is most likely related to browser upgrade than any WP version change) and your theme/plugin does fishy things. The ajax enedpoint should be uses to return data – html/json/xml. WordPress will use the text/html mime type for all responses from the ajax endpoint without any simple way I … Read more
I figured it out. Simply, in my request, under data, I added “nonce” : “<?php echo wp_create_nonce( ‘refresh_my_plugin’ ); ?>” then to verify if (isset($_POST[‘refresh_my_plugin’])) if ( wp_verify_nonce( $_POST[‘nonce’], ‘refresh_my_plugin’ ) ) refresh_my_plugin(); With incorrect wp_verify_nonce, I instead get a 403, which is reflected on the button with the error handler.
You don’t need buffer here. get_template_part(‘more’, ‘images’); die();
If you wish to do it this way, you need to use the <ServerSideRender /> component in your edit method. Here’s a basic implementation, based on the PHP block registration code you provided. import { ServerSideRender } from ‘@wordpress/components’; registerBlockType( ‘some/block’, { title: ‘Some block’, attributes: { stuff : { } }, edit( { className, … Read more