font_1 = $main_font; } $second_font = get_theme_mod('apadana_option_second_font'); if (!empty($second_font)) { $this->font_2 = $second_font; } $third_font = get_theme_mod('apadana_option_third_font'); if (!empty($third_font)) { $this->font_3 = $third_font; } $theme_main_color = get_theme_mod('apadana_option_main_color'); if (!empty($theme_main_color)) { $this->main_color = $theme_main_color; } } public function add_style() { $custom_style = ':root {'; if ($this->font_1 !== 'Open Sans') { $custom_style .= '--apadana-font-1: "' . $this->font_1 . '", Arial, Helvetica, sans-serif;'; } if ($this->font_2 !== 'Playfair Display') { $custom_style .= '--apadana-font-2: "' . $this->font_2 . '", Arial, Helvetica, sans-serif;'; } if ($this->font_3 !== 'Great Vibes') { $custom_style .= '--apadana-font-3: "' . $this->font_3 . '", Arial, Helvetica, sans-serif;'; } if (!empty($this->main_color)) { $rgb_main_color = $this->hex2rgb($this->main_color); $custom_style .= '--apadana-color-3: ' . esc_html($this->main_color) . ';--apadana-color-3-rgb: ' . esc_html($rgb_main_color) . ';'; } $custom_style .= '}'; if (!empty($custom_style)) { wp_add_inline_style('apadana-main-style-file', $custom_style); } } public function add_google_font() { wp_enqueue_style('google-fonts', $this->google_font_url(), array(), '1.0.0'); } /* Enqueue scripts and styles. */ public function google_font_url() { $font_url = ''; /* Translators: If there are characters in your language that are not supported by chosen font(s), translate this to 'off'. Do not translate into your own language. */ if ('off' !== _x('on', 'Google font: on or off', 'apadana')) { $font_url = add_query_arg('family', urlencode($this->font_1 . ':400,700,400italic,700italic|' . $this->font_2 . ':400,700|' . $this->font_3), "https://fonts.googleapis.com/css"); } return $font_url; } function hex2rgb($hex) { $hex = str_replace("#", "", $hex); if (strlen($hex) == 3) { $r = hexdec(substr($hex, 0, 1) . substr($hex, 0, 1)); $g = hexdec(substr($hex, 1, 1) . substr($hex, 1, 1)); $b = hexdec(substr($hex, 2, 1) . substr($hex, 2, 1)); } else { $r = hexdec(substr($hex, 0, 2)); $g = hexdec(substr($hex, 2, 2)); $b = hexdec(substr($hex, 4, 2)); } $rgb = array($r, $g, $b); return implode(",", $rgb); // returns the rgb values separated by commas // return $rgb; // returns an array with the rgb values } }