• Resolved peteratomic

    (@peteratomic)


    So far haven’t had a chance to dive deep enough into the documentation as to whether there’s a workaround for not automatically publishing. (New/updated records in Salesforce syncing to WordPress, creating a custom post type, which is automatically saved as a draft, rather than being published instantly.)

    I synced about 10 different “posts” from my client’s Salesforce inventory, and thought I could at least bulk edit and set as published. Did that, but nothing showed up. In running through one theory after another I had a hunch to manually save anything that wasn’t showing up. BOOM.

    Maybe because I’m using AFC fields for my custom post type rather than any default WP stuff and so “publish” just really isn’t “publish” until you click the blue update button? Seems so crazy counter-intuitive, but is exactly what’s happening.

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Jonathan Stegall

    (@jonathanstegall)

    It seems like you’re asking a couple of questions. I’ll see if I can answer.

    1. Save as a draft rather than publish instantly? Yes, by default this is what should happen. You can change it with a developer hook, or by mapping the post status field when you create the fieldmap, but if you don’t do either of those things, new records in Salesforce should be saved in WordPress as drafts.
    2. If you do want it to be published by default, like I said you can use a developer hook (example), but you can also just map the post status field to a custom field in Salesforce that has a value of “publish”.
    3. I don’t think ACF has anything to do with this. But I can say that this plugin depends on the WordPress events that occur when an object is saved. So for posts, it depends on the save_post action. WordPress doesn’t have any actions that run on bulk events, as far as I know.

    Thread Starter peteratomic

    (@peteratomic)

    hey @jonathanstegall thanks for the quick response. Apologies for the murky post… realized part way thru that it was a bit more complicated to describe than I thought, but was rushed to get it posted.

    thanks for confirming #1 and #2… that’s all I was hoping for.

    The bulk edit feature I mentioned is when you’re in post list view and you can click the checkbox in the header to select all posts and then reset various properties, like from “draft” to “published”. If in #3 “this plugin” refers to ACF (rather than yours) then I would seem to have confirmed that this bulk edit feature doesn’t trigger save_post from what I’ve seen. (Since nothing showed up until I’d manually clicked “update’.) But sounds like that also won’t happen with your suggestion in #1/2? Will check the link above and see… ??

    Plugin Author Jonathan Stegall

    (@jonathanstegall)

    Right, I’m aware of the bulk edit feature. WordPress doesn’t trigger save_post when the bulk actions run (I’m not sure why this is the case, maybe to avoid overusing server resources).

    So in #3 “this plugin” does refer to Object Sync for Salesforce. That is, when you’re trying to sync a post to Salesforce, it does rely on the save_post action in WordPress. We’ve occasionally added third-party plugin hooks so they can also run if they’re available, but that is the general rule.

    So yes, my suggestion in #1/2 doesn’t work with bulk editing, but rather it’s a way for you to set the default post_status before records are saved.

    Does that make more sense?

    Thread Starter peteratomic

    (@peteratomic)

    Excellent, thanks for the clarification @jonathanstegall .

    Thanks for the code snippet. Works! (Duh.)

    So in order to get the save_post action, I’d need a special filter, right? Looking at this:

    https://github.com/MinnPost/object-sync-for-salesforce/blob/master/docs/extending-before-and-after-saving.md#salesforce-pull

    My first guess is to use the ‘after success’ one, since this needs to fire after data is pulled in, but this code comment (“do things if the save succeeded”) makes it sound like it is for AFTER save_post fires. Or is the “save succeeded” rather “pull succeeded”?

    Plugin Author Jonathan Stegall

    (@jonathanstegall)

    Well, as far as I know you won’t ever be able to use Object Sync for Salesforce with bulk actions on posts because save_post does not run on bulk actions. So we should maybe establish that first. If you require bulk actions to work, you may have to do a lot of extra work.

    But your original question doesn’t suggest that you have to have bulk actions. But rather that you want to have a post set as publish by default. You can do that with the code snippet above as it is written. It doesn’t require any additional hooks. The save_post action is built into WordPress; it just does not run on bulk actions that you do with the checkboxes in WordPress.

    I may still be confused about what you’re trying to do, but that’s my current understanding at least.

    Thread Starter peteratomic

    (@peteratomic)

    Think we’re going in circles a bit. I only used bulk edit to change all imported posts to publish. Mentioned it only to be thorough in describing the total experience.

    The code snippet to set automatically to publish definitely works. But it doesn’t solve the problem, as the posts still won’t show up unless I manually click Update inside each one. Could live with it if we have to, but definitely isn’t as efficient.

    So from everything you said, I thought I was supposed to write a custom function to make sure save_post fires after data is imported into WP.

    FYI – once the post is manually saved using the Update button, then all data changes ARE getting instantly saved, so its just the first initial save that is needed.

    Plugin Author Jonathan Stegall

    (@jonathanstegall)

    Hm, okay. I don’t think it should work that way. I’ve never seen a case where published posts didn’t show up the way they were supposed to. But yeah, the object_sync_for_salesforce_pull_success action is probably something you could use if that’s what is happening, as long as it has the data you want (it probably does).

    If you do run a save_post action, it would try to send the data back to Salesforce (unless your fieldmap is only pulling data from Salesforce). But that isn’t necessarily a problem.

    Thread Starter peteratomic

    (@peteratomic)

    And another problem… repeatedly trying to import a SF post (possibly deleted in WP from an earlier test). Never works. Other records update just fine, but can’t get this ‘orphaned’ one to show.

    Can’t make sense out of any of this. Close to telling my client they’ll have to hire someone else to do this. Seems so incredibly buggy the whole process.

    Thread Starter peteratomic

    (@peteratomic)

    Hope my last comment didn’t come across that I was blaming you @jonathanstegall. Think you’ve done something amazing with this plugin and I can appreciate if you can’t support what seems to be an outlier case with this one.

    There may be some budget available if you or your team are able to look in to this “on the clock”.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘various steps to publish’ is closed to new replies.