get_setting( 'blogname' )->transport = 'postMessage'; $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; $wp_customize->selective_refresh->add_partial( 'blogname', array( 'selector' => '.site-title a', 'render_callback' => 'aspace_customize_partial_blogname', ) ); $wp_customize->selective_refresh->add_partial( 'blogdescription', array( 'selector' => '.site-description', 'render_callback' => 'aspace_customize_partial_blogdescription', ) ); /** * Theme options. */ $wp_customize->add_section ( 'aspace_section_basic', // $id array( // $args 'priority' => 10, 'title' => __( 'Basic Settings', 'aspace' ), 'description' => __( 'Here you will set your site-wide preferences.', 'aspace' ), //'panel' => 'aspace_panel_basic' ) ); $wp_customize->add_section( 'theme_options', array( 'title' => esc_html__( 'Theme Options', 'aspace' ), 'priority' => 130, // Before Additional CSS. ) ); $wp_customize->add_section( 'footer_custom', array( 'title' => __( 'Footer', 'aspace' ), 'priority' => 105, // Before Widgets. ) ); $wp_customize->add_section( 'topbar_custom', array( 'title' => __( 'Topbar', 'aspace' ), 'priority' => 96, // Before Widgets. ) ); /** * Nav Menu and Logo Options */ $wp_customize->add_setting ( 'site_wide_design', // $id array( // $args 'default' => 'container-fluid', 'type' => 'theme_mod', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'aspace_sanitize_select', ) ); $wp_customize->add_setting ( 'footer_author_image', // $id array( // $args 'default' => '', 'type' => 'theme_mod', 'capability' => 'edit_theme_options', 'sanitize_callback' => '', ) ); $wp_customize->add_setting ( 'text_button_topbar', // $id array( // $args 'default' => '', 'type' => 'theme_mod', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'wp_filter_nohtml_kses', ) ); $wp_customize->add_setting ( 'text_engageuserfoo', // $id array( // $args 'default' => '', 'type' => 'theme_mod', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'wp_filter_nohtml_kses', ) ); $wp_customize->add_setting ( 'text_instagramfoo_button', // $id array( // $args 'default' => '', 'type' => 'theme_mod', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'wp_filter_nohtml_kses', ) ); $wp_customize->add_setting ( 'text_by_wordpress', // $id array( // $args 'default' => '', 'type' => 'theme_mod', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'wp_filter_nohtml_kses', ) ); $wp_customize->add_setting ( 'link_by_wordpress', // $id array( // $args 'default' => '', 'type' => 'theme_mod', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'wp_filter_nohtml_kses', ) ); $wp_customize->add_setting ( 'subscribe_form_text', // $id array( // $args 'default' => 'Subscribe NOW', 'type' => 'theme_mod', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'wp_filter_nohtml_kses', ) ); $wp_customize->add_setting ( 'subscribe_form_input', // $id array( // $args 'default' => 'Enter your E-mail', 'type' => 'theme_mod', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'wp_filter_nohtml_kses', ) ); $wp_customize->add_control ( 'site_wide_design', // $id array( // $args 'settings' => 'site_wide_design', 'section' => 'aspace_section_basic', 'type' => 'select', 'label' => __( 'Design Layout', 'aspace' ), 'description' => __( 'Choose a default page layout for your pages: Fullwidth or Boxed.', 'aspace' ), 'choices' => array( 'container-fluid' => __( 'Full width (default)', 'aspace' ), 'container' => __( 'Boxed', 'aspace' ), ) ) ); $wp_customize->add_control( new WP_Customize_Media_Control( $wp_customize, 'footer_author_image', array( 'label' => __( 'Footer author Image', 'aspace' ), 'settings' => 'footer_author_image', 'section' => 'footer_custom', 'mime_type' => 'image', ) ) ); $wp_customize->add_control( 'text_button_topbar', // $id array( 'label' => __( 'Topbar text button', 'aspace' ), 'settings' => 'text_button_topbar', 'section' => 'topbar_custom', 'type' => 'text', ) ); $wp_customize->add_control( 'text_engageuserfoo', // $id array( 'label' => __( 'Text engage users', 'aspace' ), 'settings' => 'text_engageuserfoo', 'section' => 'footer_custom', 'type' => 'text', ) ); $wp_customize->add_control( 'text_instagramfoo_button', // $id array( 'label' => __( 'Text footer follow instagram', 'aspace' ), 'settings' => 'text_instagramfoo_button', 'section' => 'footer_custom', 'type' => 'text', ) ); $wp_customize->add_control( 'text_by_wordpress', // $id array( 'label' => __( 'Proudly powered by WordPress Text', 'aspace' ), 'settings' => 'text_by_wordpress', 'section' => 'footer_custom', 'type' => 'textarea', ) ); $wp_customize->add_control( 'link_by_wordpress', // $id array( 'label' => __( 'Link of the copyright footer text', 'aspace' ), 'settings' => 'link_by_wordpress', 'section' => 'footer_custom', 'type' => 'textarea', ) ); $wp_customize->add_control( 'subscribe_form_text', // $id array( 'label' => __( 'SUBSCRIB NOW', 'aspace' ), 'settings' => 'subscribe_form_text', 'section' => 'footer_custom', 'type' => 'texT', ) ); $wp_customize->add_control( 'subscribe_form_input', // $id array( 'label' => __( 'Enter your E-mail', 'aspace' ), 'settings' => 'subscribe_form_input', 'section' => 'footer_custom', 'type' => 'texT', ) ); } add_action( 'customize_register', 'aspace_customize_register' ); /** * Saving the archive theme mods to the pages so we can easily get it from checking the page rather than looping over all theme mods and checking against page */ //runs before theme mods are saved. Remove the page archive fields from before. add_action('customize_save', 'add_aspace_design', 100); function add_aspace_design(){ if(is_customize_preview()){ $aspacepress_post_types = get_post_types( array('_builtin' => false, 'has_archive' => true), 'objects' ); $aspacepress_post_types[] = get_post_type_object( 'post' ); foreach ($aspacepress_post_types as $post_type) { //delete old field from old page $archive_theme_mod = get_theme_mod('ign_archive_' . $post_type->name); if($archive_theme_mod){ delete_post_meta($archive_theme_mod, '_ign_archive_page'); } } } } add_action('customize_save_after', 'save_aspace_design', 100); function save_aspace_design(){ if(is_customize_preview()){ $aspacepress_post_types = get_post_types( array('_builtin' => false, 'has_archive' => true), 'objects' ); $aspacepress_post_types[] = get_post_type_object( 'post' ); foreach ($aspacepress_post_types as $post_type) { //save to each page a hidden custom field. $archive_theme_mod = get_theme_mod('ign_archive_' . $post_type->name); if($archive_theme_mod){ update_post_meta($archive_theme_mod, '_ign_archive_page', $post_type->name); } } } } /** * Render the site title for the selective refresh partial. * * @since aspace 1.0 * @see aspace_customize_register() * * @return void */ function aspace_customize_partial_blogname() { bloginfo( 'name' ); } /** * Render the site tagline for the selective refresh partial. * * @since aspace 1.0 * @see aspace_customize_register() * * @return void */ function aspace_customize_partial_blogdescription() { bloginfo( 'description' ); } //file input sanitization function function aspace_sanitize_file( $file, $setting ) { //allowed file types $mimes = array( 'jpg|jpeg|jpe' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png' ); //check file type from file name $file_ext = wp_check_filetype( $file, $mimes ); //if file has a valid mime type return it, otherwise return default return ( $file_ext['ext'] ? $file : $setting->default ); } function aspace_sanitize_select( $input, $setting ) { // Ensure input is a slug. $input = sanitize_key( $input ); // Get list of choices from the control associated with the setting. $choices = $setting->manager->get_control( $setting->id )->choices; // If the input is a valid key, return it; otherwise, return the default. return ( array_key_exists( $input, $choices ) ? $input : $setting->default ); } /** * Widget sanitization callback. * * @param string $value * @return string */ function aspace_sanitize_widget_area( $value ) { if ( !in_array( $value, array( 'enable', 'disable' ) ) ) { $value = 'disable'; } return $value; } /** * Checkbox sanitization callback. * * Sanitization callback for 'checkbox' type controls. This callback sanitizes `$checked` * as a boolean value, either TRUE or FALSE. * * @param bool $checked Whether the checkbox is checked. * @return bool Whether the checkbox is checked. */ function aspace_sanitize_checkbox( $checked ) { // Boolean check. return ( ( isset( $checked ) && true == $checked ) ? true : false ); } /** * HTML sanitization callback. * * - Sanitization: html * - Control: text, textarea * * Sanitization callback for 'html' type text inputs. This callback sanitizes `$html` * for HTML allowable in posts. * * * @see wp_filter_post_kses() https://developer.wordpress.org/reference/functions/wp_filter_post_kses/ * * @param string $html HTML to sanitize. * @return string Sanitized HTML. */ function aspace_sanitize_html( $html ) { return wp_filter_post_kses( $html ); } /** * URL sanitization callback. * * - Sanitization: url * - Control: text, url * * Sanitization callback for 'url' type text inputs. This callback sanitizes `$url` as a valid URL. * * NOTE: esc_url_raw() can be passed directly as `$wp_customize->add_setting()` 'sanitize_callback'. * It is wrapped in a callback here merely for example purposes. * * @see esc_url_raw() https://developer.wordpress.org/reference/functions/esc_url_raw/ * * @param string $url URL to sanitize. * @return string Sanitized URL. */ function aspace_sanitize_url( $url ) { return esc_url_raw( $url ); } /** * Bind JS handlers to instantly live-preview changes. */ /* function aspace_customize_preview_js() { wp_enqueue_script( 'aspace-customize-preview', get_theme_file_uri( '/assets/js/customize-preview.js' ), array('jquery', 'customize-preview'), '1.0', true ); } add_action( 'customize_preview_init', 'aspace_customize_preview_js' ); */ /** * Load dynamic logic for the customizer controls area. */ function aspace_panels_js() { wp_enqueue_script( 'aspace-customize-controls', get_theme_file_uri( '/assets/js/customize-controls.js' ), array(), '1.0', true ); } //add_action( 'customize_controls_enqueue_scripts', 'aspace_panels_js' );