Skip to content

Instantly share code, notes, and snippets.

View mannieschumpert's full-sized avatar

Mannie Schumpert mannieschumpert

View GitHub Profile
@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
@mannieschumpert
mannieschumpert / gist:4018296
Created November 5, 2012 16:56
Remove "Preview" button from Custom Post type edit page
// Hide "Preview" button
function hide_preview_button()
{
global $current_screen;
if ( 'CUSTOM_POST_TYPE' == $current_screen->post_type ) {
echo '<style>#preview-action,.updated a{display:none;}</style>';
}
}
add_action('admin_head', 'hide_preview_button');
@mannieschumpert
mannieschumpert / gist:8888351
Last active February 22, 2021 05:02
Some filter examples for preventing editing of certain users.
<?php
/**
* Prevent Editing of a specified user
*
* This example shows how you can protect the original admin from being edited or deleted by anyone else
*/
add_filter('map_meta_cap', 'prevent_user_edit', 10, 4 );
function prevent_user_edit( $required_caps, $cap, $user_id, $args ){
$protected_user = 1; // ID of user not editable
@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:8886289
Last active August 2, 2020 13:15
Code Examples from Andrew Nacin's "Current User Can Watch This Talk"
<?php
// If you can edit pages, you can edit widgets
add_filter( 'user_has_cap',
function( $caps ) {
if ( ! empty( $caps['edit_pages'] ) )
$caps['edit_theme_options'] = true;
return $caps;
} );
@mannieschumpert
mannieschumpert / gist:9492274
Last active April 28, 2020 12:31
QuickTip: Make an SVG Library for Your Custom Post Type Icons
<?php
// Create your SVG library function
// Put this at the bottom of your functions.php file,
// or out of the way wherever you like
function menu_icons($icon){
// Store your SVGs in an associative array
$svgs = array(
'microphone' => 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pg0KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDE2LjAuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPg0KPCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjEvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkIj4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCINCgkgd2lkdGg9IjY0cHgiIGhlaWdodD0iMTAwcHgiIHZpZXdCb3g9IjAgLTIwIDY0IDEyMCIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgNjQgMTAwOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+DQo8Zz4NCgk8Zz4NCgkJPHBhdGggZD0iTTYyLDM2LjIxNWgtM2MtMS4xLDAtMiwwLjktMiwyVjUyYzAsNi42ODYtNS4yNjYsMTgtMjUs
@mannieschumpert
mannieschumpert / gist:e5cec8723247f9490016
Created October 9, 2014 21:01
Remove Gravity Forms' "Add Form" button from all WYSIWYG editors
<?php
add_filter( 'gform_display_add_form_button', function(){return false;} );
@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
import React, { createContext, useState } from 'react';
export const FormContext = createContext();
const Form = ({ handleSubmit, children, submitButtonText }) => {
const [values, setValues] = useState({});
const setValue = ({ name, value }) => {
setValues(values => ({
...values,
@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