PHP code example of boxybird / morph

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

    

boxybird / morph example snippets


define('BB_MORPH_HASH_KEY', 'SOME_RANDOM_16_CHARACTER_STRING');



add_action('wp_enqueue_scripts', function () {
    wp_dequeue_script('bb-alpine');
});

add_filter('morph/component/path', function ($path) {
    $path = get_template_directory() . '/custom-folder/';
    
    return $path;
});

 get_header(); 



// Class

[$count] = morph_render(new class {
    public $count;

    public function __construct()
    {
        $this->count = (int) get_option('count', 0);
    }

    public function increment()
    {
        update_option('count', ++$this->count);
    }
});



// Procedural

$count = (int) get_option('count', 0);

if ($_POST['increment'] ?? false) {
    update_option('count', ++$count);
}

 get_header(); 

<div x-data>
    <button x-on:click="$dispatch('notify', 'A notification from the event.php component.')"
    >Dispatch Event</button>
</div>



$notification = $_POST['notification'] ?? null;