🐞 fix: Add updated hooks
This commit is contained in:
271
lib/hooks.php
271
lib/hooks.php
@@ -14,14 +14,14 @@ namespace BasicWP;
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
add_action(
|
add_action(
|
||||||
'wp_head',
|
'wp_head',
|
||||||
function () {
|
function () {
|
||||||
?>
|
?>
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
<?php
|
<?php
|
||||||
},
|
},
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,11 +30,11 @@ add_action(
|
|||||||
* @link https://developer.wordpress.org/reference/functions/register_nav_menus/
|
* @link https://developer.wordpress.org/reference/functions/register_nav_menus/
|
||||||
*/
|
*/
|
||||||
register_nav_menus(
|
register_nav_menus(
|
||||||
array(
|
array(
|
||||||
'main_navigation' => 'Main Navigation',
|
'main_navigation' => 'Main Navigation',
|
||||||
'aux_navigation' => 'Auxiliary Navigation',
|
'aux_navigation' => 'Auxiliary Navigation',
|
||||||
'footer_navigation' => 'Footer Navigation',
|
'footer_navigation' => 'Footer Navigation',
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,57 +45,36 @@ register_nav_menus(
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
add_action(
|
add_action(
|
||||||
'widgets_init',
|
'widgets_init',
|
||||||
function () {
|
function () {
|
||||||
$config = array(
|
$config = array(
|
||||||
'before_widget' => '<div class="widget %1$s %2$s">',
|
'before_widget' => '<div class="widget %1$s %2$s">',
|
||||||
'after_widget' => '</div>',
|
'after_widget' => '</div>',
|
||||||
'before_title' => '<h2>',
|
'before_title' => '<h2>',
|
||||||
'after_title' => '</h2>',
|
'after_title' => '</h2>',
|
||||||
);
|
);
|
||||||
|
|
||||||
$cfg_foot = array(
|
$cfg_foot = array(
|
||||||
'before_widget' => '<div class="widget %1$s %2$s">',
|
'before_widget' => '<div class="widget %1$s %2$s">',
|
||||||
'after_widget' => '</div>',
|
'after_widget' => '</div>',
|
||||||
'before_title' => '<h4>',
|
'before_title' => '<h4>',
|
||||||
'after_title' => '</h4>',
|
'after_title' => '</h4>',
|
||||||
);
|
);
|
||||||
|
|
||||||
register_sidebar(
|
register_sidebar(
|
||||||
array(
|
array(
|
||||||
'name' => 'Primary Sidebar',
|
'name' => 'Primary Sidebar',
|
||||||
'id' => 'sidebar-primary',
|
'id' => 'sidebar-primary',
|
||||||
) + $config
|
) + $config
|
||||||
);
|
);
|
||||||
|
|
||||||
register_sidebar(
|
register_sidebar(
|
||||||
array(
|
array(
|
||||||
'name' => 'Page Sidebar',
|
'name' => 'Page Sidebar',
|
||||||
'id' => 'sidebar-page',
|
'id' => 'sidebar-page',
|
||||||
) + $config
|
) + $config
|
||||||
);
|
);
|
||||||
|
}
|
||||||
register_sidebar(
|
|
||||||
array(
|
|
||||||
'name' => 'Footer Area 1',
|
|
||||||
'id' => 'footer-1',
|
|
||||||
) + $cfg_foot
|
|
||||||
);
|
|
||||||
|
|
||||||
register_sidebar(
|
|
||||||
array(
|
|
||||||
'name' => 'Footer Area 2',
|
|
||||||
'id' => 'footer-2',
|
|
||||||
) + $cfg_foot
|
|
||||||
);
|
|
||||||
|
|
||||||
register_sidebar(
|
|
||||||
array(
|
|
||||||
'name' => 'Footer Area 3',
|
|
||||||
'id' => 'footer-3',
|
|
||||||
) + $cfg_foot
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -104,70 +83,90 @@ add_action(
|
|||||||
* {Site URL}: {Title}
|
* {Site URL}: {Title}
|
||||||
*/
|
*/
|
||||||
add_filter(
|
add_filter(
|
||||||
'wp_title',
|
'wp_title',
|
||||||
function ( $title ) {
|
function ( $title ) {
|
||||||
$site_name = get_bloginfo( 'name' );
|
$site_name = get_bloginfo( 'name' );
|
||||||
|
|
||||||
return "{$site_name}: {$title}";
|
return "{$site_name}: {$title}";
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Excerpt
|
* Excerpt
|
||||||
*/
|
*/
|
||||||
add_filter(
|
add_filter(
|
||||||
'excerpt_more',
|
'excerpt_more',
|
||||||
function () {
|
function () {
|
||||||
return '…';
|
return '…';
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the page hero should hold the main h1 of the page.
|
* Whether the page hero should hold the main h1 of the page.
|
||||||
*/
|
*/
|
||||||
add_filter(
|
add_filter(
|
||||||
'include_page_title_in_hero',
|
'include_page_title_in_hero',
|
||||||
function ( $include_title ) {
|
function ( $include_title ) {
|
||||||
// Add post types that should not use the title in the hero.
|
// Add post types that should not use the title in the hero.
|
||||||
if ( is_singular( ( 'post' ) ) ) {
|
if ( is_singular( ( 'post' ) ) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $include_title;
|
return $include_title;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WP Cleanup
|
* WP Cleanup
|
||||||
*/
|
*/
|
||||||
function init() {
|
function init() {
|
||||||
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
|
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
|
||||||
remove_action( 'wp_print_styles', 'print_emoji_styles' );
|
remove_action( 'wp_print_styles', 'print_emoji_styles' );
|
||||||
remove_action( 'admin_print_styles', 'print_emoji_styles' );
|
remove_action( 'admin_print_styles', 'print_emoji_styles' );
|
||||||
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
|
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
|
||||||
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
|
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
|
||||||
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
|
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
|
||||||
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
|
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
|
||||||
wp_dequeue_style( 'wp-block-library' ); // Core block styles.
|
wp_dequeue_style( 'wp-block-library' ); // Core block styles.
|
||||||
wp_dequeue_style( 'wp-block-library-theme' ); // Block theme styles.
|
wp_dequeue_style( 'wp-block-library-theme' ); // Block theme styles.
|
||||||
wp_dequeue_style( 'global-styles' ); // Global styles.
|
wp_dequeue_style( 'global-styles' ); // Global styles.
|
||||||
wp_dequeue_style( 'core-block-supports' ); // Core block supports.
|
wp_dequeue_style( 'core-block-supports' ); // Core block supports.
|
||||||
wp_dequeue_style( 'core-block-styles' ); // Core block styles.
|
wp_dequeue_style( 'core-block-styles' ); // Core block styles.
|
||||||
remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles', 1 );
|
remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles', 1 );
|
||||||
remove_action( 'wp_enqueue_scripts', 'wp_enqueue_classic_theme_styles', 1 );
|
remove_action( 'wp_enqueue_scripts', 'wp_enqueue_classic_theme_styles', 1 );
|
||||||
remove_action( 'wp_head', 'wp_print_styles', 8 );
|
remove_action( 'wp_head', 'wp_print_styles', 8 );
|
||||||
remove_action( 'wp_head', 'wp_print_head_scripts', 9 );
|
remove_action( 'wp_head', 'wp_print_head_scripts', 9 );
|
||||||
remove_action( 'wp_head', 'wp_generator' ); // WordPress version.
|
remove_action( 'wp_head', 'wp_generator' ); // WordPress version.
|
||||||
remove_action( 'wp_head', 'rsd_link' ); // RSD link.
|
remove_action( 'wp_head', 'rsd_link' ); // RSD link.
|
||||||
remove_action( 'wp_head', 'wlwmanifest_link' ); // Windows Live Writer.
|
remove_action( 'wp_head', 'wlwmanifest_link' ); // Windows Live Writer.
|
||||||
remove_action( 'wp_head', 'wp_shortlink_wp_head' ); // Shortlink.
|
remove_action( 'wp_head', 'wp_shortlink_wp_head' ); // Shortlink.
|
||||||
remove_action( 'wp_head', 'rest_output_link_wp_head' ); // REST API link.
|
remove_action( 'wp_head', 'rest_output_link_wp_head' ); // REST API link.
|
||||||
remove_action( 'wp_head', 'wp_oembed_add_discovery_links' ); // oEmbed discovery links.
|
remove_action( 'wp_head', 'wp_oembed_add_discovery_links' ); // oEmbed discovery links.
|
||||||
remove_action( 'wp_head', 'rel_canonical' ); // Canonical URL.
|
remove_action( 'wp_head', 'rel_canonical' ); // Canonical URL.
|
||||||
remove_action( 'wp_head', 'wp_resource_hints', 2 ); // DNS Prefetch.
|
remove_action( 'wp_head', 'wp_resource_hints', 2 ); // DNS Prefetch.
|
||||||
add_filter( 'wp_img_tag_add_width_and_height_attr', '__return_false' ); // Disable intrinsic image size.
|
add_filter( 'wp_img_tag_add_width_and_height_attr', '__return_false' ); // Disable intrinsic image size.
|
||||||
add_filter( 'wp_img_tag_add_auto_sizes', '__return_false' ); // Disable auto sizes.
|
add_filter( 'wp_img_tag_add_auto_sizes', '__return_false' ); // Disable auto sizes.
|
||||||
add_filter( 'xmlrpc_enabled', '__return_false' );
|
add_filter( 'xmlrpc_enabled', '__return_false' );
|
||||||
|
|
||||||
|
// Add theme support features
|
||||||
|
add_theme_support( 'post-thumbnails' );
|
||||||
|
add_theme_support( 'title-tag' );
|
||||||
|
add_theme_support(
|
||||||
|
'html5',
|
||||||
|
array(
|
||||||
|
'caption',
|
||||||
|
'comment-form',
|
||||||
|
'comment-list',
|
||||||
|
'gallery',
|
||||||
|
'global-search-form',
|
||||||
|
'script',
|
||||||
|
'style',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
add_theme_support( 'align-wide' );
|
||||||
|
add_theme_support( 'editor-styles' );
|
||||||
|
add_theme_support( 'responsive-embeds' );
|
||||||
|
add_theme_support( 'customize-selective-refresh-widgets' );
|
||||||
}
|
}
|
||||||
|
|
||||||
add_action( 'init', __NAMESPACE__ . '\\init', 1 );
|
add_action( 'init', __NAMESPACE__ . '\\init', 1 );
|
||||||
@@ -176,47 +175,49 @@ add_action( 'init', __NAMESPACE__ . '\\init', 1 );
|
|||||||
* Allow SVG uploads
|
* Allow SVG uploads
|
||||||
*/
|
*/
|
||||||
add_filter(
|
add_filter(
|
||||||
'wp_check_filetype_and_ext',
|
'wp_check_filetype_and_ext',
|
||||||
function ( $data, $file, $filename, $mimes ) {
|
function ( $data, $file, $filename, $mimes ) {
|
||||||
global $wp_version;
|
global $wp_version;
|
||||||
|
|
||||||
if ( '4.7.1' !== $wp_version ) {
|
if ( '4.7.1' !== $wp_version ) {
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
$filetype = wp_check_filetype( $filename, $mimes );
|
$filetype = wp_check_filetype( $filename, $mimes );
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'ext' => $filetype['ext'],
|
'ext' => $filetype['ext'],
|
||||||
'type' => $filetype['type'],
|
'type' => $filetype['type'],
|
||||||
'proper_filename' => $data['proper_filename'],
|
'proper_filename' => $data['proper_filename'],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
10,
|
10,
|
||||||
4
|
4
|
||||||
);
|
);
|
||||||
|
|
||||||
add_filter(
|
add_filter(
|
||||||
'upload_mimes',
|
'upload_mimes',
|
||||||
function ( $mimes ) {
|
function ( $mimes ) {
|
||||||
$mimes['svg'] = 'image/svg+xml';
|
$mimes['svg'] = 'image/svg+xml';
|
||||||
return $mimes;
|
return $mimes;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fix display issues with SVGs in admin
|
* Fix display issues with SVGs in admin
|
||||||
*/
|
*/
|
||||||
add_action(
|
add_action(
|
||||||
'admin_head',
|
'admin_head',
|
||||||
function () {
|
function () {
|
||||||
echo '<style type="text/css">
|
echo '
|
||||||
.attachment-266x266, .thumbnail img {
|
<style type="text/css">
|
||||||
width: 100% !important;
|
.attachment-266x266, .thumbnail img {
|
||||||
height: auto !important;
|
width: 100% !important;
|
||||||
|
height: auto !important;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
';
|
||||||
}
|
}
|
||||||
</style>';
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -230,7 +231,7 @@ add_action(
|
|||||||
*/
|
*/
|
||||||
// phpcs:ignore
|
// phpcs:ignore
|
||||||
function new_mail_from( $old ) {
|
function new_mail_from( $old ) {
|
||||||
return get_option( 'admin_email' );
|
return get_option( 'admin_email' );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -244,7 +245,7 @@ function new_mail_from( $old ) {
|
|||||||
*/
|
*/
|
||||||
// phpcs:ignore
|
// phpcs:ignore
|
||||||
function new_mail_from_name( $old ) {
|
function new_mail_from_name( $old ) {
|
||||||
return get_option( 'blogname' );
|
return get_option( 'blogname' );
|
||||||
}
|
}
|
||||||
|
|
||||||
add_filter( 'wp_mail_from', __NAMESPACE__ . '\\new_mail_from' );
|
add_filter( 'wp_mail_from', __NAMESPACE__ . '\\new_mail_from' );
|
||||||
|
|||||||
Reference in New Issue
Block a user