Skip to content

Instantly share code, notes, and snippets.

View dcooney's full-sized avatar

Darren Cooney dcooney

View GitHub Profile
<?php
// File: mr-wc-integrator-plugin/btob/dashboard-b2b-widget.php
//
// Replace line #15 in the `view()` function containing raw HTML.
// <h1>Account Summary</h1>
// with the following PHP hook.
echo wp_kses_post( apply_filters( 'mr_b2b_widget_title', '<h1>Account Summary</h1>' ) );
@dcooney
dcooney / functions.js
Last active April 28, 2023 18:18
Gutenberg Functions and Hooks
// Select a block.
wp.data.dispatch("core/block-editor").selectBlock(clientId);
// Update block attributes.
wp.data.dispatch("core/block-editor").updateBlockAttributes(clientId, { content: "<p>this is the new content</p>"});
// Replace a block.
wp.data.dispatch("core/block-editor").replaceBlock(
clientId,
wp.blocks.createBlock("core/image", {
@dcooney
dcooney / functions.php
Last active March 2, 2023 16:01
Order Ajax Load More results by custom meta_query clause.
<?php
// @see https://connekthq.com/plugins/ajax-load-more/docs/filter-hooks/#alm_query_args
function my_filter_args( $args, $id ){
// [ajax_load_more id="my_alm_id"]
// Custom meta query clause.
$datum_clause = [
'key' => 'datum',
'value' => date("Ymd"),
'compare' => '>=' ,
@dcooney
dcooney / media-library.js
Last active March 1, 2023 14:08
Add Taxonomy Filters to WordPress Media Library Modal
addEventListener('DOMContentLoaded', () => {
const taxonomies = window.media_taxonomies || {}; // Pluck the taxonomies from the localized script.
const AttachmentsBrowser = wp.media.view.AttachmentsBrowser;
const AttachmentFilters = wp.media.view.AttachmentFilters;
const mediaFilterClasses = {}; // Filter class storage.
if (!taxonomies?.length || !AttachmentsBrowser || !AttachmentFilters) {
// Bail if filters or classes don't exist.
return;
}
@dcooney
dcooney / default-value-params.php
Last active February 3, 2023 19:05
Filter files
<?php
/**
* Parse the Default Values set inside the plugin.
*
* @since 1.13.0
* @package ALMFilters
*/
// Only run if Filters are present.
if ( $alm_filters_array ) {
<!-- wp:paragraph -->
<p>Integer posuere erat a ante venenatis dadpibus posuere velit aliquet. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec ullamcorper nulla non metus auctor fringilla. Sed posuere consectetur est at lobortis. Etiam porta sem malesuada magna mollis euismod.</p>
<!-- /wp:paragraph -->
<!-- wp:acf/cta {"name":"acf/cta","data":{"theme":"blue-light","_theme":"field_6385060c403eb","image":109,"_image":"field_6398c610f4064","alignment":"right","_alignment":"field_6385063c403ec","block_theme":"blue","_block_theme":"field_63a2018e311b9"},"mode":"preview"} -->
<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->
<!-- wp:heading -->
<?php
$categories = get_the_category();
if ( ! empty( $categories ) ) {
$current_cat = esc_html( $categories[0]->name );
}
echo do_shortcode('[ajax_load_more single_post="true" single_post_id="'. get_the_ID() .'" single_post_target=".type-post" post_type="post" single_post_order="query" category="' . $current_cat . '" pause_override="true"]'); ?>
OR
@dcooney
dcooney / default.php
Last active September 29, 2022 18:29
ALM GeneratePress Homepage
<?php
/**
* The template for displaying posts within the loop.
*
* @package GeneratePress
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
<?php
// id: team_filter, key: category
add_filter('alm_filters_team_filter_category', function(){
// Define empty array
$values = [];
// Get all categories
$args = array(
'order' => 'ASC',
@dcooney
dcooney / update.js
Last active December 10, 2021 18:04
/* Setup autocomplete.js sources */
var sources = [];
var suggestion_template = wp.template( config[ 'tmpl_suggestion' ] );
var sources = [{
source: algolia.autocomplete.sources.hits( client.initIndex( config[ 'index_name' ] ), {
hitsPerPage: config[ 'max_suggestions' ],
attributesToSnippet: [
'content:10'
],
highlightPreTag: '__ais-highlight__',