Skip to content

Instantly share code, notes, and snippets.

@ville6000
ville6000 / mmarmy-org-record-breakdown.js
Created June 5, 2018 13:43
MMArmy record breakdown
var record = {};
jQuery('.record').find('tr').each(function(idx, el) {
var row = jQuery(el);
var key = (row.find('td:first-child').hasClass('win') || row.find('td:first-child').hasClass('winTitle')) ? 'wins' : 'losses';
var result = row.find('td').eq(5).text();
var result_key = 'ko';
if (idx > 0) {
if (result.indexOf('Decision') >= 0) {
result_key = 'decision';
@ville6000
ville6000 / mmarmy-org-record.js
Created May 24, 2018 12:19
MMArmy record by organization
var record = {};
jQuery('.record').find('tr').each(function(idx, el) {
var row = jQuery(el);
var key = (row.find('td:first-child').hasClass('win') || row.find('td:first-child').hasClass('winTitle')) ? 'wins' : 'losses';
var organization = row.find('td').eq(7).text();
if (idx > 0) {
if (typeof record[organization] === 'undefined') {
record[organization] = {
wins: 0,
@ville6000
ville6000 / load-wp-from-outside.php
Created April 24, 2018 18:55
Load WordPress + Polylang from outside
<?php
ini_set( 'memory_limit', '512M' );
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['HTTP_HOST'] = 'siteurl.com';
define( 'USE_THEMES', false );
if ( file_exists( getenv( 'HOME' ) . '/public_html/wp-load.php' ) ) {
require_once getenv( 'HOME' ) . '/public_html/wp-load.php';
@ville6000
ville6000 / functions.php
Created January 23, 2017 12:31
Set custom Yoast SEO og:image
<?php
function company_banner_to_og_image( $image ) {
global $post;
if ( is_singular( 'company' ) ) {
$image_sizes = get_field( 'banner', $post->ID );
$image = $image_sizes['sizes']['large'];
}
@ville6000
ville6000 / functions.php
Last active January 19, 2017 07:56
Populate ACF select field's choices dynamically
<?php
function acf_load_color_scheme_field_options( $field ) {
$field['choices'] = array();
$options = fetch_my_choises(); // Fetch your choises from somewhere
if ( is_array( $options ) ) {
foreach ( $options as $option ) {
$field['choices'][ $option ] = $option;
@ville6000
ville6000 / functions.php
Created October 20, 2016 13:23
Display all tag cloud tags in the same font size
<?php
function my_theme_widget_tag_cloud_args( $args ) {
$args['largest'] = 1;
$args['smallest'] = 1;
$args['unit'] = 'em';
return $args;
}
@ville6000
ville6000 / index.php
Created May 23, 2016 07:51
Get thumbnail with attachment ID
<?php
$image_id = get_attachment_id_from_url( $image_url );
$thumb = wp_get_attachment_image_src( $image_id, 'thumbnail' );
echo $thumb[0];
@ville6000
ville6000 / functions.php
Created May 23, 2016 07:42
Get Attachment ID from Image URL
<?php
function get_attachment_id_from_url( $image_url ) {
global $wpdb;
$attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url ) );
return $attachment[0];
}
@ville6000
ville6000 / functions.php
Created April 22, 2016 08:24
Remove comment menu
<?php
function remove_comment_menu(){
remove_menu_page( 'edit-comments.php' );
}
add_action( 'admin_menu', 'remove_comment_menu' );
@ville6000
ville6000 / index.php
Last active April 6, 2016 06:43
Transients
<?php
function get_my_expensive_data() {
$cache_key = 'my-cache-key';
$transient = get_transient( $cache_key );
if ( $transient ) {
return $transient;
} else {
$data = wp_remote_get( 'http://your-service.com' );