Skip to content

Instantly share code, notes, and snippets.

Avatar

Boone Gorges boonebgorges

View GitHub Profile
@boonebgorges
boonebgorges / cboxol-fix-open-cloneable.php
Created Jan 27, 2021
Modify 'Open' and 'Cloneable' badge markup for Commons In A Box OpenLab
View cboxol-fix-open-cloneable.php
<?php
add_filter(
'openlab_badges_badge_links',
function( $badge_links, $group_id, $context ) {
foreach ( $badge_links as &$link ) {
if ( false !== strpos( $link, '>Open<' ) ) {
$link = str_replace( 'href="somelink"', 'href="#"', $link );
}
@boonebgorges
boonebgorges / prevent-bp-message-reply-notifications.php
Created Jul 7, 2020
Prevent BP message replies from triggering notifications
View prevent-bp-message-reply-notifications.php
<?php
remove_action( 'messages_message_sent', 'messages_notification_new_message', 10 );
add_action(
'messages_message_sent',
function( $message ) {
$thread_messages = BP_Messages_Thread::get_messages( $message->thread_id );
if ( 1 === count( $thread_messages ) && $message->id === $thread_messages[0]->id ) {
messages_notification_new_message( $message );
}
@boonebgorges
boonebgorges / bp-date-field-select-today.js
Created Oct 23, 2019
Default to the current date for a BP date profile field
View bp-date-field-select-today.js
$(document).ready(function(){
var $day_field = $('#field_511_day');
var $month_field = $('#field_511_month');
var $year_field = $('#field_511_year');
if ( ! $day_field.val().length && ! $month_field.val().length && ! $year_field.val().length ) {
var dateObj = new Date();
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var monthNumber = months[ dateObj.getMonth() ];
@boonebgorges
boonebgorges / run-bp-50-upgrades.php
Created Oct 22, 2019
Run BP 5.0 upgrades if they don't happen automatically
View run-bp-50-upgrades.php
<?php
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
require_once( buddypress()->plugin_dir . '/bp-core/admin/bp-core-admin-schema.php' );
bp_update_to_5_0();
@boonebgorges
boonebgorges / bp-docs-attachment-search.php
Created Dec 5, 2017
Enable BuddyPress Docs search to match based on attachment filenames
View bp-docs-attachment-search.php
<?php
/**
* This is not needed for BP Docs 2.1+. See https://github.com/boonebgorges/buddypress-docs/issues/592
*/
add_filter( 'bp_docs_pre_query_args', function( $args, BP_Docs_Query $query ) {
// For attachments, search separately and then append to WP's default search handling.
if ( bp_docs_enable_attachments() ) {
add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
@boonebgorges
boonebgorges / bbp-bp-notification-formatter.php
Created Feb 9, 2017
Networkwide BP notification formatting for bbPress non-network-activated
View bbp-bp-notification-formatter.php
<?php
/*
Plugin name: bbPress BP Notification Formatter
Description: A REST API endpoint for WP multisite installations that need to format bbPress-related BP notifications on secondary sites.
Version: 1.0
*/
/**
* Load the plugin.
@boonebgorges
boonebgorges / populate.php
Created Sep 21, 2016
populate comments and posts in bp-activity
View populate.php
<?php
$site_id = 7177;
switch_to_blog( $site_id );
$links = get_bookmarks( array(
'category_name' => 'Course Blogs',
) );
$urls = wp_list_pluck( $links, 'link_url' );
View comment.php
<?php
$comment = get_comment( 12345 );
$post_id = $comment->comment_post_ID();
$post = get_post( $post_id ); // Let's say post_title = Foo
do_action( 'comment_goodies', $comment, $post );
var_dump( $post );
@boonebgorges
boonebgorges / LaTeX.js
Created Sep 9, 2016
React component for rendering a chunk of LaTeX to be processed by MathJax
View LaTeX.js
import React, { Component } from 'react';
export default class LaTeX extends Component {
componentDidMount() {
this.updateTeX()
}
componentDidUpdate() {
this.updateTeX()
}
@boonebgorges
boonebgorges / FormattedProblem.js
Created Sep 9, 2016
React component for content that may contain LaTeX chunks
View FormattedProblem.js
import React from 'react';
import LaTeX from './LaTeX'
const FormattedProblem = React.createClass( {
getDefaultProps: function() {
return {
isVisible: true
}
},