Jump to content
saschapi

SCHEDULE PAGES not for PW3?

Recommended Posts

Hi guys,

I'm looking for the not so uncommon functionality to publish (or "un-hide") pages on a specific date and time. I did not notice till now, but this functionality seems to be missing from the core.
Scheduled pages seems to do just that but is not supported for PW3... Is there really no module or function that publishes pages in the future? I know that I need to setup a cron job or use lazy cron, but I'm wondering if I miss something? :)

Cheers Sascha

Share this post


Link to post
Share on other sites

Hi @saschapi! I'm not aware of a module that enables this along with lazyCron but you could try placing something like this under site/ready.php

$wire->addHook('LazyCron::everyDay', function($e){
    $posts = $this->pages->find('status=unpublished, template=post');
    
    foreach($posts as $post){
        if($post->schedule_publish_date <= time()){
            $post->of(false);
            $post->status([]);
            $post->save();
        }
    }
}); 

The page template you want to publish, would have a schedule_publish_date field, where you can set a publish date and time. 

  • Like 6

Share this post


Link to post
Share on other sites

Another SchedulePages user here. Works just fine for PW3 🙂

  • Like 4

Share this post


Link to post
Share on other sites

So I'm the looser coding my hook on every site 😄

  • Haha 3

Share this post


Link to post
Share on other sites

You could also do this with a simple page selector, which would be the simplest solution:

So all your pages have the status Published, but will not be shown, because the event_start field is lower than the today date.

$events = $pages->find("template=event, sort=event_start, event_start>=today");

The hook from @elabx is really overkill and modifies the page, which is not needed.

  • Like 1

Share this post


Link to post
Share on other sites
59 minutes ago, Jens Martsch - dotnetic said:

The hook from @elabx is really overkill and modifies the page, which is not needed.

To be fair publishing (or un-publishing) pages at set time vs. just listing pages based on a datetime field are two different use cases. In some cases the distinction may not matter, but in others it will — i.e. when something really shouldn't be viewable before a predefined date/time 🙂

  • Like 5

Share this post


Link to post
Share on other sites

I think my answer solves the problem, that the topic poster wanted to solve. Sometimes you have to think outside the box, and I think he just wanted to know how to not show pages that have a publish date in the future. What first comes into mind is: Leave the page unpublished until the date is actual. 

That you can tackle this problem differently may not be obvious. But you are right @teppo that there might be other use cases, for example if the page url should not be reachable at all, then the published or unpublished status would be the right thing to do.

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, teppo said:

In some cases the distinction may not matter, but in others it will — i.e. when something really shouldn't be viewable before a predefined date/time

For 90% of these kinds of cases I do it like @Jens Martsch - dotnetic suggested, and in the template of the page (event, news item, etc) I have:

// Throw 404 if item is future-dated
if(!$user->isLoggedin() && $page->getUnformatted('date_1') > time()) throw new Wire404Exception();

But on a complex site where the pages might be queried from many selectors in many different places then unpublishing is the way to go.

  • Like 6

Share this post


Link to post
Share on other sites

That works as well!

Main reasons I don't (practically) ever use this approach have already been mentioned here: I'd have to block access on template level (may need to do that on a lot of places), search features and highlight lists etc. all have to be aware of this, and so on and so forth. Potentially having multiple developers work on the site doesn't really help either. At some point you're very likely to show publicly something you didn't intend to.

Want to schedule pages? install SchedulePages. Need more scheduled content? Add two fields to the template. Easy as it gets 😋

Also, as a general rule if thumb, I try to do as little permission/access checking myself as possible. Sure, in this case it's probably not a big deal, but... 😁

"ProcessWire — there's more than one way to do it" ✌

  • Like 5

Share this post


Link to post
Share on other sites

Hi guys,

thanks for the great input. I will have a look at the plugin, but I guess @elabx solution would be more flexible in my case.

This might be the way to go! 😃

Cheers Sascha

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...