Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce filter which disables frontend styling #212

Merged
merged 2 commits into from
Oct 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions syntax-highlighting-code-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,20 @@ function register_styles( WP_Styles $styles ) {
);
}

/**
* Determines whether styling is enabled.
*
* @return bool Styling.
*/
function is_styling_enabled() {
/**
* Filters whether the Syntax-highlighting Code Block's default styling is enabled.
*
* @param bool $enabled Default styling enabled.
*/
return (bool) apply_filters( 'syntax_highlighting_code_block_styling', true );
}

/**
* Get styles.
*
Expand All @@ -342,6 +356,10 @@ function get_styles( $attributes ) {
return '';
}

if ( ! is_styling_enabled() ) {
return '';
}

static $added_inline_style = false;
static $added_highlighted_color_style = false;

Expand Down Expand Up @@ -643,6 +661,10 @@ function customize_register( $wp_customize ) {
return;
}

if ( ! is_styling_enabled() ) {
return;
}

require_highlight_php_functions();

if ( ! has_filter( BLOCK_STYLE_FILTER ) ) {
Expand All @@ -664,7 +686,7 @@ function customize_register( $wp_customize ) {
'type' => 'select',
'section' => 'colors',
'label' => __( 'Syntax Highlighting Theme', 'syntax-highlighting-code-block' ),
'description' => __( 'Preview the theme by navigating to a page with a code block to see the different themes in action.', 'syntax-highlighting-code-block' ),
'description' => __( 'Preview the theme by navigating to a page with a Code block to see the different themes in action.', 'syntax-highlighting-code-block' ),
'choices' => $choices,
]
);
Expand All @@ -686,13 +708,13 @@ function customize_register( $wp_customize ) {
'section' => 'colors',
'settings' => 'syntax_highlighting[highlighted_line_background_color]',
'label' => __( 'Highlighted Line Color', 'syntax-highlighting-code-block' ),
'description' => __( 'The background color of a highlighted line.', 'syntax-highlighting-code-block' ),
'description' => __( 'The background color of a highlighted line in a Code block.', 'syntax-highlighting-code-block' ),
]
)
);
}
}
add_action( 'customize_register', __NAMESPACE__ . '\customize_register' );
add_action( 'customize_register', __NAMESPACE__ . '\customize_register', 100 );

/**
* Override the post value for the highlighted line background color when the theme has been highlighted.
Expand Down