<?php
/*
Plugin Name: UX Shop Extensions by Develoved
Plugin URI: themes.develoved.com
Description: This plugin holds extensions for the UX Shop theme by Develoved.
Version: 1.2.3
Author: develoved
Author URI: themes.develoved.com
Text Domain: dvl-uxshop-extensions
*/

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Load plugin textdomain.
 */
function shrk_uxshop_extensions_load_textdomain() {
	load_plugin_textdomain( 'dvl-uxshop-extensions', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); 
}
add_action( 'init', 'shrk_uxshop_extensions_load_textdomain' );


function shrk_dvl_ext_redux_extension_loader($ReduxFramework) {
	$path    = plugin_dir_path( __FILE__ ) . 'ReduxExtensions/';
	$folders = scandir( $path, 1 );		   
	foreach($folders as $folder) {
		if ($folder === '.' or $folder === '..' or !is_dir($path . $folder) ) {
			continue;	
		} 
		$extension_class = 'ReduxFramework_Extension_' . $folder;
		if( !class_exists( $extension_class ) ) {
			// In case you wanted override your override, hah.
			$class_file = $path . $folder . '/extension_' . $folder . '.php';
			$class_file = apply_filters( 'redux/extension/'.$ReduxFramework->args['opt_name'].'/'.$folder, $class_file );
			if( $class_file ) {
				require_once( $class_file );
				$extension = new $extension_class( $ReduxFramework );
			}
		}
	}
}
add_action( 'redux/extensions/shrk_theme_options/before', 'shrk_dvl_ext_redux_extension_loader', 0);

/**
 * Set Importer help text
 *
 */
function shrk_redux_importer_description( $text ) {
	return esc_html__( 'Works best to import on a new install of WordPress.', 'dvl-uxshop-extensions' ) . '<br>' . esc_html__( 'Before importing demo content make sure you have installed and activated all the required plugins, and any of the recommended you are planning to use.', 'dvl-uxshop-extensions' );
}
add_filter( 'wbc_importer_description', 'shrk_redux_importer_description' );

/**
 * Set Importer Demo names
 *
 */
function shrk_redux_importer_demo_names( $directory ) {
	switch ( $directory ) {
		case 'demo1':
			$demo_name = esc_html__( 'Shoes demo', 'dvl-uxshop-extensions' );
			break;
		case 'demo2':
			$demo_name = esc_html__( 'Fashion demo', 'dvl-uxshop-extensions' );
			break;
		case 'demo3':
			$demo_name = esc_html__( 'Furniture demo', 'dvl-uxshop-extensions' );
			break;
		case 'demo4':
			$demo_name = esc_html__( 'Bikes demo', 'dvl-uxshop-extensions' );
			break;
		default:
			$demo_name = $directory;
			break;
	}

	return $demo_name;
}
add_filter( 'wbc_importer_directory_title', 'shrk_redux_importer_demo_names' );

/**
 * Get the slug of the given demo_active_import
 * 
 */
function shrk_redux_importer_get_demo( $demo_active_import ) {
	if ( !empty( $demo_active_import ) &&  is_array( $demo_active_import ) ) {

		$import = reset( $demo_active_import );
		$import_dir = !empty( $import['directory'] ) ? $import['directory'] : null;

		switch ( $import_dir ) {
			case 'demo1':
				return 'shoes';
			break;
			case 'demo2':
				return 'fashion';
			break;
			case 'demo3':
				return 'furniture';
			break;
			case 'demo4':
				return 'bikes';
			break;
			
			default:
				return false;
			break;
		}
	} else {
		return false;
	}
}