Skip to content

Instantly share code, notes, and snippets.

View eteubert's full-sized avatar

Eric Teubert eteubert

View GitHub Profile
@eteubert
eteubert / scaffolding.php
Created November 5, 2011 10:01
WordPress: Tab Layout for Settings Pages
<?php
// initialize plugin
if ( function_exists( 'add_action' ) && function_exists( 'register_activation_hook' ) ) {
add_action( 'plugins_loaded', array( 'tabbed_plugin', 'get_object' ) );
}
class tabbed_plugin
{
// singleton class variable
static private $classobj = NULL;
@eteubert
eteubert / functions-login.php
Created November 7, 2011 13:06
WordPress: Activation Email Customization
<?php
function change_welcome_mail_loginlink( $welcome_email, $user_id, $password, $meta ) {
$welcome_email = str_replace( 'LOGINLINK', 'http://www.mysite.com/my/custom/login/url', $welcome_email );
return $welcome_email;
}
add_filter( 'update_welcome_user_email', 'change_welcome_mail_loginlink', 10, 4 );
@eteubert
eteubert / gist:1351939
Created November 9, 2011 16:15
Textverkettung
<?php
$some_var = 'WordPress';
$string = 'This is my text and ' . $some_var . ' is the best publishing System in the World';
<input type="hidden" name="comments[1][content]" value="foo" />
<input type="hidden" name="comments[2][content]" value="bar" />
@eteubert
eteubert / activationhook.php
Created November 12, 2011 13:06
WordPress: PHP 5.3 in WordPress Plugins
<?php
class MyPlugin {
static function activation_hook() {
if ( ! version_compare( PHP_VERSION, '5.3.0', '>=' ) ) {
deactivate_plugins( __FILE__ );
wp_die( wp_sprintf( '%1s: ' . __( 'Sorry, This plugin has taken a bold step in requiring PHP 5.3.0+. Your server is currently running PHP %2s, Please bug your host to upgrade to a recent version of PHP which is less bug-prone.', 'myplugin' ), __FILE__ , PHP_VERSION ) );
}
}
}
register_activation_hook( __FILE__, array( 'MyPlugin', 'activation_hook' ) );
@eteubert
eteubert / example.php
Created November 14, 2011 16:17
WordPress: Implement a Content Parser
<?php
class content_parser {
public function __construct() {
// apply parser to all posts
add_filter( 'the_content', array( __CLASS__, 'parse' ) );
}
public static function parse( $text ) {
global $post;
@eteubert
eteubert / ack
Created November 18, 2011 15:25
WordPress: Shortcodes in Text Widgets
ericteubert: ~/Sites/wordpress-single
➜ ack widget_text
wp-admin/includes/schema.php
307: 'widget_text' => array(),
wp-content/plugins/ikonum/class/class.custom-field-template.php
101: add_filter('widget_text', 'do_shortcode');
wp-includes/default-widgets.php
371: $widget_ops = array('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML'));
@eteubert
eteubert / enable.php
Created November 22, 2011 16:30
WordPress: Allow Site Admins to Manage Users
<?php
function enable_edit_any_user_configuration () {
return true;
}
add_action( 'enable_edit_any_user_configuration', 'enable_edit_any_user_configuration' );
@eteubert
eteubert / attachment.php
Created November 25, 2011 10:04
WordPress: Link Attachments to the Post Displaying Them
<?php
if ( $attachment->post_parent > 0 ) {
$link = get_permalink( $attachment->post_parent );
} else {
$link = get_attachment_link( $attachment->ID );
}
$img = wp_get_attachment_image( $attachment->ID );
?>
<a href="<?php echo $link ?>"><?php echo $img ?></a>
@eteubert
eteubert / alternatives.php
Created November 27, 2011 10:20
WordPress: Template Helpers using Anonymous Functions
<?php
// Alternative 1
function my_postbox_fun() {
# code...
}
postbox( 'My Awesome Postbox', 'my_postbox_fun' );
// Alternative 2
class my_example_class
{