PHP code example of underpin / option-loader

1. Go to this page and download the library: Download underpin/option-loader library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

underpin / option-loader example snippets


// Register option
underpin()->options()->add( 'example-option', [
	'key'           => 'example-option', // on'   => 'Human-readable description',
] );

underpin()->options()->add('option-key','Namespace\To\Class');

// Fetch from global context
underpin()->options()->get( 'example-option')->get();

// Fetch, given a meta factory
$meta = underpin()->options()->get('example-meta-field');

$meta->get( $object_id );

// Fetch all registered options

// Typecasting options gets array of registered options objects.
$registered_options = (array) underpin()->options();
$values             = [];

foreach ( $registered_options as $key => $object ) {
	$values[ $key ] = $object->get();
}

// Reset all options
$registered_options = (array) underpin()->options();

foreach($registered_user_meta as $object){
  $object->reset();    
}

underpin()->options()->add( 'example-option', [
	'key'           => 'example-option', //       => 'Human-readable name',
	'description'   => 'Human-readable description',
] );

underpin()->options()->pluck( 'example-option', 'another_item' ); // 'another_value'
underpin()->options()->pluck( 'example-option', 'invalid' ); // WP_Error