PHP code example of andreilupu / wp-sockets

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

    

andreilupu / wp-sockets example snippets


use function WPSockets\Core\wp_sockets_init;

add_action( 'init', function() {
    // Basic initialization
    wp_sockets_init();
    
    // OR with custom assets URL (useful for symlinked local development)
    // wp_sockets_init( plugin_dir_url( __FILE__ ) . 'vendor/andreilupu/wp-sockets-core/assets' );
} );

use function WPSockets\Core\wp_sockets_register_page;

add_action( 'init', function() {
    wp_sockets_register_page( 'my-plugin-settings', [
        'page_title' => 'My Plugin Settings',
        'menu_title' => 'My Plugin',
        'capability' => 'manage_options',
        'mode'       => 'panel', // 'panel' or 'tabs'
        'sockets'    => [
            [
                'id'    => 'general_section',
                'type'  => 'group',
                'label' => 'General Settings',
                'children' => [
                    [
                        'id'    => 'api_key',
                        'type'  => 'text',
                        'label' => 'API Key',
                    ],
                    [
                        'id'    => 'enable_feature',
                        'type'  => 'checkbox', // Assuming checkbox type exists or will exist
                        'label' => 'Enable Feature',
                    ]
                ]
            ]
        ]
    ] );
} );