Skip to content

Instantly share code, notes, and snippets.

View renatonascalves's full-sized avatar
🇧🇷

Renato Alves renatonascalves

🇧🇷
View GitHub Profile
@khromov
khromov / gist:740578d08abd86dd093e
Last active July 26, 2016 12:08
WordPress CRON

So how does WP CRON work? Whenever an admin user loads WordPress, WP checks whether any CRON jobs need to run (they are scheduled by timestamp), and if they do, WordPress makes a secondary request to itself using the spawn_cron() function. This secondary page load will load /wp-cron.php, which in turn loads another full copy of WP.

Now we're in the secondary CRON request, you can see this as being run asynchronously with the request that spawned it - spawn_cron() uses a cute little trick and sets a very low timeout value when calling the secondary CRON request, the result being both requests run in parallel, see here: https://github.com/WordPress/WordPress/blob/2f3e567f44e7bc335b6795713ae970b4f37117cd/wp-includes/cron.php#L297

@bjornjohansen
bjornjohansen / moderate_comments.sh
Created October 2, 2016 12:12
Moderate comments in a WordPress installation with WP-CLI
#!/bin/bash
# Copyright © 2016 Bjørn Johansen
# This work is free. You can redistribute it and/or modify it under the
# terms of the Do What The Fuck You Want To Public License, Version 2,
# as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
# Check if WP-CLI is available
if ! hash wp 2>/dev/null; then
echo "WP-CLI is not available"
exit
@bjornjohansen
bjornjohansen / test-password-permutations.php
Last active February 2, 2017 11:09
Test a bunch of permutations of the password when logging into WordPress.
<?php
/**
* Test a bunch of permutations of the password when logging into WordPress.
*
* Drop this file in your mu-plugins directory.
* Inspired by Facebook: https://twitter.com/gcpascutto/status/821755332984717314/photo/1
* Works with any properly coded hashing pluggables, like Roots’ WP Password bcrypt.
*
* @author bjornjohansen
* @version 0.1.4
@khromov
khromov / deploy.php
Created June 8, 2016 07:28
Deploy WordPress with Deployer on EasyEngine
<?php
require 'recipe/common.php';
// Set configurations
set('repository', 'ssh://gogs@git.server.com:22/user/repo.git');
set('shared_files', ['public/wp-config.php']);
set('shared_dirs', ['public/wp-content/uploads']);
set('writable_dirs', []);
set('keep_releases', 10);
set('composer_command', 'composer');
@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
*/
/**
@bekarice
bekarice / wc-hide-non-free-shipping.php
Created September 22, 2016 04:11
Show only free / $0 shipping methods when available
<?php // only copy if needed
/**
* Hides any non-free shipping methods if free shipping is available
*
* @param array $rates array of \WC_Shipping_Rate objects that apply to the cart
* @return array - the updated available rates
*/
function sww_wc_hide_non_free_shipping( $rates ) {
@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/
<?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 ) {
@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.
@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.
*