Guest User

Untitled

a guest
Jul 22nd, 2014
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 13.82 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Radiate Theme Customizer
  4.  *
  5.  * @package ThemeGrill
  6.  * @subpackage Radiate
  7.  * @since Radiate 1.0
  8.  */
  9.  
  10. /**
  11.  * Add postMessage support for site title and description for the Theme Customizer.
  12.  *
  13.  * @param WP_Customize_Manager $wp_customize Theme Customizer object.
  14.  */
  15. function radiate_customize_register( $wp_customize ) {
  16.     $wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
  17.     $wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
  18.     $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
  19. }
  20. add_action( 'customize_register', 'radiate_customize_register' );
  21.  
  22. /**
  23.  * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
  24.  */
  25. function radiate_customize_preview_js() {
  26.     wp_enqueue_script( 'radiate_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20130508', true );
  27. }
  28. add_action( 'customize_preview_init', 'radiate_customize_preview_js' );
  29.  
  30. /*****************************************************************************************/
  31.  
  32. function radiate_register_theme_customizer( $wp_customize ) {
  33.     // remove control
  34.     $wp_customize->remove_control('blogdescription');
  35.      
  36.     // rename existing section
  37.     $wp_customize->add_section( 'title_tagline' , array(
  38.         'title' => __('Site Title', 'radiate' ),
  39.         'priority' => 20
  40.     ) );
  41.  
  42.     class RADIATE_ADDITIONAL_Control extends WP_Customize_Control {
  43.         public $type = 'textarea';
  44.  
  45.         public function render_content() {
  46.             ?>
  47.             <label>
  48.             <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
  49.             <textarea rows="5" style="width:100%;" <?php $this->link(); ?>><?php echo esc_textarea( $this->value() ); ?></textarea>
  50.             </label>
  51.             <?php
  52.         }
  53.     }
  54.  
  55.     $wp_customize->add_setting(
  56.         'radiate_color_scheme',
  57.             array(
  58.                 'default'       => '#632E9B',
  59.                 'sanitize_callback' => 'radiate_sanitize_hex_color',
  60.                 'sanitize_js_callback' => 'radiate_sanitize_escaping'  
  61.             )
  62.     );
  63.  
  64.     $wp_customize->add_control(
  65.         new WP_Customize_Color_Control(
  66.             $wp_customize,
  67.             'color_scheme',
  68.             array(
  69.                 'label'         => __( 'Primary Color', 'radiate' ),
  70.                 'section'       => 'colors',
  71.                 'settings'      => 'radiate_color_scheme'
  72.             )
  73.         )
  74.     );
  75.  
  76.     $wp_customize->add_section(
  77.         'radiate_custom_css_section',
  78.         array(
  79.             'title'     => __( 'Custom CSS', 'radiate' ),
  80.             'priority'  => 200
  81.         )
  82.     );
  83.  
  84.     $wp_customize->add_setting(
  85.         'radiate_custom_css',
  86.         array(
  87.         'default'    =>  '',
  88.         'sanitize_callback' => 'radiate_sanitize_custom_css',
  89.         'sanitize_js_callback' => 'radiate_sanitize_escaping'
  90.         )
  91.     );
  92.  
  93.     $wp_customize->add_control(
  94.         new RADIATE_ADDITIONAL_Control (
  95.             $wp_customize,
  96.             'radiate_custom_css',          
  97.             array(             
  98.                 'label'     => __( 'Add your custom css here and design live! (for advanced users)' , 'radiate' ),
  99.                 'section'   => 'radiate_custom_css_section',
  100.                 'settings'  => 'radiate_custom_css'
  101.             )
  102.         )
  103.     );
  104.  
  105.     $wp_customize->add_section(
  106.         'radiate_featured_section',
  107.         array(
  108.             'title'     => __( 'Front Page Featured Section', 'radiate' ),
  109.             'priority'  => 220
  110.         )
  111.     );
  112.  
  113. $wp_customize->add_setting(
  114.  'page-setting-1',
  115.  array('sanitize_callback' => 'radiate_sanitize_integer')
  116.  );
  117.    
  118. $wp_customize->add_control(
  119.  'page-setting-1',
  120.  array(
  121.  'type' => 'dropdown-pages',
  122.  'label' => __( '1 featured page', 'radiate' ),
  123.  'section' => 'radiate_featured_section',
  124.  'priority' => 1)
  125.  );
  126.  
  127. $wp_customize->add_setting(
  128.  'page-setting-2',
  129.  array('sanitize_callback' => 'radiate_sanitize_integer')
  130.  );
  131.  
  132.  $wp_customize->add_control(
  133.  'page-setting-2',
  134.  array(
  135.  'type' => 'dropdown-pages',
  136.  'label' => __( '2 featured page', 'radiate' ),
  137.  'section' => 'radiate_featured_section',
  138.  'priority' => 2)
  139.  );
  140.  
  141. $wp_customize->add_setting(
  142.  'page-setting-3',
  143.  array('sanitize_callback' => 'radiate_sanitize_integer')
  144.  );
  145.  
  146.  $wp_customize->add_control(
  147.  'page-setting-3',
  148.  array(
  149.  'type' => 'dropdown-pages',
  150.  'label' => __( '3 featured page', 'radiate' ),
  151.  'section' => 'radiate_featured_section',
  152.  'priority' => 3)
  153.  );
  154.  
  155. $wp_customize->add_setting(
  156.  'page-setting-4',
  157.  array('sanitize_callback' => 'radiate_sanitize_integer')
  158.  );
  159.  
  160.  $wp_customize->add_control(
  161.  'page-setting-4',
  162.  array(
  163.  'type' => 'dropdown-pages',
  164.  'label' => __( '4 featured page', 'radiate' ),
  165.  'section' => 'radiate_featured_section',
  166.  'priority' => 4)
  167.  );
  168.  
  169. $wp_customize->add_setting(
  170.  'page-setting-5',
  171.  array('sanitize_callback' => 'radiate_sanitize_integer')
  172.  );
  173.  
  174.  $wp_customize->add_control(
  175.  'page-setting-5',
  176.  array(
  177.  'type' => 'dropdown-pages',
  178.  'label' => __( '5 featured page', 'radiate' ),
  179.  'section' => 'radiate_featured_section',
  180.  'priority' => 5)
  181.  );
  182.  
  183. $wp_customize->add_setting(
  184.  'page-setting-6',
  185.  array('sanitize_callback' => 'radiate_sanitize_integer')
  186.  );
  187.  
  188.  $wp_customize->add_control(
  189.  'page-setting-6',
  190.  array(
  191.  'type' => 'dropdown-pages',
  192.  'label' => __( '6 featured page', 'radiate' ),
  193.  'section' => 'radiate_featured_section',
  194.  'priority' => 6)
  195.  );
  196.  
  197. $wp_customize->add_setting(
  198.  'page-setting-7',
  199.  array('sanitize_callback' => 'radiate_sanitize_integer')
  200.  );
  201.  
  202.  $wp_customize->add_control(
  203.  'page-setting-7',
  204.  array(
  205.  'type' => 'dropdown-pages',
  206.  'label' => __( '7 featured page', 'radiate' ),
  207.  'section' => 'radiate_featured_section',
  208.  'priority' => 7)
  209.  );
  210.  
  211. $wp_customize->add_setting(
  212.  'page-setting-8',
  213.  array('sanitize_callback' => 'radiate_sanitize_integer')
  214.  );
  215.  
  216.  $wp_customize->add_control(
  217.  'page-setting-8',
  218.  array(
  219.  'type' => 'dropdown-pages',
  220.  'label' => __( '8 featured page', 'radiate' ),
  221.  'section' => 'radiate_featured_section',
  222.  'priority' => 8)
  223.  );
  224.  
  225. $wp_customize->add_setting(
  226.  'page-setting-9',
  227.  array('sanitize_callback' => 'radiate_sanitize_integer')
  228.  );
  229.  
  230.  $wp_customize->add_control(
  231.  'page-setting-9',
  232.  array(
  233.  'type' => 'dropdown-pages',
  234.  'label' => __( '9 featured page', 'radiate' ),
  235.  'section' => 'radiate_featured_section',
  236.  'priority' => 9)
  237.  );
  238.  
  239. $wp_customize->add_setting(
  240.  'page-setting-10',
  241.  array('sanitize_callback' => 'radiate_sanitize_integer')
  242.  );
  243.  
  244.  $wp_customize->add_control(
  245.  'page-setting-10',
  246.  array(
  247.  'type' => 'dropdown-pages',
  248.  'label' => __( '10 featured page', 'radiate' ),
  249.  'section' => 'radiate_featured_section',
  250.  'priority' => 10)
  251.  );
  252.  
  253. $wp_customize->add_setting(
  254.  'page-setting-11',
  255.  array('sanitize_callback' => 'radiate_sanitize_integer')
  256.  );
  257.  
  258.  $wp_customize->add_control(
  259.  'page-setting-11',
  260.  array(
  261.  'type' => 'dropdown-pages',
  262.  'label' => __( '11 featured page', 'radiate' ),
  263.  'section' => 'radiate_featured_section',
  264.  'priority' => 11)
  265.  );
  266.  
  267. $wp_customize->add_setting(
  268.  'page-setting-12',
  269.  array('sanitize_callback' => 'radiate_sanitize_integer')
  270.  );
  271.  
  272.  $wp_customize->add_control(
  273.  'page-setting-12',
  274.  array(
  275.  'type' => 'dropdown-pages',
  276.  'label' => __( '12 featured page', 'radiate' ),
  277.  'section' => 'radiate_featured_section',
  278.  'priority' => 12)
  279.  );
  280.  
  281. $wp_customize->add_setting(
  282.  'page-setting-13',
  283.  array('sanitize_callback' => 'radiate_sanitize_integer')
  284.  );
  285.  
  286.  $wp_customize->add_control(
  287.  'page-setting-13',
  288.  array(
  289.  'type' => 'dropdown-pages',
  290.  'label' => __( '13 featured page', 'radiate' ),
  291.  'section' => 'radiate_featured_section',
  292.  'priority' => 13)
  293.  );
  294.  
  295. $wp_customize->add_setting(
  296.  'page-setting-14',
  297.  array('sanitize_callback' => 'radiate_sanitize_integer')
  298.  );
  299.  
  300.  $wp_customize->add_control(
  301.  'page-setting-14',
  302.  array(
  303.  'type' => 'dropdown-pages',
  304.  'label' => __( '14 featured page', 'radiate' ),
  305.  'section' => 'radiate_featured_section',
  306.  'priority' => 14)
  307.  );
  308.  
  309. $wp_customize->add_setting(
  310.  'page-setting-15',
  311.  array('sanitize_callback' => 'radiate_sanitize_integer')
  312.  );
  313.  
  314.  $wp_customize->add_control(
  315.  'page-setting-15',
  316.  array(
  317.  'type' => 'dropdown-pages',
  318.  'label' => __( '15 featured page', 'radiate' ),
  319.  'section' => 'radiate_featured_section',
  320.  'priority' => 15)
  321.  );
  322.  
  323. $wp_customize->add_setting(
  324.  'page-setting-16',
  325.  array('sanitize_callback' => 'radiate_sanitize_integer')
  326.  );
  327.  
  328.  $wp_customize->add_control(
  329.  'page-setting-16',
  330.  array(
  331.  'type' => 'dropdown-pages',
  332.  'label' => __( '16 featured page', 'radiate' ),
  333.  'section' => 'radiate_featured_section',
  334.  'priority' => 16)
  335.  );
  336.  
  337. $wp_customize->add_setting(
  338.  'page-setting-17',
  339.  array('sanitize_callback' => 'radiate_sanitize_integer')
  340.  );
  341.  
  342.  $wp_customize->add_control(
  343.  'page-setting-17',
  344.  array(
  345.  'type' => 'dropdown-pages',
  346.  'label' => __( '17 featured page', 'radiate' ),
  347.  'section' => 'radiate_featured_section',
  348.  'priority' => 17)
  349.  );
  350.  
  351. $wp_customize->add_setting(
  352.  'page-setting-18',
  353.  array('sanitize_callback' => 'radiate_sanitize_integer')
  354.  );
  355.  
  356.  $wp_customize->add_control(
  357.  'page-setting-18',
  358.  array(
  359.  'type' => 'dropdown-pages',
  360.  'label' => __( '18 featured page', 'radiate' ),
  361.  'section' => 'radiate_featured_section',
  362.  'priority' => 18)
  363.  );
  364.  
  365. $wp_customize->add_setting(
  366.  'page-setting-19',
  367.  array('sanitize_callback' => 'radiate_sanitize_integer')
  368.  );
  369.  
  370.  $wp_customize->add_control(
  371.  'page-setting-19',
  372.  array(
  373.  'type' => 'dropdown-pages',
  374.  'label' => __( '19 featured page', 'radiate' ),
  375.  'section' => 'radiate_featured_section',
  376.  'priority' => 19)
  377.  );
  378.  
  379. $wp_customize->add_setting(
  380.  'page-setting-20',
  381.  array('sanitize_callback' => 'radiate_sanitize_integer')
  382.  );
  383.  
  384.  $wp_customize->add_control(
  385.  'page-setting-20',
  386.  array(
  387.  'type' => 'dropdown-pages',
  388.  'label' => __( '20 featured page', 'radiate' ),
  389.  'section' => 'radiate_featured_section',
  390.  'priority' => 20)
  391.  );
  392.  
  393. $wp_customize->add_setting(
  394.  'page-setting-21',
  395.  array('sanitize_callback' => 'radiate_sanitize_integer')
  396.  );
  397.  
  398.  $wp_customize->add_control(
  399.  'page-setting-21',
  400.  array(
  401.  'type' => 'dropdown-pages',
  402.  'label' => __( '21 featured page', 'radiate' ),
  403.  'section' => 'radiate_featured_section',
  404.  'priority' => 21)
  405.  );
  406.  
  407. $wp_customize->add_setting(
  408.  'page-setting-22',
  409.  array('sanitize_callback' => 'radiate_sanitize_integer')
  410.  );
  411.  
  412.  $wp_customize->add_control(
  413.  'page-setting-22',
  414.  array(
  415.  'type' => 'dropdown-pages',
  416.  'label' => __( '22 featured page', 'radiate' ),
  417.  'section' => 'radiate_featured_section',
  418.  'priority' => 22)
  419.  );
  420.  
  421. $wp_customize->add_setting(
  422.  'page-setting-23',
  423.  array('sanitize_callback' => 'radiate_sanitize_integer')
  424.  );
  425.  
  426.  $wp_customize->add_control(
  427.  'page-setting-23',
  428.  array(
  429.  'type' => 'dropdown-pages',
  430.  'label' => __( '23 featured page', 'radiate' ),
  431.  'section' => 'radiate_featured_section',
  432.  'priority' => 23)
  433.  );
  434.  
  435. $wp_customize->add_setting(
  436.  'page-setting-24',
  437.  array('sanitize_callback' => 'radiate_sanitize_integer')
  438.  );
  439.  
  440.  $wp_customize->add_control(
  441.  'page-setting-24',
  442.  array(
  443.  'type' => 'dropdown-pages',
  444.  'label' => __( '24 featured page', 'radiate' ),
  445.  'section' => 'radiate_featured_section',
  446.  'priority' => 24)
  447.  );
  448.  
  449.  
  450.     function radiate_sanitize_hex_color( $color ) {
  451.         if ( $unhashed = sanitize_hex_color_no_hash( $color ) )
  452.             return '#' . $unhashed;
  453.  
  454.         return $color;
  455.     }
  456.  
  457.     function radiate_sanitize_custom_css( $input) {
  458.         $input = wp_kses_stripslashes( $input);
  459.         return $input;
  460.     }  
  461.  
  462.     function radiate_sanitize_integer( $input ) {
  463.         if( is_numeric( $input ) ) {
  464.         return intval( $input );
  465.     }
  466.     }
  467.  
  468.     function radiate_sanitize_escaping( $input) {
  469.         $input = esc_attr( $input);
  470.         return $input;
  471.     }
  472.  
  473. }
  474. add_action( 'customize_register', 'radiate_register_theme_customizer' );
  475.  
  476.  
  477. function radiate_customizer_css() {
  478.     $primary_color =  get_theme_mod( 'radiate_color_scheme' );
  479.     if( $primary_color && $primary_color != '#632e9b') {
  480.         $customizer_css = '
  481.             blockquote { border-color: #EAEAEA #EAEAEA #EAEAEA '.$primary_color.'; }
  482.             a { color: '.$primary_color.'; }
  483.             .site-title a:hover { color: '.$primary_color.'; }
  484.             .main-navigation a:hover, .main-navigation ul li.current-menu-item a, .main-navigation ul li.current_page_ancestor a, .main-navigation ul li.current-menu-ancestor a, .main-navigation ul li.current_page_item a, .main-navigation ul li:hover > a { background-color: '.$primary_color.'; }
  485.             .main-navigation ul li ul li a:hover, .main-navigation ul li ul li:hover > a, .main-navigation ul li.current-menu-item ul li a:hover { background-color: '.$primary_color.'; }
  486.             #masthead .search-form { background-color: '.$primary_color.'; }
  487.             .header-search-icon:before { color: '.$primary_color.'; }
  488.             button, input[type="button"], input[type="reset"], input[type="submit"] {   background-color: '.$primary_color.'; }
  489.             #content .entry-title a:hover { color: '.$primary_color.'; }
  490.             .entry-meta span:hover { color: '.$primary_color.'; }
  491.             #content .entry-meta span a:hover { color: '.$primary_color.'; }
  492.             #content .comments-area article header cite a:hover, #content .comments-area a.comment-edit-link:hover, #content .comments-area a.comment-permalink:hover { color: '.$primary_color.'; }
  493.             .comments-area .comment-author-link a:hover { color: '.$primary_color.'; }
  494.             .comment .comment-reply-link:hover { color: '.$primary_color.'; }
  495.             .site-header .menu-toggle { color: '.$primary_color.'; }
  496.             .site-header .menu-toggle:hover { color: '.$primary_color.'; }
  497.             .main-small-navigation li:hover { background: '.$primary_color.'; }
  498.             .main-small-navigation ul > .current_page_item, .main-small-navigation ul > .current-menu-item { background: '.$primary_color.'; }
  499.             .main-small-navigation ul li ul li a:hover, .main-small-navigation ul li ul li:hover > a, .main-small-navigation ul li.current-menu-item ul li a:hover { background-color: '.$primary_color.'; }
  500.             #featured_pages a.more-link:hover { border-color:'.$primary_color.'; color:'.$primary_color.'; }
  501.             a#back-top:before { background-color:'.$primary_color.'; }';
  502.     ?>
  503.     <style type="text/css"><?php echo $customizer_css; ?></style>
  504.     <?php
  505.     }
  506.     ?>
  507.     <style type="text/css"><?php echo trim( get_theme_mod( 'radiate_custom_css' ) ); ?></style>
  508.     <?php
  509. }
  510. add_action( 'wp_head', 'radiate_customizer_css' );
  511. ?>
Advertisement
Add Comment
Please, Sign In to add comment