| 1 |
<?php |
| 2 |
|
| 3 |
namespace Bookit\Classes; |
| 4 |
|
| 5 |
use Bookit\Classes\Admin\SettingsController; |
| 6 |
|
| 7 |
class Customization { |
| 8 |
|
| 9 |
/** |
| 10 |
* Init Customization |
| 11 |
*/ |
| 12 |
public static function init() { |
| 13 |
add_action( 'bookit_before_update_setting', array( self::class, 'custom_colors' ), 100, 1 ); |
| 14 |
} |
| 15 |
|
| 16 |
/** |
| 17 |
* Generate Styles with Custom Colors |
| 18 |
* |
| 19 |
* @param array $settings |
| 20 |
*/ |
| 21 |
public static function custom_colors( $settings, $force = false ) { |
| 22 |
if ( 'true' == $settings['custom_colors_enabled'] ) { |
| 23 |
$old_settings = SettingsController::get_settings(); |
| 24 |
$old_colors = $old_settings['custom_colors']; |
| 25 |
$new_colors = $settings['custom_colors']; |
| 26 |
|
| 27 |
if ( ( $old_colors != $new_colors ) || true == $force ) { |
| 28 |
global $wp_filesystem; |
| 29 |
|
| 30 |
if ( empty( $wp_filesystem ) ) { |
| 31 |
require_once ABSPATH . '/wp-admin/includes/file.php'; |
| 32 |
WP_Filesystem(); |
| 33 |
} |
| 34 |
|
| 35 |
$upload = wp_upload_dir(); |
| 36 |
$upload_dir = $upload['basedir'] . '/bookit'; |
| 37 |
$styles = BOOKIT_PATH . '/assets/dist/frontend/css/app.css'; |
| 38 |
|
| 39 |
if ( ! $wp_filesystem->is_dir( $upload_dir ) ) { |
| 40 |
wp_mkdir_p( $upload_dir ); |
| 41 |
} |
| 42 |
|
| 43 |
if ( file_exists( $styles ) ) { |
| 44 |
$new_colors[] = BOOKIT_URL . 'assets/dist/'; |
| 45 |
$original_colors = array( |
| 46 |
'#066', |
| 47 |
'#f0f8f8', |
| 48 |
'#ffd400', |
| 49 |
'#fff', |
| 50 |
'#272727', |
| 51 |
'../../', |
| 52 |
); |
| 53 |
|
| 54 |
$css = str_replace( $original_colors, $new_colors, file_get_contents( $styles ) ); |
| 55 |
$wp_filesystem->put_contents( $upload_dir . '/app.css', $css, FS_CHMOD_FILE ); |
| 56 |
|
| 57 |
$version = intval( get_option( 'bookit_styles_version', 1 ) ) + 1; |
| 58 |
update_option( 'bookit_styles_version', $version ); |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
|