New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
If ajax request, the plug-in cannot initialize #13
Comments
Hey @baronleung thanks for the issue. Can you provide more details about what kind of AJAX call are you trying to make? Is it an authenticated or unauthenticated AJAX call? What are you trying to achieve? Can you add some code samples so I can better understand this issue? |
@junaidbhura sorry, my english is poor. hope you can understand what I
mean.
// test plugin
|auto-cloudinary-ajax-test
|- auto-cloudinary-ajax-test.php
|- js/test.js
auto-cloudinary-ajax-test.php
----------------------------------------------------------------------------------------------------------------
<?php
/*
Plugin Name: Auto Cloudinary Ajax Test
Description: test ajax
Version: 1.0
Author: Baron Leung
Author URI: http://localhost
Text Domain: cloudinary ajax test
*/
add_action('wp_ajax_nopriv_cloudinary_test', 'cloudinary_ajax_test');
add_action('wp_ajax_cloudinary_test', 'cloudinary_ajax_test');
add_action('init',
'cloudinary_ajax_test_load_script');
if (!function_exists('cloudinary_ajax_test_load_script')) {
function cloudinary_ajax_test_load_script() {
wp_enqueue_script(
'cloudinary_ajax_test',
plugin_dir_url(__FILE__). 'js/test.js',
array('jquery')
);
wp_localize_script(
'cloudinary_ajax_test',
'cloudinary_ajax_test',
array('ajax_url' => admin_url('admin-ajax.php'))
);
}
}
if(!function_exists('cloudinary_ajax_test')) {
function cloudinary_ajax_test() {
// load template code
// use a simple alternative here
wp_send_json(array(
// check issue
// try modify the return value of
cloudinary_update_content_images()
// return JB\Cloudinary\Core::get_instance();
// @see namespace.php
// It does not initialize
JB\Cloudinary\Core::get_instance()->setup(),
// but initializes JB\Cloudinary\Admin::get_instance()->setup()
'html' => cloudinary_update_content_images('<img
class="wp-image-123" src="http:://localhost/test.jpg">')
));
wp_die();
}
}
js/test.js
-------------------------------------------------------------------------------------------------------------
(function ($) {
var test_url;
if(typeof ajaxurl === "undefined") {
test_url = cloudinary_ajax_test.ajax_url;
} else {
test_url = ajaxurl;
}
$.get(test_url, {action: "cloudinary_test"}, function (res) {
console.log(res.html);
});
})(jQuery);
…On Wed, Jan 9, 2019 at 6:36 AM Junaid Bhura ***@***.***> wrote:
Hey @baronleung <https://github.com/baronleung> thanks for the issue. Can
you provide more details about what kind of AJAX call are you trying to
make? Is it an authenticated or unauthenticated AJAX call?
What are you trying to achieve? Can you add some code samples so I can
better understand this issue?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#13 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AI4pDpmASO0WJGoT1xLE4B3bqKPqeh64ks5vBR1WgaJpZM4Z1a7X>
.
|
@baronleung Okay I understand the problem now, thank you. Let me see if I can find an elegant solution for this. |
@baronleung I've created a fix on another branch: better-ajax. Could you please download the plugin from this branch to see if it fixes your issue? If it does, I can merge it into master and release an update to the plugin. |
sorry, I'm late checking my email. check DOING is ok, that's how I handled
it
…On Wed, Jan 23, 2019 at 6:26 PM Junaid Bhura ***@***.***> wrote:
@baronleung <https://github.com/baronleung> I've created a fix on another
branch: better-ajax
<https://github.com/junaidbhura/auto-cloudinary/tree/better-ajax>.
Could you please download the plugin from this branch to see if it fixes
your issue?
If it does, I can merge it into master and release an update to the plugin.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#13 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AI4pDnOtrWo0wh-nhp8zF323enuI_iCTks5vGDjrgaJpZM4Z1a7X>
.
|
if ( is_admin() ) {
// if use admin-ajax.php, run this
// Admin stuff
Admin::get_instance()->setup();
} else {
// Front-end stuff.
Core::get_instance()->setup();
Frontend::get_instance()->setup();
}
The text was updated successfully, but these errors were encountered: