PageRenderTime 58ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/functions/functions.options.php

https://github.com/rohitink/Options-Framework
PHP | 566 lines | 468 code | 78 blank | 20 comment | 15 complexity | 82520a681c873460ebf599c35ed360fa MD5 | raw file
  1. <?php
  2. add_action('init','of_options');
  3. if (!function_exists('of_options'))
  4. {
  5. function of_options()
  6. {
  7. //Access the WordPress Categories via an Array
  8. $of_categories = array();
  9. $of_categories_obj = get_categories('hide_empty=0');
  10. foreach ($of_categories_obj as $of_cat) {
  11. $of_categories[$of_cat->cat_ID] = $of_cat->cat_name;}
  12. $categories_tmp = array_unshift($of_categories, "Select a category:");
  13. //Access the WordPress Pages via an Array
  14. $of_pages = array();
  15. $of_pages_obj = get_pages('sort_column=post_parent,menu_order');
  16. foreach ($of_pages_obj as $of_page) {
  17. $of_pages[$of_page->ID] = $of_page->post_name; }
  18. $of_pages_tmp = array_unshift($of_pages, "Select a page:");
  19. //Testing
  20. $of_options_select = array("one","two","three","four","five");
  21. $of_options_radio = array("one" => "One","two" => "Two","three" => "Three","four" => "Four","five" => "Five");
  22. //Sample Homepage blocks for the layout manager (sorter)
  23. $of_options_homepage_blocks = array
  24. (
  25. "disabled" => array (
  26. "placebo" => "placebo", //REQUIRED!
  27. "block_one" => "Block One",
  28. "block_two" => "Block Two",
  29. "block_three" => "Block Three",
  30. ),
  31. "enabled" => array (
  32. "placebo" => "placebo", //REQUIRED!
  33. "block_four" => "Block Four",
  34. ),
  35. );
  36. //Stylesheets Reader
  37. $alt_stylesheet_path = LAYOUT_PATH;
  38. $alt_stylesheets = array();
  39. if ( is_dir($alt_stylesheet_path) )
  40. {
  41. if ($alt_stylesheet_dir = opendir($alt_stylesheet_path) )
  42. {
  43. while ( ($alt_stylesheet_file = readdir($alt_stylesheet_dir)) !== false )
  44. {
  45. if(stristr($alt_stylesheet_file, ".css") !== false)
  46. {
  47. $alt_stylesheets[] = $alt_stylesheet_file;
  48. }
  49. }
  50. }
  51. }
  52. //Background Images Reader
  53. $bg_images_path = get_stylesheet_directory(). '/images/bg/'; // change this to where you store your bg images
  54. $bg_images_url = get_template_directory_uri().'/images/bg/'; // change this to where you store your bg images
  55. $bg_images = array();
  56. if ( is_dir($bg_images_path) ) {
  57. if ($bg_images_dir = opendir($bg_images_path) ) {
  58. while ( ($bg_images_file = readdir($bg_images_dir)) !== false ) {
  59. if(stristr($bg_images_file, ".png") !== false || stristr($bg_images_file, ".jpg") !== false) {
  60. natsort($bg_images); //Sorts the array into a natural order
  61. $bg_images[] = $bg_images_url . $bg_images_file;
  62. }
  63. }
  64. }
  65. }
  66. /*-----------------------------------------------------------------------------------*/
  67. /* TO DO: Add options/functions that use these */
  68. /*-----------------------------------------------------------------------------------*/
  69. //More Options
  70. $uploads_arr = wp_upload_dir();
  71. $all_uploads_path = $uploads_arr['path'];
  72. $all_uploads = get_option('of_uploads');
  73. $other_entries = array("Select a number:","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19");
  74. $body_repeat = array("no-repeat","repeat-x","repeat-y","repeat");
  75. $body_pos = array("top left","top center","top right","center left","center center","center right","bottom left","bottom center","bottom right");
  76. // Image Alignment radio box
  77. $of_options_thumb_align = array("alignleft" => "Left","alignright" => "Right","aligncenter" => "Center");
  78. // Image Links to Options
  79. $of_options_image_link_to = array("image" => "The Image","post" => "The Post");
  80. /*-----------------------------------------------------------------------------------*/
  81. /* The Options Array */
  82. /*-----------------------------------------------------------------------------------*/
  83. // Set the Options Array
  84. global $of_options;
  85. $of_options = array();
  86. $of_options[] = array( "name" => "Home Settings",
  87. "type" => "heading"
  88. );
  89. $of_options[] = array( "name" => "Hello there!",
  90. "desc" => "",
  91. "id" => "introduction",
  92. "std" => "<h3 style=\"margin: 0 0 10px;\">Welcome to the Options Framework demo.</h3>
  93. This is a slightly modified version of the original options framework by Devin Price with a couple of aesthetical improvements on the interface and some cool additional features. If you want to learn how to setup these options or just need general help on using it feel free to visit my blog at <a href=\"http://aquagraphite.com/2011/09/29/slightly-modded-options-framework/\">AquaGraphite.com</a>",
  94. "icon" => true,
  95. "type" => "info"
  96. );
  97. $of_options[] = array( "name" => "Media Uploader 3.5",
  98. "desc" => "Upload images using native media uploader from Wordpress 3.5+.",
  99. "id" => "media_upload_35",
  100. // Use the shortcodes [site_url] or [site_url_secure] for setting default URLs
  101. "std" => "",
  102. "type" => "upload"
  103. );
  104. $of_options[] = array( "name" => "Media Uploader 3.5 min",
  105. "desc" => "Upload images using native media uploader from Wordpress 3.5+. Min mod",
  106. "id" => "media_upload_356",
  107. // Use the shortcodes [site_url] or [site_url_secure] for setting default URLs
  108. "std" => "",
  109. "mod" => "min",
  110. "type" => "media"
  111. );
  112. $of_options[] = array( "name" => "JQuery UI Slider example 1",
  113. "desc" => "JQuery UI slider description.<br /> Min: 1, max: 500, step: 3, default value: 45",
  114. "id" => "slider_example_1",
  115. "std" => "45",
  116. "min" => "1",
  117. "step" => "3",
  118. "max" => "500",
  119. "type" => "sliderui"
  120. );
  121. $of_options[] = array( "name" => "JQuery UI Slider example 1 with steps(5)",
  122. "desc" => "JQuery UI slider description.<br /> Min: 0, max: 300, step: 5, default value: 75",
  123. "id" => "slider_example_2",
  124. "std" => "75",
  125. "min" => "0",
  126. "step" => "5",
  127. "max" => "300",
  128. "type" => "sliderui"
  129. );
  130. $of_options[] = array( "name" => "JQuery UI Spinner",
  131. "desc" => "JQuery UI spinner description.<br /> Min: 0, max: 300, step: 5, default value: 75",
  132. "id" => "spinner_example_2",
  133. "std" => "75",
  134. "min" => "0",
  135. "step" => "5",
  136. "max" => "300",
  137. "type" => "spinner"
  138. );
  139. $of_options[] = array( "name" => "Switch 1",
  140. "desc" => "Switch OFF",
  141. "id" => "switch_ex1",
  142. "std" => 0,
  143. "type" => "switch"
  144. );
  145. $of_options[] = array( "name" => "Switch 2",
  146. "desc" => "Switch ON",
  147. "id" => "switch_ex2",
  148. "std" => 1,
  149. "type" => "switch"
  150. );
  151. $of_options[] = array( "name" => "Switch 3",
  152. "desc" => "Switch with custom labels",
  153. "id" => "switch_ex3",
  154. "std" => 0,
  155. "on" => "Enable",
  156. "off" => "Disable",
  157. "type" => "switch"
  158. );
  159. $of_options[] = array( "name" => "Switch 4",
  160. "desc" => "Switch OFF with hidden options. ;)",
  161. "id" => "switch_ex4",
  162. "std" => 0,
  163. "folds" => 1,
  164. "type" => "switch"
  165. );
  166. $of_options[] = array( "name" => "Hidden option 1",
  167. "desc" => "This is a sample hidden option controlled by a <strong>switch</strong> button",
  168. "id" => "hidden_switch_ex1",
  169. "std" => "Hi, I\'m just a text input - nr 1",
  170. "fold" => "switch_ex4", /* the switch hook */
  171. "type" => "text"
  172. );
  173. $of_options[] = array( "name" => "Hidden option 2",
  174. "desc" => "This is a sample hidden option controlled by a <strong>switch</strong> button",
  175. "id" => "hidden_switch_ex2",
  176. "std" => "Hi, I\'m just a text input - nr 2",
  177. "fold" => "switch_ex4", /* the switch hook */
  178. "type" => "text"
  179. );
  180. $of_options[] = array( "name" => "Homepage Layout Manager",
  181. "desc" => "Organize how you want the layout to appear on the homepage",
  182. "id" => "homepage_blocks",
  183. "std" => $of_options_homepage_blocks,
  184. "type" => "sorter"
  185. );
  186. $of_options[] = array( "name" => "Slider Options",
  187. "desc" => "Unlimited slider with drag and drop sortings.",
  188. "id" => "pingu_slider",
  189. "std" => "",
  190. "type" => "slider"
  191. );
  192. $of_options[] = array( "name" => "Background Images",
  193. "desc" => "Select a background pattern.",
  194. "id" => "custom_bg",
  195. "std" => $bg_images_url."bg0.png",
  196. "type" => "tiles",
  197. "options" => $bg_images,
  198. );
  199. $of_options[] = array( "name" => "Typography",
  200. "desc" => "Typography option with each property can be called individually.",
  201. "id" => "custom_type",
  202. "std" => array('size' => '12px','style' => 'bold italic'),
  203. "type" => "typography"
  204. );
  205. $of_options[] = array( "name" => "General Settings",
  206. "type" => "heading"
  207. );
  208. $url = ADMIN_DIR . 'assets/images/';
  209. $of_options[] = array( "name" => "Main Layout",
  210. "desc" => "Select main content and sidebar alignment. Choose between 1, 2 or 3 column layout.",
  211. "id" => "layout",
  212. "std" => "2c-l-fixed.css",
  213. "type" => "images",
  214. "options" => array(
  215. '1col-fixed.css' => $url . '1col.png',
  216. '2c-r-fixed.css' => $url . '2cr.png',
  217. '2c-l-fixed.css' => $url . '2cl.png',
  218. '3c-fixed.css' => $url . '3cm.png',
  219. '3c-r-fixed.css' => $url . '3cr.png'
  220. )
  221. );
  222. $of_options[] = array( "name" => "Tracking Code",
  223. "desc" => "Paste your Google Analytics (or other) tracking code here. This will be added into the footer template of your theme.",
  224. "id" => "google_analytics",
  225. "std" => "",
  226. "type" => "textarea"
  227. );
  228. $of_options[] = array( "name" => "Footer Text",
  229. "desc" => "You can use the following shortcodes in your footer text: [wp-link] [theme-link] [loginout-link] [blog-title] [blog-link] [the-year]",
  230. "id" => "footer_text",
  231. "std" => "Powered by [wp-link]. Built on the [theme-link].",
  232. "type" => "textarea"
  233. );
  234. $of_options[] = array( "name" => "Styling Options",
  235. "type" => "heading"
  236. );
  237. $of_options[] = array( "name" => "Theme Stylesheet",
  238. "desc" => "Select your themes alternative color scheme.",
  239. "id" => "alt_stylesheet",
  240. "std" => "default.css",
  241. "type" => "select",
  242. "options" => $alt_stylesheets
  243. );
  244. $of_options[] = array( "name" => "Body Background Color",
  245. "desc" => "Pick a background color for the theme (default: #fff).",
  246. "id" => "body_background",
  247. "std" => "",
  248. "type" => "color"
  249. );
  250. $of_options[] = array( "name" => "Header Background Color",
  251. "desc" => "Pick a background color for the header (default: #fff).",
  252. "id" => "header_background",
  253. "std" => "",
  254. "type" => "color"
  255. );
  256. $of_options[] = array( "name" => "Footer Background Color",
  257. "desc" => "Pick a background color for the footer (default: #fff).",
  258. "id" => "footer_background",
  259. "std" => "",
  260. "type" => "color"
  261. );
  262. $of_options[] = array( "name" => "Body Font",
  263. "desc" => "Specify the body font properties",
  264. "id" => "body_font",
  265. "std" => array('size' => '12px','face' => 'arial','style' => 'normal','color' => '#000000'),
  266. "type" => "typography"
  267. );
  268. $of_options[] = array( "name" => "Custom CSS",
  269. "desc" => "Quickly add some CSS to your theme by adding it to this block.",
  270. "id" => "custom_css",
  271. "std" => "",
  272. "type" => "textarea"
  273. );
  274. $of_options[] = array( "name" => "Example Options",
  275. "type" => "heading"
  276. );
  277. $of_options[] = array( "name" => "Typography",
  278. "desc" => "This is a typographic specific option.",
  279. "id" => "typography",
  280. "std" => array(
  281. 'size' => '12px',
  282. 'face' => 'verdana',
  283. 'style' => 'bold italic',
  284. 'color' => '#123456'
  285. ),
  286. "type" => "typography"
  287. );
  288. $of_options[] = array( "name" => "Border",
  289. "desc" => "This is a border specific option.",
  290. "id" => "border",
  291. "std" => array(
  292. 'width' => '2',
  293. 'style' => 'dotted',
  294. 'color' => '#444444'
  295. ),
  296. "type" => "border"
  297. );
  298. $of_options[] = array( "name" => "Colorpicker",
  299. "desc" => "No color selected.",
  300. "id" => "example_colorpicker",
  301. "std" => "",
  302. "type" => "color"
  303. );
  304. $of_options[] = array( "name" => "Colorpicker (default #2098a8)",
  305. "desc" => "Color selected.",
  306. "id" => "example_colorpicker_2",
  307. "std" => "#2098a8",
  308. "type" => "color"
  309. );
  310. $of_options[] = array( "name" => "Input Text",
  311. "desc" => "A text input field.",
  312. "id" => "test_text",
  313. "std" => "Default Value",
  314. "type" => "text"
  315. );
  316. $of_options[] = array( "name" => "Input Checkbox (false)",
  317. "desc" => "Example checkbox with false selected.",
  318. "id" => "example_checkbox_false",
  319. "std" => 0,
  320. "type" => "checkbox"
  321. );
  322. $of_options[] = array( "name" => "Input Checkbox (true)",
  323. "desc" => "Example checkbox with true selected.",
  324. "id" => "example_checkbox_true",
  325. "std" => 1,
  326. "type" => "checkbox"
  327. );
  328. $of_options[] = array( "name" => "Normal Select",
  329. "desc" => "Normal Select Box.",
  330. "id" => "example_select",
  331. "std" => "three",
  332. "type" => "select",
  333. "options" => $of_options_select
  334. );
  335. $of_options[] = array( "name" => "Mini Select",
  336. "desc" => "A mini select box.",
  337. "id" => "example_select_2",
  338. "std" => "two",
  339. "type" => "select",
  340. "mod" => "mini",
  341. "options" => $of_options_radio
  342. );
  343. $of_options[] = array( "name" => "Google Font Select",
  344. "desc" => "Some description. Note that this is a custom text added added from options file.",
  345. "id" => "g_select",
  346. "std" => "Select a font",
  347. "type" => "select_google_font",
  348. "preview" => array(
  349. "text" => "This is my preview text!", //this is the text from preview box
  350. "size" => "30px" //this is the text size from preview box
  351. ),
  352. "options" => array(
  353. "none" => "Select a font",//please, always use this key: "none"
  354. "Lato" => "Lato",
  355. "Loved by the King" => "Loved By the King",
  356. "Tangerine" => "Tangerine",
  357. "Terminal Dosis" => "Terminal Dosis"
  358. )
  359. );
  360. $of_options[] = array( "name" => "Google Font Select2",
  361. "desc" => "Some description.",
  362. "id" => "g_select2",
  363. "std" => "Select a font",
  364. "type" => "select_google_font",
  365. "options" => array(
  366. "none" => "Select a font",//please, always use this key: "none"
  367. "Lato" => "Lato",
  368. "Loved by the King" => "Loved By the King",
  369. "Tangerine" => "Tangerine",
  370. "Terminal Dosis" => "Terminal Dosis"
  371. )
  372. );
  373. $of_options[] = array( "name" => "Input Radio (one)",
  374. "desc" => "Radio select with default of 'one'.",
  375. "id" => "example_radio",
  376. "std" => "one",
  377. "type" => "radio",
  378. "options" => $of_options_radio
  379. );
  380. $url = ADMIN_DIR . 'assets/images/';
  381. $of_options[] = array( "name" => "Image Select",
  382. "desc" => "Use radio buttons as images.",
  383. "id" => "images",
  384. "std" => "warning.css",
  385. "type" => "images",
  386. "options" => array(
  387. 'warning.css' => $url . 'warning.png',
  388. 'accept.css' => $url . 'accept.png',
  389. 'wrench.css' => $url . 'wrench.png'
  390. )
  391. );
  392. $of_options[] = array( "name" => "Textarea",
  393. "desc" => "Textarea description.",
  394. "id" => "example_textarea",
  395. "std" => "Default Text",
  396. "type" => "textarea"
  397. );
  398. $of_options[] = array( "name" => "Multicheck",
  399. "desc" => "Multicheck description.",
  400. "id" => "example_multicheck",
  401. "std" => array("three","two"),
  402. "type" => "multicheck",
  403. "options" => $of_options_radio
  404. );
  405. $of_options[] = array( "name" => "Select a Category",
  406. "desc" => "A list of all the categories being used on the site.",
  407. "id" => "example_category",
  408. "std" => "Select a category:",
  409. "type" => "select",
  410. "options" => $of_categories
  411. );
  412. //Advanced Settings
  413. $of_options[] = array( "name" => "Advanced Settings",
  414. "type" => "heading"
  415. );
  416. $of_options[] = array( "name" => "Folding Checkbox",
  417. "desc" => "This checkbox will hide/show a couple of options group. Try it out!",
  418. "id" => "offline",
  419. "std" => 0,
  420. "folds" => 1,
  421. "type" => "checkbox"
  422. );
  423. $of_options[] = array( "name" => "Hidden option 1",
  424. "desc" => "This is a sample hidden option 1",
  425. "id" => "hidden_option_1",
  426. "std" => "Hi, I\'m just a text input",
  427. "fold" => "offline", /* the checkbox hook */
  428. "type" => "text"
  429. );
  430. $of_options[] = array( "name" => "Hidden option 2",
  431. "desc" => "This is a sample hidden option 2",
  432. "id" => "hidden_option_2",
  433. "std" => "Hi, I\'m just a text input",
  434. "fold" => "offline", /* the checkbox hook */
  435. "type" => "text"
  436. );
  437. $of_options[] = array( "name" => "Hello there!",
  438. "desc" => "",
  439. "id" => "introduction_2",
  440. "std" => "<h3 style=\"margin: 0 0 10px;\">Grouped Options.</h3>
  441. You can group a bunch of options under a single heading by removing the 'name' value from the options array except for the first option in the group.",
  442. "icon" => true,
  443. "type" => "info"
  444. );
  445. $of_options[] = array( "name" => "Some pretty colors for you",
  446. "desc" => "Color 1.",
  447. "id" => "example_colorpicker_3",
  448. "std" => "#2098a8",
  449. "type" => "color"
  450. );
  451. $of_options[] = array( "name" => "",
  452. "desc" => "Color 2.",
  453. "id" => "example_colorpicker_4",
  454. "std" => "#2098a8",
  455. "type" => "color"
  456. );
  457. $of_options[] = array( "name" => "",
  458. "desc" => "Color 3.",
  459. "id" => "example_colorpicker_5",
  460. "std" => "#2098a8",
  461. "type" => "color"
  462. );
  463. $of_options[] = array( "name" => "",
  464. "desc" => "Color 4.",
  465. "id" => "example_colorpicker_6",
  466. "std" => "#2098a8",
  467. "type" => "color"
  468. );
  469. // Backup Options
  470. $of_options[] = array( "name" => "Backup Options",
  471. "type" => "heading",
  472. "icon" => ADMIN_IMAGES . "icon-slider.png"
  473. );
  474. $of_options[] = array( "name" => "Backup and Restore Options",
  475. "id" => "of_backup",
  476. "std" => "",
  477. "type" => "backup",
  478. "desc" => 'You can use the two buttons below to backup your current options, and then restore it back at a later time. This is useful if you want to experiment on the options but would like to keep the old settings in case you need it back.',
  479. );
  480. $of_options[] = array( "name" => "Transfer Theme Options Data",
  481. "id" => "of_transfer",
  482. "std" => "",
  483. "type" => "transfer",
  484. "desc" => 'You can tranfer the saved options data between different installs by copying the text inside the text box. To import data from another install, replace the data in the text box with the one from another install and click "Import Options".',
  485. );
  486. }//End function: of_options()
  487. }//End chack if function exists: of_options()
  488. ?>