'', 'slug' => '', 'primary' => '#ffffff', 'secondary' => '#000000', 'tertiary' => '#ff0000', 'section' => 'default', ) ); /** * Sanatize inputs. */ $forbidden_slugs = array( 'custom' ); if ( in_array( $args['slug'], $forbidden_slugs ) ) { wp_die( 'The color slug selected is forbidden' ); } $this->primary_color = sanitize_hex_color( $args['primary'] ); $this->secondary_color = sanitize_hex_color( $args['secondary'] ); $this->tertiary_color = sanitize_hex_color( $args['tertiary'] ); $this->name = esc_html( $args['name'] ); $this->slug = esc_attr( $args['slug'] ); $this->section = esc_attr( $args['section'] ); } /** * Get the primary color * * @return string The primary color */ public function get_primary_color() { return $this->primary_color; } /** * Get the secondary color * * @return string The secondary color */ public function get_secondary_color() { return $this->secondary_color; } /** * Get the tertiary color * * @return string The tertiary color */ public function get_tertiary_color() { return $this->tertiary_color; } /** * Get the color scheme name * * @return string The color scheme name */ public function get_name() { return $this->name; } /** * Get the color scheme slug * * @return string The color scheme slug */ public function get_slug() { return $this->slug; } /** * Get the CSS of the color scheme * * @param string $prefix The desired css prefix. * @return string The color scheme css. */ public function get_css( $prefix = null ) { $css = $this->generate_css_color_scheme( $prefix ); return $css; } /** * Generate the css needed to display the color scheme * * @param string $prefix The desired css prefix. * @return string The generated CSS */ private function generate_css_color_scheme( $prefix = null ) { ob_start(); $this->generate_wp_color_syntax( $prefix, 'primary', $this->get_primary_color() ); $this->generate_wp_color_syntax( $prefix, 'secondary', $this->get_secondary_color() ); $this->generate_wp_color_syntax( $prefix, 'tertiary', $this->get_tertiary_color() ); $this->generate_color_syntax( $prefix, 'primary', $this->get_primary_color() ); $this->generate_color_syntax( $prefix, 'secondary', $this->get_secondary_color() ); $this->generate_color_syntax( $prefix, 'tertiary', $this->get_tertiary_color() ); $this->generate_custom_syntax( $prefix ); $css = ob_get_clean(); return $this->minify( $css ); } /** * Geneate the WP classes for the theme * * @param string $prefix The classes prefix. * @param string $name The name of the color. * @param string $color The hex of the color. * * @return void */ private function generate_wp_color_syntax( $prefix, $name, $color ) { $class_base = $prefix . '.has-' . $name; ?> -color { color: !important; } -background-color { background-color: !important; } { color: ; } --background { background-color: ; } --border { border-color: ; } --hover:hover { color: ; } --background-hover:hover { background-color: ; } --border-hover:hover { border-color: ; } --before:before, --before :before { color: ; } --before-hover:hover:before, --before-hover:hover :before { color: ; } --background-before:before, --background-before :before { background-color: ; } --after:after, --after > :after { color: ; } --background-after:after, --background-after :after { background-color: ; } --fa .fa { color: ; } --fa-background .fa { background-color: ; } --fa-hover:hover .fa { color: ; } --a a { color: ; } --a-hover a:hover { color: ; } a { color: get_tertiary_color() ); ?>; } a:hover { color: get_secondary_color() ); ?>; } .pagination .nav-links .prev, .pagination .nav-links .next { background-color: get_primary_color() ); ?>; border-color: get_primary_color() ); ?>; } .pagination .nav-links .prev:hover, .pagination .nav-links .next:hover { border-color: get_secondary_color() ); ?>; color: get_secondary_color() ); ?>; } .pagination .nav-links .page-numbers:not(.prev):not(.next) { color: get_primary_color() ); ?>; } .pagination .nav-links .page-numbers:not(.prev):not(.next):hover { color: get_secondary_color() ); ?>; } . $css = preg_replace( '/(,|:|;|\{|}|\*\/|>) /', '$1', $css ); // Remove space before , ; { } ( ) >. $css = preg_replace( '/ (,|;|\{|}|\(|\)|>)/', '$1', $css ); // Strips leading 0 on decimal values (converts 0.5px into .5px). $css = preg_replace( '/(:| )0\.([0-9]+)(%|em|ex|px|in|cm|mm|pt|pc)/i', '${1}.${2}${3}', $css ); // Strips units if value is 0 (converts 0px to 0). $css = preg_replace( '/(:| )(\.?)0(%|em|ex|px|in|cm|mm|pt|pc)/i', '${1}0', $css ); // Converts all zeros value into short-hand. $css = preg_replace( '/0 0 0 0/', '0', $css ); // Shortern 6-character hex color codes to 3-character where possible. $css = preg_replace( '/#([a-f0-9])\\1([a-f0-9])\\2([a-f0-9])\\3/i', '#\1\2\3', $css ); return trim( $css ); } }