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
@jenssogaard
jenssogaard / ACF Gutenberg get block fields
Created February 22, 2019 21:08
Helper class for ACF and Gutenberg. Get blocks fields by passing block_id and post_id.
<?php
namespace JensSogaard;
class BlockHelper
{
/**
* Gets ACF fields for a specific block on a given post
* @author Jens Soegaard <[email protected]>
*/
public function getBlockFromPage(string $block_id, int $post_id)
@cameronjonesweb
cameronjonesweb / functions.php
Last active June 26, 2023 19:48
Takes custom classes out of the list item and adds them to the anchor element in WordPress menus. Perfect for font icons
<?php
add_filter( 'nav_menu_link_attributes','cameronjonesweb_move_custom_menu_item_class_to_anchor_element', 10, 4 );
add_filter( 'nav_menu_css_class', 'cameronjonesweb_remove_custom_menu_item_class_from_li_element', 10, 4 );
/**
* Get the custom item menu classes and add them to the anchor element
*
* @link https://cameronjonesweb.com.au/blog/how-to-move-the-custom-menu-item-classes-to-the-anchor-element/
* @param array $atts The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored.
@hlashbrooke
hlashbrooke / functions.php
Created October 12, 2018 12:52
Filtering items available in media library - taken from v1 of the WooCommerce Product Vendors extension.
/**
* Only show current vendor's media in the media library
* @param array $request Default request arguments
* @return array Modified request arguments
*/
add_filter( 'request', 'pv_restrict_media_library', 10, 1 );
function pv_restrict_media_library( $request = array() ) {
if( ! is_admin() ) {
return $request;
@Neoglyph
Neoglyph / rgb2cmyk.php
Last active November 17, 2023 21:57
Convert RGB to CMYK in PHP with Imagick
<?php
$iccProfile = '../path_to_icc/Profile.icc';
$image = new Imagick();
$image->clear();
$image->readImage($imagePath);
if ($image->getImageColorspace() == Imagick::COLORSPACE_CMYK) {
return;
}
$iccCmyk = file_get_contents($iccProfile);
@cameronjonesweb
cameronjonesweb / add-field-type-to-class.php
Created October 4, 2018 06:17
Adds a class that defines the type of field to the <li> element in Gravity Forms
<?php
add_filter( 'gform_field_css_class', 'cameronjonesweb_add_field_type_to_class', 10, 3 );
/**
* Adds a class that defines the type of field to the li element in Gravity Forms
*
* @param string $css_class The existing CSS classes.
* @param GF_Field $field The field object.
* @param array $form The form object.
* @return string
@cameronjonesweb
cameronjonesweb / create-index-php.sh
Last active October 7, 2020 23:40
Recursively creates an index.php file in all subfolders that don't include an index.php file
shopt -s globstar
for i in **; do
if [ -d "$i" ]; then
# update this line to include directories to ignore
if [[ "${i##/*}" != *"node_modules"* && "${i##/*}" != *"bower_components"* ]]; then
if [ ! -f "${i##/*}/index.php" ]; then
printf "Creating index file in %s\n" "${i##/*}"
printf "<?php\n// Silence is golden." > ${i##/*}/index.php
fi
fi
@koskinenaa
koskinenaa / wordpress-filter-custom-post-type-by-custom-taxonomy.php
Last active June 6, 2020 21:36
Add taxonomy to a WordPress post type as a filter. See https://gist.github.com/koskinenaa/86fd3acd75959e9aa0635ce00934e26c for multiple post types and taxonomies
public function filter_post_type_by_taxonomy( $post_type, $which ) {
if ( 'my_post_type' == $post_type ) {
$taxonomy = get_taxonomy( 'my_taxonomy' );
if ( $taxonomy ) {
// Retrieve taxonomy terms
$terms = get_terms( $taxonomy->name );
// Display filter HTML
echo "<select name='{$taxonomy->name}' id='{$taxonomy->name}' class='postform'>";
echo '<option value="">' . sprintf( esc_html__( 'Show All %s', 'text-domain' ), $taxonomy->labels->name ) . '</option>';
@maheshwaghmare
maheshwaghmare / create-user.php
Last active July 15, 2021 13:20
Create WordPress user though FTP.
<?php
/**
* Create new user.
*
* @todo remove `prefix_` with your own slug.
*
* @since 1.0.0
*/
if( ! function_exists( 'prefix_add_new_user' ) ) :
function prefix_add_new_user() {
@maheshwaghmare
maheshwaghmare / bulk-post-update.php
Created July 3, 2018 11:34
Update bulk post using wp_update_post().
<?php
$ids = array(18821,18811,18817,18805,18807,18777,18774,18775);
foreach ($ids as $key => $id) {
$my_post = array(
'ID' => $id,
'tax_input' => array(
'<taxonomy-name>' => array( `<tax-id1>`, `<tax-id2>`, `<tax-id-n` ),
),
<?php
/*
Plugin Name: Enable/Disable plugins when doing local dev
Plugin URL: https://gist.github.com/pbiron/52bb63042cf220256ece89bc07fb57b0
Description: If the WP_LOCAL_DEV constant is true, enables/disables plugins that you specify
Version: 0.1
License: GPL version 2 or any later version
Author: Paul V. Biron/Sparrow Hawk Computing
Author URI: https://sparrowhawkcomputing.com
*/