Skip to content

Hook Additional Options onto Action #31

@gasatrya

Description

@gasatrya

I'm sorry about title, I have no idea what is the best title for my question.

I'm trying to split the customizer option into seperated files, so I tried to added 'hook' in the middle of code, somethin like this

function standard_customizer_register() {

    // Stores all the controls that will be added
    $options = array();

    // Stores all the sections to be added
    $sections = array();

    // Stores all the panels to be added
    $panels = array();

    // Adds the sections to the $options array
    $options['sections'] = $sections;

    // Hook to add the custom customizer.
    do_action( 'standard_register_customizer', $options, $sections, $panels );

    // Adds the sections to the $options array
    $options['sections'] = $sections;

    // Adds the panels to the $options array
    $options['panels'] = $panels;

    $customizer_library = Customizer_Library::Instance();
    $customizer_library->add_options( $options );

}
add_action( 'init', 'standard_customizer_register' );

then I called the file and hook in to add the panels/sections.

$path = trailingslashit( get_template_directory() ) . 'admin/panels/';
require_once( $path . 'general.php' );

general.php

function standard_customizer_general_panel( $sections, $panels, $options) {

    // Panel ID
    $panel = 'panel';

    $panels[] = array(
        'id' => $panel,
        'title' => __( 'General', 'Standard' ),
        'priority' => 10
    );

    // Logo
    $section = 'logo';

    $sections[] = array(
        'id' => $section,
        'title' => __( 'Image Example', 'demo' ),
        'priority' => '30',
        'description' => __( 'Example section description.', 'demo' ),
        'panel' => $panel
    );
    $options['logo'] = array(
        'id' => 'logo',
        'label'   => __( 'Logo', 'demo' ),
        'section' => $section,
        'type'    => 'image',
        'default' => ''
    );

}
add_action( 'standard_register_customizer', 'standard_customizer_general_panel', 10, 3 );

But it didn't worked. My question:

  1. Is it possible to split the options files?
  2. Am I missing something in the code?

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions