Skip to content

Instantly share code, notes, and snippets.

View kellenmace's full-sized avatar

Kellen Mace kellenmace

View GitHub Profile
@kellenmace
kellenmace / remove-duplicate-objects-from-array.php
Created February 2, 2019 16:21
If you have an indexed array of objects, and you want to remove duplicates by comparing a specific property in each object, a function like the remove_duplicate_models() one below can be used.
<?php
class Car {
private $model;
public function __construct( $model ) {
$this->model = $model;
}
public function get_model() {
@kellenmace
kellenmace / get-all-super-admins.php
Created January 7, 2019 18:44
Get all Super Admin users in WordPress
<?php
/**
* Get all Super Admin users on the current site.
*
* @return array WP_User objects.
*/
function get_all_superadmin_users() {
return get_users([
'login__in' => get_super_admins()
@kellenmace
kellenmace / get-all-non-super-admins.php
Created January 7, 2019 18:42
Get all non-Super Admin users in WordPress
<?php
/**
* Get all non-Super Admin users on the current site.
*
* @return array WP_User objects.
*/
function get_all_non_superadmin_users() {
return get_users([
'login__not_in' => get_super_admins()
{
1 => [
'en-us' => [
'name' => 'Puff Pastry',
'description' => 'Sign up for Puff Pastry news...'
],
'fr-ca' => [
'name' => {French translation},
'description' => {French transalation}
]
@kellenmace
kellenmace / forecast-expand-row-tampermonkey-script.js
Created October 4, 2018 20:49
Forecast Expand Row Tampermonkey Script
// ==UserScript==
// @name Expand Forecast Row
// @version 1.0
// @description Expand Forecast Row
// @author Kellen Mace
// @match https://forecastapp.com/485680/schedule/team*
// @grant none
// ==/UserScript==
(function(document) {
@kellenmace
kellenmace / php-sandbox-tampermonkey-script.js
Created October 4, 2018 20:47
sandbox.onlinephpfunctions.com Tampermonkey Script
// ==UserScript==
// @name PHP Sandbox
// @version 0.1
// @description Customize PHP Sandbox styles
// @author Kellen Mace
// @match http://sandbox.onlinephpfunctions.com/
// @grant none
// ==/UserScript==
(function() {
@kellenmace
kellenmace / get-template-part-path.php
Created September 28, 2018 11:12
WordPress - get template part path
<?php
/**
* Get template part path. This function is identical to WP's
* get_template_part(), except that it doesn't load the template -
* just returns it so that it can be required elsewhere and have
* access to variables in the local scope.
*
* Example usage:
* $template_data = 'make this variable available in template part';
<?php
function test_get_beaver_builder_module_list() {
$bb_module_list = new KM_Beaver_Builder_Module_List();
// Get a list of the BB modules on the current page.
$current_page_modules_list = $bb_module_list->get();
// Get a list of the BB modules on the page with a post ID of '123'.
$page_123_modules_list = $bb_module_list->get( 123 );
@kellenmace
kellenmace / get-beaver-builder-modules-on-page.php
Last active October 21, 2023 04:17
Get a list of all the Beaver Builder modules on a page
<?php
/**
* Class for getting a list of Beaver Builder modules.
*/
class KM_Beaver_Builder_Module_List {
/**
* Get the list of Beaver Builder modules.
*
* @param int $post_id The post ID. Default is the current post being
<?php
$projects = wds_get_projects();
// ...do some work...
$active_projects = array_filter( $projects, function( $project ) {
return 'active' === $project['status'];
});