Skip to content

Instantly share code, notes, and snippets.

View itsmereal's full-sized avatar
👋
Hi there

Al-Mamun Talukder itsmereal

👋
Hi there
View GitHub Profile
@Ciantic
Ciantic / wp-allow-svg.php
Last active February 18, 2023 05:19
WordPress allow uploading SVG, even without the XML declaration
<?php
// Mind you, this does not make SVG files safe. This script is meant for sites where only trusted people can upload.
add_action("init", function() {
// First line of defence defused
add_filter('upload_mimes', function ($mimes) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
});
@swoboda
swoboda / gravity-forms-option-groups.php
Created May 26, 2020 21:26
Option groups in the Gravity Forms drop down field
<?php
// Do NOT include the opening php tag
add_filter( 'gform_field_choice_markup_pre_render', function ( $choice_markup, $choice, $field ) {
if ( $field->get_input_type() == 'select' ) {
$choice_value = rgar( $choice, 'value' );
if ( $choice_value === 'optgroup-start' ) {
return sprintf( '<optgroup label="%s">', esc_html( $choice['text'] ) );
} elseif ( $choice_value === 'optgroup-end' ) {
return '</optgroup>';
@stianandreassen
stianandreassen / acf_wysiwyg_height.php
Last active January 24, 2022 22:35
Add a height field to ACF WYSIWYG Field
<?php
/**
* Add height field to ACF WYSIWYG
*/
function wysiwyg_render_field_settings( $field ) {
acf_render_field_setting( $field, array(
'label' => __('Height of Editor'),
'instructions' => __('Height of Editor after Init'),
'name' => 'wysiwyg_height',
'type' => 'number',
@khromov
khromov / acf-nowhere-location-rule.php
Created October 2, 2017 17:36
"Nowhere" location rule for Advanced Custom Fields - never matches
<?php
/*
Plugin Name: Advanced Custom Fields: Nowhere location rules
Description: Adds a "Nowhere" location rule in ACF
*/
add_filter('acf/location/rule_types', function($rules) {
$rules['Extra']['nowhere'] = 'Nowhere';
@timwhitlock
timwhitlock / disable-wp-json.php
Created February 11, 2017 12:39
Disable WordPress REST API completely
<?php
/**
* Plugin Name: Disable REST API
* Version: 0
*/
// completely disable wp-json access
add_filter( 'rest_authentication_errors', function( $access ){
return new WP_Error( 'rest_cannot_access', 'Bye', array( 'status' => 403 ) );
} );
@BODA82
BODA82 / acf-change-file-upload-directory.php
Created October 24, 2016 23:42
Change the upload directory of Advanced Custom Fields file upload field.
<?php
// ACF upload prefilter
function gist_acf_upload_dir_prefilter($errors, $file, $field) {
// Only allow editors and admins, change capability as you see fit
if( !current_user_can('edit_pages') ) {
$errors[] = 'Only Editors and Administrators may upload attachments';
}
// This filter changes directory just for item being uploaded
@DevinWalker
DevinWalker / remove-rev-slider-metabox.php
Created May 14, 2014 20:32
This code removed the Revolution Slider metabox on pages, posts and CTPs
/**
* Remove Rev Slider Metabox
*/
if ( is_admin() ) {
function remove_revolution_slider_meta_boxes() {
remove_meta_box( 'mymetabox_revslider_0', 'page', 'normal' );
remove_meta_box( 'mymetabox_revslider_0', 'post', 'normal' );
remove_meta_box( 'mymetabox_revslider_0', 'YOUR_CUSTOM_POST_TYPE', 'normal' );
}
@spivurno
spivurno / gw-gravity-forms-multi-file-merge-tag-usage.php
Last active November 22, 2018 15:49
Gravity Wiz // Multi-file Merge Tag for Post Content Templates
<?php
# Basic Usage:
# Applies default markup to all forms
gw_multi_file_merge_tag()->register_settings();
# Exclude Form(s):
# Applies default markup to all forms excluding the specified forms
gw_multi_file_merge_tag()->register_settings( array(
'exclude_forms' => 2 // multiple forms: array( 2, 4 )
@BFTrick
BFTrick / gettext-filter-multiple.php
Last active March 30, 2023 07:18
Use the gettext WordPress filter to change any translatable string.
<?php
/**
* Change text strings
*
* @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
*/
function my_text_strings( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'Sale!' :
$translated_text = __( 'Clearance!', 'woocommerce' );
@billerickson
billerickson / gist:2047229
Last active July 10, 2023 22:04
Improve performance of WP_Query
<?php
$args = array(
// Normal query goes here //
'no_found_rows' => true, // counts posts, remove if pagination required
'update_post_term_cache' => false, // grabs terms, remove if terms required (category, tag...)
'update_post_meta_cache' => false, // grabs post meta, remove if post meta required
);