Skip to content

Instantly share code, notes, and snippets.

View mannieschumpert's full-sized avatar

Mannie Schumpert mannieschumpert

View GitHub Profile
@mannieschumpert
mannieschumpert / gist:7188426
Last active December 30, 2020 14:51
When using Gravity Forms on a client project, you might want the client to be able to view and manipulate form entries, without giving them administrator access. The user_has_cap filter allows us to add capabilities without changing the role in the database. This gist allows users with the editor role to view and manipulate form entries.
<?php
/**
* Add Gravity Forms capabilities
*/
add_filter('user_has_cap',
function( $caps ){
if (! empty( $caps['edit_pages'] ) ) { // user has edit capabilities
$caps['gravityforms_delete_entries'] = true;
$caps['gravityforms_edit_entries'] = true;
$caps['gravityforms_edit_entry_notes'] = true;
@mannieschumpert
mannieschumpert / gist:6127173
Last active December 20, 2015 11:59
Generate a random number of a given length in PHP.
<?php
// how long the string should be
$length = 8;
$num = '';
for ($i = 0; $i < $length; $i++) {
$num .= mt_rand(0, 9);
}
@mannieschumpert
mannieschumpert / gist:6105315
Last active August 12, 2019 21:40
Remove user fields for specific user role in WordPress
<?php
// Hook into the admin footer
add_action( 'admin_footer-user-edit.php', 'remove_user_fields' );
function remove_user_fields(){
// Set desired user role to target
$role = 'subscriber';
// Check for user ID query string
@mannieschumpert
mannieschumpert / gist:6105148
Last active February 22, 2018 21:31
Remove unneeded User settings fields in WordPress
<?php
// Hook into the admin footer
add_action( 'admin_footer-user-edit.php', 'remove_user_fields' );
// Print jQuery that removes unneeded elements
function remove_user_fields(){
?>
<script type="text/javascript">
jQuery(document).ready( function($) {
var ids = ['#rich_editing', // Rich editing button
@mannieschumpert
mannieschumpert / gist:5855129
Last active December 18, 2015 22:29
Bash function for initializing a WordPress theme repo and setting it up to receive push. Directories are of course specific to my workflow. Change as necessary. (Note: works with HostGator. I'm not sure if it works universally.) Git-specific info via @mexitek. http://www.arlocarreon.com/blog/git/push-git-repo-into-shared-hosting-account-like-hos…
devinit() {
# move to dev themes
cd public_html/dev/wp-content/themes
# create theme directory
mkdir ${1}
# move into it
cd ${1}
#initialize git
git init
# configure for receiving pushes
@mannieschumpert
mannieschumpert / Get&Set Multisite Blog Option Transients.md
Last active December 16, 2015 10:28
Gets/stores a transient set to an array of blog option meta for sites across a multisite network.

Network-wide queries are very costly, performance-wise. If you need to get or display lists of per-blog meta values network-wide, it's better to save it as a transient so that the query doesn't bog down the site.

####To Do:

  • remove $time parameter, and just set the expiry far in the future
  • call delete_site_transient whenever a site is added or has its status changed, or when a site modifies the specified meta
@mannieschumpert
mannieschumpert / gist:5344974
Last active December 16, 2015 00:09
A simple PHP function to print copyright date
function copyright($start, $owner) {
$date = date('Y');
echo "© Copyright ";
if ( $start < $date ) {
echo "{$start} - ";
}
echo "{$date} {$owner}";
}
/*
@mannieschumpert
mannieschumpert / gist:5321866
Last active December 15, 2015 20:58
Sass absolute positioning mixin demo
// Gist at https://gist.github.com/mannieschumpert/5321866
// Future enhancements: support all four direction attributes (probably needs a different technique to avoid verboseness)
// Sass v3.2.7
=absolute($args: NULL)
position: absolute
@if $args != NULL
#{nth($args, 1)}: nth($args, 2)
@if length($args) == 4
#{nth($args, 3)}: nth($args, 4)
@mannieschumpert
mannieschumpert / gist:5321261
Created April 5, 2013 17:53
Inspired by the Sass Pt.2 course on CodeSchool.com, this Sass mixin gist also adds a parameter to adjust the size of the "caret".
=caret($point,$size)
$opposite: opposite-position($point)
border: $size solid transparent
border-#{$opposite}: $size solid #000
border-#{$point}: 0
height: 0
width: 0
$cols: 12
$gutter: 2%
$one_col: (100% - ($gutter * ($cols - 1))) / $cols
@mixin cols($num)
width: ($one_col * $num) + ($gutter * ($num - 1))
@mixin sub_cols($num_child, $num_parent)