Jump to content

Unpublished pages in $users->find()


suntrop
 Share

Recommended Posts

I am wondering why this one 

<?php
	$tsubscribers = wire('users')->find('template=user');
	foreach ($tsubscribers as $ts) {
		echo $ts->email . '<br>';
	}
?>

will include unpublished users as well. The docs say https://processwire.com/api/selectors/#access_control

Pages with hidden or unpublished status will not appear in the results from database-querying selectors that can return multiple pages (i.e. functions that return the PageArray type). For instance $pages->find("..."), $page->children(), etc.

The site is running PW 2.7.2 … is this only new to PW 3?

I had all users unpublished and see them as unpublished in the back-end. But when selecting users via API the unpublished are included as well. I have to add status!=unpublished to opt them out.

Link to comment
Share on other sites

I guess $pages->find() and $users->find() behave differently. You could always use $pages->find() instead...

$tsubscribers = wire('pages')->find('template=user');

Be aware that PW does not provide good support for unpublished users. Besides there being no built-in controls in the admin interface for unpublishing a user or saving the user in an unpublished state, there are other gotchas such as the password inputfield being forced to an uncollapsed and required state when editing an unpublished user with no possibility of preventing this via hook (for collapsed state anyway).

I requested better support for unpublished users a while back.

  • Like 1
Link to comment
Share on other sites

Robin, thanks for that! Indeed this one works differently. It feels a bit off the road using the wire('pages') instead of wire('users), but that would work as expected.

But again, this is quite against the "everything is a page" mantra in PW. However, I will include a status!=unpublished in the selectors.

Thanks again! 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...