Skip to content

Instantly share code, notes, and snippets.

View mannieschumpert's full-sized avatar

Mannie Schumpert mannieschumpert

View GitHub Profile
@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: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: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:7200062
Created October 28, 2013 16:29
A quick filter to allow the editor role to edit theme options.
<?php
/**
* Allow editor role to edit theme options
*/
add_filter('user_has_cap',
function( $caps ){
if (! empty( $caps['edit_pages'] ) )
$caps['edit_theme_options'] = true;
return $caps;
});
@mannieschumpert
mannieschumpert / gist:7250269
Created October 31, 2013 13:59
When using ACF, and registering fields via PHP (and not using Lite mode), your fields might not show, the likely problem being that your registration code ran before the ACF plugin was initiated. To solve, wrap your fields registrations in a plugins_loaded hook.
<?php
add_action( 'plugins_loaded', 'register_my_fields' );
function register_my_fields(){
// put the exported PHP field registration code here
}
@mannieschumpert
mannieschumpert / SassMeister-input.scss
Created December 4, 2013 16:50 — forked from lunelson/SassMeister-input.scss
Generated by SassMeister.com.
// ----
// Sass (v3.3.0.rc.1)
// Compass (v0.13.alpha.10)
// ----
/*
A slightly more automated approach to BEM modifier classes:
using '&' parent selector interpolation, modifiers extend their bases,
so that HTML markup requires only the modifier class not the base *and* modifier
*/
@mannieschumpert
mannieschumpert / SassMeister-input.scss
Created December 6, 2013 16:58
Generated by SassMeister.com.
// ----
// Sass (v3.3.0.rc.1)
// Compass (v0.13.alpha.10)
// ----
@import "SassyLists";
// ----
// Sass (v3.3.0.rc.1)
// Compass (v0.13.alpha.10)
@mannieschumpert
mannieschumpert / SassMeister-input.sass
Created December 6, 2013 16:59 — forked from scottkellum/SassMeister-input.sass
Generated by SassMeister.com.
// ----
// Sass (v3.3.0.rc.1)
// Compass (v0.13.alpha.7)
// ----
=e($name)
@at-root #{&}__#{$name}
@content
=m($name)
@at-root #{&}--#{$name}
@mannieschumpert
mannieschumpert / enqueue.php
Last active December 31, 2015 04:29
Optionally enqueue LiveReload for local development.
<?php
/**
* Enqueue LiveReload if local install
*
* Assumes livereload.js is in the root folder of your local site
*
* This should be fairly reliable,
* but may need to be changed for some environments
*/
@mannieschumpert
mannieschumpert / gist:8334811
Last active August 20, 2023 14:58
Filter the submit button in Gravity Forms to change the <input type="submit> element to a <button> element. There's an example in the Gravity Forms documentation, but it lacks the proper code to show your custom button text, AND removes important attributes like the onclick that prevents multiple clicks. I was trying to solve that.
<?php
// filter the Gravity Forms button type
add_filter("gform_submit_button", "form_submit_button", 10, 2);
function form_submit_button($button, $form){
// The following line is from the Gravity Forms documentation - it doesn't include your custom button text
// return "<button class='button' id='gform_submit_button_{$form["id"]}'>'Submit'</button>";
// This includes your custom button text:
return "<button class='button' id='gform_submit_button_{$form["id"]}'>{$form['button']['text']}</button>";
}
// Oops this strips important stuff