If anyone is facing any issues where the plugin show Error in Processing!. Please check the browser network and console to make sure there is no JavaScript conflict with other plugin and it has a permission to run AJAX. Please give the permission to WP_AJAX hook and disable other plugin that might caused an issue and then try again.
After following the above request if still anyone is facing any issue, then please raise the comment I will connect ASAP and try to resolve the issue.
]]>class Test{
private $infos;
function get_info() {
if ( isset($_REQUEST['my_info']) ) {
$this->infos = $_REQUEST['my_info'];
echo 'your input is:'.$this->infos;
}
// Always die in functions echoing ajax content or it will display 0 or another word
// die();
}
function salcodes_year() {
echo 'the data is:'.$this->var;
return $this->var;
}
function js2php_register(){
add_action( 'wp_ajax_test_info', array($this, 'get_info') );
add_action( 'wp_ajax_nopriv_test_info', array($this, 'get_info') );
add_shortcode( 'current_year', array($this, 'salcodes_year') );
}
}
$test = new Test;
$test->js2php_register();
Version:
WordPress 5.8.2
PHP 7.4.27
MySQL 5.7.37 Community Server (GPL)
Help me, please!
]]>This is HTML:
</div>
<form class="row g-3" id="my_form">
<div class="col-md-12">
<label for="url" class="form-label">Input URL</label>
<input type="text" class="form-control my_info" id="url" required>
<div class="col-12">
<button class="btn btn-primary submit" type="button">Submit form</button>
</div>
</form>
</div>
This is JavaScript:
function getBaseUrl() {
var re = new RegExp(/^.*\//);
var my_local_url = re.exec(window.location.href)[0];
return my_local_url;
}
console.log(getBaseUrl())
jQuery(document).ready(function($) {
console.log('test');
// We'll pass this variable to the PHP function example_ajax_request
var fruit = 'Banana';
$('.submit').click(function (){
// This does the ajax request
$.ajax({
url: getBaseUrl() + 'admin-ajax.php',
data: {
'action':'crawler_info',
'my_info' : document.getElementById('url').value
},
success:function(data) {
// This outputs the result of the ajax request
console.log(data);
},
error: function(errorThrown){
console.log(errorThrown);
}
});
})
});
This is PHP:
function get_info() {
// The $_REQUEST contains all the data sent via ajax
if ( isset($_REQUEST) ) {
$infos = $_REQUEST['my_info'];
// Now we'll return it to the javascript function
// Anything outputted will be returned in the response
echo $infos;
// If you're debugging, it might be useful to see what was sent in the $_REQUEST
print_r($_REQUEST);
}
// Always die in functions echoing ajax content or it will display 0 or another word
die();
}
add_action( 'wp_ajax_crawler_info', 'get_info' );
add_action( 'wp_ajax_nopriv_crawler_info', 'get_info' );
Does anybody know how to solve my problem,Thanks
]]>Constant PHP message since updating WooCommerce:
The is_ajax function is deprecated since version 6.1.0. Replace with wp_doing_ajax.
Which seems to originate from this plugin. As this is appears to be a plugin ‘validated’ by WooCommerce themselves, how has it not been updated? Is the Pro version also outdated?
Will look to implement another solution now, but please do keep on top of developments with WooCommerce if you develop plugins for it. After 2 years you should really have confirmed it’s still compatible or not by updating version numbers. COuld you give a time frame for fixing this?
Or if you have any other input please let me know.
]]>I’ve cleared cache, i’ve deactivated it and others; still a no go.
Got anyideas on how to get this to show on all posts not just the first page; or to call on each paginated page click?
Please don’t confuse this with my pagination not working; it is working fine on its own; I guess its just not talking to this plugin?
Using 4.7.3 WP and Jupiter -> 5.7
– mod_rewrite Option Is Enabled
– links are set to /%postname%/
I can’t figure out what happens with my post_admin hook.
Here is my code in a custom plugin :
/** Shortcode pour créer un formulaire de réinitialisation du mot de passe **/
add_shortcode("NEO7_FIRSTPASSWORD", "neo7_first_password_form");
function neo7_first_password_form( $attrs ) {
global $current_user;
if (is_user_logged_in()){
$output='<!-- Change Password Form -->';
$output.=' <form action="'.esc_url( admin_url('admin-post.php') ).'" method="post" class="neo7_change_password_form">';
$output.=' <div><label for="password">Nouveau mot de passe</label><br/>';
$output.=' <input name="password" type="password" class="form-control password1" /></div>';
$output.=' <div><label for="password2">Saisir à nouveau le mot de passe</label><br/>';
$output.=' <input name="password2" type="password" class="form-control password2" /></div>';
$output.=' <input type="hidden" name="action" value="first_password">';;
$output.=' <input type="submit" name="btn-change-pass" class="um-button" id="btn-change-pass" value="Changer le mot de passe"/>';
$output.=' </form>';
}
else{$output="Accès non autorisé à cette page.";}
return $output;
}
add_action( 'admin_post_nopriv_first_password', 'admin_first_password' );
add_action( 'admin_post_first_password', 'admin_first_password' );
function admin_first_password() {
global $current_user;
error_log("Lancement de la fonction admin_first_password() pour exécuter le changement de mot de passe.");
if(isset($_POST['action']) && $_POST['action'] == 'first_password') {
//Sanitize received password
$password = sanitize_text_field($_POST['password']);
error_log("Mot de passe bien re?u : ".$password);
// Define arguments that will be passed to the wp_update_user()
$userdata = array(
'ID' => $current_user->ID,
'user_pass' => $password // WordPress automatically applies the wp_hash_password() function to the user_pass field.
);
$user_id = wp_update_user($userdata);
// wp_update_user() will return the user_id on success and an array of error messages on failure.
// so bellow we are going to check if the returned string is equal to the current user ID, if yes then we proceed updating the user meta field
if($user_id == $current_user->ID){
update_user_meta($current_user->ID, 'neo7_changepass_status', 1);
wp_redirect( home_url( '/mot-de-passe-ok/' ) );
} else {
wp_redirect( home_url( '/mot-de-passe-erreur/' ) );
}
}
// Always exit to avoid further execution
exit();
}
As you can see, I have a shortcode creating a form in order to change the password.
WHAT IS STRANGE : the hook is triggered normally when I’m logged out (useless in my context) and when I’m logged in as an admin.
But it is not triggered when I’m logged in as a member.
I tried both with the FORM submition and using directly the URL (…/wp-admin/admin-post.php?action=first_password)
I put a log in admin-post.php, but it is not called (by the way, how is it possible when the URL is called directly..?). And once again, it IS triggered when logged as an admin.
Any suggestion would help…
Thank you
]]>I am attempting to use wp_ajax_. The code for the form is in a class:
class CourseSearch {
public function __construct( $plugin ) {
add_action( 'wp_ajax_subject_search', array( $this, 'return_subjects') );
add_action( 'wp_ajax_nopriv_subject_search', array( $this, 'return_subjects') );
}
function return_subjects() {
$subjects = $this->get_subjects( $_POST['grade'] );
echo json_encode( $subjects );
}
}
Javascript:
$('#select_grade').on( 'change', function( event ) {
display_subjects( event );
});
/** Functions
------------------------------------------------------------------------*/
function display_subjects( event ) {
var grade = event.currentTarget.value;
var path = plugin.path + 'classes/class-course-search.php';
console.log( path, grade );
$.ajax({
url: path,
type: 'post',
dataType: 'json',
data: {
grade: grade,
action: 'subject_search'
},
success: populate_subject_list,
error: clear_subject_list,
});
}
function populate_subject_list( data ) {
console.log( 'success', this, data );
}
function clear_subject_list( data ) {
console.log( 'fail', data );
}
I am at a dead end, so any help is appreciated.
]]>I want edit wp_ajax_find_posts
it is in wp-admin/includes/ajax-actions.php
when I try add any action or filter it doesnt work, is any other way to edit this function ?
Matt
]]>I’ve been trying to solve this problem for a few hours now, so any help would be greatly appreciated!!
I wrote an AJAX function to load two different pages that toggled using 2 links. Each of these pages includes native wordpress functions like get_current_user_id(). They work fine if I load them normally by entering in the address in the address bar, but when I call the page using ajax, I receive a fatal error of an undefined function.
I’ve done a lot of searching for this on the web already, and it seems like everybody refers to the AJAX in Plugins page, which tells me to use add_action(‘wp_ajax…’,’…’). I’ve sunk many hours into trying to implement this with no success. Can anyone give me some pointers?
Thanks,
Ben
Here’s my code:
HTML:
<ul id='learn-selector'>
<h2>QUIZZES</h2>
<li class='quiz-new'><a href='?learn=quiz-overview'>New Quiz</a></li>
<li class='quiz-clinic-settings'><a href='?learn=quiz-error'>Settings</a></li>
</ul>
<div id='learn-body'>
<?php
if (isset($_GET['learn'])){
switch ($_GET['learn']){
case 'quiz-overview':
include 'quiz-overview.php';
break;
case 'quiz-error':
include 'quiz-error.php';
break;
}
}
?>
</div> <!-- learn-body-->
Javascript:
function getHTTPObject() {
var xhr = false;
if (window.XMLHttpRequest){
xhr = new XMLHttpRequest();
}
else if (window.ActiveXObject){
try{
xhr = new ActiveXObject('Msxml2.XMLHTTP');
}
catch(e){
try{
xhr = new ActiveXObject('Microsoft.XMLHTTP');
}
catch(e){
xhr = false;
}
}
}
return xhr;
}
function grabFile(file){
var request = getHTTPObject();
if (request){
request.onreadystatechange = function (){
parseResponse(request);
};
request.open('GET',file,true);
request.send(null);
return true;
}
else {
return false;
}
}
window.onload = prepareLinks;
function prepareLinks(){
if (!document.getElementById || !document.getElementsByTagName){
return;
}
var list = document.getElementById('learn-selector');
var links = list.getElementsByTagName('a');
for (var i=0; i<links.length;i++){
links[i].onclick=function(){
var query = this.getAttribute('href').split('?learn=')[1];
var url ='https://eyeguru.org/wp-content/themes/thesis_185/custom/'+query+'.php';
return !grabFile(url);
};
}
}
function parseResponse(request){
if (request.readyState ==4){
if(request.status == 200 || request.status == 304){
var details = document.getElementById('learn-body');
details.innerHTML = request.responseText;
}
}
}
]]>