We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34193
    • 330 Posts
    I am currently trying to write a plugin that will post to Facebook and Twitter when a new news item has been published.

    I have the plugin code working, my main problem is getting the plugin to run. I have OnDocPublished checked for the plugin.

    It runs fine if I create the page and save it unpublished, and then right click on the page in the resource tree and select publish there.

    But if I create the page click the published box and save it, it doesn’t seem to fire the plugin.

    Any help appreciated, is there a diff system event that i am missing for doing this.

    Using MODx Revolution 2.0.0-rc-1 rev6254

      • 32699 ☆ A M B ☆
      • 427 Posts
      This issue has been discussed before:

      http://www.muddydogpaws.com/notebook/auto-post-to-twitter-when-publishing-in-modx.html

      He did the same thing and had the same issue.
        Get your copy of MODX Revolution Building the Web Your Way http://www.sanitypress.com/books/modx-revolution-building-the-web-your-way.html

        Check out my MODX || xPDO resources here: http://www.shawnwilkerson.com
        • 28215
        • 4,149 Posts
        Still, that’s a bug. It should be fired every time the doc is changed from unpublish to publish, regardless of the access point.

        Could you file it here: http://bugs.modxcms.com/

        Thanks!
          shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
          • 34193
          • 330 Posts
          Posted
            • 22303 MODX Staff
            • 10,725 Posts
            All you need do is have the plugin listen on both OnDocPublished and OnDocFormSave to handle cases where someone is directly calling the publishing action, with it’s own event vs. editing a document and changing the published status (potentially along with a great many other things).

            I do not agree that this is a bug; it may not be totally intuitive to have to handle both events, but this is the way the event model is currently implemented and used.
              • 34193
              • 330 Posts
              ok so if I set both will the plugin only be called if the publish state has changed or will I need to do some checks within the code to see if the published has changed from unpublished to published.
                • 22303 MODX Staff
                • 10,725 Posts
                Quote from: peteedley at Jan 09, 2010, 12:08 PM

                ok so if I set both will the plugin only be called if the publish state has changed or will I need to do some checks within the code to see if the published has changed from unpublished to published.
                In the case of OnDocFormSave you’ll need to check.
                  • 6316
                  • 92 Posts
                  Quote from: OpenGeek at Jan 09, 2010, 11:08 AM

                  All you need do is have the plugin listen on both OnDocPublished and OnDocFormSave to handle cases where someone is directly calling the publishing action, with it’s own event vs. editing a document and changing the published status (potentially along with a great many other things).

                  I do not agree that this is a bug; it may not be totally intuitive to have to handle both events, but this is the way the event model is currently implemented and used.
                  This is great but how do I get the id of a document in case of OnDocFormSave given

                  Will be 0 for new Resources.

                  ?

                  I don’t want to tell my clients that they have to press "Save" twice.
                    • 3749
                    • 24,544 Posts
                    Take a look at the ActivationEmail plugin. It sends an email when the user’s status changes from inactive to active. You want to do the same thing when a resource changes from unpublished to published.

                    You should be able to copy it and modify it to do what you want (changing the events, changing $user to $resource, and changing the field it looks at and performing your action instead of sending the email).
                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting
                      • 6316
                      • 92 Posts
                      Thank you for the reply! I’ve checked the plugin but I’m afraid I still don’t understand what to do.

                      What I have in mind is a plugin which makes a new topic on phpBB forum once manager on my site creates a new document (and my MODx is configured to publish all new documents by default). The plugin must take the ID of the new document to generate a link. I figured how to check if the state of the document has changed (so, the case when the document already exists and the manager publishes it), but it’s still vague for me what event I should connect my plugin to, in order to be able to retrieve the ID of a newly created document.

                      Could you please explain a bit further?