options = array( 'settings' => array(), 'sections' => array(), 'panels' => array(), ); } /** * Add customizer info buttons to infobuttons Array * * @since 2.0.0 * @access public * @return void */ public function add_infobuttons( $infobuttons = array() ) { $add_buttons = apply_filters( "hoot_customizer_add_infobuttons" , $infobuttons ); if ( is_array( $infobuttons ) && !empty( $infobuttons ) ) { $this->infobuttons = array_merge( $this->infobuttons, $add_buttons ); } } /** * Remove customizer info buttons from infobuttons Array * * @since 2.0.0 * @access public * @return void */ public function remove_infobuttons( $key ) { if ( is_array( $key ) ) { foreach ( $key as $singlekey ) { if ( isset( $this->infobuttons[$singlekey] ) ) unset( $this->infobuttons[$singlekey] ); } } elseif ( isset( $this->infobuttons[$key] ) ) { unset( $this->infobuttons[$key] ); } } /** * Get infobuttons Array * * @since 2.0.0 * @access public * @return array */ public function get_infobuttons() { return $this->infobuttons; } /** * Add customizer option to Options Array * * @since 2.0.0 * @access public * @return void */ public function add_options( $options = array() ) { foreach ( array( 'settings', 'sections', 'panels' ) as $key ) { if ( isset( $options[ $key ] ) && is_array( $options[ $key ] ) && !empty( $options[ $key ] ) ) { $add_options = $options[ $key ]; $add_options = apply_filters( "hoot_customizer_add_{$key}" , $add_options ); if ( is_array( $add_options ) && !empty( $add_options ) ) $this->options[ $key ] = array_merge( $this->options[ $key ], $add_options ); } } } /** * Remove customizer settings from Options Array Settings * * @since 2.0.0 * @access public * @return void */ public function remove_settings( $key ) { if ( is_array( $key ) ) { foreach ( $key as $singlekey ) { if ( isset( $this->options['settings'][$singlekey] ) ) unset( $this->options['settings'][$singlekey] ); } } elseif ( isset( $this->options['settings'][$key] ) ) { unset( $this->options['settings'][$key] ); } } /** * Edit customizer settings from Options Array Settings * * Avoid using 'recursive' merge as array_replace_recursive is only available in PHP5.3 * and unfortunately we still have a lot of users on the legac PHP versions * * @since 2.0.0 * @access public * @return void */ public function edit_settings( $new_options, $merge = 'merge' ) { if ( is_array( $new_options ) ) { $new_options = apply_filters( "hoot_customizer_add_settings" , $new_options ); if ( is_array( $new_options ) ) { foreach ( $new_options as $key => $value ) { if ( isset( $this->options['settings'][$key] ) ) // 'array_replace_recursive' overwrites numeric keys as well. Hence take necessary // steps in sub-arrays without keys (example betterbackground['options']) // Possible solution: // betterbackground['options']=array('color','','','','',''); if ( $merge == 'replace' || $merge == 'recursive' ) $this->options['settings'][$key] = array_replace_recursive( $this->options['settings'][$key], $value ); else $this->options['settings'][$key] = array_merge( $this->options['settings'][$key], $value ); } } } } /** * Edit customizer sections from Options Array Sections * * Avoid using 'recursive' merge as array_replace_recursive is only available in PHP5.3 * and unfortunately we still have a lot of users on the legac PHP versions * * @since 2.0.0 * @access public * @return void */ public function edit_sections( $new_options, $merge = 'merge' ) { if ( is_array( $new_options ) ) { $new_options = apply_filters( "hoot_customizer_add_sections" , $new_options ); if ( is_array( $new_options ) ) { foreach ( $new_options as $key => $value ) { if ( isset( $this->options['sections'][$key] ) ) // 'array_replace_recursive' overwrites numeric keys as well. Hence take necessary // steps if merge data contains sub-arrays without keys (example betterbackground['options']) // Possible solution: // betterbackground['options']=array('color','','','','',''); if ( $merge == 'replace' || $merge == 'recursive' ) $this->options['sections'][$key] = array_replace_recursive( $this->options['sections'][$key], $value ); else $this->options['sections'][$key] = array_merge( $this->options['sections'][$key], $value ); } } } } /** * Edit customizer panels from Options Array Panels * * Avoid using 'recursive' merge as array_replace_recursive is only available in PHP5.3 * and unfortunately we still have a lot of users on the legac PHP versions * * @since 2.0.0 * @access public * @return void */ public function edit_panels( $new_options, $merge = 'merge' ) { if ( is_array( $new_options ) ) { $new_options = apply_filters( "hoot_customizer_add_panels" , $new_options ); if ( is_array( $new_options ) ) { foreach ( $new_options as $key => $value ) { if ( isset( $this->options['panels'][$key] ) ) // 'array_replace_recursive' overwrites numeric keys as well. Hence take necessary // steps in sub-arrays without keys (example betterbackground['options']) // Possible solution: // betterbackground['options']=array('color','','','','',''); if ( $merge == 'replace' || $merge == 'recursive' ) $this->options['panels'][$key] = array_replace_recursive( $this->options['panels'][$key], $value ); else $this->options['panels'][$key] = array_merge( $this->options['panels'][$key], $value ); } } } } /** * Get Options Array * * @since 2.0.0 * @access public * @param string $return Select which option array to return, or to return whole array * @return array */ public function get_options( $return = '' ) { switch( $return ) { case 'settings': if ( !empty( $this->options['settings'] ) ) return $this->options['settings']; else return array(); break; case 'sections': if ( !empty( $this->options['sections'] ) ) return $this->options['sections']; else return array(); break; case 'panels': if ( !empty( $this->options['panels'] ) ) return $this->options['panels']; else return array(); break; } return $this->options; } /** * Instantiate or return the one Hoot_Customizer instance. * * @since 2.0.0 * @access public * @return Hoot_Customizer */ public static function get_instance() { if ( is_null( self::$instance ) ) { self::$instance = new self(); } return self::$instance; } } /** Allow to include functions and files **/ do_action( 'hoot_customizer_loaded' );