Airy_Framework

The WooCommerce Pay to Upload Airy Framework class.

Defined (1)

The class is defined in the following location(s).

/classes/class-airy-framework.php  
  1. class Airy_Framework { 
  2.  
  3. /** 
  4. * Public Variables 
  5. **/ 
  6. public $shortname = 'airy_framework'; 
  7. public $plugin_name = 'Airy Framework'; 
  8. public $desc = 'A plugin built on the Airy Framework'; 
  9. public $version = '0.0.0'; 
  10. public $framework_version = '1.1.0'; 
  11. public $framework_url = 'http://www.patrickgarman.com/wordpress-plugin-category/airy/'; 
  12. public $capability = 'manage_options'; 
  13. public $menu_location = 'plugins.php'; 
  14. public $nonce = '_airy_nonce'; 
  15. public $settings = array(); 
  16. public $fields = array(); 
  17.  
  18. /** 
  19. * Private Variables 
  20. **/ 
  21. private $no_settings = array(); 
  22.  
  23. /** 
  24. * __construct function. 
  25. *  
  26. * @access public 
  27. * @return void 
  28. */ 
  29. function __construct() { 
  30. /** 
  31. * Actions 
  32. **/ 
  33. add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); 
  34. add_action( 'admin_init', array( &$this, 'settings_init' ) ); 
  35. add_action( 'admin_init', array( &$this, 'admin_style' ) ); 
  36. add_action( 'admin_menu', array( &$this, 'admin_menu' ) ); 
  37.  
  38. /** 
  39. * Create full settings array 
  40. **/ 
  41. $this->fields = apply_filters( $this->shortname, array( 
  42. $this->shortname . '_general' => array( 
  43. 'title' => $this->plugin_name,  
  44. 'desc' => $this->desc,  
  45. 'settings' => $this->fields,  
  46. ),  
  47. )); 
  48.  
  49. /** 
  50. * Load the settings into $this 
  51. **/ 
  52. $this->settings_load(); 
  53.  
  54. add_action( 'init', array( &$this, '_register_post_types' ) ); 
  55. add_action( 'init', array( &$this, '_register_taxonomies' ) ); 
  56. add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue' ) ); 
  57. add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue' ) ); 
  58.  
  59. /** 
  60. * plugins_loaded function. 
  61. *  
  62. * @access public 
  63. * @return void 
  64. */ 
  65. function plugins_loaded() { 
  66. /** 
  67. * Localisation 
  68. **/ 
  69. load_plugin_textdomain( $this->shortname, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 
  70.  
  71. /** 
  72. * admin_menu function. 
  73. *  
  74. * @access public 
  75. * @return void 
  76. */ 
  77. function admin_menu() { 
  78. /** 
  79. * Add submenu pages 
  80. * http://codex.wordpress.org/Function_Reference/add_submenu_page 
  81. **/ 
  82. add_submenu_page( $this->menu_location, $this->plugin_name, $this->plugin_name, $this->capability, $this->shortname, array( &$this, '_options_page' ) ); 
  83.  
  84. /** 
  85. * admin_style function. 
  86. *  
  87. * @access public 
  88. * @return void 
  89. */ 
  90. function admin_style() { 
  91.  
  92. /** 
  93. * settings_init function. 
  94. *  
  95. * @access public 
  96. * @return void 
  97. */ 
  98. function settings_init() { 
  99.  
  100. foreach( $this->fields as $tab => $section ) { 
  101.  
  102. add_settings_section( $tab, $section['title'], array( &$this, 'section_desc' ), $tab ); 
  103. if( count( $section['settings'] ) > 0 ) { 
  104. foreach( $section['settings'] as $setting => $option ) { 
  105. $default = ( isset( $option['default'] ) ) ? $option['default'] : ''; 
  106. add_settings_field( $option['name'], $option['title'], array( &$this, 'settings_fields' ), $tab, $tab, $option ); 
  107. register_setting( $tab, $option['name'] ); 
  108. add_option( $option['name'], $default ); 
  109. } else { $this->no_settings[] = $tab; } 
  110. $this->settings_load(); 
  111.  
  112. /** 
  113. * settings_load function. 
  114. *  
  115. * @access public 
  116. * @return void 
  117. */ 
  118. function settings_load() { 
  119. foreach( $this->fields as $section ) { 
  120. foreach ( $section['settings'] as $option ) { 
  121. if( isset( $option['name'] ) ) { 
  122. $this->$option['name'] = get_option( $option['name'] ); 
  123. $this->nonce = '_nonce_' . $this->shortname; 
  124.  
  125. /** 
  126. * section_desc function. 
  127. *  
  128. * @access public 
  129. * @param mixed $section 
  130. * @return void 
  131. */ 
  132. function section_desc($section) { echo wpautop( $this->fields[$section['id']]['desc'] ); } 
  133.  
  134. /** 
  135. * settings_fields function. 
  136. *  
  137. * @access public 
  138. * @param mixed $args 
  139. * @return void 
  140. */ 
  141. function settings_fields($args) { 
  142. extract($args); 
  143. if(isset($type)) { 
  144. switch($type) { 
  145. case 'text': 
  146. echo '<input type="text" name="'.$name.'" id="'.$name.'" value="'.$default.'" />'; 
  147. if(isset($desc) && $desc != '') echo '<span class="description">'.$desc.'</span>'; 
  148. break; 
  149. case 'password': 
  150. echo '<input type="password" name="'.$name.'" id="'.$name.'" value="'.$default.'" />'; 
  151. if(isset($desc) && $desc != '') echo '<span class="description">'.$desc.'</span>'; 
  152. break; 
  153. case 'select': 
  154. echo '<select name="'.$name.'" id="'.$name.'">'; 
  155. foreach($values as $key=>$title) { 
  156. echo '<option value="'.$key.'" '.selected($default, $key, false).'>'.$title.'</option>'; 
  157. echo '</select>'; 
  158. if(isset($desc) && $desc != '') echo '<span class="description">'.$desc.'</span>'; 
  159. break; 
  160. case 'multiselect': 
  161. echo '<select multiple="multiple" name="'.$name.'" id="'.$name.'">'; 
  162. foreach($values as $key=>$title) { 
  163. echo '<option value="'.$key.'" '.selected($name, $key, true).'>'.$title.'</option>'; 
  164. echo '</select>'; 
  165. if(isset($desc) && $desc != '') echo '<span class="description">'.$desc.'</span>'; 
  166. break; 
  167. case 'textarea': 
  168. echo '<textarea type="text" name="'.$name.'" id="'.$name.'">'.$default.'</textarea>'; 
  169. if(isset($desc) && $desc != '') echo '<span class="description">'.$desc.'</span>'; 
  170. break; 
  171. case 'checkbox': 
  172. echo '<input type="hidden" name="'.$name.'" id="'.$name.'" value="no" />'; 
  173. echo '<input type="checkbox" name="'.$name.'" id="'.$name.'" value="yes" '.checked($this->$name, 'yes', false).' />'; 
  174. if(isset($desc) && $desc != '') echo '<span class="description">'.$desc.'</span>'; 
  175. break; 
  176.  
  177. /** 
  178. * _options_page function. 
  179. *  
  180. * @access public 
  181. * @return void 
  182. */ 
  183. function _options_page() { 
  184. echo '<div class="wrap"><div class="icon32" id="icon-options-general"><br /></div>'; 
  185. echo '<h2 class="nav-tab-wrapper">'; 
  186. $tab = ( isset( $_GET['tab'] ) ) ? $_GET['tab'] : $this->shortname . '_general'; 
  187. foreach( $this->fields as $key => $data ) { 
  188. $active = ( $key == $tab ) ? 'nav-tab-active' : ''; 
  189. echo '<a class="nav-tab ' . $active . '" href="' . add_query_arg( array( 'tab' => $key ) ) . '">' . $data['title'] . '</a>'; 
  190. echo '</h2>'; 
  191. echo '<form method="post" id="mainform" action="options.php">'; 
  192. settings_fields( $tab ); 
  193. do_settings_sections( $tab ); 
  194. if( !in_array( $tab, $this->no_settings ) ) { 
  195. echo '<p class="submit"><input type="submit" class="button-primary" value="'.__('Save Changes', $this->shortname ).'" /></p>'; 
  196. echo '</form>'; 
  197. // By removing this line you forfeight all your internet, murder puppies, and love cats. I don't like cats... it's not like anyone but site admins see this anways! 
  198. echo '<p style="border-top:1px solid #DFDFDF; padding:10px 0;"><a href="' . $this->framework_url . '" target="_blank">Airy Framework</a> Version: ' . $this->framework_version . '</p>'; 
  199. echo '</div>'; 
  200.  
  201. function assets_url( $name ) { 
  202. return plugins_url( 'assets/' . $name, dirname(__FILE__) ); 
  203.  
  204. /** 
  205. * admin_enqueue function. 
  206. *  
  207. * @access public 
  208. * @return void 
  209. */ 
  210. function admin_enqueue() { 
  211. wp_enqueue_style( 'jquery-ui' ); 
  212. wp_enqueue_style( 'jquery-ui-slider' ); 
  213.  
  214. /** 
  215. * enqueue function. 
  216. *  
  217. * @access public 
  218. * @return void 
  219. */ 
  220. function enqueue() { 
  221.  
  222. /** 
  223. * post_types function. 
  224. *  
  225. * @access public 
  226. * @return void 
  227. */ 
  228. function _register_post_types() { 
  229.  
  230. $posts = array(); 
  231. foreach( apply_filters( $this->shortname . '_post_types', $posts ) as $name => $data ) { 
  232.  
  233. $menu_name = ( isset( $data['menu_name'] ) ) ? $data['menu_name'] : $data['plural']; 
  234.  
  235. $args = array( 
  236. 'label' => $data['plural'],  
  237. 'labels' => array( 
  238. 'name' => $data['plural'],  
  239. 'singular_name' => $data['single'],  
  240. 'add_new' => 'Add New',  
  241. 'add_new_item' => sprintf( 'Add New %s', $data['single'] ),  
  242. 'edit_item' => sprintf( 'Edit %s', $data['single'] ),  
  243. 'new_item' => sprintf( 'New %s', $data['single'] ),  
  244. 'all_items' => sprintf( 'All %s', $data['plural'] ),  
  245. 'view_item' => sprintf( 'View %s', $data['single'] ),  
  246. 'search_items' => sprintf( 'Search %s', $data['plural'] ),  
  247. 'not_found' => sprintf( 'No %s found', $data['plural'] ),  
  248. 'not_found_in_trash' => sprintf( 'No %s found in trash', $data['plural'] ),  
  249. 'parent_item_colon' => '',  
  250. 'menu_name' => $menu_name,  
  251. ),  
  252. ); 
  253.  
  254. $keys = array( 'label', 'labels', 'description', 'public', 'exclude_from_search', 'show_ui', 'show_in_nav_menus', 'show_in_menu', 'show_in_admin_bar', 'menu_position', 'menu_icon', 'capability_type', 'capabilities', 'map_meta_cap', 'hierarchical', 'supports', 'register_meta_box_cb', 'taxonomies', 'has_archive', 'permalink_epmask', 'rewrite', 'query_var', 'can_export' ); 
  255.  
  256. foreach( $keys as $key ) { 
  257. if( isset( $data[ $key ] ) ) { 
  258. $args[ $key ] = $data[ $key ]; 
  259. register_post_type( $name, $args ); 
  260.  
  261. flush_rewrite_rules(); 
  262.  
  263. /** 
  264. * taxonomies function. 
  265. *  
  266. * @access public 
  267. * @return void 
  268. */ 
  269. function _register_taxonomies() { 
  270.  
  271. $taxonomies = apply_filters( $this->shortname . '_taxonomies', array() ); 
  272. foreach( $taxonomies as $name => $data ) { 
  273.  
  274. if( isset( $data['post_types'] ) ) { 
  275. $post_types = $data['post_types']; 
  276. } else { continue; } 
  277.  
  278. $menu_name = ( isset( $data['menu_name'] ) ) ? $data['menu_name'] : $data['plural']; 
  279.  
  280. $args = array( 
  281. 'label' => $data['plural'],  
  282. 'labels' => array( 
  283. 'name' => $data['plural'],  
  284. 'singular_name' => $data['single'],  
  285. 'search_items' => sprintf( 'Search %s', $data['plural'] ),  
  286. 'popular_items' => sprintf( 'Popular %s', $data['plural'] ),  
  287. 'all_items' => sprintf( 'All %s', $data['plural'] ),  
  288. 'add_new' => 'Add New',  
  289. 'parent_item' => sprintf( 'Parent %s', $data['single'] ),  
  290. 'parent_item_colon' => sprintf( 'Parent %s:', $data['single'] ),  
  291. 'edit_item' => sprintf( 'Edit %s', $data['single'] ),  
  292. 'update_item' => sprintf( 'Update %s', $data['single'] ),  
  293. 'add_new_item' => sprintf( 'Add New %s', $data['single'] ),  
  294. 'new_item_name' => sprintf( 'New %s Name', $data['single'] ),  
  295. 'separate_items_with_commas' => sprintf( 'Separate %s with commas', $data['plural'] ),  
  296. 'add_or_remove_items' => sprintf( 'Add or remove %s', $data['plural'] ),  
  297. 'choose_from_most_used' => sprintf( 'Choose from the most used %s', $data['plural'] ),  
  298. 'menu_name' => $menu_name,  
  299. ),  
  300. ); 
  301.  
  302. $keys = array( 'label', 'labels', 'public', 'show_in_nav_menus', 'show_ui', 'show_tagcloud', 'hierarchical', 'update_count_callback', 'query_var', 'rewrite', 'capabilities' ); 
  303.  
  304. foreach( $keys as $key ) { 
  305. if( isset( $data[ $key ] ) ) { 
  306. $args[ $key ] = $data[ $key ]; 
  307. register_taxonomy( $name, $post_types, $args ); 
  308.  
  309. flush_rewrite_rules(); 
  310.