PHP code example of arcath / theme-options

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

    

arcath / theme-options example snippets


$themeOptions = new Arcath\ThemeOptions('slug');

function slug_custom_fields(){
  global $themeOptions;

  $themeOptions->addThemeOptionCustomControl('logo_light',
    array(
      'type' => 'option',
      'default' => 0
    ),
    array(
      'section' => 'images',
      'label' => __('Light Logo', 'slug'),
      'description' => __('Light Logo used on darker backgrounds', 'glug'),
    ),
    'WP_Customize_Image_Control'
  );

  $themeOptions->addThemeOption('email',
    array(
      'capability' => 'edit_theme_options',
      'type'       => 'option',
      'default'    => '[email protected]',
    ),
    array(
      'label' => 'Email',
      'section' => 'text',
      'description' => __('Your Email')
    )
  );
}

add_action('init', 'slug_custom_fields');

function slug_apply_custom_fields($wp_customize){
  global $themeOptions;

  $wp_customize->add_panel('global', array(
    'priority' => 1,
    'capability'     => 'edit_theme_options',
    'theme_supports' => '',
    'title'          => __('Global Options', 'slug'),
    'description'    => __('Global options that affect every page.', 'edit2017'),
  ));

  $wp_customize->add_section(
    'images',
    array(
      'title' => 'Images',
      'description' => 'Images used throughout the Theme',
      'capability' => 'edit_theme_options',
      'panel' => 'global'
    )
  );

  $wp_customize->add_section(
    'text',
    array(
      'title' => 'Text',
      'description' => 'Text Fields',
      'capability' => 'edit_theme_options',
      'panel' => 'global'
    )
  );
}

add_action('customize_register', 'slug_apply_custom_fields');


global $themeOptions;
echo($themeOptions->themeOption('email'));


// Template Name: RED
global $themeOptions;

add_filter('theme_slug_color', function($color){
  // Over ride option to red on this page
  return "#f00";
})

echo($themeOptions->themeOption('color'));