191 lines
4.8 KiB
PHP
191 lines
4.8 KiB
PHP
<?php
|
|
|
|
// enqueue custom css on front-end and editor
|
|
function jett_editor_css() {
|
|
add_editor_style( get_theme_file_uri('/assets/css/custom.css') );
|
|
}
|
|
add_action( 'after_setup_theme', 'jett_editor_css' );
|
|
|
|
function jett_frontend_css() {
|
|
wp_enqueue_style('jett_css', get_theme_file_uri('/assets/css/custom.css'));
|
|
}
|
|
add_action('wp_enqueue_scripts', 'jett_frontend_css');
|
|
|
|
|
|
// define block styles
|
|
function jett_block_styles() {
|
|
register_block_style(
|
|
'core/heading',
|
|
array(
|
|
'name' => 'gradient',
|
|
'label' => __( 'Gradient', 'jett' ),
|
|
'inline_style' => '
|
|
.wp-block-heading.is-style-gradient {
|
|
background: var(--wp--preset--gradient--violet-to-green);
|
|
-webkit-background-clip: text;
|
|
-webkit-text-fill-color: transparent;
|
|
line-height: 1.1;
|
|
}
|
|
'
|
|
)
|
|
);
|
|
register_block_style(
|
|
'core/paragraph',
|
|
array(
|
|
'name' => 'gradient',
|
|
'label' => __( 'Gradient', 'jett' ),
|
|
'inline_style' => '
|
|
p.is-style-gradient {
|
|
background: var(--wp--preset--gradient--violet-to-green);
|
|
-webkit-background-clip: text;
|
|
-webkit-text-fill-color: transparent;
|
|
line-height: 1.1;
|
|
}
|
|
'
|
|
)
|
|
);
|
|
register_block_style(
|
|
'core/list',
|
|
array(
|
|
'name' => 'arrow',
|
|
'label' => __( 'Arrow', 'lex-scotland' ),
|
|
'inline_style' => '
|
|
ul.is-style-arrow {
|
|
list-style: none;
|
|
}
|
|
ul.is-style-arrow div {
|
|
display: inline;
|
|
}
|
|
ul.is-style-arrow li::before {
|
|
content: "→";
|
|
margin-right: 0.5em;
|
|
font-weight: bold;
|
|
}
|
|
'
|
|
)
|
|
);
|
|
register_block_style(
|
|
'core/post-terms',
|
|
array(
|
|
'name' => 'hashtags',
|
|
'label' => __('Hashtags', 'lex-scotland'),
|
|
'inline_style' => '
|
|
.is-style-hashtags.taxonomy-post_tag.wp-block-post-terms a::before {
|
|
content: "#";
|
|
}
|
|
|
|
.is-style-hashtags.taxonomy-post_tag.wp-block-post-terms a {
|
|
background: var(--wp--preset--color--black);
|
|
padding: .5rem;
|
|
display: inline-block;
|
|
color: white;
|
|
font-family: var(--wp--preset--font-family--instrument-sans);
|
|
text-decoration: none;
|
|
margin-right: 5px;
|
|
margin-bottom: 5px;
|
|
font-size: 13px;
|
|
font-weight: 500;
|
|
border: 1px solid var(--wp--preset--color--black);
|
|
}
|
|
|
|
.is-style-hashtags.taxonomy-post_tag.wp-block-post-terms a:hover {
|
|
background: var(--wp--preset--gradient--violet-to-green);
|
|
color: var(--wp--preset--color--black);
|
|
}
|
|
'
|
|
)
|
|
);
|
|
}
|
|
add_action( 'init', 'jett_block_styles' );
|
|
|
|
/* Remove default CSS variables that come with Wordpress
|
|
https://github.com/WordPress/gutenberg/issues/56180#issuecomment-1819222376
|
|
*/
|
|
function custom_wp_theme_json_default( $theme_json ) {
|
|
$new_data = array(
|
|
'version' => 2,
|
|
'settings' => array(
|
|
'color' => array(
|
|
'palette' => array(),
|
|
'gradients' => array(),
|
|
),
|
|
'shadow' => array(
|
|
'presets' => array(),
|
|
),
|
|
'typography' => array(
|
|
'fontSizes' => array(),
|
|
),
|
|
// 'dimensions' => array(
|
|
// 'aspectRatios' => array(),
|
|
// ),
|
|
// 'spacing' => array(
|
|
// 'spacingScale' => array(
|
|
// 'steps' => 0,
|
|
// ),
|
|
// ),
|
|
),
|
|
);
|
|
return $theme_json->update_with( $new_data );
|
|
}
|
|
add_filter( 'wp_theme_json_data_default', 'custom_wp_theme_json_default' );
|
|
|
|
// enable svg uploads
|
|
add_filter( 'wp_check_filetype_and_ext', function($data, $file, $filename, $mimes) {
|
|
|
|
global $wp_version;
|
|
if ( $wp_version !== '4.7.1' ) {
|
|
return $data;
|
|
}
|
|
|
|
$filetype = wp_check_filetype( $filename, $mimes );
|
|
|
|
return [
|
|
'ext' => $filetype['ext'],
|
|
'type' => $filetype['type'],
|
|
'proper_filename' => $data['proper_filename']
|
|
];
|
|
|
|
}, 10, 4 );
|
|
function cc_mime_types($mimes) {
|
|
$mimes['svg'] = 'image/svg+xml';
|
|
return $mimes;
|
|
}
|
|
add_filter('upload_mimes', 'cc_mime_types');
|
|
|
|
// remove current post from related posts query loop
|
|
add_filter( 'query_loop_block_query_vars', function( $query_vars, $block ) {
|
|
if ( isset( $block->attributes['metadata']['name'] ) && $block->attributes['metadata']['name'] === 'Related Post' ) {
|
|
$query_vars['post__not_in'] = array( get_the_ID() );
|
|
}
|
|
|
|
return $query_vars;
|
|
}, 10, 2 );
|
|
|
|
function jett_remove_current_from_queries( $query_vars, $block ) {
|
|
do_action( 'qm/debug', $block->parsed_block );
|
|
|
|
if ( 'related-post' === $block->parsed_block['attrs']['className'] )
|
|
$query_vars['post__not_in'] = array( get_the_ID() );
|
|
return $query_vars;
|
|
}
|
|
add_filter( 'query_loop_block_query_vars', 'jett_remove_current_from_queries', 10, 2 );
|
|
|
|
|
|
// Remove default block patterns
|
|
add_action('init', function() {
|
|
remove_theme_support('core-block-patterns');
|
|
}, 9 );
|
|
|
|
|
|
// Register custom pattern categories
|
|
if ( function_exists( 'register_block_pattern_category' ) ) {
|
|
register_block_pattern_category(
|
|
'jett',
|
|
array( 'label' => __( 'JETT', 'jett' ) )
|
|
);
|
|
|
|
register_block_pattern_category(
|
|
'jett_full_page_layouts',
|
|
array( 'label' => __( 'Page Layouts', 'jett' ) )
|
|
);
|
|
} |