Coder Social home page Coder Social logo

andyadams / struts Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thethemefoundry/struts

0.0 2.0 0.0 190 KB

A simple theme options framework for WordPress

Home Page: http://thethemefoundry.com

License: MIT License

PHP 91.56% JavaScript 8.44%

struts's Introduction

Struts is a simple theme options framework for WordPress.

Struts is an Options library for WordPress that aims to make setting up Theme options a breeze.

How it works:

  • In your functions.php file, all you need to do to setup your theme options

      <?php
      function mytheme_options_init() {
      	locate_template( array( 'path/to/struts/classes/struts.php' ), true );
    
      	Struts::load_config( array(
      		'struts_root_uri' => get_template_directory_uri() . '/path/to/struts', // required, set this to the URI of the root Struts directory
      		'use_struts_skin' => true, // optional, overrides the Settings API html output
      	) );
    
      	global $mytheme_options;
    
      	$mytheme_options = new Struts_Options( 'mytheme', 'theme_mytheme_options' );
    
      	// Setup the option sections
      	$mytheme_options->add_section( 'section_one', __( 'Section One', 'mytheme' ), 200 ); // 200 is priority of section in the customizer
      	$mytheme_options->add_section( 'section_two', __( 'Section Two', 'mytheme' ), 201 );
    
      	/* Section One
      	 * ------------------------------------------------------------------ */
    
      	$mytheme_options->add_option( 'option_one', 'image', 'section_one' )
      		->default_value( '' )
      		->label( __( 'Image option:', 'mytheme' ) )
      		->description( __( 'Upload an image (making sure to click <strong>"Insert into post"</strong>) or enter an <abbr title="Universal resource locator">URL</abbr> for your image.', 'mytheme' ) );
    
      	$mytheme_options->add_option( 'option_two', 'select', 'section_one' )
      		->valid_values( array(
      			'first_value' => __( 'First Value', 'mytheme' ),
      			'second_value' => __( 'Second Value', 'mytheme' ) ) )
      		->default_value( 'first_value' )
      		->label( __( 'Select option:', 'mytheme' ) )
      		->description( __( 'Select an option from the select dropdown.', 'mytheme' ) );
    
      	/* Section Two
      	 * ------------------------------------------------------------------ */
    
      	$mytheme_options->add_option( 'option_three', 'checkbox', 'section_two' )
      		->default_value( false )
      		->label( __( 'Checkbox option', 'mytheme' ) )
      		->description( __( 'A checkbox option.', 'mytheme' ) );
    
      	$mytheme_options->add_option( 'option_four', 'text', 'section_two' )
      		->label( __( 'A text option:', 'mytheme' ) )
      		->description( __( 'A text input.', 'mytheme' ) );
      }
    
      add_action( 'after_setup_theme', 'mytheme_options_init', 5 );
    
      // Gets the value for a requested option.
      function mytheme_option( $option_name ) {
      	global $mytheme_options;
    
      	return $mytheme_options->get_value( $option_name );
      }
    

Struts makes options as simple as possible, so you can get setup and running quickly.

Powered by The Theme Foundry

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.