Skip to content

Instantly share code, notes, and snippets.

View mattneal-stafflink's full-sized avatar

Matthew Neal mattneal-stafflink

View GitHub Profile
@mattneal-stafflink
mattneal-stafflink / disable-gutenberg.php
Created January 20, 2021 01:03
Disable Gutenberg Editor
//Disables the Gutenberg editor and brings back the WYSIWYG editor.
add_filter('use_block_editor_for_post', '__return_false', 10);
@mattneal-stafflink
mattneal-stafflink / disable-comments.php
Last active January 20, 2021 01:06
Disable WordPress Comments
<?php /* Disables All comments */
add_action('admin_init', function () {
// Redirect any user trying to access comments page
global $pagenow;
if ($pagenow === 'edit-comments.php') {
wp_redirect(admin_url());
exit;
}
@mattneal-stafflink
mattneal-stafflink / .gitignore
Created April 6, 2021 00:54
WordPress WP Engine Gitignore File for ignoring Core & WP Engine Specific Files.
*~
.DS_Store
.svn
.cvs
*.bak
*.swp
Thumbs.db
.htaccess
.vscode/
@mattneal-stafflink
mattneal-stafflink / register.php
Last active May 26, 2021 04:19
User registration functions to sign up agency staff. Place all functions in functions.php of the hubs' theme.
<?php
function is_valid_email_domain($login, $email, $errors ){
$valid_email_domains = array("ocre.com.au","stafflink.com.au");// whitelist email domain lists
$valid = false;
foreach( $valid_email_domains as $d ){
$d_length = strlen( $d );
$current_email_domain = strtolower( substr( $email, -($d_length), $d_length));
if( $current_email_domain == strtolower($d) ){
$valid = true;
break;
<?php
// Stop Authors from accessing the admin dashboard unless you are an admin.
function prevent_author_access(){
if( current_user_can( 'author' ) && is_admin() ) {
// do something here. maybe redirect to homepage
wp_safe_redirect( get_bloginfo( 'url' ) );
}
}
add_action( 'admin_init', 'prevent_author_access' );
@mattneal-stafflink
mattneal-stafflink / stafflink_user_goals.php
Created June 2, 2021 23:13
Display the user goals form on the front end using a shortcode.
@mattneal-stafflink
mattneal-stafflink / wp_login_changes.php
Created June 2, 2021 23:18
Style the /wp-login page and form.
<?php
/**
* Change logo and branding of the WordPress login page.
* Replace the background Image URL CSS element to update the image.
* Ensure you have a file called style-login.css in the root directory of your child theme.
*
* @since 1.0.0
*/
function my_login_logo() {
echo '
@mattneal-stafflink
mattneal-stafflink / is_valid_email_domain.php
Created June 2, 2021 23:24
Check if the submitted email on the register process is valid. Runs right before registering a user.
<?php
/**
* Check to ensure the users' email address matches the allowed list.
* Update the $valid_email_domains array to a comma separated list of string email addresses.
*
* @since 1.0.0
*/
function is_valid_email_domain($login, $email, $errors ) {
$valid_email_domains = array("imageproperty.com.au","stafflink.com.au");// whitelist email domain lists
@mattneal-stafflink
mattneal-stafflink / update_user_groups.php
Created June 2, 2021 23:34
Assigns a newly registered user to a LearnDash group. Must be registered through a gravity forms form.
<?hp
/**
* Assign the user to their selected groups. Comment out what is not used where possible.
* usage: ld_update_group_access('Id of user (found in $user_id), 'id of group:bool (enter manually after creating group', false);
* $entry[7] is the form line 7. In this case, it is a single select drop down.
*
* @since 1.0.0
*/
add_action( 'gform_user_registered', 'update_user_groups', 10, 4 );
@mattneal-stafflink
mattneal-stafflink / my_forcelogin_bypass.php
Created June 2, 2021 23:36
Allow /register to be accessed when using forcelogin plugin.
<?php
/**
* Bypass Force Login to allow for exceptions. Used to push everyone to the login page, except if they are registering.
* As it stands, this code allows the forcelogin plugin to ignores /register.
*
* @param bool $bypass Whether to disable Force Login. Default false.
* @param string $visited_url The visited URL.
* @return bool
*/