Skip to content

Instantly share code, notes, and snippets.

View saltnpixels's full-sized avatar

Eric saltnpixels

View GitHub Profile
@saltnpixels
saltnpixels / WP_reverse_post_navigation
Created April 14, 2020 16:29
WP Reverse Post Navigation
//found this somewhere on the internet. Reverses the navigation.
//works well with the Post Type Order navigation here https://wordpress.org/plugins/simple-custom-post-order/
//shows the prev and next post in reverse which helps when ordering posts not by date
function the_reverse_post_navigation( $args = array() ) {
$args = wp_parse_args( $args, array(
'prev_text' => '%title',
'next_text' => '%title',
'in_same_term' => false,
@saltnpixels
saltnpixels / upload_url.php
Created January 30, 2020 00:05
WP Upload URL to Media Library
<?php
/**
* @param $url url to upload
* @param int $post_id post to attach it to
*
* Add a url to the media library and attach it to a post if wanted
* @return bool|int|string|WP_Error
*/
@saltnpixels
saltnpixels / filter_render_block.php
Created January 21, 2020 16:18
WP Render Block Filter
/**
* @param $block_content
* @param $block
*
* @return string
Surrounds block with html.
* Some blocks are too naked to work nicely like ul
*/
function surround_block( $block_content, $block ) {
if ( empty( trim( $block_content ) ) ) {
@saltnpixels
saltnpixels / Render Block Filter
Created December 10, 2019 19:04
Render_block_filter.php
function test_filter( $block_content, $block ) {
if ( empty( trim( $block_content ) ) ) {
return $block_content;
}
if ( $block['blockName'] == 'core/paragraph' ) {
return sprintf(
'<section class="block-%1$s">%2$s</section>',
sanitize_title( $block['blockName'] ),
$block_content
@saltnpixels
saltnpixels / term_checkbox_fix.php
Created May 30, 2019 15:30
Show child term checkboxes in WP properly even after selected
add_filter( 'wp_terms_checklist_args',
function ( $args ) {
$args['checked_ontop'] = false;
return $args;
} );
@saltnpixels
saltnpixels / WP_local_theme_remote_db.php
Created March 6, 2019 16:22
WordPress Workflow with remote DB on local
<?php
//Working on a WordPress theme with others can be difficult if you want to use the same database, but work locally and use git for the code.
//To do this we came up with a solution that allows working with a remote DB that everyone on the team can access, while still developing locally.
//First make sure that your wp-config file is set to use the remote db:
//set the credentials for the remote DB username and table
//change DB host to be the ip of the remote server
//Example:
@saltnpixels
saltnpixels / wp_menu_auto_post_type.php
Created July 25, 2018 18:55
WP hierarichal menu of any post type. posts are auto added, like pages can be
//hijack menu and output a whole post type in hierarchical order.
//post type must have hierarchical order capability and menu name must match post type
//add post types for this inside $post_types below
add_filter( 'wp_get_nav_menu_items', 'cpt_auto_add_menu', 10, 3 );
function cpt_auto_add_menu( $items, $menu, $args ) {
$post_types = array( 'add_post_types', 'that_you_want' );
$menu_slug = $menu->slug;
@saltnpixels
saltnpixels / gform_stripe_subscriptions.php
Created October 10, 2017 15:25
Gravity forms stripe cancel from front end
<?php
/**
* Payment subscriptions and updating billing and cancelling subscriptions takes place with these hooks
* We need the stripe customer user id for updating billing
* we need the entry id of subscription so we can cancel it.
*/
/**
* @param $entry
@saltnpixels
saltnpixels / save_upload_field_to_custom_field.php
Last active January 18, 2024 20:32
gravity form upload file to media library and use attachment ID in custom field
add_action( 'gform_after_create_post', 'gf_add_to_media_library', 10, 3 );
/**
* Save file upload fields under custom post field to the library
*
* @param $post_id The post identifier
* @param $entry The entry
* @param $form The form
*/
@saltnpixels
saltnpixels / add_post_image.php
Last active November 21, 2016 01:18
map gravity form post image to a pods field
/*--------------------------------------------------------------
# Gravity forms does not let you map a post image field in a custom field
# If you use pods and you would like to be able to map a post image to a pods image field make sure:
# the post image is not featured as that would become the post thumbnail
# add a css class tot he post image field in the form of of field_pod_field_name ( must start with field_ )
--------------------------------------------------------------*/
add_action( 'gform_after_submission', 'add_pod_images', 10, 2 );
function add_pod_images( $entry, $form ) {