OptionTree - Version 1.1.6

Version Description

  • Theme Integration added.
  • Made the upload XML file openbase_dir compliant.
Download this release

Release Info

Developer valendesigns
Plugin Icon wp plugin OptionTree
Version 1.1.6
Comparing to
See all releases

Code changes from version 1.1.5 to 1.1.6

Files changed (4) hide show
  1. classes/class.admin.php +159 -38
  2. front-end/docs.php +34 -0
  3. index.php +2 -2
  4. readme.txt +13 -4
classes/class.admin.php CHANGED
@@ -9,10 +9,26 @@
9
  */
10
  class OT_Admin
11
  {
12
- private $table_name = NULL;
13
- private $version = NULL;
14
- private $option_array = array();
15
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  function __construct()
17
  {
18
  global $table_prefix;
@@ -20,6 +36,23 @@ class OT_Admin
20
  $this->table_name = $table_prefix . 'option_tree';
21
  $this->version = OT_VERSION;
22
  $this->option_array = $this->option_tree_data();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  }
24
 
25
  /**
@@ -40,14 +73,13 @@ class OT_Admin
40
  {
41
  // check for activation
42
  $check = get_option( 'option_tree_activation' );
43
-
44
- // redirect on activation
45
- if ($check != "set")
46
  {
47
  // set blank option values
48
  foreach ( $this->option_array as $value )
49
  {
50
- $key = $value->item_id;
51
  $new_options[$key] = '';
52
  }
53
 
@@ -58,8 +90,19 @@ class OT_Admin
58
  // load DB activation function if updating plugin
59
  $this->option_tree_activate();
60
 
61
- // Redirect
62
- wp_redirect( admin_url().'admin.php?page=option_tree_settings#import_options' );
 
 
 
 
 
 
 
 
 
 
 
63
  }
64
  return false;
65
  }
@@ -79,14 +122,14 @@ class OT_Admin
79
  if ( $type == 'create' )
80
  {
81
  $sql = "CREATE TABLE {$this->table_name} (
82
- id mediumint(9) NOT NULL AUTO_INCREMENT PRIMARY KEY,
83
- item_id VARCHAR(50) NOT NULL,
84
- item_title VARCHAR(100) NOT NULL,
85
- item_desc LONGTEXT,
86
- item_type VARCHAR(30) NOT NULL,
87
- item_options VARCHAR(250) DEFAULT NULL,
88
- item_sort mediumint(9) DEFAULT '0' NOT NULL,
89
- UNIQUE KEY (item_id)
90
  ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;";
91
  }
92
  return $sql;
@@ -120,7 +163,7 @@ class OT_Admin
120
 
121
  // add/update table
122
  if ( $installed_ver != $this->version )
123
- {
124
  // run query
125
  require_once( ABSPATH . 'wp-admin/includes/upgrade.php');
126
  dbDelta( $this->option_tree_table( 'create' ) );
@@ -129,7 +172,7 @@ class OT_Admin
129
  // new install default data
130
  if ( $new_installation )
131
  {
132
- $this->option_tree_default_data();
133
  }
134
 
135
  // New Version Update
@@ -171,11 +214,54 @@ class OT_Admin
171
  *
172
  * @return void
173
  */
174
- function option_tree_default_data()
175
  {
176
  global $wpdb;
177
 
178
- // default data
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  $wpdb->query( $wpdb->prepare( "
180
  INSERT INTO {$this->table_name}
181
  ( item_id, item_title, item_type )
@@ -187,6 +273,7 @@ class OT_Admin
187
  ( item_id, item_title, item_type )
188
  VALUES ( %s, %s, %s ) ",
189
  array('test_input','Test Input','input') ) );
 
190
  }
191
 
192
  /**
@@ -216,7 +303,14 @@ class OT_Admin
216
  $this->option_tree_activate();
217
 
218
  // Redirect
219
- wp_redirect( admin_url().'admin.php?page=option_tree_settings' );
 
 
 
 
 
 
 
220
  }
221
 
222
  /**
@@ -265,19 +359,32 @@ class OT_Admin
265
  // upload xml data
266
  $this->option_tree_import_xml();
267
 
268
- // set admin color
269
- $icon = ( get_user_option( 'admin_color' ) == 'classic' ) ? OT_PLUGIN_URL.'/assets/images/icon_classic.png' : OT_PLUGIN_URL.'/assets/images/icon_dark.png';
270
-
271
- // create menu items
272
- add_object_page( 'OptionTree', 'OptionTree', 'level_7', 'option_tree', array( $this, 'option_tree_options_page' ), $icon);
273
- $option_tree_options = add_submenu_page( 'option_tree', 'OptionTree', 'Theme Options', 'level_7', 'option_tree', array( $this, 'option_tree_options_page' ) );
274
- $option_tree_docs = add_submenu_page( 'option_tree', 'OptionTree', 'Documentation', 'level_7', 'option_tree_docs', array( $this, 'option_tree_docs_page' ) );
275
- $option_tree_settings = add_submenu_page( 'option_tree', 'OptionTree', 'Settings', 'level_10', 'option_tree_settings', array( $this, 'option_tree_settings_page' ) );
276
-
277
- // add menu items
278
- add_action( "admin_print_styles-$option_tree_options", array( $this, 'option_tree_load' ) );
279
- add_action( "admin_print_styles-$option_tree_docs", array( $this, 'option_tree_load' ) );
280
- add_action( "admin_print_styles-$option_tree_settings", array( $this, 'option_tree_load' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
281
  }
282
 
283
  /**
@@ -327,7 +434,7 @@ class OT_Admin
327
  function option_tree_data()
328
  {
329
  global $wpdb;
330
-
331
  // create an array of options
332
  $db_options = $wpdb->get_results( "SELECT * FROM {$this->table_name} ORDER BY item_sort ASC" );
333
  return $db_options;
@@ -792,7 +899,21 @@ class OT_Admin
792
  // success - it's XML
793
  if ( preg_match( "/(.xml)$/i", $_FILES["import"]['name'] ) )
794
  {
795
- $rawdata = file_get_contents( $_FILES["import"]["tmp_name"] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
796
  $new_options = new SimpleXMLElement( $rawdata );
797
 
798
  // drop table
9
  */
10
  class OT_Admin
11
  {
12
+ private $table_name;
13
+ private $version;
14
+ private $option_array;
15
+ private $ot_file;
16
+ private $theme_options_xml;
17
+ private $theme_options_txt;
18
+ private $has_xml;
19
+ private $has_txt;
20
+
21
+ /**
22
+ * PHP4 contructor
23
+ */
24
+ function OT_Admin()
25
+ {
26
+ $this->__construct();
27
+ }
28
+
29
+ /**
30
+ * PHP5 contructor
31
+ */
32
  function __construct()
33
  {
34
  global $table_prefix;
36
  $this->table_name = $table_prefix . 'option_tree';
37
  $this->version = OT_VERSION;
38
  $this->option_array = $this->option_tree_data();
39
+
40
+ // file path & name without extention
41
+ $this->ot_file = '/option-tree/theme-options';
42
+
43
+ // XML file path
44
+ $this->theme_options_xml = get_stylesheet_directory() . $this->ot_file.'.xml';
45
+ if ( $this->theme_options_xml == '' ) // no file try parent theme
46
+ $this->theme_options_xml = get_template_directory() . $this->ot_file.'.xml';
47
+
48
+ // TXT file path
49
+ $this->theme_options_txt = get_stylesheet_directory() . $this->ot_file.'.txt';
50
+ if ( $this->theme_options_txt == '' ) // no file try parent theme
51
+ $this->theme_options_xml = get_template_directory() . $this->ot_file.'.txt';
52
+
53
+ // check for files
54
+ $this->has_xml = ( is_readable( $this->theme_options_xml ) ) ? true : false;
55
+ $this->has_txt = ( is_readable( $this->theme_options_txt ) ) ? true : false;
56
  }
57
 
58
  /**
73
  {
74
  // check for activation
75
  $check = get_option( 'option_tree_activation' );
76
+
77
+ if ( $check != "set" )
 
78
  {
79
  // set blank option values
80
  foreach ( $this->option_array as $value )
81
  {
82
+ $key = $value->item_id;
83
  $new_options[$key] = '';
84
  }
85
 
90
  // load DB activation function if updating plugin
91
  $this->option_tree_activate();
92
 
93
+ if ( $this->has_xml == true )
94
+ {
95
+ // load defaults from XML
96
+ $this->option_tree_default_data(false);
97
+
98
+ // Redirect
99
+ wp_redirect( admin_url().'themes.php?page=option_tree' );
100
+ }
101
+ else
102
+ {
103
+ // Redirect
104
+ wp_redirect( admin_url().'admin.php?page=option_tree_settings#import_options' );
105
+ }
106
  }
107
  return false;
108
  }
122
  if ( $type == 'create' )
123
  {
124
  $sql = "CREATE TABLE {$this->table_name} (
125
+ id mediumint(9) NOT NULL AUTO_INCREMENT PRIMARY KEY,
126
+ item_id VARCHAR(50) NOT NULL,
127
+ item_title VARCHAR(100) NOT NULL,
128
+ item_desc LONGTEXT,
129
+ item_type VARCHAR(30) NOT NULL,
130
+ item_options VARCHAR(250) DEFAULT NULL,
131
+ item_sort mediumint(9) DEFAULT '0' NOT NULL,
132
+ UNIQUE KEY (item_id)
133
  ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;";
134
  }
135
  return $sql;
163
 
164
  // add/update table
165
  if ( $installed_ver != $this->version )
166
+ {
167
  // run query
168
  require_once( ABSPATH . 'wp-admin/includes/upgrade.php');
169
  dbDelta( $this->option_tree_table( 'create' ) );
172
  // new install default data
173
  if ( $new_installation )
174
  {
175
+ $this->option_tree_default_data(true);
176
  }
177
 
178
  // New Version Update
214
  *
215
  * @return void
216
  */
217
+ function option_tree_default_data($new = false)
218
  {
219
  global $wpdb;
220
 
221
+ if ( $this->has_xml == true )
222
+ {
223
+ $rawdata = file_get_contents( $this->theme_options_xml );
224
+ $new_options = new SimpleXMLElement( $rawdata );
225
+
226
+ // drop table
227
+ $wpdb->query( "DROP TABLE $this->table_name" );
228
+
229
+ // create table
230
+ $wpdb->query( $this->option_tree_table( 'create' ) );
231
+
232
+ foreach ( $new_options->row as $value )
233
+ {
234
+ $wpdb->insert( $this->table_name,
235
+ array(
236
+ 'item_id' => $value->item_id,
237
+ 'item_title' => $value->item_title,
238
+ 'item_desc' => $value->item_desc,
239
+ 'item_type' => $value->item_type,
240
+ 'item_options' => $value->item_options
241
+ )
242
+ );
243
+ }
244
+
245
+ // check for TXT file and is new install
246
+ if ( $new && $this->has_txt == true )
247
+ {
248
+ $rawdata = file_get_contents( $this->theme_options_txt );
249
+ $new_options = unserialize( base64_decode( $rawdata ) );
250
+
251
+ // check if array()
252
+ if ( is_array( $new_options ) )
253
+ {
254
+ // delete old options
255
+ delete_option( 'option_tree' );
256
+
257
+ // create new options
258
+ add_option('option_tree', $new_options);
259
+ }
260
+ }
261
+ return false;
262
+ }
263
+
264
+ // default data no XML file
265
  $wpdb->query( $wpdb->prepare( "
266
  INSERT INTO {$this->table_name}
267
  ( item_id, item_title, item_type )
273
  ( item_id, item_title, item_type )
274
  VALUES ( %s, %s, %s ) ",
275
  array('test_input','Test Input','input') ) );
276
+
277
  }
278
 
279
  /**
303
  $this->option_tree_activate();
304
 
305
  // Redirect
306
+ if ( is_readable( $this->theme_options_xml ) )
307
+ {
308
+ wp_redirect( admin_url().'themes.php?page=option_tree' );
309
+ }
310
+ else
311
+ {
312
+ wp_redirect( admin_url().'admin.php?page=option_tree_settings' );
313
+ }
314
  }
315
 
316
  /**
359
  // upload xml data
360
  $this->option_tree_import_xml();
361
 
362
+ // if XML file came with the theme don't build the whole UI
363
+ if ( $this->has_xml == true )
364
+ {
365
+ // create menu item
366
+ $option_tree_options = add_submenu_page( 'themes.php', 'OptionTree Theme Options','Theme Options', 'activate_plugins', 'option_tree', array( $this, 'option_tree_options_page' ) );
367
+
368
+ // add menu item
369
+ add_action( "admin_print_styles-$option_tree_options", array( $this, 'option_tree_load' ) );
370
+ }
371
+ else
372
+ {
373
+ // set admin color for icon
374
+ $icon = ( get_user_option( 'admin_color' ) == 'classic' ) ? OT_PLUGIN_URL.'/assets/images/icon_classic.png' : OT_PLUGIN_URL.'/assets/images/icon_dark.png';
375
+
376
+ // create menu items
377
+ add_object_page( 'OptionTree', 'OptionTree', 'level_7', 'option_tree', array( $this, 'option_tree_options_page' ), $icon);
378
+ $option_tree_options = add_submenu_page( 'option_tree', 'OptionTree', 'Theme Options', 'level_7', 'option_tree', array( $this, 'option_tree_options_page' ) );
379
+ $option_tree_docs = add_submenu_page( 'option_tree', 'OptionTree', 'Documentation', 'level_7', 'option_tree_docs', array( $this, 'option_tree_docs_page' ) );
380
+ $option_tree_settings = add_submenu_page( 'option_tree', 'OptionTree', 'Settings', 'level_10', 'option_tree_settings', array( $this, 'option_tree_settings_page' ) );
381
+
382
+ // add menu items
383
+ add_action( "admin_print_styles-$option_tree_options", array( $this, 'option_tree_load' ) );
384
+ add_action( "admin_print_styles-$option_tree_docs", array( $this, 'option_tree_load' ) );
385
+ add_action( "admin_print_styles-$option_tree_settings", array( $this, 'option_tree_load' ) );
386
+ }
387
+
388
  }
389
 
390
  /**
434
  function option_tree_data()
435
  {
436
  global $wpdb;
437
+
438
  // create an array of options
439
  $db_options = $wpdb->get_results( "SELECT * FROM {$this->table_name} ORDER BY item_sort ASC" );
440
  return $db_options;
899
  // success - it's XML
900
  if ( preg_match( "/(.xml)$/i", $_FILES["import"]['name'] ) )
901
  {
902
+
903
+ $mimes = apply_filters( 'upload_mimes', array(
904
+ 'xml' => 'text/xml'
905
+ ));
906
+
907
+ $overrides = array('test_form' => false, 'mimes' => $mimes);
908
+ $import = wp_handle_upload($_FILES['import'], $overrides);
909
+
910
+ if (!empty($import['error']))
911
+ {
912
+ header("Location: admin.php?page=option_tree_settings&error=true#import_options");
913
+ die();
914
+ }
915
+
916
+ $rawdata = file_get_contents( $import['file'] );
917
  $new_options = new SimpleXMLElement( $rawdata );
918
 
919
  // drop table
front-end/docs.php CHANGED
@@ -21,6 +21,7 @@
21
  <li><a href="#general">Usage &amp; Examples</a><span></span></li>
22
  <li><a href="#option_types">Option Types</a><span></span></li>
23
  <li><a href="#settings">Creating Options</a><span></span></li>
 
24
  </ul>
25
 
26
  <div id="general" class="block">
@@ -452,6 +453,39 @@ function new_slider_fields($array)
452
 
453
  </div>
454
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
455
  <br class="clear" />
456
  </div>
457
  </div>
21
  <li><a href="#general">Usage &amp; Examples</a><span></span></li>
22
  <li><a href="#option_types">Option Types</a><span></span></li>
23
  <li><a href="#settings">Creating Options</a><span></span></li>
24
+ <li><a href="#integration">Theme Integration</a><span></span></li>
25
  </ul>
26
 
27
  <div id="general" class="block">
453
 
454
  </div>
455
 
456
+ <div id="integration" class="block">
457
+ <h2>Theme Integration</h2>
458
+ <h3>Overview on how Theme Integration works.</h3>
459
+
460
+ <p>
461
+ <strong>For Developers</strong>:<br />
462
+ If you have a theme that you want to be OptionTree aware, keep reading.
463
+ </p>
464
+
465
+ <p>
466
+ After you've built your theme and created all your options on the 'Settings' page and populated your options with default data on the 'Theme Options' page, you can now seamlessly integrate with OptionTree by including two files with your theme (only one is required). It's that simple!
467
+ </p>
468
+
469
+ <p style="padding-bottom:5px">
470
+ <strong>Getting OtionTree aware</strong>:<br />
471
+ <span style="color:red;">Follow these instructions.</span>
472
+ </p>
473
+ <ul class="doc_list">
474
+ <li>Export your <a href="http://localhost/framework/wp-admin/admin.php?page=option_tree_settings#export_options">Theme Options XML</a> file and save it somewhere you can get to it and once it's saved, rename it to '<strong>theme-options.xml</strong>'.</li>
475
+ <li>Copy the <a href="http://localhost/framework/wp-admin/admin.php?page=option_tree_settings#export_options">Theme Options Data</a> string to a new .txt file and name it '<strong>theme-options.txt</strong>' and save it where you can get to it.</li>
476
+ <li>Create a new directory in the root of your themes directory and name it '<strong>option-tree</strong>'.</li>
477
+ <li>Move your '<strong>theme-options.xml</strong>' and '<strong>theme-options.txt</strong>' into the '<strong>option-tree</strong>' directory and when the plugin is activated it will populate the defaults from those files.</li>
478
+ </ul>
479
+
480
+ <p>
481
+ <span style="color:red;">NOTE</span>: the .txt file is optional and will only be used to populate the data on activation.<br />
482
+ <span style="color:red;">NOTE</span>: The file names are important, so be sure you have named them correctly.<br />
483
+ <span style="color:red;">NOTE</span>: If the theme options are not creating properly or you can still see the OptionTree menu the .xml file is not readable to the server or you have the files in the wrong place.<br />
484
+ <span style="color:red;">NOTE</span>: The plugin looks for the '<strong>option-tree</strong>' directory in the child themes root directory first, then the parent if you use a child/parent theme relationship.
485
+ </p>
486
+
487
+ </div>
488
+
489
  <br class="clear" />
490
  </div>
491
  </div>
index.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: OptionTree
4
  Plugin URI: http://wp.envato.com
5
  Description: Customizable WordPress Theme Options Admin Interface
6
- Version: 1.1.5
7
  Author: Derek Herman
8
  Author URI: http://valendesigns.com
9
  */
@@ -13,7 +13,7 @@ Author URI: http://valendesigns.com
13
  *
14
  * @since 1.0.0
15
  */
16
- define( 'OT_VERSION', '1.1.5' );
17
  define( 'OT_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . dirname( plugin_basename( __FILE__ ) ) );
18
  define( 'OT_PLUGIN_URL', WP_PLUGIN_URL . '/' . dirname( plugin_basename( __FILE__ ) ) );
19
 
3
  Plugin Name: OptionTree
4
  Plugin URI: http://wp.envato.com
5
  Description: Customizable WordPress Theme Options Admin Interface
6
+ Version: 1.1.6
7
  Author: Derek Herman
8
  Author URI: http://valendesigns.com
9
  */
13
  *
14
  * @since 1.0.0
15
  */
16
+ define( 'OT_VERSION', '1.1.6' );
17
  define( 'OT_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . dirname( plugin_basename( __FILE__ ) ) );
18
  define( 'OT_PLUGIN_URL', WP_PLUGIN_URL . '/' . dirname( plugin_basename( __FILE__ ) ) );
19
 
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === OptionTree ===
2
  Contributors: valendesigns
3
- Donate link:
4
  Tags: admin, theme options, options, admin interface, ajax
5
  Requires at least: 3.0
6
- Tested up to: 3.1
7
- Stable tag: 1.1.5
8
 
9
  Customizable WordPress Theme Options Admin Interface
10
 
@@ -16,7 +16,9 @@ With OptionTree you can create as many Theme Options as your project requires an
16
 
17
  Included is the ability to Import/Export all the theme options and data for packaging with custom themes or local development. With the Import/Export feature you can get a theme set up on a live server in minutes. Theme authors can now create different version of their themes and include them with the download. It makes setting up different theme styles & options easier than ever because a theme user installs the plugin and theme and either adds their own settings or imports your defaults.
18
 
19
- OptionTree is a project sponsored by ThemeForest, the largest WordPress theme marketplace on the web, and was originally conceived to help ThemeForest authors quickly power up their themes. But it's here for the benefit of one and all, so option up folks!
 
 
20
 
21
  == Installation ==
22
 
@@ -39,6 +41,10 @@ Sorry, but yes. OptionTree requires PHP5 to work correctly.
39
 
40
  == Changelog ==
41
 
 
 
 
 
42
  = 1.1.5 =
43
  * Fixed multiple sliders issue
44
 
@@ -69,6 +75,9 @@ Sorry, but yes. OptionTree requires PHP5 to work correctly.
69
 
70
  == Upgrade Notice ==
71
 
 
 
 
72
  = 1.1.5 =
73
  Having multiple sliders caused a naming collision in the JavaScript and is now fixed. Upgrade ASAP to have multiple sliders available in the UI.
74
 
1
  === OptionTree ===
2
  Contributors: valendesigns
3
+ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=accounts@valendesigns.com&item_name=Optiontree
4
  Tags: admin, theme options, options, admin interface, ajax
5
  Requires at least: 3.0
6
+ Tested up to: 3.1.1
7
+ Stable tag: 1.1.6
8
 
9
  Customizable WordPress Theme Options Admin Interface
10
 
16
 
17
  Included is the ability to Import/Export all the theme options and data for packaging with custom themes or local development. With the Import/Export feature you can get a theme set up on a live server in minutes. Theme authors can now create different version of their themes and include them with the download. It makes setting up different theme styles & options easier than ever because a theme user installs the plugin and theme and either adds their own settings or imports your defaults.
18
 
19
+ **Update**: Since v1.1.6 it's now possible to have a default XML file included in your theme to populate the theme options and hide the 'Settings' and 'Documentation' pages from the end uses. You can read more about this in the plugins built in documentation by clicking the 'Theme Integration' tab.
20
+
21
+ OptionTree is a project sponsored by <a href="http://themeforest.net/?ref=valendesigns">ThemeForest</a>, the largest WordPress theme marketplace on the web, and was originally conceived to help ThemeForest authors quickly power up their themes. But it's here for the benefit of one and all, so option up folks!
22
 
23
  == Installation ==
24
 
41
 
42
  == Changelog ==
43
 
44
+ = 1.1.6 =
45
+ * Theme Integration added.
46
+ * Made the upload XML file openbase_dir compliant.
47
+
48
  = 1.1.5 =
49
  * Fixed multiple sliders issue
50
 
75
 
76
  == Upgrade Notice ==
77
 
78
+ = 1.1.6 =
79
+ Added theme integration for developers. It's now possible to have a default XML file included in your theme to populate the theme options and hide the settings and docs pages. Read more about this in the plugins built in documentation.
80
+
81
  = 1.1.5 =
82
  Having multiple sliders caused a naming collision in the JavaScript and is now fixed. Upgrade ASAP to have multiple sliders available in the UI.
83