PHP code example of wpsocio / wp-utils

1. Go to this page and download the library: Download wpsocio/wp-utils 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/ */

    

wpsocio / wp-utils example snippets




$option_key    = 'option_name_here';
$store_as_json = false

$options = new \WPSocio\WPUtils\Options( $option_key, $store_as_json );

$options->get( 'some_key' ); // false
$options->get( 'some_key', 'default_value' ); // 'default_value'

$options->set( 'some_key', 'some_value' );
$options->get( 'some_key' ); // 'some_value'

// Updates the value in the database if $option_key is provided
$options->set_data( [
    'first' => 'some_value',
    'second' => [
        'a1' => 'a1-value',
        'a2' => 'a2-value',
    ],
] );

$options->get_path( 'second.a2' ); // 'a2-value'


$plugin_file = '/path/to/plugin/file.php';

$Do something
}

$details = $',
            'min'     => '7.0',
        ],
        'WP'  => [
            'version' => '5.3',
            'min'     => '5.3',
        ],
    ],
    'satisfied' => true,
]
*/


$assets_dir = untrailingslashit( plugin_dir_path( __FILE__ ) ) . '/assets/build';
$assets_url = untrailingslashit( plugins_url( '', __FILE__ ) ) . '/assets/build';

$assets = new \WPSocio\WPUtils\ViteWPReactAssets( $assets_dir, $assets_url );

$entry = 'js/settings/index.tsx';

$assets->enqueue(
    $entry,
    [
        'handle'              => 'some-js-handle',
        'script-dependencies' => [ 'wp-element', 'wp-i18n' ],
        'style-dependencies'  => ['wp-components'],
    ]
);

// OR

[ $script_handle, $style_handles ] = $assets->register(
    $entry,
    [
        'handle'              => 'some-js-handle',
        'script-dependencies' => [ 'wp-element', 'wp-i18n' ],
        'style-dependencies'  => ['wp-components'],
    ]
);

// Later on
$assets->enqueue( $entry );
// or
wp_enqueue_script( $script_handle );
foreach ( $style_handles as $style_handle ) {
    wp_enqueue_style( $style_handle );
}