| @@ -167,54 +167,10 @@ | ||
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - // 3. Country Targeting | |
| 172 | - if ( !empty($settings['country_targeting']) && is_array($settings['country_targeting']) && !in_array('all', $settings['country_targeting'])) { | |
| 173 | - $visitor_country = Helper::nx_get_visitor_country_code(); | |
| 174 | - // If we couldn't determine the country or it's not in the target list | |
| 175 | - $countryValues = array_column( $settings['country_targeting'], 'value' ); | |
| 176 | - $normalizedCountries = array_map('strtoupper', $countryValues); | |
| 177 | - $visitor_country = strtoupper($visitor_country); | |
| 178 | - if (empty($visitor_country)) { | |
| 179 | - return true; | |
| 180 | - } | |
| 181 | - // Only apply country filtering if 'ALL' is not in the list | |
| 182 | - if (!in_array('ALL', $normalizedCountries)) { | |
| 183 | - if (empty($visitor_country) || !in_array($visitor_country, $normalizedCountries)) { | |
| 184 | - return true; | |
| 185 | - } | |
| 186 | - } | |
| 187 | - } | |
| 188 | - | |
| 189 | - // 4. User Role Targeting | |
| 190 | - if (!empty($settings['targeting_user_roles']) && | |
| 191 | - !in_array('all_users', $settings['targeting_user_roles'])) { | |
| 192 | - | |
| 193 | - // For logged out users | |
| 194 | - if (!is_user_logged_in() && !in_array('guest', $settings['targeting_user_roles'])) { | |
| 195 | - return true; | |
| 196 | - } | |
| 197 | - | |
| 198 | - // For logged in users | |
| 199 | - if (is_user_logged_in()) { | |
| 200 | - $user = wp_get_current_user(); | |
| 201 | - $user_roles = (array) $user->roles; | |
| 202 | - | |
| 203 | - // Check if any of the user's roles match the targeted roles | |
| 204 | - $has_targeted_role = false; | |
| 205 | - foreach ($user_roles as $role) { | |
| 206 | - if (in_array($role, $settings['targeting_user_roles'])) { | |
| 207 | - $has_targeted_role = true; | |
| 208 | - break; | |
| 209 | - } | |
| 210 | - } | |
| 211 | - | |
| 212 | - if (!$has_targeted_role) { | |
| 213 | - return true; | |
| 214 | - } | |
| 215 | - } | |
| 216 | - } | |
| 171 | + // Country & user-role targeting are enforced globally for every type in | |
| 172 | + // NotificationX\Core\Targeting (also hooked on nx_show_on_exclude). | |
| 217 | 173 | |
| 218 | 174 | // If we've made it here, don't exclude the notification |
| 219 | 175 | return $exclude; |
| 220 | 176 | } |