Skip to content

Instantly share code, notes, and snippets.

View markoheijnen's full-sized avatar

Marko Heijnen markoheijnen

View GitHub Profile
@markoheijnen
markoheijnen / gist:5312334
Last active December 15, 2015 19:38
Structure example for deprecated methods
Index: tests/image/size.php
===================================================================
--- tests/image/size.php (revision 1257)
+++ tests/image/size.php (working copy)
@@ -95,57 +95,6 @@
$this->assertequals(array(525, 700), $out);
}
- function test_shrink_dimensions_default() {
- $out = wp_shrink_dimensions(640, 480);
@markoheijnen
markoheijnen / gist:5304289
Created April 3, 2013 19:08
update of /tests/image/resize.php
Index: tests/image/resize.php
===================================================================
--- tests/image/resize.php (revision 1254)
+++ tests/image/resize.php (working copy)
@@ -6,107 +6,114 @@
* @group upload
*/
abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase {
- // image_resize( $file, $max_w, $max_h, $crop=false, $suffix=null, $dest_path=null, $jpeg_quality=75)
@markoheijnen
markoheijnen / editor-gd.php
Created March 11, 2013 13:28
Cropping Post Thumbnails from Top instead of Center in WordPress
<?php
class Unknown_Crop_Top_Center_Editor extends WP_Image_Editor_GD {
/**
* Processes current image and saves to disk
* multiple sizes from single source.
*
* @since 3.5.0
* @access public
@markoheijnen
markoheijnen / gist:5108283
Last active December 14, 2015 15:29
How to escape this? I'm now using sanitize_text_field(). Was first esc_attr().
<?php
function ajax_save_columns() {
global $wp_registered_sidebars;
header( "Content-Type: application/json" );
if( isset( $_POST['sidebar'], $_POST['amount_columns'] ) && ! empty( $wp_registered_sidebars[ $_POST['sidebar'] ] ) ) {
$options = get_option( 'horizontal_sidebar_columns', array() );
$options[ $_POST['sidebar'] ] = absint( $_POST['amount_columns'] );
update_option( 'horizontal_sidebar_columns', $options );
@markoheijnen
markoheijnen / gist:4635255
Created January 25, 2013 15:29
Add Photobox support to WordPress galleries
<?php
class Gallery_Javascript {
private $link;
function __construct() {
add_filter( 'post_gallery', array( $this, 'enqueue_script' ), 20, 2 );
add_filter( 'gallery_style', array( $this, 'add_class' ) );
}
@markoheijnen
markoheijnen / gist:4448611
Last active December 10, 2015 14:38
Give wp_nav_menu() a different class then default. In some cases themes style on the class 'menu'. What result in possible weird behavior.
<?php
class Nav_Menu_Widget_Classname {
public function __construct() {
add_action( 'widget_display_callback', array( $this, 'menu_different_class' ), 10, 2 );
}
public function menu_different_class( $settings, $widget ) {
if( $widget instanceof WP_Nav_Menu_Widget )
add_filter( 'wp_nav_menu_args', array( $this, 'wp_nav_menu_args' ) );
@markoheijnen
markoheijnen / gist:4424020
Created January 1, 2013 00:00
Enqueue child and parent style from the WordPress.org theme 'Responsive'
<?php
class Responsive_Childtheme_Enqueue {
public function __construct() {
add_action( 'wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ) );
}
public function wp_enqueue_scripts() {
wp_deregister_style( 'responsive-style' );
wp_register_style( 'responsive-style', get_template_directory_uri() . '/style.css', false, get_responsive_template_version() );
@markoheijnen
markoheijnen / gist:4349227
Created December 20, 2012 22:41
Hotfixing bug in wp_save_image() in WordPress 3.5
<?php
add_action( 'wp_ajax_image-editor', 'fix_wp_ajax_image_editor', 0 );
function fix_wp_ajax_image_editor() {
$attachment_id = intval( $_POST['postid'] );
if ( empty( $attachment_id ) || ! current_user_can( 'edit_post', $attachment_id ) )
wp_die( -1 );
@markoheijnen
markoheijnen / gist:4236025
Last active October 13, 2015 18:17
WordPress Engine shortcode
<?php
class Marko_Shortcodes {
public function __construct() {
add_shortcode( 'engine_info', array( $this, 'engine_info' ) );
}
public function engine_info( $atts ) {
global $wp_version, $wpdb, $batcache, $wp_object_cache;
@markoheijnen
markoheijnen / gist:3965864
Created October 27, 2012 19:46
Get the plugins of an author on WordPress.org
<?php
class Connection_Wordpress {
private $base_url = 'http://api.wordpress.org/';
function __construct() {
add_action( 'widgets_init', array( $this, '_register_widgets' ) );
}
function _register_widgets() {