wpusrpt
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: Function not working after calling classIn case someone else has this problem, I found the fix on https://www.sitepoint.com/displaying-errors-from-the-save-post-hook-in-wordpress/
Forum: Developing with WordPress
In reply to: How to load function with a hookThanks once again. I have added it to a class and that is working fine. I would still like to get the function to work just so I understand the concept. I will work on that at some point and use your instructions as a guide.
Forum: Developing with WordPress
In reply to: How to load function with a hookThanks again for the help. It allowed me to see the problem. I changed the call to
register_activation_hook( __FILE__ ,'test_install' );
And then added this to the main file:
function test_install() { return 'yes'; }
And when I call that function it works. So it appears that any function I want to use needs to be in the main file. There will be other functions I need to add so I thought it would make the code easier to follow if they were all grouped in an external file. That’s why I was trying to do it as I did. Is that not possible?
Would it be better to add the functions as a class and extend the one I am using? I’m not new to coding but this is my first try at WP so I want to learn the correct way to do things.
Forum: Developing with WordPress
In reply to: How to load function with a hookThank you for responding. The error displayed in admin is
There has been a critical error on this website. Please check your site admin email inbox for instructions.
That is for the whole admin so I guess the WP code is doing some sanity checks. I never receive an email. If I comment out the register_activation_hook line, everything load but the database function is not loaded.
Forum: Developing with WordPress
In reply to: 400 Bad Request and ajax pathI’m not sure what I did wrong but I deleted it all and re-did it and it is working now. Thanks again for the help. I do appreciate it. ??
Forum: Developing with WordPress
In reply to: 400 Bad Request and ajax pathThank you both. The missing callback was the problem. I have added it and it seems to be working but I don’t see how to use the data on the page. Here is the code I added”
function my_script_action() { $path = __DIR__ . '/myscript.php'; require $path; wp_die(); //die(); } add_action( 'wp_ajax_my_script_action', 'my_script_action' ); //ajax file - myscript.php if (isset($_POST['extract'])) { $result = 'hello ajax'; echo $result; exit;
And in my class file I added a div for results
class Myscript_Settings { public function __construct( $plugin_basename ) {} public function display_panel() { ?> <div id="run-myscript"><button>Run</button></div> <div id="ajax-results"></div> <?php } }
If I run the script the callback function displays “hello ajax” in the console but I don’t see how to place that result into the div I added. I know how to populate the div with jquery. Do I need to add more jquery code and pass the result to it from the callback? That seems convoluted. By the way, the fixed code by @zakirbd63 shows a console.log in the post result code but that never displays. That is where I would normally add the jquery code to populate the result div but since that is not being called, I can’t do that. Can someone please explain how to handle the result from the ajax file?
Forum: Developing with WordPress
In reply to: Removing non-existent fileThank you. I needed to clear the data in Firefox. The test.php file was the name of my ajax file. That is still not working but I will post a new question since you fixed this one. ??
Forum: Developing with WordPress
In reply to: Form submits but results not showingThanks again for the suggestions. I have done away with the functions file and moved the form handler to the class and it is working now. I’m sure the function could be be made to work but this probably makes more sense in the long run.
Forum: Developing with WordPress
In reply to: Form submits but results not showingThank you for your reply. I changed the print_r to use $_REQUEST but all that it shows are the form elements. I don’t think the function to handle the form is ever being called. I found the admin_post action in the docs that sounds like it was for this purpose. In the class above the submit button I added
<input type="hidden" name="action" value="my_panel_action" />
and in the main file after calling my functions file I added
add_action( 'admin_post_my_panel_action', 'traitement_formulaire_don_cagnotte' );
But the above didn’t make any difference. Did I use that code correctly? How does the form handler get called?
Regarding this code, it is just an example I found on the web. I’m only using it to learn how to handle the form.