Skip to content

Instantly share code, notes, and snippets.

View eteubert's full-sized avatar

Eric Teubert eteubert

View GitHub Profile
<?php
/**
* Parse partial seconds to milliseconds.
*
* Expects the integer from behind the dot.
* If the original time string is "1.23" it expects "23" and will return "230"
*
* @param string $ms_string
* @return int
*/
@eteubert
eteubert / move_comments.php
Created March 3, 2013 20:28
WordPress: move comments between posts
<?php
function move_comments( $from_post_id, $to_post_id ) {
global $wpdb;
$sql = sprintf(
'UPDATE %s SET comment_post_id=%s WHERE comment_post_id=%s;',
$wpdb->comments,
(int) $to_post_id,
(int) $from_post_id
);
@eteubert
eteubert / copy_comments.php
Last active December 14, 2015 11:19
WordPress: copy comments between posts
<?php
// copy all comments from post $post_id to post $new_post_id
foreach ( get_comments( array( 'post_id' => $post_id ) ) as $comment ) {
$comment->comment_post_ID = $new_post_id;
wp_insert_comment( (array) $comment );
}
@eteubert
eteubert / wordpress_release.rb
Last active January 26, 2016 01:35
WordPress Release Script für Podlove Publisher (and other WordPress plugins)
require "yaml"
class Object
def blank?
respond_to?(:empty?) ? empty? : !self
end
def present?
!blank?
<?php
spl_autoload_register( function ( $class_name ) {
$camelcase_to_snakecase = function ( $string ) {
return preg_replace( '/([a-z])([A-Z])/', '$1_$2', $string );
};
$split = explode( '\\\\', $class_name );
// remove "Inpsyde" namespace
$vendor = array_shift( $split );
@eteubert
eteubert / mp4chaps_to_psc.php
Created November 20, 2012 21:27
mp4chaps to PSC converter
<?php
namespace Podlove;
/**
* Chapter management class.
* Consumes mp4chaps and spits out valid psc xml.
*
* @see http://podlove.org/simple-chapters/
*/
class Chapters {
@eteubert
eteubert / woocommerce_german_add_asterisk.php
Created November 15, 2012 08:43
Adds asterisk after currency symbol.
<?php
/**
* Adds asterisk after currency symbol.
*
* Hint: It will only look ok if your currency symbol is to the *right* of the
* price (10$*). Otherwise it won't look as intended ($*10).
*
* @param string $currency_symbol
* @param string $currency
* @return string
@eteubert
eteubert / Rakefile
Created October 22, 2012 07:32
WordPress Rakefile for Plugin Development
require "uglifier" # gem install uglifier, requires node.js
require "yui/compressor" # gem install require "yui/compressor"
require "fileutils"
desc "prepare javascript files for production"
task "prepare:js" do
minify "js/*.js" do |file|
Uglifier.compile File.read(file)
end
end
➜ curl -I http://rederadio.de/
HTTP/1.1 200 OK
Date: Thu, 13 Sep 2012 18:23:58 GMT
Server: Apache/2.2.15 (CentOS)
X-Powered-By: PHP/5.4.4
X-Pingback: http://rederadio.de/xmlrpc.php
Connection: close
Content-Type: text/html; charset=UTF-8
@eteubert
eteubert / flexfit.diff
Created September 12, 2012 13:54
FlexFit Theme: Child Theme Compatibility
235,236c235,236
< define( 'RWMB_URL', trailingslashit( get_stylesheet_directory_uri().'/framework/functions/meta-box' ) );
< define( 'RWMB_DIR', trailingslashit( get_stylesheet_directory().'/framework/functions/meta-box' ) );
---
> define( 'RWMB_URL', get_template_directory_uri().'/framework/functions/meta-box/' );
> define( 'RWMB_DIR', get_template_directory().'/framework/functions/meta-box/' );
242c242
< include get_stylesheet_directory().'/framework/functions/meta-box.php';
---
> include get_template_directory().'/framework/functions/meta-box.php';