403Webshell
Server IP : 65.108.144.40  /  Your IP : 216.73.217.165
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux ubuntu-8gb-hel1-1 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64
User : dev ( 1000)
PHP Version : 8.2.30
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/successkpi/wp-content/themes/successkpi/inc/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/successkpi/wp-content/themes/successkpi/inc//blocks.php
<?php
/**
 * Gutenberg Block Registration
 *
 * Registers the custom block category and auto-discovers all blocks
 * inside the /blocks/ directory by scanning for block.json files.
 */

// ─────────────────────────────────────────────────────────────────────────────
// Custom Block Category
// ─────────────────────────────────────────────────────────────────────────────

/**
 * Prepend a "Success KPI" category to the block editor inserter.
 */
function sk_block_category( $categories, $post ) {
    return array_merge(
        array(
            array(
                'slug'  => 'success-kpi',
                'title' => __( 'Success KPI', 'successkpi' ),
                'icon'  => null,
            ),
        ),
        $categories
    );
}
add_filter( 'block_categories_all', 'sk_block_category', 10, 2 );

// ─────────────────────────────────────────────────────────────────────────────
// Register Navigation Menus
// ─────────────────────────────────────────────────────────────────────────────

register_nav_menus( array(
    'primary-menu' => 'Header Menu',
) );

// ─────────────────────────────────────────────────────────────────────────────
// Auto-Register ACF Blocks from /blocks/ Directory
// ─────────────────────────────────────────────────────────────────────────────

/**
 * Scans the /blocks/ folder and registers each block that contains a block.json.
 * This is the "single entry point" approach — no need to manually list blocks.
 */
function sk_register_acf_blocks() {
    if ( ! function_exists( 'register_block_type' ) ) return;

    $blocks_dir = get_theme_file_path( '/blocks' );
    if ( ! is_dir( $blocks_dir ) ) return;

    foreach ( scandir( $blocks_dir ) as $folder ) {
        if ( in_array( $folder, array( '.', '..' ), true ) ) continue;

        $block_path      = $blocks_dir . '/' . $folder;
        $block_json_path = $block_path . '/block.json';

        if ( is_dir( $block_path ) && file_exists( $block_json_path ) ) {
            register_block_type( $block_path );
        }
    }
}
add_action( 'acf/init', 'sk_register_acf_blocks' );
function sk_enqueue_block_scripts() {

    if ( is_admin() ) {
        return;
    }

    $blocks_dir = get_theme_file_path( '/blocks' );

    if ( ! is_dir( $blocks_dir ) ) {
        return;
    }

    foreach ( scandir( $blocks_dir ) as $folder ) {

        if ( in_array( $folder, array( '.', '..' ), true ) ) {
            continue;
        }

        $block_path      = $blocks_dir . '/' . $folder;
        $block_json_path = $block_path . '/block.json';

        if ( ! file_exists( $block_json_path ) ) {
            continue;
        }

        $block_meta = json_decode(
            file_get_contents( $block_json_path ),
            true
        );

        $block_name = $block_meta['name'] ?? '';

        if (
            empty( $block_name ) ||
            ! has_block( $block_name )
        ) {
            continue;
        }

        $script_path = $block_path . '/script.js';

        if ( file_exists( $script_path ) ) {

            wp_enqueue_script(
                'sk-block-' . $folder,
                get_theme_file_uri(
                    '/blocks/' . $folder . '/script.js'
                ),
                array(),
                filemtime( $script_path ),
                true
            );
        }
    }
}

add_action(
    'wp_enqueue_scripts',
    'sk_enqueue_block_scripts'
);

Youez - 2016 - github.com/yon3zu
LinuXploit