Advertisement
Guest User

Parse Error

a guest
Mar 7th, 2014
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.41 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Options Framework
  4. Plugin URI: http://www.wptheming.com
  5. Description: A framework for building theme options.
  6. Version: 0.8
  7. Author: Devin Price
  8. Author URI: http://www.wptheming.com
  9. License: GPLv2
  10. */
  11. /*
  12. This program is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU General Public License
  14. as published by the Free Software Foundation; either version 2
  15. of the License, or (at your option) any later version.
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. GNU General Public License for more details.
  20. You should have received a copy of the GNU General Public License
  21. along with this program; if not, write to the Free Software
  22. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  23. */
  24. /* Basic plugin definitions */
  25. define('OPTIONS_FRAMEWORK_VERSION', '0.9');
  26. /* Make sure we don't expose any info if called directly */
  27. if ( !function_exists( 'add_action' ) ) {
  28. echo "Hi there! I'm just a little plugin, don't mind me.";
  29. exit;
  30. }
  31. /* If the user can't edit theme options, no use running this plugin */
  32. add_action('init', 'optionsframework_rolescheck' );
  33. function optionsframework_rolescheck () {
  34. if ( current_user_can( 'edit_theme_options' ) ) {
  35. // If the user can edit theme options, let the fun begin!
  36. add_action( 'admin_menu', 'optionsframework_add_page');
  37. add_action( 'admin_init', 'optionsframework_init' );
  38. add_action( 'admin_init', 'optionsframework_mlu_init' );
  39. //add_action( 'admin_head', 'optionsframework_mlu_css' );
  40. //add_action( 'admin_head', 'optionsframework_mlu_js' );
  41. }
  42. }
  43. /* Loads the file for option sanitization */
  44. add_action('init', 'optionsframework_load_sanitization' );
  45. function optionsframework_load_sanitization() {
  46. require_once dirname( __FILE__ ) . '/options-sanitize.php';
  47. }
  48. /*
  49. * Creates the settings in the database by looping through the array
  50. * we supplied in options.php. This is a neat way to do it since
  51. * we won't have to save settings for headers, descriptions, or arguments.
  52. *
  53. * Read more about the Settings API in the WordPress codex:
  54. * http://codex.wordpress.org/Settings_API
  55. *
  56. */
  57. function optionsframework_init() {
  58. // Include the required files
  59. require_once dirname( __FILE__ ) . '/options-interface.php';
  60. require_once dirname( __FILE__ ) . '/options-medialibrary-uploader.php';
  61. // Loads the options array from the theme **This is for the BioSphere theme
  62. if ( $optionsfile = locate_template( array('themeOptions/options.php') ) ) {
  63. require_once($optionsfile);
  64. }
  65. else if (file_exists( dirname( __FILE__ ) . '/options.php' ) ) {
  66. require_once dirname( __FILE__ ) . '/options.php';
  67. }
  68. $optionsframework_settings = get_option('optionsframework' );
  69. // Updates the unique option id in the database if it has changed
  70. optionsframework_option_name();
  71. // Gets the unique id, returning a default if it isn't defined
  72. if ( isset($optionsframework_settings['id']) ) {
  73. $option_name = $optionsframework_settings['id'];
  74. }
  75. else {
  76. $option_name = 'optionsframework';
  77. }
  78. // If the option has no saved data, load the defaults
  79. if ( ! get_option($option_name) ) {
  80. optionsframework_setdefaults();
  81. }
  82. // Registers the settings fields and callback
  83. register_setting( 'optionsframework', $option_name, 'optionsframework_validate' );
  84. }
  85. /*
  86. * Adds default options to the database if they aren't already present.
  87. * May update this later to load only on plugin activation, or theme
  88. * activation since most people won't be editing the options.php
  89. * on a regular basis.
  90. *
  91. * http://codex.wordpress.org/Function_Reference/add_option
  92. *
  93. */
  94. function optionsframework_setdefaults() {
  95. $optionsframework_settings = get_option('optionsframework');
  96. // Gets the unique option id
  97. $option_name = $optionsframework_settings['id'];
  98. /*
  99. * Each theme will hopefully have a unique id, and all of its options saved
  100. * as a separate option set. We need to track all of these option sets so
  101. * it can be easily deleted if someone wishes to remove the plugin and
  102. * its associated data. No need to clutter the database.
  103. *
  104. */
  105. if ( isset($optionsframework_settings['knownoptions']) ) {
  106. $knownoptions = $optionsframework_settings['knownoptions'];
  107. if ( !in_array($option_name, $knownoptions) ) {
  108. array_push( $knownoptions, $option_name );
  109. $optionsframework_settings['knownoptions'] = $knownoptions;
  110. update_option('optionsframework', $optionsframework_settings);
  111. }
  112. } else {
  113. $newoptionname = array($option_name);
  114. $optionsframework_settings['knownoptions'] = $newoptionname;
  115. update_option('optionsframework', $optionsframework_settings);
  116. }
  117. // Gets the default options data from the array in options.php
  118. $options = optionsframework_options();
  119. // If the options haven't been added to the database yet, they are added now
  120. $values = of_get_default_values();
  121. if ( isset($values) ) {
  122. add_option( $option_name, $values ); // Add option with default settings
  123. }
  124. }
  125. /* Add a subpage called "Theme Options" to the appearance menu. */
  126. if ( !function_exists( 'optionsframework_add_page' ) ) {
  127. function optionsframework_add_page() {
  128. $of_page = add_theme_page('Theme Options', '', 'edit_theme_options', 'options-framework','optionsframework_page');
  129. // Adds actions to hook in the required css and javascript
  130. add_action("admin_print_styles-$of_page",'optionsframework_load_styles');
  131. add_action("admin_print_scripts-$of_page", 'optionsframework_load_scripts');
  132. }
  133. }
  134. /* Loads the CSS */
  135. function optionsframework_load_styles() {
  136. wp_enqueue_style('admin-style', OPTIONS_FRAMEWORK_DIRECTORY.'css/admin-style.css');
  137. wp_enqueue_style('color-picker', OPTIONS_FRAMEWORK_DIRECTORY.'css/colorpicker.css');
  138. wp_enqueue_style('engage.itoggle', OPTIONS_FRAMEWORK_DIRECTORY.'css/engage.itoggle.css');
  139. $_html = '';
  140. $_html .= '<link rel="stylesheet" href="' . site_url() . '/' . WPINC . '/js/thickbox/thickbox.css" type="text/css" media="screen" />' . "\n";
  141. $_html .= '<script type="text/javascript">
  142. var tb_pathToImage = "' . site_url() . '/' . WPINC . '/js/thickbox/loadingAnimation.gif";
  143. var tb_closeImage = "' . site_url() . '/' . WPINC . '/js/thickbox/tb-close.png";
  144. </script>' . "\n";
  145. echo $_html;
  146. }
  147. /* Loads the javascript */
  148. function optionsframework_load_scripts() {
  149. // Inline scripts from options-interface.php
  150. add_action('admin_head', 'of_admin_head');
  151. // Enqueued scripts
  152.  
  153. wp_enqueue_script('jquery-ui-core');
  154. wp_enqueue_script('color-picker', OPTIONS_FRAMEWORK_DIRECTORY.'js/colorpicker.js', array('jquery'));
  155. wp_enqueue_script('options-custom', OPTIONS_FRAMEWORK_DIRECTORY.'js/options-custom.js', array('jquery'));
  156. wp_enqueue_script('engage.itoggle', OPTIONS_FRAMEWORK_DIRECTORY.'js/engage.itoggle.js', array('jquery'));
  157. wp_enqueue_script('easing', OPTIONS_FRAMEWORK_DIRECTORY.'js/easing.js', array('jquery'));
  158. wp_enqueue_script('of-medialibrary-uploader', OPTIONS_FRAMEWORK_DIRECTORY .'js/of-medialibrary-uploader.js', array( 'jquery', 'thickbox' ));
  159. wp_enqueue_script( 'media-upload' );
  160. }
  161. function of_admin_head() {
  162. // Hook to add custom scripts
  163. do_action( 'optionsframework_custom_scripts' );
  164. }
  165. /*
  166. * Builds out the options panel.
  167. *
  168. * If we were using the Settings API as it was likely intended we would use
  169. * do_settings_sections here. But as we don't want the settings wrapped in a table,
  170. * we'll call our own custom optionsframework_fields. See options-interface.php
  171. * for specifics on how each individual field is generated.
  172. *
  173. * Nonces are provided using the settings_fields()
  174. *
  175. */
  176. if ( !function_exists( 'optionsframework_page' ) ) {
  177. function optionsframework_page() {
  178. $return = optionsframework_fields();
  179. // izbrisano zbog slidera settings_errors();
  180. ?>
  181. <div id="wrap">
  182. <form action="options.php" method="post">
  183. <div id="main">
  184. <div class="nav-tab-wrapper"> <img id="logo-img" src="<?php echo get_template_directory_uri(); ?>/themeOptions/admin/images/logo_panel.jpg"> <?php echo $return[1]; ?> </div>
  185. <div class="metabox-holder">
  186. <div id="optionsframework" class="postbox">
  187. <div id="theme_header">
  188. <div class="theme_logo">
  189. <h2> Hey there admin!</h2>
  190. </div>
  191. <div class="visit">
  192. <p style="margin:13px 0 0 15px;">Visit our profile!</p>
  193. <a class="visit_profile" href="http://themeforest.net/user/Skywarrior" target="_blank"></a> </div>
  194. <div class="need_help">
  195. <p>Need help?</p>
  196. <a class="documentation" href="http://skywarriorthemes.com/hikari/instructions/instructions.html" target="_blank"></a> <a class="forum" href="http://support.skywarriorthemes.com" target="_blank"></a> </div>
  197. <div class="icon-option"> </div>
  198. <div class="clear"></div>
  199. </div>
  200. <?php settings_fields('optionsframework'); ?>
  201. <?php echo $return[0]; /* Settings */ ?>
  202. </div>
  203. <!-- / #container -->
  204. </div>
  205. <div class="clear"></div>
  206. </div>
  207. <!-- / #main -->
  208. <div class="save_bar_top">
  209. <div id="optionsframework-submit">
  210. <input type="submit" class="button-primary" name="update" value="<?php esc_attr_e( 'Save All Changes' ); ?>" />
  211. <input type="submit" class="reset-button button-secondary" name="reset" value="<?php esc_attr_e( 'Restore Defaults Options' ); ?>" onclick="return confirm( '<?php print esc_js( __( 'Click OK to reset. Any theme settings will be lost!' , 'hikari') ); ?>' );" />
  212. <div class="clear"></div>
  213. </div>
  214. </div>
  215. </form>
  216. </div>
  217. <!-- / #wrap -->
  218. <?php
  219. }
  220. }
  221. /**
  222. * Validate Options.
  223. *
  224. * This runs after the submit/reset button has been clicked and
  225. * validates the inputs.
  226. *
  227. * @uses $_POST['reset']
  228. * @uses $_POST['update']
  229. */
  230. function optionsframework_validate( $input ) {
  231. /*
  232. * Restore Defaults.
  233. *
  234. * In the event that the user clicked the "Restore Defaults"
  235. * button, the options defined in the theme's options.php
  236. * file will be added to the option for the active theme.
  237. */
  238. if ( isset( $_POST['reset'] ) ) {
  239. add_settings_error( 'options-framework', 'restore_defaults', __( 'Default options restored.', 'hikari' ), 'updated fade' );
  240. return of_get_default_values();
  241. }
  242. /*
  243. * Udpdate Settings.
  244. */
  245. if ( isset( $_POST['update'] ) ) {
  246. $clean = array();
  247. $options = optionsframework_options();
  248. foreach ( $options as $option ) {
  249. if ( ! isset( $option['id'] ) ) {
  250. continue;
  251. }
  252. if ( ! isset( $option['type'] ) ) {
  253. continue;
  254. }
  255. $id = preg_replace( '/[^a-zA-Z0-9._\-]/', '', strtolower( $option['id'] ) );
  256. // Set checkbox to false if it wasn't sent in the $_POST
  257. if ( 'checkbox' == $option['type'] && ! isset( $input[$id] ) ) {
  258. $input[$id] = '0';
  259. }
  260. if ( 'jqueryselect' == $option['type'] && ! isset( $input[$id] ) ) {
  261. $input[$id] = '0';
  262. }
  263. // Set each item in the multicheck to false if it wasn't sent in the $_POST
  264. if ( 'multicheck' == $option['type'] && ! isset( $input[$id] ) ) {
  265. foreach ( $option['options'] as $key => $value ) {
  266. $input[$id][$key] = '0';
  267. }
  268. }
  269. // For a value to be submitted to database it must pass through a sanitization filter
  270. if ( has_filter( 'of_sanitize_' . $option['type'] ) ) {
  271. $clean[$id] = apply_filters( 'of_sanitize_' . $option['type'], $input[$id], $option );
  272. }
  273. }
  274. add_settings_error( 'options-framework', 'save_options', __( 'Options saved.', 'hikari' ), 'updated fade' );
  275. return $clean;
  276. }
  277. /*
  278. * Request Not Recognized.
  279. */
  280. return of_get_default_values();
  281. }
  282. /**
  283. * Format Configuration Array.
  284. *
  285. * Get an array of all default values as set in
  286. * options.php. The 'id','std' and 'type' keys need
  287. * to be defined in the configuration array. In the
  288. * event that these keys are not present the option
  289. * will not be included in this function's output.
  290. *
  291. * @return array Rey-keyed options configuration array.
  292. *
  293. * @access private
  294. */
  295. function of_get_default_values() {
  296. $output = array();
  297. $config = optionsframework_options();
  298. foreach ( (array) $config as $option ) {
  299. if ( ! isset( $option['id'] ) ) {
  300. continue;
  301. }
  302. if ( ! isset( $option['std'] ) ) {
  303. continue;
  304. }
  305. if ( ! isset( $option['type'] ) ) {
  306. continue;
  307. }
  308. if ( has_filter( 'of_sanitize_' . $option['type'] ) ) {
  309. $output[$option['id']] = apply_filters( 'of_sanitize_' . $option['type'], $option['std'], $option );
  310. }
  311. }
  312. return $output;
  313. }
  314. /**
  315. * Add Theme Options menu item to Admin Bar.
  316. */
  317. add_action( 'wp_before_admin_bar_render', 'optionsframework_adminbar' );
  318. function optionsframework_adminbar() {
  319. global $wp_admin_bar;
  320. $wp_admin_bar->add_menu( array(
  321. 'parent' => 'appearance',
  322. 'id' => 'of_theme_options',
  323. 'title' => __( 'Theme Options' , 'hikari'),
  324. 'href' => admin_url( 'themes.php?page=options-framework' )
  325. ));
  326. }
  327. if ( ! function_exists( 'of_get_option' ) ) {
  328. /**
  329. * Get Option.
  330. *
  331. * Helper function to return the theme option value.
  332. * If no value has been saved, it returns $default.
  333. * Needed because options are saved as serialized strings.
  334. */
  335. function of_get_option( $name, $default = false ) {
  336. $config = get_option( 'optionsframework' );
  337. if ( ! isset( $config['id'] ) ) {
  338. return $default;
  339. }
  340. $options = get_option( $config['id'] );
  341. if ( isset( $options[$name] ) ) {
  342. return $options[$name];
  343. }
  344. return $default;
  345. }
  346. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement