Skip to content

Instantly share code, notes, and snippets.

View annalinneajohansson's full-sized avatar
🐱

Anna annalinneajohansson

🐱
  • Frontwalker Group AB
  • Sweden
  • 17:16 (UTC +02:00)
View GitHub Profile
@annalinneajohansson
annalinneajohansson / text-widget-additional-settings.php
Created June 9, 2014 16:22
Add link field to WP_Widget_Text (the native text widget)
<?php
/**
* Add link field to WP_Widget_Text (the native text widget)
*/
add_action( 'in_widget_form', 'hip_textwidget_in_widget_form', 1, 3 );
add_filter( 'widget_update_callback', 'hip_textwidget_in_widget_form_update', 1, 4 );
add_filter( 'dynamic_sidebar_params', 'hip_textwidget_dynamic_sidebar_params' );
function hip_textwidget_in_widget_form( $item, $return, $instance ){
if( $item->id_base !== "text" )
@annalinneajohansson
annalinneajohansson / hip-uam-widget-access.php
Last active August 29, 2015 14:02
Manage the access for widgets. Requires User Access Manager ( http://www.gm-alex.de/projects/wordpress/plugins/user-access-manager) #WordPress #UserAccessManager
<?php
/*
Plugin Name: User Access Manager - Widgets addon
Plugin URI:
Description: Manage the access for widgets. Requires <a href="http://www.gm-alex.de/projects/wordpress/plugins/user-access-manager/">User Access Manager</a>.
Version: 1
Author: Hippies
Author URI: http://hippies.se/
**************************************************************************
@annalinneajohansson
annalinneajohansson / WP_Widget.php
Created May 22, 2014 13:32
WordPress widget template
<?php
add_action( 'widgets_init', 'PREFIX_register_widgets' );
function PREFIX_register_widgets(){
register_widget( 'WP_Widget_FOOBAR' );
}
class WP_Widget_FOOBAR extends WP_Widget {
/**
* Register widget with WordPress.
*/
@annalinneajohansson
annalinneajohansson / apply_filters_term_description.php
Created May 16, 2014 15:13
Treat term_description as the_content
<?php
$term_description = term_description();
if ( ! empty( $term_description ) ) :
echo '<div class="term-description">';
echo apply_filters( "the_content", $term_description );
echo '</div>';
endif;
@annalinneajohansson
annalinneajohansson / hip_replace_term_description_field.php
Last active August 29, 2015 14:01
Replace the default textarea (description) on terms with a WYSIWYG field. A little bit buggy, wouldn't bet your kids college funds on it. #WordPress
<?php
/**
* Replace the default textarea#decription on terms with a WYSIWYG field
*/
add_action( 'admin_init', 'hip_replace_term_description_field', 10, 2 );
function hip_replace_term_description_field() {
$taxonomies = get_taxonomies( array( 'public' => true ) );
foreach ( $taxonomies as $taxonomy ) {
add_action( $taxonomy . '_add_form_fields', 'hip_wysiwyg_term_description', 10, 2 );
add_action( $taxonomy . '_edit_form_fields', 'hip_wysiwyg_term_description', 10, 2 );
// Autosave, do nothing
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// AJAX
if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
return;
// Check user permissions
if ( ! current_user_can( 'edit_post', $post_id ) )
return;
// Return if it's a post revision
@annalinneajohansson
annalinneajohansson / hip_mc_move_settings_box.php
Created May 11, 2014 03:49
Move advanced meta boxes to below after the title
<?php
/**
* Move advanced meta boxes to below after the title
*/
function hip_mc_move_settings_box() {
# Get the globals:
global $post, $wp_meta_boxes;
$posttype = "post";
@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 ) {
<?php
$args = array(
'post_type' => 'product',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'color',
'value' => 'blue',
'compare' => 'NOT LIKE'
),
@annalinneajohansson
annalinneajohansson / hip_exclude_from_wp_list_pages.php
Created April 4, 2014 08:10
Exclude pages with meta value 'hide_page_in_menus' set to 1 from wp_list_pages
add_filter( 'get_pages', 'hip_exclude_from_wp_list_pages', 10, 2 );
/**
* Exclude pages with meta value 'hide_page_in_menus' set to 1 from wp_list_pages
* @param array $pages
* @param array $args
* @return array $pages
*/
function hip_exclude_from_wp_list_pages( $pages, $args ) {
// Check for 'walker' key to see if this is being used by wp_list_pages()