Skip to content

Instantly share code, notes, and snippets.

View rmorse's full-sized avatar

Ross Morsali rmorse

View GitHub Profile
@rmorse
rmorse / sf-pro-filter-input-object.php
Last active February 6, 2024 23:01
Search & Filter Pro - Filter Input Object
<?php
function filter_input_object($input_object, $sfid)
{
//ensure we are only filtering the correct field name - in this case the field we want to filter has the name `_sfm_colours`
//we also want to make sure its a `select` input type we're filtering
if(($input_object['name']!='_sfm_colours')||($input_object['type']!='select'))
{
return $input_object;
}
<?php
/**
* Output an ACF post relationship field type using a shortcode:
* [ca_acf_relationship_field field="field_name"]
* You can also pass `post_id` as an attribute
*
* Works with Post Object and Relationship fields, when the return
* format is both post object and post ID
*
* This code assumes you are copying this into functions.php of
@rmorse
rmorse / sf-pro-active-query-search-term.php
Last active January 7, 2024 03:09
Search & Filter Pro - Active Query - Get the search term
<?php
//Get the search term
//replace `1526` with the ID of your search form
global $searchandfilter;
$sf_current_query = $searchandfilter->get(1526)->current_query();
echo $sf_current_query->get_search_term();
?>
@rmorse
rmorse / filter-sf-pro-query.php
Last active January 7, 2024 03:09 — forked from dryan1144/filter-sf-pro-query.php
This modifies the $query_args object (rather than replacing it, which removes all the settings that are already in the object created by S&F).
<?php
function hck_filter_taxonomy_archives( $query_args, $sfid ) {
if( $sfid == 509 ) {
$query_args['post_type'] = 'articles';
}
return $query_args;
}
@rmorse
rmorse / add-custom-editor-colors.php
Last active January 7, 2024 02:58
Add custom colors to the WordPress editor via `add_theme_support`
<?php
/**
* Add custom colors to the WordPress editor via `add_theme_support`
*
* This takes the existing colours (if your theme or a plugin has set any)
* and combines them with a new set of colours defined in the function
*
* New colours should be visible in the various color pickers found in
* WordPress admin
*/
@rmorse
rmorse / react-router-dom-v.6.02.prompt.blocker.js
Last active December 21, 2023 04:22
Adds back in `useBlocker` and `usePrompt` to `react-router-dom` version 6.0.2 (they removed after the 6.0.0 beta, temporarily)
/**
* These hooks re-implement the now removed useBlocker and usePrompt hooks in 'react-router-dom'.
* Thanks for the idea @piecyk https://github.com/remix-run/react-router/issues/8139#issuecomment-953816315
* Source: https://github.com/remix-run/react-router/commit/256cad70d3fd4500b1abcfea66f3ee622fb90874#diff-b60f1a2d4276b2a605c05e19816634111de2e8a4186fe9dd7de8e344b65ed4d3L344-L381
*/
import { useContext, useEffect, useCallback } from 'react';
import { UNSAFE_NavigationContext as NavigationContext } from 'react-router-dom';
/**
* Blocks all navigation attempts. This is useful for preventing the page from
* changing until some condition is met, like saving form data.
/**
* WordPress dependencies
*/
import { createReduxStore, register, controls } from '@wordpress/data';
import apiFetch from '@wordpress/api-fetch';
import { addQueryArgs } from '@wordpress/url';
export const STORE_NAME = 'search-filter/settings';
const getUniqueKey = ( args ) => {
@rmorse
rmorse / block-edit-unique-id.js
Last active February 20, 2023 05:36
Generate unique IDs (as attributes) for blocks - ensure that duplicating a block will generate a new ID
/**
* WordPress dependencies
*/
import { useSelect, dispatch } from '@wordpress/data';
import { useLayoutEffect } from '@wordpress/element';
import './store';
const storeName = 'plugin-name/block';
function Edit( { attributes, setAttributes, clientId } ) {
// Get the stored attribute field ID.
@rmorse
rmorse / sf-divi-ajax-blog.js
Created March 23, 2017 18:27
Search & Filter Pro - Divi Theme & Ajax - Blog Module (Grid)
//this code does the re-layout work needed when using S&F with the blog module, and when S&F Ajax is enabled
(function ( $ ) {
"use strict";
$(document).on("sf:ajaxfinish", ".searchandfilter", function(){
console.log("ajax complete");
var grids = document.getElementsByClassName('et_pb_blog_grid');
salvattore['register_grid'](grids[0]);
});
}(jQuery));
@rmorse
rmorse / sf-pro-ajax-events.js
Last active December 8, 2022 22:16
Search & Filter Pro - Ajax Events
//detects the start of an ajax request being made
$(document).on("sf:ajaxstart", ".searchandfilter", function(){
console.log("ajax start");
});
//detects when the ajax request has finished and the content has been updated
// - add scripts that apply to your results here
$(document).on("sf:ajaxfinish", ".searchandfilter", function(){
console.log("ajax complete");
//so load your lightbox or JS scripts here again