Skip to content

Instantly share code, notes, and snippets.

View dgoze's full-sized avatar
💭
I may be slow to respond.

Daniel dgoze

💭
I may be slow to respond.
View GitHub Profile
@strsar
strsar / admin.php
Created October 7, 2021 01:40
[WP] Admin starting point after some cleanup
<?php defined('ABSPATH') or header('Location: /');
/**
* Cleanup WP admin and unwanted code...
*/
// Remove actions
remove_action('welcome_panel', 'wp_welcome_panel');
remove_action('dashboard_primary', 'wp_dashboard_primary');
remove_action('admin_color_scheme_picker', 'admin_color_scheme_picker');
@sabrina-zeidan
sabrina-zeidan / find_acf_fields_by_type.php
Last active September 13, 2021 22:26
Find all ACF image fields used on the site (including subfields) [WordPress]
//For example we need to modify all <img> tags in the templates that use ACF img fields.
//To locate them in the theme we need to know their names.
//This snippet will list the names of all ACF fields of image type used on the site, so that we'll be able to search for them in the theme files
$field_groups = acf_get_field_groups();
$all_fields = array();
foreach ($field_groups as $field_group){
$fields = acf_get_fields($field_group['key']);
$all_fields = array_merge($all_fields, $fields);
}
@carlalexander
carlalexander / expect-header-fix.php
Last active August 13, 2021 00:40
WordPress "Expect" header fix
<?php
/**
* By default, cURL sends the "Expect" header all the time which severely impacts
* performance. Instead, we'll send it if the body is larger than 1 mb like
* Guzzle does.
*/
function add_expect_header(array $arguments)
{
$arguments['headers']['expect'] = '';
@sabrina-zeidan
sabrina-zeidan / acf_get_user_fields.php
Created November 13, 2020 20:54
Get all ACF's assigned to user profile
// get all field groups that have location User Add/Edit Form
$field_groups = acf_get_field_groups(array( 'user_form' => 'edit'));
$all_fields = array();
foreach ($field_groups as $field_group){
$fields = acf_get_fields($field_group['key']);
$all_fields = array_merge($all_fields, $fields); //get all user's fields together
}
@sabrina-zeidan
sabrina-zeidan / acf_in_shortcode.php
Created October 15, 2020 16:11
ACF form inside a shortcode (buffering) otherwise broken XML sitemaps, headers already sent etc
add_shortcode( 'acf_registration', 'acf_registration' );
function acf_registration() {
$args = array(); //arguments here
ob_start();
acf_form( $args );
$registration_form = ob_get_contents();
ob_end_clean();
return $registration_form;
<?php
/**
* Delete the option setting for the default category
*
* @link https://cameronjonesweb.com.au/blog/how-to-remove-the-uncategorised-category-from-wordpress-and-woocommerce
*/
function cameronjonesweb_delete_default_category_option() {
if ( get_option( 'default_category' ) ) {
delete_option( 'default_category' );
}
<?php
function cameronjonesweb_colour_scheme() {
return array(
array(
'name' => 'White',
'slug' => 'white',
'color' => '#ffffff',
),
array(
<?php
add_filter( 'acf/register_block_type_args', 'cameronjonesweb_automatically_enqueue_block_stylesheet' );
function cameronjonesweb_automatically_enqueue_block_stylesheet( $args ) {
if ( empty( $args['enqueue_style'] ) ) {
$file = get_template_directory_uri() . '/blocks/' . ltrim( $args['name'], 'acf/' ) . '/block.css';
if ( file_exists( str_replace( get_template_directory_uri(), get_template_directory(), $file ) ) ) {
$args['enqueue_style'] = $file;
}
}
<?php
/**
* Add rewrite rule.
*
* @since 1.0.0
*
* @param array $rules Existing rewrite rules
* @return array
*/
if( ! function_exists( 'prefix_add_rewrite_rules' ) ) {
@maheshwaghmare
maheshwaghmare / custom-post-type-rewrite.php
Last active June 6, 2020 22:09
WordPress custom post type permalink rewrite structure rule for taxonomies.
<?php
/**
* WP_Dev_Rewrites initial setup
*
* @since 1.0.0
*/
if( !class_exists('WP_Dev_Rewrites') ) {
class WP_Dev_Rewrites {