Skip to content

Instantly share code, notes, and snippets.

@RalfAlbert
RalfAlbert / autoimporter.php
Created April 27, 2013 17:30
WordPress: Class to allow automatically import posts/pages
<?php
/** Display verbose errors */
define( 'IMPORT_DEBUG', false );
// Load Importer API
require_once ABSPATH . 'wp-admin/includes/import.php';
if ( ! class_exists( 'WP_Importer' ) ) {
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
if ( file_exists( $class_wp_importer ) )
@RalfAlbert
RalfAlbert / membersince.php
Created January 1, 2013 13:35
WordPress: Show date of registration in user profile
<?php
namespace ShowMemberSince;
add_action( 'plugins_loaded', 'ShowMemberSince\init' );
/**
* Adding needed action hooks
*/
function init(){
@RalfAlbert
RalfAlbert / _wp_environment_check.php
Created January 11, 2012 06:39
WordPress Environment Check - Checks the minimum needed versions (WP, PHP, MySQL)
<?php
/**
*
* Class to check the environment (WordPress-, PHP and MySQL-version)
* Test only on minimum or equal version
*
* @author Ralf Albert
* @version 1.0
* @link https://gist.github.com/1593410
* @license GPL
@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 / gist:5372635
Created April 12, 2013 14:57
PHP execution shortcode for WordPress Usage: [php]<?php echo 'Hello World!'; ?>[/php]
add_shortcode(
'php',
function( $atts, $content = null ){
// un-texturize $content
$char_codes = array( '&#8216;', '&#8217;', '&#8220;', '&#8221;', '&#8242;', '&#8243;' );
$replacements = array( "'", "'", '"', '"', "'", '"' );
$content = str_replace( $char_codes, $replacements, $content );
// decode html-entities
$content = html_entity_decode( $content );
@RalfAlbert
RalfAlbert / file_upload.php
Last active May 18, 2018 19:23
WordPress: Simple class to handle file uploads to the wp-content directory and creating an attachment post
<?php
class File_Upload
{
/**
* Index key from upload form
* @var string
*/
public $index_key = '';
/**
<?php
/*
* Since PHP5 there is no need to pass an reference of $this
*
* @see http://php.net/manual/en/language.oop5.references.php
* [...] As of PHP 5, an object variable doesn't contain the object itself as value anymore [...]
*/
add_action( 'load-upload.php', array( $this, 'custom_bulk_action' ) );
<?php
function create_onetime_nonce( $action = -1 ) {
$time = time();
$nonce = wp_create_nonce( $time . $action );
set_transient( '_nonce_' . $time, 1, 60*60 ); // adjust the lifetime of the transient
return $nonce . '-' . $time;
}
function verify_onetime_nonce( $_nonce, $action = -1 ) {
@list( $nonce, $time ) = explode( '-', $_nonce );
<?php
/**
* WordPress-Plugin Simple Facebook Avatar
*
* PHP version 5.3
*
* @category PHP
* @package WordPress
* @subpackage Simple Facebook Avatar
* @author Ralf Albert <me@neun12.de>
@RalfAlbert
RalfAlbert / class-custom_import.php
Created February 9, 2013 04:13
A custoim importer for WordPress
<?php
/*
Plugin Name: Custom Importer
Plugin URI:
Description: Import posts or not
Author: Ralf Albert
Author URI: http://yoda.neun12.de
Version: 0.1
Text Domain: custom-importer
License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html