Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook Additional Options onto Action #31

Open
gasatrya opened this issue May 20, 2015 · 7 comments
Open

Hook Additional Options onto Action #31

gasatrya opened this issue May 20, 2015 · 7 comments

Comments

@gasatrya
Copy link

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.

@devinsays
Copy link
Owner

Options can just be added altogether in one call. I'm sure it's possible to rework this code a bit so multiple can be added, but I'd need to spend some time with it.

@gasatrya
Copy link
Author

I see, thank you @devinsays

@devinsays
Copy link
Owner

Let's leave this issue open. I'll take a look next time I need to make some updates to this codebase.

@devinsays devinsays reopened this May 21, 2015
@devinsays devinsays changed the title Question Hook Additional Options onto Action Jul 9, 2015
@Misplon
Copy link

Misplon commented Dec 19, 2016

@Satrya Thanks for posting this and for your pull request. Were you able to make any progress with this request? I'd like to add additional theme options via a plugin.

@RescueThemes
Copy link

RescueThemes commented Dec 19, 2016

I'm not sure this project is maintained anymore, but here is what I have done in the past: Add an filter and then hook into it in your child theme or plugin.
$options['panels'] = $panels; // Hook to add the custom customizer in child theme. $options= apply_filters( 'yourplugin_add_customizer_child_options' , $options ); $customizer_library = Customizer_Library::Instance();

Then use the filter:

`
function child_customizer_library_gateway_plus_options( $options ) {
// Add some code to set up your sections and panels, then add them below
$options['sections'] = array_merge( $custom_sections, $options['sections'] );
$options['panels'] = array_merge( $custom_panels, $options['panels'] );

return $options;
}
add_action('yourplugin_add_customizer_child_options','child_customizer_library_gateway_plus_options';

`

@gasatrya
Copy link
Author

@Misplon I am sorry I am not using this library anymore, but I have tried by calling the file directly and it was worked, something like below

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;

    // Call the customizer settings/controls
    require_once( $path . 'general.php' );

    // 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' );

@Misplon
Copy link

Misplon commented Dec 20, 2016

Thanks guys, I really appreciate your replies.

@RescueThemes @Satrya

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants