Home Plugin documentation Hooks and functions Functions pip_maybe_get()

 

 

Here we go!

 

pip_maybe_get()

Heads up!

This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don’t provide support for code customizations or 3rd party development.

Object version of acf_maybe_get()

/**
 * Pilo'Press version of acf_maybe_get
 * (that also handles object type)
 *
 * @see acf_maybe_get()
 *
 * @param int  $key
 * @param null $default
 * @param      $data
 *
 * @return mixed|null
 */
function pip_maybe_get( $data, $key = 0, $default = null ) {

    if ( is_object( $data ) ) {
        $data = (object) $data;

        return isset( $data->$key ) ? $data->$key : $default;

    } elseif ( is_array( $data ) ) {
        $data = (array) $data;

        return isset( $data[ $key ] ) ? $data[ $key ] : $default;
    }

    return $default;
}

You didn’t find the answer you were looking for?

or you think a specific topic deserve more informations?

 

Wave to bottom