| @@ 103-125 (lines=23) @@ | ||
| 100 | // determine statuses |
|
| 101 | $status = $args['status']; |
|
| 102 | $status = ( $status ) ? explode( ',', $status ) : array( 'publish' ); |
|
| 103 | if ( is_user_logged_in() ) { |
|
| 104 | $statuses_whitelist = array( |
|
| 105 | 'publish', |
|
| 106 | 'pending', |
|
| 107 | 'draft', |
|
| 108 | 'future', |
|
| 109 | 'private', |
|
| 110 | 'trash', |
|
| 111 | 'any', |
|
| 112 | ); |
|
| 113 | $status = array_intersect( $status, $statuses_whitelist ); |
|
| 114 | } else { |
|
| 115 | // logged-out users can see only published posts |
|
| 116 | $statuses_whitelist = array( 'publish', 'any' ); |
|
| 117 | $status = array_intersect( $status, $statuses_whitelist ); |
|
| 118 | ||
| 119 | if ( empty( $status ) ) { |
|
| 120 | // requested only protected statuses? nothing for you here |
|
| 121 | return array( 'found' => 0, 'posts' => array() ); |
|
| 122 | } |
|
| 123 | // clear it (AKA published only) because "any" includes protected |
|
| 124 | $status = array(); |
|
| 125 | } |
|
| 126 | ||
| 127 | // let's be explicit about defaulting to 'post' |
|
| 128 | $args['type'] = isset( $args['type'] ) ? $args['type'] : 'post'; |
|
| @@ 113-135 (lines=23) @@ | ||
| 110 | ||
| 111 | // determine statuses |
|
| 112 | $status = ( ! empty( $args['status'] ) ) ? explode( ',', $args['status'] ) : array( 'publish' ); |
|
| 113 | if ( is_user_logged_in() ) { |
|
| 114 | $statuses_whitelist = array( |
|
| 115 | 'publish', |
|
| 116 | 'pending', |
|
| 117 | 'draft', |
|
| 118 | 'future', |
|
| 119 | 'private', |
|
| 120 | 'trash', |
|
| 121 | 'any', |
|
| 122 | ); |
|
| 123 | $status = array_intersect( $status, $statuses_whitelist ); |
|
| 124 | } else { |
|
| 125 | // logged-out users can see only published posts |
|
| 126 | $statuses_whitelist = array( 'publish', 'any' ); |
|
| 127 | $status = array_intersect( $status, $statuses_whitelist ); |
|
| 128 | ||
| 129 | if ( empty( $status ) ) { |
|
| 130 | // requested only protected statuses? nothing for you here |
|
| 131 | return array( |
|
| 132 | 'found' => 0, |
|
| 133 | 'posts' => array(), |
|
| 134 | ); |
|
| 135 | } |
|
| 136 | // clear it (AKA published only) because "any" includes protected |
|
| 137 | $status = array(); |
|
| 138 | } |
|
| @@ 135-157 (lines=23) @@ | ||
| 132 | ||
| 133 | // determine statuses |
|
| 134 | $status = ( ! empty( $args['status'] ) ) ? explode( ',', $args['status'] ) : array( 'publish' ); |
|
| 135 | if ( is_user_logged_in() ) { |
|
| 136 | $statuses_whitelist = array( |
|
| 137 | 'publish', |
|
| 138 | 'pending', |
|
| 139 | 'draft', |
|
| 140 | 'future', |
|
| 141 | 'private', |
|
| 142 | 'trash', |
|
| 143 | 'any', |
|
| 144 | ); |
|
| 145 | $status = array_intersect( $status, $statuses_whitelist ); |
|
| 146 | } else { |
|
| 147 | // logged-out users can see only published posts |
|
| 148 | $statuses_whitelist = array( 'publish', 'any' ); |
|
| 149 | $status = array_intersect( $status, $statuses_whitelist ); |
|
| 150 | ||
| 151 | if ( empty( $status ) ) { |
|
| 152 | // requested only protected statuses? nothing for you here |
|
| 153 | return array( |
|
| 154 | 'found' => 0, |
|
| 155 | 'posts' => array(), |
|
| 156 | ); |
|
| 157 | } |
|
| 158 | // clear it (AKA published only) because "any" includes protected |
|
| 159 | $status = array(); |
|
| 160 | } |
|