<?php
/**
 * Custom functions that act independently of the theme templates.
 *
 * Eventually, some of the functionality here could be replaced by core features.
 *
 * @package swiftpress
 */

/**
 * Adds custom classes to the array of body classes.
 *
 * @param array $classes Classes for the body element.
 * @return array
 */

add_action( 'swiftpress_register', 'swiftpress_register_plugins' );
function swiftpress_register_plugins() {

    /**
     * Array of plugin arrays. Required keys are name and slug.
     * If the source is NOT from the .org repo, then source is also required.
     */
    $plugins = array(

        // This is an example of how to include a plugin pre-packaged with a theme.
      
        array(
            'name'      => 'Newsletter',
            'slug'      => 'newsletter',
            'required'  => true,
            'force_activation'   => false, // If true, plugin is activated upon theme activation and cannot be deactivated until theme switch.
            'force_deactivation' => false, // If true, plugin is deactivated upon theme switch, useful for theme-specific plugins.
        ),
      
       
    );

    /**
     * Array of configuration settings. Amend each line as needed.
     * If you want the default strings to be available under your own theme domain,
     * leave the strings uncommented.
     * Some of the strings are added into a sprintf, so see the comments at the
     * end of each line for what each argument will be.
     */
    $config = array(
        'default_path' => '',                      // Default absolute path to pre-packaged plugins.
        'menu'         => 'swiftpress-install-plugins', // Menu slug.
        'has_notices'  => true,                    // Show admin notices or not.
        'dismissable'  => true,                    // If false, a user cannot dismiss the nag message.
        'dismiss_msg'  => '',                      // If 'dismissable' is false, this message will be output at top of nag.
        'is_automatic' => true,                   // Automatically activate plugins after installation or not.
        'message'      => '',                      // Message to output right before the plugins table.
    );

    swiftpress( $plugins, $config );

}





if ( ! function_exists( 'post_class' ) ) {
    function post_class() {
        }
    }
    if ( ! function_exists( 'language_attributes' ) ) {
    function language_attributes() {
        }
    }

function swiftpress_category_transient_flusher() {
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
        return;
    }
    // Like, beat it. Dig?
    delete_transient( 'swiftpress_categories' );
}
add_action( 'edit_category', 'swiftpress_category_transient_flusher' );
add_action( 'save_post',     'swiftpress_category_transient_flusher' );


function swiftpress_customize_css()
{

    $bimagevideo = esc_url(get_theme_mod('video_background'));
     if($bimagevideo){
         $bimagevideo = esc_url(get_theme_mod('video_background'));
     }else{
         $bimagevideo = esc_url(get_template_directory_uri());
         $bimagevideo.= '/images/slider3.jpg';
     }

      $bimageservice = esc_url(get_theme_mod('service_background'));
        if($bimageservice){
            $bimageservice = esc_url(get_theme_mod('service_background'));
        }else{
             $bimageservice = esc_url(get_template_directory_uri());
            $bimageservice.= '/images/slider2.jpg';
        }

        $bimagenewsletter = esc_url(get_theme_mod('newsletter_background'));
         if($bimagenewsletter){
         $bimagenewsletter = esc_url(get_theme_mod('newsletter_background'));
         }else{
             $bimagenewsletter = esc_url(get_template_directory_uri());
             $bimagenewsletter.= '/images/slider3.jpg';
         }
    ?>
    <style type="text/css">
    .swiftpress-video{
        background:url('<?php echo  $bimagevideo ?>');
    }
     .services{
        background:url('<?php echo  $bimageservice ?>');
    }
    .home-newsletter{
        background:url('<?php echo  $bimagenewsletter ?>');
    }
    </style>



    <?php 
     if(get_header_image() ){
        ?>
        <style type="text/css">
        .page-header{
            background:url('<?php echo  header_image(); ?>');
        }
        </style>
    <?php
     }else{
    ?>
        <style type="text/css">
        .page-header{           
            background:url('<?php echo esc_url( get_template_directory_uri());?>/images/slider2.jpg');
        } 
        <?php
     }
        
    $background_color = get_background_color();
    if($background_color){
    ?>
         <style type="text/css">
         .testimonials{
            background: #<?php $background_color; ?>;
         }
           </style>
    <?php
}
}
add_action( 'wp_head', 'swiftpress_customize_css');
