The effects of alcohol on sustanon 250 leucine for – real weight loss & bodybuilding benefits?
Search
Close
AI Search
Classic Search
 Search Phrase:
 Search Type:
Advanced search options
 Search in Forums:
 Search in date period:

 Sort Search Results by:

AI Assistant
Redirect to new pos...
 
Notifications
Clear all

Question [Solved] Redirect to new post after comment submit from action hook

3 Posts
2 Users
2 Reactions
2,251 Views
(@dc10000)
Posts: 3
Active Member
Topic starter
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
 
[#7559]

I suspect this has an easy solution but I'm banging my head and hopefully someone willing to kindly help me out.

Quick version:

Is there a wpdiscus action hook that fires after a comment has saved, that will also allow for a javascript page redirect without the "unsaved changes" popup confirmation dialog firing? I've tried wpdiscuz_after_comment_post but the page believes that there are unsaved changes no matter what I do.

Longer version with details:

I have a post called "New Topic" that I plan to use as a special spot where users can submit to any Topic based on a query_var in the URL (so ?topic_id=345 etc.)

I have a function working using the standard WP 'comment_post' action, which basically looks for the topic id, then updates the comment comment_post_ID to whatever topic post the comment should be moved to.

All that works, but I want to redirect after the comment is saved, to the topic post where the new comment has ben assigned.

PHP redirect won't work because the headers have been sent. I tried echoing javascipt with window.href= etc., and that does work, but I get the popup confirmation that there are unsaved changes on the page. I need to avoid that.

Any suggestions? Any built in redirect hooks that I can leverage maybe?

Thanks!


 
Posted : 13/08/2023 11:51 pm
Asti
 Asti
(@asti)
Posts: 8267
Illustrious Member Support
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
 

First solution

We may suggest you check out the wpDiscuz built-in "Redirect First Comment to" option. It's located in the Dashboard > wpDiscuz > Settings > General tab.

More info here: https://wpdiscuz.com/docs/wpdiscuz-7/plugin-settings/general-settings/  

Another solution

wpDiscuz has a wpdiscuz_ajax_callbacks hook. You can use it to get it to work as you like: 

The PHP code: 

add_filter("wpdiscuz_ajax_callbacks", function ($response) {
    $response["callbackFunctions"][] = "myCustomCallback";
    return $response;
});

Your JS code:

window.myCustomCallback = function (response) {
        if (response.success) {
            //do something
        }
    };

 


In case you want to say thank you! 🙂
We'd really appreciate if you leave a good review on the plugin page.
This is the best way to say thank you to this project and the support team.

 
Posted : 14/08/2023 2:08 pm
DC10000 reacted
(@dc10000)
Posts: 3
Active Member
Topic starter
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
 

Brilliant! Thank you so much, a tiny bit of fiddling and console.logging, but wpdiscuz_ajax_callbacks worked perfectly, and probably opens up answers to a whole slew of upcoming challenges. Thanks so much, really appreciate the quick and thorough answer. BTW I've already bought one paid addon, I'm sure I'll be back for more.


 
Posted : 14/08/2023 10:47 pm
Asti reacted