ffub Posted October 31, 2011 Share Posted October 31, 2011 Hi, I'm making some simple modules to publish new pages to Facebook, Twitter, Email et al. Is there an easy way with the save page hook to test if the page created is a new page? Thanks, Stephen Link to comment Share on other sites More sharing options...
ryan Posted October 31, 2011 Share Posted October 31, 2011 It's pretty easy if you are doing a before hook because the page's 'id' will be 0. But I'm guessing you need an after hook. ProcessWire doesn't populate the page's 'created' date until after it's been loaded from the database the first time. As a result, your after save hook can check the $page->created property. If it's empty, then the page is new. 1 Link to comment Share on other sites More sharing options...
ffub Posted October 31, 2011 Author Share Posted October 31, 2011 Thanks, Ryan. I would never have figured that out on my own. Stephen Link to comment Share on other sites More sharing options...
diogo Posted October 9, 2013 Share Posted October 9, 2013 Old thread I know. But this is not working with me because it when $page created doesn't exist yet, the fields are also not populated. I need to do something the first time a page is saved after the editor had the chance to fill in the fields. Isn't there a "publish" hook? I can't find it... Link to comment Share on other sites More sharing options...
ryan Posted October 13, 2013 Share Posted October 13, 2013 Diogo, would the Pages::added hook be what you are looking for? Link to comment Share on other sites More sharing options...
diogo Posted October 13, 2013 Share Posted October 13, 2013 Thanks Ryan, but no. This only triggers the action when the page is created, before the editor had any chance to fill the info I need. For, now what I did was to add a hidden check box that the module changes to 1 right after the action was performed, this deactivates future actions on this page. The module also checks if the page is published and if the needed field is not empty. if($page->get($this->check) !== 1 && $page->status === 1 != "" && $page->get($this->message) != "") Unrelated: I just noticed a small incoherence with the page saving interface. If a page is unpublished, and you go to "settings" and uncheck the "Unpublished: Not visible on site" checkbox and then press on the button "Save + Keep Unpublished", the page is published. Of course we can assume that someone that unchecks that box wants the page to be published, but but it's still incoherent. Maybe it would be enough if the button would change to "publish" when that checkbox is unchecked, that's easily achieved with an event handler in javascript. edit: the button on the bottom should also be removed. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now