Skip to content

Instantly share code, notes, and snippets.

@RalfAlbert
RalfAlbert / automatic_activate_plugin.php
Created December 4, 2011 18:02
automatic activate a plugin after install
add_filter( 'upgrader_post_install', 'autoactivate_plugin_after_install', 10, 3 );
function autoactivate_plugin_after_install( $value, $hook_extra, $result ){
$p_tmp = get_plugins('/' . $result['destination_name']);
$p_key = array_keys( $p_tmp );
$pre = ! empty( $result['destination_name'] ) ? $result['destination_name'] . '/' : '';
$plugin = $pre . $p_key[0];
$plugins = get_option('active_plugins');
@RalfAlbert
RalfAlbert / show_comment_numbers.php
Created December 5, 2011 03:19
WordPress - Show comment-numbers in a comment-thread
<?php
/**
* Plugin Name: Show Comment Number
* Plugin URI: http://neun12.de
* Text Domain:
* Domain Path:
* Description: Dieses Plugin zeigt die laufende Kommentar-Nummer in einem Kommentar-Thread an.
* Author: Ralf Albert
* Version: 0.1
* Author URI: http://neun12.de/
@RalfAlbert
RalfAlbert / do_not_nag_non-admins_on_updates.php
Created December 11, 2011 09:41
Removing update notifications for non-admins
/* put this function in your functions.php. You can use it very often */
function __return_null(){
return NULL;
}
/* stop informing non-admins */
global $current_user;
if( ! current_user_can( 'update_core' ) ){
# 2.8 to 3.0:
remove_action( 'wp_version_check', 'wp_version_check' );
@RalfAlbert
RalfAlbert / some_foobar_controller.php
Created December 12, 2011 19:59
Something like MVC
<?php
function get_some_foo(){
return array( 'foo_one', 'foo_two', 'foo_three' );
}
function get_some_bar(){
return array( 'bar_one', 'bar_two', 'bar_three' );
}
function some_view( $the_array ){
@RalfAlbert
RalfAlbert / file1.php
Created December 18, 2011 05:29
Selector with classes
<?php
/* Plugin Name Some Code */
class PluginInit
{
/**
* mocking code
*/
CONST WP_VERSION = '3.3';
private function get_wp_version(){ return '3.3' ; }
private function get_wp_network() { return false; }
@RalfAlbert
RalfAlbert / selector.php
Created December 18, 2011 06:29
Selector with Namespaces
<?php
/* Plugin Name Some Code */
namespace PluginInit
{
/**
* mocking code
*/
CONST WP_VERSION = '3.3';
function get_wp_version(){ return '3.3' ; }
@RalfAlbert
RalfAlbert / example.php
Created December 23, 2011 01:40 — forked from eteubert/activate.php
WordPress: Find Users by Last Login Activity
<?php
/*
Plugin Name: User Activity
Plugin URI:
Description: Provides means to query users by last login activity.
Version: 1.0
Author: Eric Teubert, Ralf Albert
Author URI: ericteubert@googlemail.com, neun12@googlemail.com
License: MIT
*/
@RalfAlbert
RalfAlbert / sortable_posts_column.php
Created December 26, 2011 02:29
WordPress - Make posts column sortable
<?php
/*
Plugin Name: Sortable post column
Description: Make posts column on users screen sortable
Version: 0.0.1
Author: Ralf Albert
Author URI: http://yoda.neun12.de
*/
// make posts-column sortable
@RalfAlbert
RalfAlbert / quicklogin.php
Created December 28, 2011 18:27
WordPress Quicklogin
<?php
require( dirname(__FILE__) . '/wp-load.php' );
is_wp_error(
wp_signon(
array(
'user_login'=>'YourLoginName',
'user_password'=>'YoUrAw3s0M3P455W0rD'
)
)
) ? die('Mooo... :(') : wp_safe_redirect( admin_url() );
@RalfAlbert
RalfAlbert / file1.php
Created January 8, 2012 16:34
Simple DataContainer with overwrite protection
<?php
class DataContainer
{
private static $data = array();
public static function __set( $name, $value ){
if( ! isset( self::$data[$name] ) )
self::$data[$name] = $value;
else
return FALSE;