init.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <?php
  2. /**
  3. * Title: Core Initializer
  4. *
  5. * Description: Initializes the core. Adds all required files.
  6. *
  7. * Please do not edit this file. This file is part of the Cyber Chimps Framework and all modifications
  8. * should be made in a child theme.
  9. *
  10. * @category Cyber Chimps Framework
  11. * @package Framework
  12. * @since 1.0
  13. * @author CyberChimps
  14. * @license http://www.opensource.org/licenses/gpl-license.php GPL v3.0 (or later)
  15. * @link http://www.cyberchimps.com/
  16. */
  17. if ( !function_exists( 'cyberchimps_core_setup_theme' ) ):
  18. // Setup the theme
  19. function cyberchimps_core_setup_theme() {
  20. // Set directory path
  21. $directory = get_template_directory();
  22. // Load core functions file
  23. require_once( $directory . '/cyberchimps/functions.php' );
  24. // Load core hooks file
  25. require_once( $directory . '/cyberchimps/inc/hooks.php' );
  26. // Load element files before meta and options
  27. require_once( $directory . '/elements/init.php' );
  28. // Load santize before options-init and options core
  29. require_once( $directory . '/cyberchimps/options/options-sanitize.php' );
  30. // Load core options file
  31. require_once( $directory . '/cyberchimps/options/options-init.php' );
  32. // Load default core settings
  33. require_once( $directory . '/cyberchimps/options/options-core.php' );
  34. // Load core hooks file
  35. require_once( $directory . '/cyberchimps/inc/cc-custom-background.php' );
  36. //Load pro features if a pro theme. Load prior to meta boxes so that filters work
  37. if ( cyberchimps_theme_check() == 'pro' ) {
  38. require_once( $directory . '/elements/setup/features.php' );
  39. }
  40. // Load new meta box class
  41. require_once( $directory . '/cyberchimps/options/meta-box-class/my-meta-box-class.php' );
  42. // Load new meta box options
  43. require_once( $directory . '/cyberchimps/options/meta-box-class/meta-box.php' );
  44. // Load theme upsell.
  45. require_once( $directory . '/cyberchimps/options/theme-upsell.php' );
  46. // Core Translations can be filed in the /inc/languages/ directory
  47. load_theme_textdomain( 'cyberchimps_core', $directory . '/cyberchimps/lib/languages' );
  48. load_theme_textdomain( 'cyberchimps_elements', $directory . '/elements/lib/languages' );
  49. // Add support for the Aside Post Formats
  50. add_theme_support( 'post-formats', array( 'aside', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio', 'chat' ) );
  51. // Add default posts and comments RSS feed links to head
  52. add_theme_support( 'automatic-feed-links' );
  53. // Enable support for Post Thumbnails
  54. add_theme_support( 'post-thumbnails' );
  55. // add theme support for backgrounds
  56. $defaults = array(
  57. 'default-color' => apply_filters( 'default_background_color', '' ),
  58. 'default-image' => apply_filters( 'default_background_image', '' ),
  59. 'wp-head-callback' => 'cyberchimps_custom_background_cb'
  60. );
  61. $defaults = apply_filters( 'cyberchimps_background_default_args', $defaults );
  62. add_theme_support( 'custom-background', $defaults );
  63. // This theme uses wp_nav_menu() in one location.
  64. register_nav_menus( array(
  65. 'primary' => __( 'Primary Menu', 'cyberchimps_core' ),
  66. ) );
  67. //set up defaults
  68. $option_defaults = cyberchimps_get_default_values();
  69. if ( !get_option( 'cyberchimps_options' ) && isset( $_GET['activated'] ) ) {
  70. update_option( 'cyberchimps_options', $option_defaults );
  71. } //if not then set up defaults for this theme
  72. elseif ( get_option( 'cyberchimps_options' ) && isset( $_GET['activated'] ) ) {
  73. $options = get_option( 'cyberchimps_options' );
  74. $options['header_section_order'] = $option_defaults['header_section_order'];
  75. $options['theme_backgrounds'] = $option_defaults['theme_backgrounds'];
  76. update_option( 'cyberchimps_options', $options );
  77. }
  78. }
  79. endif; // cyberchimps_core_setup_theme
  80. add_action( 'after_setup_theme', 'cyberchimps_core_setup_theme' );
  81. function cyberchimps_custom_background_cb() {
  82. // $background is the saved custom image, or the default image.
  83. $background = get_background_image();
  84. // $color is the saved custom color.
  85. // A default has to be specified in style.css. It will not be printed here.
  86. $color = get_theme_mod( 'background_color' );
  87. // CyberChimps background image
  88. $cc_background = get_theme_mod( 'cyberchimps_background' );
  89. if ( !$background && !$color && !$cc_background ) {
  90. return;
  91. }
  92. if ( $background ) {
  93. $image = " background-image: url('$background');";
  94. $repeat = get_theme_mod( 'background_repeat', 'repeat' );
  95. if ( !in_array( $repeat, array( 'no-repeat', 'repeat-x', 'repeat-y', 'repeat' ) ) ) {
  96. $repeat = 'repeat';
  97. }
  98. $repeat = " background-repeat: $repeat;";
  99. $position = get_theme_mod( 'background_position_x', 'left' );
  100. if ( !in_array( $position, array( 'center', 'right', 'left' ) ) ) {
  101. $position = 'left';
  102. }
  103. $position = " background-position: top $position;";
  104. $attachment = get_theme_mod( 'background_attachment', 'scroll' );
  105. if ( !in_array( $attachment, array( 'fixed', 'scroll' ) ) ) {
  106. $attachment = 'scroll';
  107. }
  108. $attachment = " background-attachment: $attachment;";
  109. $style = $image . $repeat . $position . $attachment;
  110. }
  111. else if( $cc_background != 'none' ) {
  112. $img_url = get_template_directory_uri() . '/cyberchimps/lib/images/backgrounds/' . $cc_background . '.jpg';
  113. $style = "background-image: url( '$img_url' );";
  114. }
  115. else if( $color ) {
  116. $style = "background-color: #$color;";
  117. $style .= "background-image: none;";
  118. } ?>
  119. <style type="text/css">
  120. body {
  121. <?php echo trim( $style ); ?>
  122. }
  123. </style>
  124. <?php
  125. }
  126. // Register our sidebars and widgetized areas.
  127. function cyberchimps_widgets_init() {
  128. // Add left sidebar only to pro themes as it is not avialble in free.
  129. if ( 'pro' == cyberchimps_theme_check() ) {
  130. register_sidebar( array(
  131. 'name' => __( 'Sidebar Left', 'cyberchimps_core' ),
  132. 'id' => 'sidebar-left',
  133. 'before_widget' => apply_filters( 'cyberchimps_sidebar_before_widget', '<aside id="%1$s" class="widget-container %2$s">' ),
  134. 'after_widget' => apply_filters( 'cyberchimps_sidebar_after_widget', '</aside>' ),
  135. 'before_title' => apply_filters( 'cyberchimps_sidebar_before_widget_title', '<h3 class="widget-title">' ),
  136. 'after_title' => apply_filters( 'cyberchimps_sidebar_after_widget_title', '</h3>' )
  137. ) );
  138. }
  139. register_sidebar( array(
  140. 'name' => __( 'Sidebar Right', 'cyberchimps_core' ),
  141. 'id' => 'sidebar-right',
  142. 'before_widget' => apply_filters( 'cyberchimps_sidebar_before_widget', '<aside id="%1$s" class="widget-container %2$s">' ),
  143. 'after_widget' => apply_filters( 'cyberchimps_sidebar_after_widget', '</aside>' ),
  144. 'before_title' => apply_filters( 'cyberchimps_sidebar_before_widget_title', '<h3 class="widget-title">' ),
  145. 'after_title' => apply_filters( 'cyberchimps_sidebar_after_widget_title', '</h3>' )
  146. ) );
  147. register_sidebar( array(
  148. 'name' => __( 'Footer Widgets', 'cyberchimps_core' ),
  149. 'id' => 'cyberchimps-footer-widgets',
  150. 'before_widget' => apply_filters( 'cyberchimps_footer_before_widget', '<aside id="%1$s" class="widget-container span3 %2$s">' ),
  151. 'after_widget' => apply_filters( 'cyberchimps_footer_after_widget', '</aside>' ),
  152. 'before_title' => apply_filters( 'cyberchimps_footer_before_widget_title', '<h3 class="widget-title">' ),
  153. 'after_title' => apply_filters( 'cyberchimps_footer_after_widget_title', '</h3>' )
  154. ) );
  155. }
  156. add_action( 'widgets_init', 'cyberchimps_widgets_init' );
  157. function cyberchimps_load_hooks() {
  158. // Set the path to hooks directory.
  159. $hooks_path = get_template_directory() . "/cyberchimps/hooks/";
  160. require_once( $hooks_path . 'wp-head-hooks.php' );
  161. require_once( $hooks_path . 'header-hooks.php' );
  162. require_once( $hooks_path . 'blog-hooks.php' );
  163. require_once( $hooks_path . 'page-hooks.php' );
  164. require_once( $hooks_path . 'footer-hooks.php' );
  165. }
  166. add_action( 'after_setup_theme', 'cyberchimps_load_hooks' );
  167. //after install redirect user to options page if it's a pro theme.
  168. function cyberchimps_pro_welcome_notice() {
  169. global $pagenow;
  170. if ( is_admin() && isset( $_GET['activated'] ) && $pagenow == "themes.php" ) {
  171. if ( 'pro' == cyberchimps_theme_check() ) {
  172. wp_redirect( 'themes.php?page=cyberchimps-theme-options' );
  173. }
  174. }
  175. }
  176. add_action( 'after_setup_theme', 'cyberchimps_pro_welcome_notice' );
  177. //Incase of free show a welcome message with link to theme options.
  178. function cyberchimps_welcome_notice() {
  179. global $pagenow;
  180. if ( is_admin() && isset( $_GET['activated'] ) && $pagenow == "themes.php" ) {
  181. if ( 'free' == cyberchimps_theme_check() ) {
  182. ?>
  183. <div id="welcome" style="
  184. background: #81c7ef;
  185. padding: 0 20px 20px;
  186. margin: 20px 20px 20px 0;
  187. font-size: 1.5em;
  188. border: 1px solid #5ba9d3;
  189. -webkit-border-radius: 3px;
  190. border-radius: 3px;">
  191. <p style="color: #ffffff;
  192. text-align: center;
  193. line-height: 1.4em;
  194. font-weight: bold;
  195. margin: 5px 0 0;">
  196. <img src="<?php echo get_template_directory_uri(). '/cyberchimps/options/lib/images/chimp.png'; ?>" alt="CyberChimps" style="position:relative; top:10px; left:0; margin-right:
  197. 5px;">
  198. Welcome to <?php echo apply_filters( 'cyberchimps_current_theme_name', 'CyberChimps ' ); ?> by <a target="_blank" href="http://www.cyberchimps.com/">CyberChimps</a>. Please visit the <a href="themes.php?page=cyberchimps-theme-options">Theme Options</a> to setup and build your website.</p>
  199. </div>
  200. <?php
  201. }
  202. }
  203. }
  204. add_action( 'admin_notices', 'cyberchimps_welcome_notice' );