Giter Site home page Giter Site logo

mattiasghodsian / wp_theme_settings Goto Github PK

View Code? Open in Web Editor NEW
28.0 6.0 8.0 87 KB

A custom WordPress class for creating theme settings page

CSS 23.57% PHP 57.20% JavaScript 19.23%
wp-theme-settings wordpress wordpress-theme custom-wordpress settings theme theme-options

wp_theme_settings's Introduction

wp_theme_settings (Discontinued)

A custom WordPress class for creating theme settings page (Compatible Wordpress 4.5+, Tested on Wordpress 4.7.3)

Extras

NOTE

This is a utility class intended to create a theme settings page. Read full docs and changelog

Installation

Place wp_theme_settings.php, wp_theme_settings.js and wp_theme_settings.css in your WordPress theme folder /wp-content/your-theme/

Open your WordPress themes functions.php file /wp-content/your-theme/functions.php add the following code:

include 'wp_theme_settings.php';

Add both CSS & JS file to Wordpress with admin_enqueue_scripts

add_action('admin_enqueue_scripts', 'wp_theme_settings_add_stylesheet');
function wp_theme_settings_add_stylesheet(){
  wp_enqueue_style('wp_theme_settings', get_template_directory_uri().'/wp_theme_settings.css');
  wp_register_script('wp_theme_settings',get_template_directory_uri() . '/wp_theme_settings.js', array( 'wp-color-picker' ));
  wp_enqueue_script('wp_theme_settings');
}

Example

include 'wp_theme_settings.php';

$wpts = new wp_theme_settings(
  array(
    'general' => array('description' => 'A custom WordPress class for creating theme settings page'),
    'settingsID' => 'wp_theme_settings',
    'settingFields' => array('wp_theme_settings_title'), 
    'tabs' => array(
      'general' => array('text' => 'General', 'dashicon' => 'dashicons-admin-generic' ),
      'buttons' => array('text' => 'Buttons')
      ),
  )
);

add_action('wpts_tab_general' , 'general');
function general(){
?>
<p><label>Title</label></p>
<input type="text" name="wp_theme_settings_title" value="<?php echo esc_attr( get_option('wp_theme_settings_title') ); ?>" />
<?php

}

add_action('admin_enqueue_scripts', 'wp_theme_settings_add_stylesheet');
function wp_theme_settings_add_stylesheet(){
  wp_enqueue_style('wp_theme_settings', get_template_directory_uri().'/wp_theme_settings.css');
  wp_register_script('wp_theme_settings',get_template_directory_uri() . '/wp_theme_settings.js', array('jquery'));
  wp_enqueue_script('wp_theme_settings');
}

wp_theme_settings's People

Contributors

mattiasghodsian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

wp_theme_settings's Issues

Not work on WP 4.7

Warning: Invalid argument supplied for foreach() in site.dev\wp-content\themes\flowers\wp_theme_settings.php on line 193

Code in functions.php : your example

Warning: Illegal string offset 'name'

Hi, I get this error for every type of input I want to add:
Warning: Illegal string offset 'name' in C:\xampp\htdocs\wordpress\wp-content\themes\test\wp_theme_settings.php on line 57

Google Adsense codes do not work in text fields

This really is fascinating, the most complete I've seen.

Congratulations.

I open this comment because despite all the great benefits, there is something I need and is that, when it comes to adding Google Adsense codes in the fields, they do not work, I think the script tries to run the GA code.

If only I could add the external scripts in the fields, I would feel more grateful.

Missing Changelog causing repeated PHP timeouts

I recently noticed a great deal of slowdown on the sites I'm using your system with. It turned out to be an issue with the get_wpts_git_version function in wp_theme_settings.php, lines 423 + 424. The changelog file (http://wpts.nexxoz.com/changelog.txt) and your website in general seem to be currently unavailable, so the file_get_contents command keeps timing out. The rest of the WP installation reacts by loading very sluggishly on both front-end and the admin side. Clearing out the function works fine as a temporary solution, but I wanted to post this anyway in case you weren't aware your site was down.

Thanks for creating WPTS, by the way. You've turned a daunting experience into a much simpler process. Great stuff!

empty() and esc_attr()

empty() needs to access the value by reference (in order to check whether that reference points to something that exists), but PHP before 5.5 didn't support references to temporary values returned from functions.

Empty is just an alias for !isset($thing) || !$thing. When the thing you're checking always exists (in PHP results of function calls always exist), the empty() function is nothing but a negation operator.

Remove empty() in wp_theme_settings.php, line 166 and 173:

'.((esc_attr(get_option($array['name']))) ? 'checked="checked" ' : '').'

Invalid argument supplied for foreach()

Warning: Invalid argument supplied for foreach() in site.dev\wp-content\themes\flowers\wp_theme_settings.php on line 193

I used your example in my theme functions.php, i don't know what i do wrong.

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.