: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @copyright Copyright (c) 2023, Code Atlantic LLC
if ( ! defined( 'ABSPATH' ) ) {
* Class PUM_Admin_Helpers
class PUM_Admin_Helpers {
public static function post_type_dropdown_options( $args = [], $compare = 'and' ) {
'publicly_queryable' => null,
'exclude_from_search' => null,
'capability_type' => null,
'permalink_epmask' => null,
foreach ( $args as $key => $value ) {
foreach ( get_post_types( $args, 'objects', $compare ) as $post_type ) {
if ( in_array( $post_type->name, [ 'revision', 'nav_menu_item', 'custom_css', 'customize_changeset', 'oembed_cache', 'popup_theme', 'nf_sub' ] ) ) {
$labels = get_post_type_labels( $post_type );
$options[ esc_attr( $post_type->name ) ] = esc_html( $labels->name );
* @see PUM_Helper_Array::move_item
* @param int|string $move
* @param string|null $key2
public static function move_item( &$ref_arr, $key1, $move, $key2 = null ) {
return PUM_Utils_Array::move_item( $ref_arr, $key1, $move, $key2 );
* @see PUM_Helper_Array::remove_keys_starting_with
public static function remove_keys_starting_with( $array, $string = false ) {
return PUM_Utils_Array::remove_keys_starting_with( $array, $string );
* @see PUM_Helper_Array::sort_by_sort
public static function sort_by_sort( $a, $b ) {
return PUM_Utils_Array::sort_by_sort( $a, $b );
public static function get_field_defaults( $fields = [] ) {
foreach ( $fields as $field_id => $field ) {
if ( isset( $field['std'] ) ) {
$defaults[ $field_id ] = $field['std'];
$defaults[ $field_id ] = 'checkbox' === $field['type'] ? null : false;
* @see PUM_Utils_Array::from_object instead.
public static function replace_key( $array, $old_key, $new_key ) {
return PUM_Utils_Array::replace_key( $array, $old_key, $new_key );
public static function flatten_fields_array( $tabs ) {
foreach ( $tabs as $tab_id => $tab_sections ) {
if ( self::is_field( $tab_sections ) ) {
$fields[ $tab_id ] = $tab_sections;
foreach ( $tab_sections as $section_id => $section_fields ) {
if ( self::is_field( $tab_sections ) ) {
$fields[ $section_id ] = $section_fields;
foreach ( $section_fields as $field_id => $field ) {
$fields[ $field_id ] = $field;
public static function parse_field( $field ) {
'object_type' => 'post_type',
'unit' => __( 'ms', 'popup-maker' ),
'desc_position' => 'bottom',
'button_type' => 'submit',
public static function parse_tab_fields( $fields, $args = [] ) {
if ( $args['has_subtabs'] ) {
foreach ( $fields as $tab_id => $tab_sections ) {
foreach ( $tab_sections as $section_id => $section_fields ) {
if ( self::is_field( $section_fields ) ) {
// Allow for flat tabs with no sections.
$section_id => $section_fields,
$fields[ $tab_id ][ $section_id ] = self::parse_fields( $section_fields, $args['name'] );
foreach ( $fields as $tab_id => $tab_fields ) {
$fields[ $tab_id ] = self::parse_fields( $tab_fields, $args['name'] );
public static function parse_fields( $fields, $name = '%' ) {
if ( is_array( $fields ) && ! empty( $fields ) ) {
foreach ( $fields as $field_id => $field ) {
if ( ! is_array( $field ) || ! self::is_field( $field ) ) {
if ( is_numeric( $field_id ) && ! empty( $field['id'] ) ) {
$fields = PUM_Utils_Array::replace_key( $fields, $field_id, $field['id'] );
} catch ( Exception $e ) {
$field_id = $field['id'];
} elseif ( empty( $field['id'] ) && ! is_numeric( $field_id ) ) {
$field['id'] = $field_id;
if ( ! empty( $field['name'] ) && empty( $field['label'] ) ) {
$field['label'] = $field['name'];
if ( empty( $field['name'] ) ) {
$field['name'] = sprintf( $name, $field_id );
$fields[ $field_id ] = self::parse_field( $field );
$fields = PUM_Utils_Array::sort( $fields, 'priority' );
* Sort array by priority value
* @see PUM_Utils_Array::sort_by_priority instead.
public static function sort_by_priority( $a, $b ) {
return PUM_Utils_Array::sort_by_priority( $a, $b );
* Checks if an array is a field.
public static function is_field( $array = [] ) {
! isset( $array['type'] ) && ( isset( $array['label'] ) || isset( $array['desc'] ) ),
isset( $array['type'] ) && is_string( $array['type'] ),
return in_array( true, $field_tests );
* Checks if an array is a section.
public static function is_section( $array = [] ) {
return ! self::is_field( $array );
public static function modal( $args = [] ) {
'cancel_button_text' => __( 'Cancel', 'popup-maker' ),
'save_button_text' => __( 'Add', 'popup-maker' ),
<div id="<?php echo $args['id']; ?>" class="pum-modal-background <?php echo esc_attr( $args['class'] ); ?>" role="dialog" aria-modal="false" aria-labelledby="<?php echo $args['id']; ?>-title"
if ( '' !== $args['description'] ) {
aria-describedby="<?php echo $args['id']; ?>-description"<?php } ?>>
<div class="pum-modal-wrap">
<div class="pum-modal-header">
<?php if ( '' !== $args['title'] ) { ?>
<span id="<?php echo $args['id']; ?>-title" class="pum-modal-title"><?php echo $args['title']; ?></span>
<button type="button" class="pum-modal-close" aria-label="<?php _e( 'Close', 'popup-maker' ); ?>"></button>
<?php if ( '' !== $args['description'] ) { ?>
<span id="<?php echo $args['id']; ?>-description" class="screen-reader-text"><?php echo $args['description']; ?></span>
<div class="pum-modal-content">
<?php echo $args['content']; ?>
<?php if ( $args['save_button'] || $args['cancel_button'] ) { ?>
<div class="pum-modal-footer submitbox">
<?php if ( $args['cancel_button'] ) { ?>
<button type="button" class="submitdelete no-button" href="#"><?php echo $args['cancel_button_text']; ?></button>
<?php if ( $args['save_button'] ) { ?>
<span class="spinner"></span>
<button class="button button-primary"><?php echo $args['save_button_text']; ?></button>
* @see PUM_Utils_Array::from_object instead.
public static function object_to_array( $obj ) {
return PUM_Utils_Array::from_object( $obj );