Skip to content

Instantly share code, notes, and snippets.

View renatonascalves's full-sized avatar
🇧🇷

Renato Alves renatonascalves

🇧🇷
View GitHub Profile
@imath
imath / bp-example-block.php
Created July 31, 2019 05:16
BuddyPress example block: Put this two file into a `bp-example-block` folder before dropping it into `/wp-content/plugins/`
<?php
/**
* Plugin Name: BP Example Block
* Plugin URI: https://buddypress.org/
* Description: Example of BuddyPress block.
* Author: The BuddyPress Community
* Author URI: https://buddypress.org/
* Version: 1.0.0
* Text Domain: buddypress
* Domain Path: /languages/
@imath
imath / bp-custom.php
Created July 12, 2019 14:17
Registering REST Fields for the BP REST API
<?php
// Registers a REST field for the Activity Endpoints.
function example_register_activity_rest_field() {
bp_rest_register_field(
'activity', // Id of the BuddyPress component the REST field is about
'example_field', // Used into the REST response/request
array(
'get_callback' => 'example_get_rest_field_callback', // The function to use to get the value of the REST Field
'update_callback' => 'example_update_rest_field_callback', // The function to use to update the value of the REST Field
@mikowl
mikowl / oneliners.js
Last active March 28, 2024 20:52
👑 Awesome one-liners you might find useful while coding.
// Inspired by https://twitter.com/coderitual/status/1112297299307384833 and https://tapajyoti-bose.medium.com/7-killer-one-liners-in-javascript-33db6798f5bf
// Remove any duplicates from an array of primitives.
const unique = [...new Set(arr)]
// Sleep in async functions. Use: await sleep(2000).
const sleep = (ms) => (new Promise(resolve => setTimeout(resolve, ms)));
// or
const sleep = util.promisify(setTimeout);
<?php
/**
* Filters wp_remote_get() to:
* 1. Return a value from the cache when it's available.
* 2. Write a value to the cache when it's been fetched.
*
* Requires the WP_IMPORT_CACHE constant to be set to a writable directory.
*/
if ( defined( 'WP_CLI' ) && WP_CLI ) {
@westonruter
westonruter / shutdown-handler.php
Last active March 22, 2019 18:48
Disable WSOD detection on WordPress 5.1 so that fatal errors during development don't constantly cause plugins to suspend
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName
/*
* Plugin Name: Non-Handling Shutdown Handler
* Description: Disable WSOD protection so that plugins will not auto-suspend during development while errors often occur.
* Plugin URI: https://gist.github.com/westonruter/583a42392a0b8684dc268b40d44eb7f1
* Plugin Author: Weston Ruter
*/
/**
@DavidKuennen
DavidKuennen / minimal-analytics-snippet.js
Last active March 28, 2024 01:45
Minimal Analytics Snippet
(function (context, trackingId, options) {
const history = context.history;
const doc = document;
const nav = navigator || {};
const storage = localStorage;
const encode = encodeURIComponent;
const pushState = history.pushState;
const typeException = 'exception';
const generateId = () => Math.random().toString(36);
const getId = () => {
@dcavins
dcavins / compose.php
Last active September 17, 2022 08:23
Limit access to the private message form if the user has sent too many messages today.
<?php
/**
* BuddyPress - Members Single Messages Compose
*
* @package BuddyPress
* @subpackage bp-legacy
*/
?>
@bjornjohansen
bjornjohansen / auth.php
Last active October 16, 2020 12:33
Changes the expiration of the WordPress authentication cookie to 365 days if the user ticks the “Remember Me” checkbox.
<?php
/**
* Authentication customizations.
*
* @package BJ\Auth
*/
/**
* Filters the duration of the authentication cookie expiration period.
*
@dcavins
dcavins / add-roles-to-avatar-classes.php
Created December 14, 2017 16:02
Add the user's roles to the classes applied to a BuddyPress avatar.
<?php
add_filter( 'bp_get_member_avatar', 'my_add_user_level_to_avatars', 10, 2 );
/**
* @param string $value Formatted HTML <img> element, or raw avatar URL based on $html arg.
* @param array $r Array of parsed arguments. See {@link bp_get_member_avatar()}.
*/
function my_add_user_level_to_avatars( $value, $r ) {
global $members_template;
// The args have already been parsed in bp_get_member_avatar. We'll use them except for the css class.
@westonruter
westonruter / wp-42573.php
Last active September 21, 2023 13:41
WP Trac #42573: Fix for theme template caching. https://core.trac.wordpress.org/ticket/42573
<?php
/**
* Plugin name: WP Trac #42573: Fix for theme template file caching.
* Description: Flush the theme file cache each time the admin screens are loaded which uses the file list.
* Plugin URI: https://core.trac.wordpress.org/ticket/42573
* Author: Weston Ruter, XWP.
* Author URI: https://weston.ruter.net
*/
function wp_42573_fix_template_caching( WP_Screen $current_screen ) {