Skip to content

Instantly share code, notes, and snippets.

View annalinneajohansson's full-sized avatar
🐱

Anna annalinneajohansson

🐱
  • Frontwalker Group AB
  • Sweden
  • 04:49 (UTC +02:00)
View GitHub Profile
@annalinneajohansson
annalinneajohansson / .htaccess
Last active November 18, 2019 09:55
# Attempt to load files from production if they're not in our local version. Adapted from: http://stevegrunwell.com/blog/keeping-wordpress-under-version-control-with-git
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^local.site\.com$
RewriteRule ^wp-content/uploads/(.*)$ https://production.site.com/wp-content/uploads/$1 [NC,L]
<?php
/**
* Add "first" and "last" CSS classes to dynamic sidebar widgets. Also adds numeric index class for each widget (widget-1, widget-2, etc.)
*/
function hip_widget_first_last_classes( $params ) {
global $my_widget_num; // Global a counter array
$this_id = $params[0]['id']; // Get the id for the current sidebar we're processing
$arr_registered_widgets = wp_get_sidebars_widgets(); // Get an array of ALL registered widgets
@annalinneajohansson
annalinneajohansson / WP_Widget.php
Created October 29, 2015 15:20
Base for WP_Widget
<?php
class My_Widget extends WP_Widget {
public function __construct() {
$widget_ops = array(
'classname' => 'my-widget',
'description' => __( 'My Widget description', 'textdomain' ),
);
$this->WP_Widget( 'My_Widget', __( 'My Widget title', 'textdomain' ), $widget_ops );
}
foreach ( $product_post_ids as $id ) {
$product = wc_get_product( $id );
$product->set_stock_status( 'instock' );
$product->set_manage_stock( 0 );
$product->save();
}
@annalinneajohansson
annalinneajohansson / order_by_multiple_meta_values.php
Last active January 17, 2018 14:40
Solution to order posts by two different meta values (the same way ORDER val1, val2 would with SQL) http://wordpress.stackexchange.com/a/67391/5045
<?php
/*
* Solution to order first by date, then by start time (both are meta values)
* http://wordpress.stackexchange.com/a/67391/5045
* */
add_action( 'pre_get_posts', 'pre_get_posts_programpunkter' );
function pre_get_posts_programpunkter( $query ) {
if( !is_admin() && is_post_type_archive( 'programpunkt' ) && $query->is_main_query() ) {
@annalinneajohansson
annalinneajohansson / dequeue_paupress_scripts.php
Last active February 9, 2017 17:14
Dequeue #PauPress plugin scripts on all admin pages besides the ones where they are actually needed.
<?php
add_action( 'wp_print_scripts', 'dequeue_paupress_scripts', 99999 );
function dequeue_paupress_scripts() {
if( is_admin() ) :
$current = get_current_screen();
$allowed_screens = array(
'users',
'toplevel_page_paupress_options',
@annalinneajohansson
annalinneajohansson / auto_core_update_email.php
Created February 26, 2015 08:12
Change the recipient email for auto_core_update_email
<?php
function hip_filter_auto_update_email( $email ) {
$email['to'] = 'username@example.com';
return $email;
}
add_filter( 'auto_core_update_email', 'hip_filter_auto_update_email', 1 );
@annalinneajohansson
annalinneajohansson / getSimilarColor.js
Created September 8, 2016 11:01
Get similar color from a predefined sprectrum @link http://stackoverflow.com/a/8575671
function getSimilarColor ( color ) {
var base_colors=["660000","990000","cc0000","cc3333","ea4c88","993399","663399","333399","0066cc","0099cc","66cccc","77cc33","669900","336600","666600","999900","cccc33","ffff00","ffcc33","ff9900","ff6600","cc6633","996633","663300","000000","999999","cccccc","ffffff"];
//Convert to RGB, then R, G, B
var color_rgb = hex2rgb(color);
var color_r = color_rgb.split(',')[0];
var color_g = color_rgb.split(',')[1];
var color_b = color_rgb.split(',')[2];
//Create an emtyp array for the difference betwwen the colors
function __construct() {
parent::__construct( awsAccessKey, awsSecretKey );
$settings = get_option( 'op5dwnl_settings' );
$this->buckets = ( isset( $settings['buckets'] ) ) ? $settings['buckets'] : false;
add_filter( 'acf/load_field/name=amazon_s3_file', array( $this, 'acf_load_field' ) );
}
@annalinneajohansson
annalinneajohansson / post_thumbnail_html.matthewruddy.php
Last active July 4, 2016 19:31
Ability to create image sizes on the fly in the_post_thumbnail(), using Matthew Ruddys Wordpress Timthumb Alternative (http://matthewruddy.github.io/Wordpress-Timthumb-alternative/)
<?php
/*
Simply put the desired image size in the_post_thumbnail( $size );
Sizes are declared as [height-in-pixels]x[width-in-pixels].
Example: the_post_thumbnail('400x300');
Dependencies: http://matthewruddy.github.io/Wordpress-Timthumb-alternative/
*/
add_filter( 'post_thumbnail_html', 'matthewruddy_post_thumbnail_resize', 20, 5 );
function matthewruddy_post_thumbnail_resize( $html, $post_id, $post_thumbnail_id, $size, $attr ) {