Skip to content

Instantly share code, notes, and snippets.

View genesis16's full-sized avatar

Jane James genesis16

View GitHub Profile
/*
* Whitelist email domains from your WPForms.
*
* @link https://wpforms.com/developers/how-to-restrict-email-domains/
*
*/
function wpf_whitelist_domains( $field_id, $field_submit, $form_data ) {
$domain = substr( strrchr( $field_submit, "@" ), 1 );
$whitelist = array( 'icloud.com', 'me.com' );
if( ! in_array( $domain, $whitelist ) ) {
@genesis16
genesis16 / wp forms blacklist
Created April 16, 2021 06:04
wp forms blacklist
function wpf_blacklist_domains( $field_id, $field_submit, $form_data ) {
$domain = substr( strrchr( $field_submit, "@" ), 1 );
$blacklist = array( 'yahoo.com', 'hotmail.com' );
if( in_array( $domain, $blacklist ) ) {
wpforms()->process->errors[ $form_data['id'] ][ $field_id ] = esc_html__( 'We apologize for any inconvenience, we are unable to accept emails from this domain.', 'wpforms' );
return;
}
}
add_action('wpforms_process_validate_email', 'wpf_blacklist_domains', 10, 3 );
@genesis16
genesis16 / gist:4c13c5115d3d9eed6ddaa182f0bd4273
Created September 3, 2021 06:56
Disable admin bar from all non admins and editors
// Disabled wordpress admin bar to all non admininstrators or editors - Jane James
function disable_admin_bar() {
if (current_user_can('administrator') || current_user_can('editor') ) {
// user can view admin bar
show_admin_bar(true); // this line isn't essentially needed by default...
} else {
// hide admin bar
show_admin_bar(false);
}
<?php
/*
Name: WordPress Post Like System
Description: A simple and efficient post like system for WordPress.
Version: 0.5.2
Author: Jon Masterson
Author URI: http://jonmasterson.com/
License:
Copyright (C) 2015 Jon Masterson
(function( $ ) {
'use strict';
$(document).on('click', '.sl-button', function() {
var button = $(this);
var post_id = button.attr('data-post-id');
var security = button.attr('data-nonce');
var iscomment = button.attr('data-iscomment');
var allbuttons;
if ( iscomment === '1' ) { /* Comments can have same id */
allbuttons = $('.sl-comment-button-'+post_id);
@genesis16
genesis16 / vendor-event.php
Created December 14, 2021 03:05
Vendor event template
<?php
/**
Template Name: Vendor Event Template
Template Post Type: event
*/
get_header();
?>
<div id="primary" class="content-area bb-grid-cell">
<main id="main" class="site-main">
@genesis16
genesis16 / single-event.php
Created December 14, 2021 04:36
Custom post type template file
<?php
/*
Template Name: Custom Event Template
Template Post Type: event
*/
<?php
/**
* The template for displaying the Event Index
*
* @package PSN WordPress Theme
* @version 1.0
*/
// Exit if accessed directly.
@genesis16
genesis16 / functions.php
Created April 27, 2022 04:48
redirect canonical
1. // use the page url and append the CPT template file you would like to redirect canoncial URL's
add_action( 'template_redirect', 'insight_template_redirect', 1 );
function insight_template_redirect() {
if ( is_paged() && is_single( 'yourwebsite.com/category' ) ) {
remove_action( 'template_redirect', 'redirect_canonical' );
}
}
2. // Declare pagination function and use paged parameter in wp_query
// for practical purposes I have called this template archive-template
but if your custom post type category is moves you would call this archive-movies.php.
I have set the posts to 9, but you can set it to however many you want.
$paged = ( get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'insight',
'post_status' => 'publish',
'posts_per_page' => 9,