예제 #1
0
 function wm_generate_main_css($args = array())
 {
     //Requirements check
     if (!function_exists('wma_amplifier')) {
         return false;
     }
     //Helper viariables
     $args = wp_parse_args($args, apply_filters('wmhook_wm_generate_main_css_args', array('gzip' => false, 'message' => __("<big>The main theme CSS stylesheet was regenerated.<br /><strong>Please refresh your web browser's and server's cache</strong> <em>(if you are using a website server caching solution)</em>.</big>", 'wm_domain'), 'message_after' => '', 'message_before' => '', 'type' => '')));
     $output = $output_min = '';
     if (!$args['gzip']) {
         $args['gzip'] = wm_option('general-gzip') || wm_option('skin-gzip');
     }
     $args['gzip'] = apply_filters('wmhook_wm_generate_main_css_gzip', $args['gzip'], $args);
     $args['type'] = trim($args['type']);
     //Preparing output
     //Get the file content with output buffering
     if ($args['gzip']) {
         //GZIP enabled
         ob_start('ob_gzhandler');
     } else {
         //no GZIP
         ob_start();
     }
     //Get the file from child theme if exists
     $css_dir_child = get_stylesheet_directory() . '/assets/css/';
     $css_generator_file = '_generate' . $args['type'] . '-css.php';
     if (file_exists($css_dir_child . $css_generator_file)) {
         $css_generator_file_check = $css_dir_child . $css_generator_file;
     } else {
         $css_generator_file_check = get_template_directory() . '/assets/css/' . $css_generator_file;
     }
     if (file_exists($css_generator_file_check)) {
         locate_template('assets/css/' . $css_generator_file, true);
     }
     $output = ob_get_clean();
     if (!$output) {
         return false;
     }
     //Minify output if set
     $output_min = apply_filters('wmhook_wm_generate_main_css_output_min', $output, $args);
     //Output
     //Create the theme CSS folder
     $wp_upload_dir = wp_upload_dir();
     $theme_css_url = trailingslashit($wp_upload_dir['baseurl']) . 'wmtheme-' . WM_THEME_SHORTNAME;
     $theme_css_dir = trailingslashit($wp_upload_dir['basedir']) . 'wmtheme-' . WM_THEME_SHORTNAME;
     if (!wma_create_folder($theme_css_dir)) {
         set_transient('wmamp-admin-notice', array("<strong>ERROR: Wasn't able to create a theme CSS folder! Contact the theme support.</strong>", 'error', 'switch_themes', 2), 60 * 60 * 48);
         delete_option(WM_THEME_SETTINGS_PREFIX . WM_THEME_SHORTNAME . $args['type'] . '-css');
         delete_option(WM_THEME_SETTINGS_PREFIX . WM_THEME_SHORTNAME . $args['type'] . '-files');
         return false;
     }
     $css_file_name = apply_filters('wmhook_wm_generate_main_css_css_file_name', 'global' . $args['type'], $args);
     $global_css_path = apply_filters('wmhook_wm_generate_main_css_global_css_path', trailingslashit($theme_css_dir) . $css_file_name . '.css', $args, $css_file_name);
     $global_css_url = apply_filters('wmhook_wm_generate_main_css_global_css_url', trailingslashit($theme_css_url) . $css_file_name . '.css', $args, $css_file_name);
     $global_css_path_dev = apply_filters('wmhook_wm_generate_main_css_global_css_path_dev', trailingslashit($theme_css_dir) . $css_file_name . '.dev.css', $args, $css_file_name);
     if ($output) {
         wma_write_local_file($global_css_path, $output_min);
         wma_write_local_file($global_css_path_dev, $output);
         //Store the CSS files paths and urls in DB
         update_option(WM_THEME_SETTINGS_PREFIX . WM_THEME_SHORTNAME . $args['type'] . '-css', $global_css_url);
         update_option(WM_THEME_SETTINGS_PREFIX . WM_THEME_SHORTNAME . '-files', str_replace($wp_upload_dir['basedir'], '', $theme_css_dir));
         //Admin notice
         set_transient('wmamp-admin-notice', array($args['message_before'] . $args['message'] . $args['message_after'], '', 'switch_themes'), 60 * 60 * 24);
         //Run custom actions
         do_action('wmhook_wm_generate_main_css', $args);
         return true;
     }
     delete_option(WM_THEME_SETTINGS_PREFIX . WM_THEME_SHORTNAME . $args['type'] . '-css');
     delete_option(WM_THEME_SETTINGS_PREFIX . WM_THEME_SHORTNAME . $args['type'] . '-files');
     return false;
 }
예제 #2
0
 function wm_save_skin($value = array(), $old_value = array())
 {
     //Requirements check
     if (empty($value) && !is_array($value)) {
         return $value;
     }
     //Helper variables
     $skin_new = $skin_load = '';
     $wp_upload_dir = wp_upload_dir();
     $theme_skin_dir = apply_filters('wmhook_wm_save_skin_theme_skin_dir', trailingslashit($wp_upload_dir['basedir']) . 'wmtheme-' . WM_THEME_SHORTNAME . '/skins');
     //Preparing output
     //Set a new skin file name
     //New skin
     if (isset($value[WM_THEME_SETTINGS_PREFIX . 'skin-new'])) {
         $skin_new = trim(sanitize_title($value[WM_THEME_SETTINGS_PREFIX . 'skin-new']));
         unset($value[WM_THEME_SETTINGS_PREFIX . 'skin-new']);
     }
     //Load skin
     if (isset($value[WM_THEME_SETTINGS_PREFIX . 'skin-load'])) {
         $skin_load = trim($value[WM_THEME_SETTINGS_PREFIX . 'skin-load']);
         if ($pos = strpos($skin_load, trailingslashit(WM_SETUP_DIR) . 'skins')) {
             $skin_load = substr($skin_load, $pos, -4);
             if (is_child_theme()) {
                 $skin_load = trailingslashit(get_stylesheet_directory()) . $skin_load;
             } else {
                 $skin_load = trailingslashit(get_template_directory()) . $skin_load;
             }
             $skin_load .= 'json';
         }
         unset($value[WM_THEME_SETTINGS_PREFIX . 'skin-load']);
     }
     //Create a new skin
     if ($skin_new) {
         //Create the theme skins folder
         if (!wma_create_folder($theme_skin_dir)) {
             set_transient('wmamp-admin-notice', array("<strong>ERROR: Wasn't able to create a theme skins folder! Contact the theme support.</strong>", 'error', 'switch_themes', 2), 60 * 60 * 48);
             delete_option(WM_THEME_SETTINGS_PREFIX . WM_THEME_SHORTNAME . '-skins');
         }
         //Write the skin JSON file
         $json_path = apply_filters('wmhook_wm_save_skin_json_path', trailingslashit($theme_skin_dir) . $skin_new . '.json');
         $value = apply_filters('wmhook_wm_save_skin_output', $value);
         if (wma_write_local_file($json_path, json_encode($value))) {
             update_option(WM_THEME_SETTINGS_PREFIX . WM_THEME_SHORTNAME . '-skins', array_unique(array(WM_SKINS, WM_SKINS_CHILD, $theme_skin_dir)));
         } else {
             delete_option(WM_THEME_SETTINGS_PREFIX . WM_THEME_SHORTNAME . '-skins');
         }
         //Run additional actions
         do_action('wmhook_save_skin', $skin_new, $value, $old_value);
         //Load a selected skin
     } elseif ($skin_load && file_exists($skin_load)) {
         //Get the skin slug
         $skin_slug = str_replace(array('.json', WM_SKINS, WM_SKINS_CHILD, $theme_skin_dir), '', $skin_load);
         //We don't need to write to the file, so just open for reading.
         $skin_load = wma_read_local_file($skin_load);
         $replacements = (array) apply_filters('wmhook_generate_css_replacements', array());
         $skin_load = strtr($skin_load, $replacements);
         //Decoding new imported skin JSON string and converting object to array
         if (!empty($skin_load)) {
             $value = json_decode(trim($skin_load), true);
             update_option(WM_THEME_SETTINGS_PREFIX . WM_THEME_SHORTNAME . '-skin-used', $skin_slug);
         }
         //Run additional actions
         do_action('wmhook_load_skin', $skin_load, $value, $old_value);
     }
     //Output
     return $value;
 }