Advertisement
Guest User

customize.php

a guest
Nov 17th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.70 KB | None | 0 0
  1. <?php
  2.  
  3. add_action('customize_register', 'comicpress_customize_register');
  4. add_action('customize_preview_init', 'comicpress_customize_preview');
  5. add_action('wp_head', 'comicpress_customize_wp_head', 19);
  6. add_filter('body_class', 'comicpress_customize_body_class');
  7.  
  8. function comicpress_customize_body_class($classes = array()){
  9. $classes[] = 'scheme-'.get_theme_mod('comicpress-customize-select-scheme', 'none');
  10. if (get_theme_mod('comicpress-customize-checkbox-rounded', false)) $classes[] = 'rounded-posts';
  11. if (function_exists('ceo_pluginfo') && get_theme_mod('comicpress-customize-comic-in-column', false)) $classes[] = 'cnc';
  12. return $classes;
  13. }
  14.  
  15. /*
  16. <span class="customize-control-title" style="font-size: 14px; color: #21759B;"><?php echo esc_html( $this->label ); ?></span>
  17. <?php if (isset( $this->description)) { ?>
  18. <span class="customize-control-title" style="line-height: 16px; font-size: 11px; font-weight: 400;"><?php echo esc_html( $this->description); ?></span>
  19. */
  20.  
  21. function comicpress_customize_register( $wp_customize ) {
  22. global $css_array;
  23.  
  24. $wp_customize->remove_section('colors');
  25. $wp_customize->remove_section('title_tagline');
  26. $wp_customize->add_section('comicpress-scheme-options' , array('title' => __('Options','comicpress'), 'priority' => 10));
  27. // $wp_customize->add_section('comicpress-background-colors' , array('title' => __('Background Colors','comicpress')));
  28. $wp_customize->add_section('colors' , array('title' => __('Background Colors','comicpress'), 'description' => __('some description here','comicpress'), 'priority' => 20));
  29. $wp_customize->add_section('comicpress-text-colors' , array('title' => __('Text Colors','comicpress'), 'priority' => 30));
  30. $wp_customize->add_section('comicpress-link-colors' , array('title' => __('Link Colors','comicpress'), 'priority' => 40));
  31. $wp_customize->add_section('comicpress-logo-options', array('title' => __('Logo','comicpress'), 'priority' => 50));
  32.  
  33. $css_array = array(
  34. // Background Colors
  35. array('slug' => 'page_background', 'description' => '#page', 'section' => 'colors', 'label' => 'Entire Content Area'),
  36. array('slug' => 'header_background', 'description' => '#header', 'section' => 'colors', 'label' => 'Header'),
  37. array('slug' => 'menubar_background', 'description' => '#menubar-wrapper', 'section' => 'colors', 'label' => 'Menubar'),
  38. array('slug' => 'menubar_submenu_background', 'description' => '.menu ul li ul li a', 'section' => 'colors', 'label' => 'Menubar Dropdown'),
  39. array('slug' => 'menubar_mouseover_background', 'description' => '.menu ul li a:hover', 'section' => 'colors', 'label' => 'Menubar When Mouseover'),
  40. array('slug' => 'breadcrumb_background', 'description' => '#breadcrumb-wrapper', 'section' => 'colors', 'label' => 'Breadcrumbs'),
  41. array('slug' => 'content_wrapper_background', 'description' => '#content-wrapper', 'section' => 'colors', 'label' => 'Content Area Below Menubar'),
  42. array('slug' => 'subcontent_wrapper_background', 'description' => '#subcontent-wrapper', 'section' => 'colors', 'label' => 'Content Area Below Comic'),
  43. array('slug' => 'narrowcolumn_widecolumn_background', 'description' => '#content-column', 'section' => 'colors', 'label' => 'Content Column'),
  44. array('slug' => 'post_page_navigation_background', 'description' => '.uentry, #comment-wrapper, #wp-paginav, #pagenav', 'section' => 'colors', 'label' => 'Entire Post Area'),
  45. array('slug' => 'post_info_background', 'description' => '.post-info', 'section' => 'colors', 'label' => 'Top Section of a Post'),
  46. array('slug' => 'comment_background', 'description' => '.comment, #comment-wrapper #wp-paginav', 'section' => 'colors', 'label' => 'Comment Section'),
  47. array('slug' => 'comment_meta_data_background', 'description' => '.comment-meta-data', 'section' => 'colors', 'label' => 'Comment Info. Line'),
  48. array('slug' => 'bypostauthor_background', 'description' => '.bypostauthor', 'section' => 'colors', 'label' => 'Comments Made By Post Author'),
  49. array('slug' => 'bypostauthor_meta_data_background', 'description' => '.bypostauthor .comment-meta-data', 'section' => 'colors', 'label' => 'Info. Line Of Post Author'),
  50. array('slug' => 'footer_background', 'description' => '#footer', 'section' => 'colors', 'label' => 'Footer'),
  51. // Text Colors
  52. array('slug' => 'content_text_color', 'description' => 'body', 'section' => 'comicpress-text-colors', 'label' => 'Sitewide Textcolor'),
  53. array('slug' => 'header_textcolor', 'description' => '#header', 'section' => 'comicpress-text-colors', 'label' => ''),
  54. array('slug' => 'header_description_textcolor', 'description' => '.header-info .description', 'section' => 'comicpress-text-colors', 'label' => 'Site Tagline'),
  55. array('slug' => 'breadcrumb_textcolor', 'description' => '#breadcrumb-wrapper', 'section' => 'comicpress-text-colors', 'label' => ''),
  56. array('slug' => 'lrsidebar_widgettitle_textcolor', 'description' => 'h2.widget-title', 'section' => 'comicpress-text-colors', 'label' => 'Widget Titles'),
  57. array('slug' => 'lrsidebar_textcolor', 'description' => '.sidebar', 'section' => 'comicpress-text-colors', 'label' => 'Sidebar Textcolor'),
  58. array('slug' => 'posttitle_textcolor', 'description' => 'h2.post-title', 'section' => 'comicpress-text-colors', 'label' => 'Non-Link Post Titles'),
  59. array('slug' => 'pagetitle_textcolor', 'description' => 'h2.page-title', 'section' => 'comicpress-text-colors', 'label' => 'Page Titles'),
  60. array('slug' => 'postinfo_textcolor', 'description' => '.post-info', 'section' => 'comicpress-text-colors', 'label' => ''),
  61. array('slug' => 'post_page_navigation_textcolor', 'description' => '.uentry, #comment-wrapper, #wp-paginav', 'section' => 'comicpress-text-colors', 'label' => 'Post/Page Comments'),
  62. array('slug' => 'footer_copyright_textcolor', 'description' => '.copyright-info', 'section' => 'comicpress-text-colors', 'label' => 'Copyright'),
  63. // Link Colors
  64. array('slug' => 'content_link_acolor', 'description' => 'body a:link', 'section' => 'comicpress-link-colors', 'label' => ''),
  65. array('slug' => 'content_link_vcolor', 'description' => 'body a:visited', 'section' => 'comicpress-link-colors', 'label' => ''),
  66. array('slug' => 'content_link_hcolor', 'description' => 'body a:hover', 'section' => 'comicpress-link-colors', 'label' => ''),
  67. array('slug' => 'header_title_acolor', 'description' => '#header h1 a', 'section' => 'comicpress-link-colors', 'label' => ''),
  68. array('slug' => 'header_title_hcolor', 'description' => '#header h1 a:hover', 'section' => 'comicpress-link-colors', 'label' => ''),
  69. array('slug' => 'menubar_top_acolor', 'description' => '.menu ul li a:link, .menu ul li a:visited, .mininav-prev a, .mininav-next a', 'section' => 'comicpress-link-colors', 'label' => ''),
  70. array('slug' => 'menubar_hcolor', 'description' => '.menu ul li a:hover, .menu ul li a.selected, .menu ul li ul li a:hover', 'section' => 'comicpress-link-colors', 'label' => ''),
  71. array('slug' => 'menubar_sub_acolor', 'description' => '.menu ul li ul li a:link, .menu ul li ul li a:visited', 'section' => 'comicpress-link-colors', 'label' => ''),
  72. array('slug' => 'breadcrumb_acolor', 'description' => '.breadcrumbs a', 'section' => 'comicpress-link-colors', 'label' => ''),
  73. array('slug' => 'breadcrumb_hcolor', 'description' => '.breadcrumbs a:hover', 'section' => 'comicpress-link-colors', 'label' => ''),
  74. array('slug' => 'sidebar_acolor', 'description' => '.sidebar .widget a', 'section' => 'comicpress-link-colors', 'label' => ''),
  75. array('slug' => 'sidebar_hcolor', 'description' => '.sidebar .widget a:hover', 'section' => 'comicpress-link-colors', 'label' => ''),
  76. array('slug' => 'postpagenav_acolor', 'description' => '.entry a, .blognav a, #paginav a, #pagenav a', 'section' => 'comicpress-link-colors', 'label' => ''),
  77. array('slug' => 'postpagenav_hcolor', 'description' => '.entry a:hover, .blognav a:hover, #paginav a:hover, #pagenav a:hover', 'section' => 'comicpress-link-colors', 'label' => ''),
  78. array('slug' => 'footer_copyright_acolor', 'description' => '.copyright-info a', 'section' => 'comicpress-link-colors', 'label' => 'Copyright'),
  79. array('slug' => 'footer_copyright_hcolor', 'description' => '.copyright-info a:hover', 'section' => 'comicpress-link-colors', 'label' => ''),
  80. );
  81. // Additions for CE
  82. if (function_exists('ceo_pluginfo')) {
  83. $css_array[] = array('slug' => 'comic_wrap_background', 'description' => '#comic-wrap', 'section' => 'colors', 'label' => 'Comic Area');
  84. $css_array[] = array('slug' => 'comic_wrap_textcolor', 'description' => '#comic-wrap', 'section' => 'comicpress-text-colors', 'label' => '');
  85. $css_array[] = array('slug' => 'comic_nav_background', 'description' => 'table#comic-nav-wrapper', 'section' => 'colors', 'label' => 'Default Comic Navigation');
  86. }
  87. $priority_value = 11;
  88. foreach ($css_array as $setinfo) {
  89. $setinfo_register_name = 'comicpress-customize['.$setinfo['slug'].']';
  90. $wp_customize->add_setting($setinfo_register_name, array('default' => ''));
  91. $wp_customize->add_control(
  92. new WP_Customize_Color_Control(
  93. $wp_customize,
  94. $setinfo['slug'],
  95. array('label' => $setinfo['description'], 'description' => $setinfo['label'], 'section' => $setinfo['section'], 'settings' => $setinfo_register_name, 'priority' => $priority_value)
  96. )
  97. );
  98. $priority_value++;
  99. }
  100.  
  101. $wp_customize->add_setting( 'comicpress-customize-select-scheme', array('default' => 'none'));
  102. $wp_customize->add_control( 'comicpress-customize-select-scheme-control' , array(
  103. 'label' => __('Choose a default scheme.','comicpress'),
  104. 'settings' => 'comicpress-customize-select-scheme',
  105. 'section' => 'comicpress-scheme-options',
  106. 'type' => 'select',
  107. 'choices' => array(
  108. 'none' => 'No Scheme',
  109. 'boxed' => 'Boxed',
  110. 'sandy' => 'Sandy',
  111. 'mecha' => 'Mecha',
  112. 'ceasel' => 'CEasel',
  113. 'high' => 'High Society'
  114. )
  115. ));
  116.  
  117. $wp_customize->add_setting( 'comicpress-customize-checkbox-rounded', array('default' => false));
  118. $wp_customize->add_control( 'comicpress-customize-checkbox-rounded-control', array(
  119. 'settings' => 'comicpress-customize-checkbox-rounded',
  120. 'label' => __( 'Rounded corners on Post/Page Navigation Sections','comicpress'),
  121. 'section' => 'comicpress-scheme-options',
  122. 'type' => 'checkbox'
  123. ));
  124.  
  125. $wp_customize->add_setting( 'comicpress-customize-checkbox-header-hotspot', array('default' => false));
  126. $wp_customize->add_control( 'comicpress-customize-checkbox-header-hotspot-control', array(
  127. 'settings' => 'comicpress-customize-checkbox-header-hotspot',
  128. 'label' => __( 'Make the header title and description become a clickable hotspot for the entire header? (If you do the logo will not display right)','comicpress'),
  129. 'section' => 'header_image',
  130. 'type' => 'checkbox'
  131. ));
  132.  
  133. $wp_customize->add_setting( 'comicpress-customize[logo]', array('default' => ''));
  134. $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'comicpress-customize-logo-image', array('label' => __( 'Logo, 120px height x 160px width', 'comicpress' ), 'section' => 'comicpress-logo-options', 'settings' => 'comicpress-customize[logo]')));
  135.  
  136. if (function_exists('ceo_pluginfo')) {
  137. $wp_customize->add_setting( 'comicpress-customize-comic-in-column', array('default' => false));
  138. $wp_customize->add_control( 'comicpress-customize-comic-in-column-control', array(
  139. 'settings' => 'comicpress-customize-comic-in-column',
  140. 'label' => __('Put the Comic in the content column?','comicpress'),
  141. 'section' => 'comicpress-scheme-options',
  142. 'type' => 'checkbox'
  143. ));
  144. }
  145. foreach ($css_array as $setting) {
  146. $wp_customize->get_setting($setting['slug'])->transport='postMessage';
  147. }
  148. if ($wp_customize->is_preview() && !is_admin())
  149. add_action('wp_footer', 'comicpress_customize_preview');
  150. }
  151.  
  152. function comicpress_customize_preview() {
  153. global $settings_array;
  154. if (!empty($settings_array)) {
  155. ?>
  156. <script type="text/javascript">
  157. ( function( $ ){
  158. <?php foreach ($settings_array as $setting) { ?>
  159. wp.customize('<?php echo $setting['slug']; ?>',function( value ) {
  160. value.bind(function(to) {
  161. $('<?php echo $setting['element']; ?>').css('<?php echo $setting['style']; ?>', to ? to : '' );
  162. });
  163. });
  164. <?php } ?>
  165. } )( jQuery )
  166. </script>
  167. <?php
  168. }
  169. }
  170.  
  171. function comicpress_customize_wp_head() {
  172. global $settings_array;
  173. $important = '';
  174. $settings_array = array(
  175. // background colors
  176. array('slug' => 'page_background', 'element' => '#page', 'style' => 'background-color', 'default' => '', 'important' => false),
  177. array('slug' => 'header_background', 'element' => '#header', 'style' => 'background-color', 'default' => '', 'important' => false),
  178. array('slug' => 'menubar_background', 'element' => '#menubar-wrapper', 'style' => 'background-color', 'default' => '#000000', 'important' => false),
  179. array('slug' => 'menubar_submenu_background', 'element' => '.menu ul li ul li a', 'style' => 'background-color', 'default' => '', 'important' => false),
  180. array('slug' => 'menubar_mouseover_background', 'element' => '.menu ul li a:hover, .menu ul li a.selected', 'style' => 'background-color', 'default' => '', 'important' => false),
  181. array('slug' => 'breadcrumb_background', 'element' => '#breadcrumb-wrapper', 'style' => 'background-color', 'default' => '', 'important' => false),
  182. array('slug' => 'content_wrapper_background', 'element' => '#content-wrapper', 'style' => 'background-color', 'default' => '', 'important' => false),
  183. array('slug' => 'subcontent_wrapper_background', 'element' => '#subcontent-wrapper', 'style' => 'background-color', 'default' => '', 'important' => false),
  184. array('slug' => 'narrowcolumn_widecolumn_background', 'element' => '.narrowcolumn, .widecolumn', 'style' => 'background-color', 'default' => '', 'important' => false),
  185. array('slug' => 'post_page_navigation_background', 'element' => '.uentry, #comment-wrapper, #wp-paginav, .blognav, #pagenav', 'style' => 'background-color', 'default' => '', 'important' => false),
  186. array('slug' => 'post_info_background', 'element' => '.post-info', 'style' => 'background-color', 'default' => '', 'important' => false),
  187. array('slug' => 'comment_background', 'element' => '.comment, #comment-wrapper #wp-paginav', 'style' => 'background-color', 'default' => '', 'important' => false),
  188. array('slug' => 'comment_meta_data_background', 'element' => '.comment-meta-data', 'style' => 'background-color', 'default' => '', 'important' => false),
  189. array('slug' => 'bypostauthor_background', 'element' => '.bypostauthor', 'style' => 'background-color', 'default' => '', 'important' => true),
  190. array('slug' => 'bypostauthor_meta_data_background', 'element' => '.bypostauthor .comment-meta-data', 'style' => 'background-color', 'default' => '', 'important' => false),
  191. array('slug' => 'footer_background', 'element' => '#footer', 'style' => 'background-color', 'default' => '', 'important' => false),
  192. // text colors
  193. array('slug' => 'content_text_color', 'element' => 'body', 'style' => 'color', 'default' => '', 'important' => false),
  194. array('slug' => 'header_textcolor', 'element' => '#header', 'style' => 'color', 'default' => '', 'important' => false),
  195. array('slug' => 'header_description_textcolor', 'element' => '.header-info', 'style' => 'color', 'default' => '', 'important' => false),
  196. array('slug' => 'breadcrumb_textcolor', 'element' => '#breadcrumb-wrapper', 'style' => 'color', 'default' => '', 'important' => false),
  197. array('slug' => 'lrsidebar_widgettitle_textcolor', 'element' => 'h2.widget-title', 'style' => 'color', 'default' => '', 'important' => false),
  198. array('slug' => 'lrsidebar_textcolor', 'element' => '.sidebar', 'style' => 'color', 'default' => '', 'important' => false),
  199. array('slug' => 'posttitle_textcolor', 'element' => 'h2.post-title', 'style' => 'color', 'default' => '', 'important' => false),
  200. array('slug' => 'pagetitle_textcolor', 'element' => 'h2.page-title', 'style' => 'color', 'default' => '', 'important' => false),
  201. array('slug' => 'postinfo_textcolor', 'element' => '.post-info', 'style' => 'color', 'default' => '', 'important' => false),
  202. array('slug' => 'post_page_navigation_textcolor', 'element' => '.uentry, #comment-wrapper, #wp-paginav', 'style' => 'color', 'default' => '', 'important' => false),
  203. array('slug' => 'footer_copyright_textcolor', 'element' => '.copyright-info', 'style' => 'color', 'default' => '', 'important' => false),
  204. // link colors
  205. array('slug' => 'content_link_acolor', 'element' => 'a:link, a:visited', 'style' => 'color', 'default' => '', 'important' => false),
  206. array('slug' => 'content_link_vcolor', 'element' => 'a:visited', 'style' => 'color', 'default' => '', 'important' => false),
  207. array('slug' => 'content_link_hcolor', 'element' => 'a:hover', 'style' => 'color', 'default' => '', 'important' => false),
  208. array('slug' => 'content_link_vcolor', 'element' => 'a:visited', 'style' => 'color', 'default' => '', 'important' => false),
  209. array('slug' => 'header_title_acolor', 'element' => '#header h1 a:link, #header h1 a:visited', 'style' => 'color', 'default' => '', 'important' => false),
  210. array('slug' => 'header_title_hcolor', 'element' => '#header h1 a:hover', 'style' => 'color', 'default' => '', 'important' => false),
  211. array('slug' => 'menubar_top_acolor', 'element' => '.menu ul li a:link, .menu ul li a:visited, .mininav-prev a, .mininav-next a', 'style' => 'color', 'default' => '', 'important' => false),
  212. array('slug' => 'menubar_hcolor', 'element' => '.menu ul li a:hover, .menu ul li a.selected, .menu ul li ul li a:hover', 'style' => 'color', 'default' => '', 'important' => false),
  213. array('slug' => 'menubar_sub_acolor', 'element' => '.menu ul li ul li a:link, .menu ul li ul li a:visited', 'style' => 'color', 'default' => '', 'important' => false),
  214. array('slug' => 'breadcrumb_acolor', 'element' => '.breadcrumbs a', 'style' => 'color', 'default' => '', 'important' => false),
  215. array('slug' => 'breadcrumb_hcolor', 'element' => '.breadcrumbs a:hover', 'style' => 'color', 'default' => '', 'important' => false),
  216. array('slug' => 'sidebar_acolor', 'element' => '.sidebar .widget a', 'style' => 'color', 'default' => '', 'important' => false),
  217. array('slug' => 'sidebar_hcolor', 'element' => '.sidebar .widget a:hover', 'style' => 'color', 'default' => '', 'important' => false),
  218. array('slug' => 'postpagenav_acolor', 'element' => '.entry a, .blognav a, #paginav a, #pagenav a', 'style' => 'color', 'default' => '', 'important' => false),
  219. array('slug' => 'postpagenav_hcolor', 'element' => '.entry a:hover, .blognav a:hover, #paginav a:hover, #pagenav a:hover', 'style' => 'color', 'default' => '', 'important' => false),
  220. array('slug' => 'footer_copyright_acolor', 'element' => '.copyright-info a', 'style' => 'color', 'default' => '', 'important' => false),
  221. array('slug' => 'footer_copyright_hcolor', 'element' => '.copyright-info a:hover, .blognav a:hover, #paginav a:hover', 'style' => 'color', 'default' => '', 'important' => false),
  222. );
  223. if (function_exists('ceo_pluginfo')) {
  224. $settings_array[] = array('slug' => 'comic_wrap_background', 'element' => '#comic-wrap', 'style' => 'background-color', 'default' => '', 'important' => true);
  225. $settings_array[] = array('slug' => 'comic_wrap_textcolor', 'element' => '#comic-wrap', 'style' => 'color', 'default' => '', 'important' => true);
  226. $settings_array[] = array('slug' => 'comic_nav_background', 'element' => 'table#comic-nav-wrapper', 'style' => 'background-color', 'default' => '', 'important' => true);
  227. }
  228. $output = '';
  229. $style_output = '';
  230. $customize = get_theme_mod('comicpress-customize');
  231. if (!empty($customize)) {
  232. foreach ($settings_array as $setting) {
  233. if (isset($customize[$setting['slug']])) $content = $customize[$setting['slug']];
  234. if (empty($content)) $content = $setting['default'];
  235. $important = ($setting['important']) ? '!important' : '';
  236. if (!empty($content)) $style_output .= $setting['element'].' { '.$setting['style'].': '.$content.$important.'; } ';
  237. }
  238. }
  239. if (isset($customize['logo']) && !empty($customize['logo'])) {
  240. $style_output .= '.header-info { display: inline-block; float: left; padding: 0; }';
  241. $style_output .= '.header-info h1 { margin: 0; padding: 0; background: url("'.$customize['logo'].'") top left no-repeat; background-size: contain; display: cover; }';
  242. $style_output .= '.header-info h1 a { padding: 0; margin: 0; height: 120px; width: 180px; text-indent: -9999px; white-space: nowrap; overflow: hidden; display: block;}';
  243. $style_output .= '.header-info .description { display: none!important; }';
  244. }
  245. if (!empty($style_output)) {
  246. $output = '<style type="text/css">'."\r\n";
  247. $output .= $style_output;
  248. $output .= "\r\n</style>\r\n";
  249. echo $output;
  250. }
  251. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement