Skip to content

Commit

Permalink
Codestyle changes VisualComposer#328
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytro-kovalov committed Jul 6, 2022
1 parent 5ea8acb commit f7558cb
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 119 deletions.
2 changes: 1 addition & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ function visualcomposerstarter_customizer_scripts() {
'wp-util',
), null, true );

// Add current fonts for "revert" button
// Add current fonts for "revert" button.
$fonts = array(
'vct_fonts_and_style_h1_font_family' => get_theme_mod( 'vct_fonts_and_style_h1_font_family' ),
'vct_fonts_and_style_h2_font_family' => get_theme_mod( 'vct_fonts_and_style_h2_font_family' ),
Expand Down
41 changes: 23 additions & 18 deletions inc/customizer/class-visualcomposerstarter-customizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function include_controls( $wp_customize ) {
$wp_customize->register_control_type( 'VisualComposerStarter_Toggle_Switch_Control' );

require_once get_template_directory() . '/inc/customizer/controls/class-visualcomposerstarter-google-fonts-control.php';
// Do not register "google-fonts" control as it is rendered via php
// Do not register "google-fonts" control as it is rendered via php.
}

/**
Expand Down Expand Up @@ -2921,12 +2921,11 @@ public function ajax_check_font() {
wp_send_json_error( esc_html__( 'Invalid security token sent.', 'visual-composer-starter' ) );
}

if ( empty( $_POST['font'] ) ) {
$font = sanitize_text_field( wp_unslash( $_POST['font'] ) );
if ( empty( $font ) ) {
wp_send_json_error( esc_html__( 'Invalid font family.', 'visual-composer-starter' ) );
}

$font = sanitize_text_field( $_POST['font'] );

$is_google_font = VisualComposerStarter_Fonts::is_google_font( $font );
$exists_locally = false;
if ( $is_google_font ) {
Expand All @@ -2951,18 +2950,23 @@ public function ajax_check_fonts() {
wp_send_json_error( esc_html__( 'Invalid security token sent.', 'visual-composer-starter' ) );
}

if ( empty( $_POST['fonts'] ) ) {
$fonts = array_map( 'sanitize_text_field', wp_unslash( $_POST['fonts'] ) );
if ( empty( $fonts ) ) {
wp_send_json_error( esc_html__( 'Fonts are missing.', 'visual-composer-starter' ) );
}

foreach ( $_POST['fonts'] as $font ) {
foreach ( $fonts as $font ) {
$is_google_font = VisualComposerStarter_Fonts::is_google_font( $font );
if ( $is_google_font && ! VisualComposerStarter_Fonts::is_google_font_exists_locally( $font ) ) {
wp_send_json_success( array( 'at_least_one_missing' => true ) );
wp_send_json_success( array(
'at_least_one_missing' => true,
) );
}
}

wp_send_json_success( array( 'all_fonts_exists' => true ) );
wp_send_json_success( array(
'all_fonts_exists' => true,
) );
}

/**
Expand All @@ -2977,21 +2981,21 @@ public function ajax_download_font() {
wp_send_json_error( esc_html__( 'Invalid security token sent.', 'visual-composer-starter' ) );
}

if ( empty( $_POST['font'] ) ) {
$font = sanitize_text_field( wp_unslash( $_POST['font'] ) );
if ( empty( $font ) ) {
wp_send_json_error( esc_html__( 'Invalid font family.', 'visual-composer-starter' ) );
}

$font = sanitize_text_field( $_POST['font'] );

$is_google_font = VisualComposerStarter_Fonts::is_google_font( $font );
if ( ! $is_google_font ) {
wp_send_json_error( esc_html__( 'Not a Google Font.', 'visual-composer-starter' ) );
}

if ( $is_google_font && VisualComposerStarter_Fonts::is_google_font_exists_locally( $font ) ) {
wp_send_json_error( esc_html__(
sprintf( 'Font %s already exists locally.', $font ),
'visual-composer-starter'
wp_send_json_error( sprintf(
/* translators: %s is a font family name */
esc_html__( 'Font %s already exists locally.', 'visual-composer-starter' ),
$font
) );
}

Expand All @@ -3015,17 +3019,18 @@ public function ajax_download_fonts() {
wp_send_json_error( esc_html__( 'Invalid security token sent.', 'visual-composer-starter' ) );
}

if ( empty( $_POST['fonts'] ) ) {
$fonts = array_map( 'sanitize_text_field', wp_unslash( $_POST['fonts'] ) );
if ( empty( $fonts ) ) {
wp_send_json_error( esc_html__( 'Missing fonts.', 'visual-composer-starter' ) );
}

foreach ( $_POST['fonts'] as $font ) {
// Check if provided font is from Google Fonts library
foreach ( $fonts as $font ) {
// Check if provided font is from Google Fonts library.
if ( ! VisualComposerStarter_Fonts::is_google_font( $font ) ) {
continue;
}

// Check if provided font already downloaded
// Check if provided font already downloaded.
if ( VisualComposerStarter_Fonts::is_google_font_exists_locally( $font ) ) {
continue;
}
Expand Down
Loading

0 comments on commit f7558cb

Please sign in to comment.