I’ve now looked into this a bit further, and I see that the plugin I’m trying to get to work with BNFW (Anspress) actually has two hooks that work only for new posts, and not for edits.
So I can get BNFW to fire if, around line 118 of bnfw.php
(i.e. just above the line add_action( 'draft_to_publish', array( $this, 'publish_post' ) );
I add the following:
if( class_exists( 'AnsPress_Process_Form' ) ) {
add_action( 'ap_after_new_question', array( $this, 'insert_post' ), 10, 3 );
add_action( 'ap_after_new_answer', array( $this, 'insert_post' ), 10, 3 );
}
I realize that you might not want to add that to a future update to BNFW, but is there a way I could somehow achieve the same result with a function in my child theme’s functions.php
file or in an mu-plugin
?
Plugin Author
bnfw
(@voltronik)
Hi KTS915,
If you’re able to extract the sections of BNFW that store $this
then I don’t see why not.
You’ll have to traverse the functions to find out where it ends in order to then pull these out and put them into your own feature plugin or functions.php file.
Hope this helps!
Jack
Jack, sorry to keep banging on about this, but I think I’ve finally found a solution for all front-end submissions, and it’s much simpler than trying to inject something from outside. It involves just the following two changes to version 1.4:
Replace lines 113 to 126 with just the following line:
add_action( 'wp_insert_post', array( $this, 'insert_post' ), 10, 3 );
Then replace the insert_post
function (currently on lines 217 to 219) with this:
public function insert_post( $post_id, $post, $update ) {
$action = did_action( 'pre_post_update' );
if( ( $post->post_status == "publish") && ( 0 === $action ) ) {
$this->publish_post( $post );
}
}
Would you consider making these changes for BNFW?
Plugin Author
bnfw
(@voltronik)
Hi KTS915,
I’ll need to investigate this and get back to you. It might be a few days but I’ll let you know how I get on.
Thanks for digging into this,
Jack
Plugin Author
bnfw
(@voltronik)
Hi KTS915,
On further investigation, it looks like this won’t work for all plugins π
Currently, the most universal way really is to use the filter already provided in BNFW.
Really? What’s the nature of the problem, and when have you experienced it?
I have tried this with Anspress, FEP Pro, Write Here, and User Submitted Posts, and it works perfectly with all of them.
@kts915
Thanks mate!
you can’t imagine how useful your comments have been to me and mine. We’ve been struggling to fix this problem and eventually had to write a (very complicated) workaround. Your snippets solved it smooth and nicely and we wera able to revert to our original built design.
Just passing by after some testing to say thanks.
Our issue was that no notifications went through when posting with FEP PRO (as you may read at the top of this thread).
Hail and Kudoz to thee!
@prangesco, Thank you for taking the time to come back on here and say so!
(I’ve been away, so have only just got this.)
It remains a real shame that Jack won’t add this to BNFW when it works so much better than the current filter. So we either have to persist with a modded version of the plugin, or else keep modding BNFW as it gets updated. But it’s his plugin …
Plugin Author
bnfw
(@voltronik)
Hi,
I’m going to re-investigate this shortly.
Thanks,
Jack
Jack, have you made any progress in your re-investigation?
Plugin Author
bnfw
(@voltronik)
Hi @kts915,
Ok, after lots (and lots and lots) of testing, I can 100% confirm that I cannot use wp_insert_post
in BNFW because it triggers on auto-draft_to_publish
which causes huge problems in a number of areas:
* New posts immediately trigger notifications as soon as they’re created but not published.
* New pages (and old pages!) trigger notifications.
* Plugins that use auto-draft are triggering notifications.
Unfortunately at this point, it’s just too error prone for me to include it as part of the BNFW core plugin. If you want to continue using your fix and it works well for you then please do – you just might have to add it back in after each BNFW update but hopefully, this isn’t too often.
Hope this helps.
Thanks,
Jack
Jack,
Thanks for reporting back, and for all your testing. I understand entirely what you say; I guess I just don’t ever have reason to move auto-drafts to publish!
For the moment, I will continue just to add my fix back in to each update. But I will also make a note for the New Year to see if I can devote some time to hunting for a way to avoid triggering the auto-draft_to_publish
hook.
Thanks again!
Plugin Author
bnfw
(@voltronik)
Hi @kts915,
No probs at all.
Merry Christmas.
Jack
Jack,
Merry Christmas to you too!
Despite saying that I would leave this to the New Year, I have been unable to stop wondering whether, when you said my fix was triggering the auto-draft_to_publish
hook, that was what you really meant. Surely, if the user has decided to publish (whether from an autosave or otherwise) then a new post notification should be sent out?
So I have also been wondering if what you really meant was that my fix was triggering a notification simply when an autosave or revision was made. If so, then I think the fix for that is straightforward. The relevant function just needs an additional conditional, so that it looks like this:
public function insert_post( $post_id, $post, $update ) {
if ( ! ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) ) {
$action = did_action( 'pre_post_update' );
if ( ( $post->post_status == "publish") && ( 0 === $action ) ) {
$this->publish_post( $post );
}
}
}
See https://tommcfarlin.com/wordpress-save_post-called-twice/
-
This reply was modified 7 years, 4 months ago by KTS915.