PHP code example of offset / packs

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

    

offset / packs example snippets


use Offset\Pack;
use Offset\Packs;

class PackDemo extends Pack
{
    public $title = 'Demo';
    public $name = 'demo';
    public $version = '1.0.0';
    public $dir = __DIR__ . '/blocks';
    public $url = '/wp-content/plugins/offset-demo/blocks';
    public $editor_styles = array(
        array(
            'handle' => 'offset-demo-editor-style',
            'src' => '/wp-content/plugins/offset-demo/assets/css/admin.css',
        ),
    );
    public $editor_scripts = array(
        array(
            'handle' => 'offset-demo-editor-script',
            'src' => '/wp-content/plugins/offset-demo/assets/js/admin.js',
        ),
    );
    public $styles = array(
        array(
            'handle' => 'offset-demo-style',
            'src' => '/wp-content/plugins/offset-demo/assets/css/style.css',
        ),
    );
    public $scripts = array(
        array(
            'handle' => 'offset-demo-script',
            'src' => '/wp-content/plugins/offset-demo/assets/js/script.js',
        ),
    );
}

$packs_manager = Packs::getInstance();
$pack_demo = new PackDemo();

$packs_manager->addPack($pack_demo);

add_filter('offset_packs_is_styles_enqueue', '__return_false');

add_filter('offset_packs_is_scripts_enqueue', '__return_false');

function packs_styles($packs) {
    return array_diff($packs, array('demo')); // Remove styles from "Demo" pack
}

add_filter('offset_packs_styles', 'packs_styles', 10, 1);

function packs_scripts($packs) {
    return array_diff($packs, array('demo')); // Remove scripts from "Demo" pack
}

add_filter('offset_packs_scripts', 'packs_scripts', 10, 1);

// Remove bootstrap style load by packs
function packs_styles_enqueued($packs_styles) {
    return array_filter($packs_styles, function ($style) {
        return !is_int(mb_stripos($style['src'], 'bootstrap'));
    });
}
add_filter('offset_packs_styles_enqueued', 'packs_styles_enqueued', 10, 1);

// Remove bootstrap script load by packs
function packs_scripts_enqueued($packs_scripts) {
    return array_filter($packs_scripts, function ($script) {
        return !is_int(mb_stripos($script['src'], 'bootstrap'));
    });
}
add_filter('offset_packs_scripts_enqueued', 'packs_scripts_enqueued', 10, 1);