: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* ConditionCallbacks class
* @copyright Copyright (c) 2023, Code Atlantic LLC
class PUM_ConditionCallbacks {
* Checks if this is one of the selected post_type items.
* @param array $condition
public static function post_type( $condition = [] ) {
$target = explode( '_', $condition['target'] );
// Modifier should be the last key.
$modifier = array_pop( $target );
// Post type is the remaining keys combined.
$post_type = implode( '_', $target );
$selected = ! empty( $condition['settings']['selected'] ) ? $condition['settings']['selected'] : [];
if ( is_post_type_archive( $post_type ) ) {
// Checks for valid post type, if $post_type is page, then include the front page as most users simply expect this.
if ( self::is_post_type( $post_type ) || ( 'page' === $post_type && is_front_page() ) ) {
if ( self::is_post_type( $post_type ) && is_singular( $post_type ) && in_array( $post->ID, wp_parse_id_list( $selected ) ) ) {
if ( ! is_post_type_hierarchical( $post_type ) || ! is_singular( $post_type ) ) {
$selected = wp_parse_id_list( $selected );
foreach ( $selected as $id ) {
if ( $post->post_parent === $id ) {
if ( ! is_post_type_hierarchical( $post_type ) || ! is_singular( $post_type ) ) {
// Ancestors of the current page.
$ancestors = get_post_ancestors( $post->ID );
// Chosen parent/grandparents.
$selected = wp_parse_id_list( $selected );
foreach ( $selected as $id ) {
if ( in_array( $id, $ancestors ) ) {
if ( is_page() && is_page_template( $selected ) ) {
* Checks if this is one of the selected taxonomy term.
* @param array $condition
public static function taxonomy( $condition = [] ) {
$target = explode( '_', $condition['target'] );
// Remove the tax_ prefix.
// Assign the last key as the modifier _all, _selected
$modifier = array_pop( $target );
// Whatever is left is the taxonomy.
$taxonomy = implode( '_', $target );
if ( 'category' === $taxonomy ) {
return self::category( $condition );
} elseif ( 'post_tag' === $taxonomy ) {
return self::post_tag( $condition );
if ( is_tax( $taxonomy ) ) {
$selected = ! empty( $condition['settings']['selected'] ) ? $condition['settings']['selected'] : [];
if ( is_tax( $taxonomy, wp_parse_id_list( $selected ) ) ) {
* Checks if this is one of the selected categories.
* @param array $condition
public static function category( $condition = [] ) {
$target = explode( '_', $condition['target'] );
// Assign the last key as the modifier _all, _selected
$modifier = array_pop( $target );
$selected = ! empty( $condition['settings']['selected'] ) ? $condition['settings']['selected'] : [];
if ( is_category( wp_parse_id_list( $selected ) ) ) {
* Checks if this is one of the selected tags.
* @param array $condition
public static function post_tag( $condition = [] ) {
$target = explode( '_', $condition['target'] );
// Assign the last key as the modifier _all, _selected
$modifier = array_pop( $target );
$selected = ! empty( $condition['settings']['selected'] ) ? $condition['settings']['selected'] : [];
if ( is_tag( wp_parse_id_list( $selected ) ) ) {
* Checks if the post_type has the selected categories.
* @param array $condition
public static function post_type_tax( $condition = [] ) {
$target = explode( '_w_', $condition['target'] );
// First key is the post type.
$post_type = array_shift( $target );
// Last Key is the taxonomy
$taxonomy = array_pop( $target );
if ( 'category' === $taxonomy ) {
return self::post_type_category( $condition );
} elseif ( 'post_tag' === $taxonomy ) {
return self::post_type_tag( $condition );
$selected = ! empty( $condition['settings']['selected'] ) ? $condition['settings']['selected'] : [];
if ( self::is_post_type( $post_type ) && has_term( wp_parse_id_list( $selected ), $taxonomy ) ) {
* Checks if the post_type has the selected categories.
* @param array $condition
public static function post_type_category( $condition = [] ) {
$target = explode( '_w_', $condition['target'] );
// First key is the post type.
$post_type = array_shift( $target );
$selected = ! empty( $condition['settings']['selected'] ) ? $condition['settings']['selected'] : [];
if ( self::is_post_type( $post_type ) && has_category( wp_parse_id_list( $selected ) ) ) {
* Checks is a post_type has the selected tags.
* @param array $condition
public static function post_type_tag( $condition = [] ) {
$target = explode( '_w_', $condition['target'] );
// First key is the post type.
$post_type = array_shift( $target );
$selected = ! empty( $condition['settings']['selected'] ) ? $condition['settings']['selected'] : [];
if ( self::is_post_type( $post_type ) && has_tag( wp_parse_id_list( $selected ) ) ) {
public static function is_post_type( $post_type ) {
return is_object( $post ) && ( is_singular( $post_type ) || $post->post_type === $post_type );