Skip to content

Instantly share code, notes, and snippets.

View danielbachhuber's full-sized avatar

Daniel Bachhuber danielbachhuber

View GitHub Profile
@danielbachhuber
danielbachhuber / term-link-id.php
Created April 24, 2018 22:17
Use term ids for tag links
@danielbachhuber
danielbachhuber / term-permissions.md
Last active April 24, 2018 06:40
Review of UI-based permissions based on WordPress user role

Tags

Role Assign Tags Create Modify Delete
Contributor Y Y N N
Author Y Y N N
Editor Y Y Y Y

Categories

@danielbachhuber
danielbachhuber / http-to-https.php
Created March 28, 2018 19:45
Update a specific site from 'http://' to 'https://'.
<?php
/**
* Update a specific site from 'http://' to 'https://'.
*
* Only touches the 'home' and 'siteurl' options.
* Depending on plugins, etc., you may need to update other options too.
*
* Run on WordPress multisite with:
*
* wp site list --field=url | xargs -I % wp eval-file http-to-https.php --url=%
<?php
/**
* Strips out unnecessary testsuites data from PHPUnit test results
*
* Run with `wp eval-file cleanup-results-key.php`
*/
global $wpdb;
$post_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE post_type='result'" );
foreach( $post_ids as $h => $post_id ) {
<?php
list( $log_file ) = $args;
if ( ! is_file( $log_file ) ) {
WP_CLI::error( 'Invalid log file.' );
}
$contents = file_get_contents( $log_file );
$bits = explode( 'Running: plugin install', $contents );
plugin classic_percent_diff gutenberg_percent_diff gallery_link
contact-form-7 0% 0% http://gutensnaps.handbuilt.co/index.php?plugin_name=contact-form-7
wordpress-seo 2.923% 0.82% http://gutensnaps.handbuilt.co/index.php?plugin_name=wordpress-seo
akismet 0% 0% http://gutensnaps.handbuilt.co/index.php?plugin_name=akismet
jetpack 0% 0% http://gutensnaps.handbuilt.co/index.php?plugin_name=jetpack
wordpress-importer 0% 0% http://gutensnaps.handbuilt.co/index.php?plugin_name=wordpress-importer
all-in-one-seo-pack 4.657% 0.72% http://gutensnaps.handbuilt.co/index.php?plugin_name=all-in-one-seo-pack
google-sitemap-generator 0% 0% http://gutensnaps.handbuilt.co/index.php?plugin_name=google-sitemap-generator
limit-login-attempts 0% 0% http://gutensnaps.handbuilt.co/index.php?plugin_name=limit-login-attempts
tinymce-advanced 0.862% 0% http://gutensnaps.handbuilt.co/index.php?plugin_name=tinymce-advanced
@danielbachhuber
danielbachhuber / 248-plugins.log
Last active January 10, 2018 12:43
248 plugins analyzed with gutensnaps.php
Success: Plugin already deactivated.
Running: plugin install contact-form-7
Taking before screenshots...
Running: plugin activate contact-form-7
Installed and activated Contact Form 7 (4.9.2)
-> [Contact Form 7](https://wordpress.org/plugins/contact-form-7/)
Taking after screenshots...
Running: plugin deactivate contact-form-7
Running: plugin delete contact-form-7
<?php
use WP_CLI\Utils;
class GutenSnaps {
/**
* Plugin to test.
*
* @var string
<?php
/**
* After creating the necessary table, run with `wp eval-file plugin-stats.php`
*/
use WP_CLI\Utils;
global $wpdb;
$original_request_url = 'https://wordpress.org/plugins/wp-json/plugins/v1/query-plugins?s=&posts_per_page=100';
@danielbachhuber
danielbachhuber / bylines-register-user.php
Created July 28, 2017 14:26
Create a byline when a new user is created
<?php
/**
* Create a byline when a new user is created.
*
* @see https://bylines.io/docs/create-new-byline-automatically-user/
*/
add_action( 'user_register', function( $user_id ) {
\Bylines\Objects\Byline::create_from_user( $user_id );
});