226 lines
7.0 KiB
PHP
226 lines
7.0 KiB
PHP
<?php
|
|
/*This file is part of HelloChildTheme*/
|
|
/*Load the parent stylesheet then child theme stylesheet*/
|
|
if ( ! function_exists( 'suffice_child_enqueue_child_styles' ) ) {
|
|
function HelloChildTheme_enqueue_child_styles() {
|
|
// loading parent style
|
|
// wp_register_style('parente2-style',get_template_directory_uri() . '/style.css', array(), rand(111,9999),'all');
|
|
|
|
// wp_enqueue_style( 'parente2-style' );
|
|
|
|
// loading child style
|
|
wp_register_style('childe2-style',get_stylesheet_directory_uri() . '/style.css', array(), rand(111,9999),'all');
|
|
|
|
wp_enqueue_style( 'childe2-style');
|
|
}
|
|
}
|
|
add_action( 'wp_enqueue_scripts', 'HelloChildTheme_enqueue_child_styles' );
|
|
|
|
|
|
// Add custom JS scripts
|
|
function myprefix_enqueue_scripts() {
|
|
wp_enqueue_script( 'scripts', get_stylesheet_directory_uri() . '/assets/js/scripts.js', array('jquery'), rand(111,9999), true );
|
|
}
|
|
add_action( 'wp_enqueue_scripts', 'myprefix_enqueue_scripts' );
|
|
|
|
|
|
// Change WP Login screen error message
|
|
add_filter( 'login_errors', function( $error ) {
|
|
global $errors;
|
|
$err_codes = $errors->get_error_codes();
|
|
|
|
// Invalid username.
|
|
// Default: '<strong>ERROR</strong>: Invalid username. <a href="%s">Lost your password</a>?'
|
|
if ( in_array( 'invalid_username', $err_codes ) ) {
|
|
$error = '<strong>ERROR</strong>: Wrong information.';
|
|
}
|
|
|
|
// Invalid email.
|
|
if ( in_array( 'invalid_email', $err_codes ) ) {
|
|
$error = '<strong>ERROR</strong>: Wrong information.';
|
|
}
|
|
|
|
// Incorrect password.
|
|
// Default: '<strong>ERROR</strong>: The password you entered for the username <strong>%1$s</strong> is incorrect. <a href="%2$s">Lost your password</a>?'
|
|
if ( in_array( 'incorrect_password', $err_codes ) ) {
|
|
$error = '<strong>ERROR</strong>: Wrong information.';
|
|
}
|
|
|
|
return $error;
|
|
} );
|
|
|
|
|
|
add_action('admin_init', function () {
|
|
// Redirect any user trying to access comments page
|
|
global $pagenow;
|
|
|
|
if ($pagenow === 'edit-comments.php') {
|
|
wp_safe_redirect(admin_url());
|
|
exit;
|
|
}
|
|
|
|
// Remove comments metabox from dashboard
|
|
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
|
|
|
|
// Disable support for comments and trackbacks in post types
|
|
foreach (get_post_types() as $post_type) {
|
|
if (post_type_supports($post_type, 'comments')) {
|
|
remove_post_type_support($post_type, 'comments');
|
|
remove_post_type_support($post_type, 'trackbacks');
|
|
}
|
|
}
|
|
});
|
|
|
|
// Close comments on the front-end
|
|
add_filter('comments_open', '__return_false', 20, 2);
|
|
add_filter('pings_open', '__return_false', 20, 2);
|
|
|
|
// Hide existing comments
|
|
add_filter('comments_array', '__return_empty_array', 10, 2);
|
|
|
|
// Remove comments page in menu
|
|
add_action('admin_menu', function () {
|
|
remove_menu_page('edit-comments.php');
|
|
});
|
|
|
|
// Remove comments links from admin bar
|
|
function my_admin_bar_render() {
|
|
global $wp_admin_bar;
|
|
$wp_admin_bar->remove_menu('comments');
|
|
}
|
|
add_action( 'wp_before_admin_bar_render', 'my_admin_bar_render' );
|
|
|
|
|
|
// Move Yoast to Bottom of Edit Screen
|
|
add_filter( 'wpseo_metabox_prio', function() { return 'low'; } );
|
|
|
|
|
|
// Remove jQuery Migrate
|
|
// function remove_jquery_migrate($scripts)
|
|
// {
|
|
// if (!is_admin() && isset($scripts->registered['jquery'])) {
|
|
// $script = $scripts->registered['jquery'];
|
|
|
|
// if ($script->deps) { // Check whether the script has any dependencies
|
|
// $script->deps = array_diff($script->deps, array(
|
|
// 'jquery-migrate'
|
|
// ));
|
|
// }
|
|
// }
|
|
// }
|
|
// add_action('wp_default_scripts', 'remove_jquery_migrate');
|
|
|
|
|
|
/**
|
|
* Disable the emoji's
|
|
*/
|
|
function disable_emojis() {
|
|
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
|
|
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
|
|
remove_action( 'wp_print_styles', 'print_emoji_styles' );
|
|
remove_action( 'admin_print_styles', 'print_emoji_styles' );
|
|
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
|
|
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
|
|
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
|
|
add_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' );
|
|
add_filter( 'wp_resource_hints', 'disable_emojis_remove_dns_prefetch', 10, 2 );
|
|
}
|
|
add_action( 'init', 'disable_emojis' );
|
|
|
|
/**
|
|
* Filter function used to remove the tinymce emoji plugin.
|
|
*
|
|
* @param array $plugins
|
|
* @return array Difference betwen the two arrays
|
|
*/
|
|
function disable_emojis_tinymce( $plugins ) {
|
|
if ( is_array( $plugins ) ) {
|
|
return array_diff( $plugins, array( 'wpemoji' ) );
|
|
} else {
|
|
return array();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Remove emoji CDN hostname from DNS prefetching hints.
|
|
*
|
|
* @param array $urls URLs to print for resource hints.
|
|
* @param string $relation_type The relation type the URLs are printed for.
|
|
* @return array Difference betwen the two arrays.
|
|
*/
|
|
function disable_emojis_remove_dns_prefetch( $urls, $relation_type ) {
|
|
if ( 'dns-prefetch' == $relation_type ) {
|
|
/** This filter is documented in wp-includes/formatting.php */
|
|
$emoji_svg_url = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/2/svg/' );
|
|
|
|
$urls = array_diff( $urls, array( $emoji_svg_url ) );
|
|
}
|
|
|
|
return $urls;
|
|
}
|
|
|
|
|
|
// Disable dashicon
|
|
// function remove_dashicons_wordpress() {
|
|
// if ( ! is_user_logged_in() ) {
|
|
// wp_dequeue_style('dashicons');
|
|
// wp_deregister_style( 'dashicons' );
|
|
// }
|
|
// }
|
|
// add_action( 'wp_enqueue_scripts', 'remove_dashicons_wordpress' );
|
|
|
|
|
|
// Deactivate Eicons in Elementor
|
|
add_action( 'wp_enqueue_scripts', 'js_remove_default_stylesheet', 20 );
|
|
function js_remove_default_stylesheet() {
|
|
|
|
// Don't remove it in the backend
|
|
if ( is_admin() || current_user_can( 'manage_options' ) ) {
|
|
return;
|
|
}
|
|
wp_deregister_style( 'elementor-icons' );
|
|
}
|
|
|
|
|
|
// Disable WP Embed
|
|
function remove_wp_embed(){
|
|
wp_dequeue_script( 'wp-embed' );
|
|
}
|
|
add_action( 'wp_footer', 'remove_wp_embed' );
|
|
|
|
|
|
// Change gravity form error message from h2 to span
|
|
add_filter( 'gform_validation_message', 'change_message', 10, 2 );
|
|
function change_message( $message, $form ) {
|
|
return "<span>There was a problem with your submission. Please review the fields below.</span>";
|
|
}
|
|
// Change gravity form required legend text
|
|
add_filter( 'gform_required_legend', function( $legend, $form ) {
|
|
return 'An asterisk (*) indicates a required field.';
|
|
}, 10, 2 );
|
|
// force AJAX on all GForms
|
|
add_filter( 'gform_form_args', 'setup_form_args' );
|
|
function setup_form_args( $form_args ) {
|
|
$form_args['ajax'] = true;
|
|
return $form_args;
|
|
}
|
|
|
|
|
|
|
|
// This code snippet will programmatically replace the URLs returned by get_permalink(),
|
|
// this updates the HTML to point to the external URL instead of relying only on a redirect.T
|
|
function pm_use_external_redirects_as_canonical_urls( $permalink, $post ) {
|
|
global $permalink_manager_external_redirects;
|
|
|
|
$post = ( is_integer( $post ) ) ? get_post( $post ) : $post;
|
|
|
|
if ( !empty( $permalink_manager_external_redirects[ $post->ID ] ) ) {
|
|
$permalink = $permalink_manager_external_redirects[ $post->ID ];
|
|
}
|
|
|
|
return $permalink;
|
|
}
|
|
add_filter( 'permalink_manager_filter_final_post_permalink', 'pm_use_external_redirects_as_canonical_urls', 10, 2 );
|
|
|
|
|