register_control_type( 'Epsilon_Control_Typography' ); } /** * Add custom parameters to pass to the JS via JSON. * * @since 1.2.0 * @access public */ public function json() { $json = parent::json(); $json['id'] = $this->id; $json['link'] = $this->get_link(); $json['value'] = $this->value(); $json['choices'] = $this->choices; $json['default'] = $this->default; $json['fontDefaults'] = $this->set_font_defaults(); $json['inputs'] = $this->get_values( $this->id ); $json['fonts'] = $this->google_fonts(); $json['selectors'] = $this->set_selectors(); $json['stylesheet'] = $this->stylesheet; $i = 0; if ( in_array( 'font-family', $json['choices'] ) ) { $i ++; } if ( in_array( 'font-weight', $json['choices'] ) ) { $i ++; } if ( in_array( 'font-style', $json['choices'] ) ) { $i ++; } if ( in_array( 'letter-spacing', $json['choices'] ) || in_array( 'line-height', $json['choices'] ) || in_array( 'font-size', $json['choices'] ) ) { $i ++; } $arr = array( 1 => 'one', 2 => 'two', 3 => 'three', 4 => 'full', ); $json['styleHelper'] = $arr[ $i ]; return $json; } /** * Sets the typography defaults */ public function set_font_defaults() { $arr = array(); if ( empty( $this->font_defaults ) ) { $arr[ $this->id ] = array(); } if ( ! empty( $this->font_defaults ) ) { $arr[ $this->id ] = $this->font_defaults; } return $arr; } /** * Enqueues selectize js * * @since 1.0.0 * @access public * @return void */ public function enqueue() { wp_enqueue_script( 'jquery-ui' ); wp_enqueue_script( 'jquery-ui-slider' ); wp_enqueue_style( 'selectize', EPSILON_URI . '/assets/vendors/selectize/selectize.css' ); wp_enqueue_script( 'selectize', EPSILON_URI . '/assets/vendors/selectize/selectize.min.js', array( 'jquery' ), '1.0.0', true ); } /** * Grabs the value from the json and creates a k/v array * * @since 1.0.0 * * @param $values * * @return array */ public function get_values( $values ) { $defaults = $this->set_font_defaults(); $defaults = $defaults[ $this->id ]; if ( empty( $defaults ) ) { $defaults = array( 'font-family' => 'Select font', 'font-weight' => '', 'font-style' => '', 'letter-spacing' => '0', 'font-size' => '16', 'line-height' => '18', ); } $arr = array(); foreach ( $this->choices as $choice ) { if ( array_key_exists( $choice, $defaults ) ) { $arr[ $choice ] = $defaults[ $choice ]; } } if ( empty( $values ) ) { return $arr; } $json = get_theme_mod( $values, '' ); if ( '' === $json ) { return $arr; } $json = str_replace( '"', '"', $json ); $json = (array) json_decode( $json ); $options = (array) $json['json']; /** * Changed these options (font-style and weight) in toggles */ if ( ! empty( $options['font-style'] ) ) { $options['font-style'] = 'on'; } if ( ! empty( $options['font-weight'] ) ) { $options['font-weight'] = 'on'; } $return = array_merge( $arr, $options ); foreach ( $return as $k => $v ) { $return[ $k ] = esc_attr( $v ); } return $return; } /** * Access the GFonts Json and parse its content. * * @since 1.0.0 * @access public * @return array|mixed|object */ public function google_fonts() { global $wp_filesystem; if ( empty( $wp_filesystem ) ) { require_once( ABSPATH . '/wp-admin/includes/file.php' ); WP_Filesystem(); } $path = EPSILON_PATH . '/assets/data/gfonts.json'; $gfonts = $wp_filesystem->get_contents( $path ); $gfonts = json_decode( $gfonts ); if ( null === $gfonts ) { return new stdClass(); } return $gfonts; } /** * @return string */ public function set_selectors() { return implode( ',', $this->selectors ); } /** * Display the control's content * * @since 1.2.0 * @access public */ public function content_template() { //@formatter:off ?>