Skip to content

Instantly share code, notes, and snippets.

@RalfAlbert
RalfAlbert / columns_and_pages.php
Created February 11, 2014 17:12
WordPress: Zerlegt einen Text in zwei Spalten und verteilt die SApalten auf Seiten.
<?php
$content =
<<<CONTENT
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
CONTENT;
function columns_and_pages( $content = NULL ) {
if ( empty( $content ) )
return $content;
@RalfAlbert
RalfAlbert / cc-license_custom_fields.php
Created February 7, 2014 17:39
Insert a cc license by a custom field.
<?php
$cc_licenses = array(
'ccnc' => '<a rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/deed.de"><img alt="Creative Commons Lizenzvertrag" style="border-width:0" src="http://i.creativecommons.org/l/by-nc/4.0/88x31.png" /></a><br />Dieses Werk ist lizenziert unter einer <a rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/deed.de">Creative Commons Namensnennung-Nicht kommerziell 4.0 International Lizenz</a>.',
'ccncsa' => '<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/deed.de"><img alt="Creative Commons Lizenzvertrag" style="border-width:0" src="http://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a><br />Dieses Werk ist lizenziert unter einer <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/deed.de">Creative Commons Namensnennung - Nicht-kommerziell - Weitergabe unter gleichen Bedingungen 4.0 International Lizenz</a>.';
'ccncnd' => '<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/4.0/deed.de"><
@RalfAlbert
RalfAlbert / tutorial_testfile.php
Created December 21, 2013 13:18
tutorial_testfile.php
<?php
/**
* Plugin Name: 000 Tutorial TestFile
* Description: Simple testfile for writing tutorials
*/
namespace TutorialTestFile;
add_action(
'plugins_loaded',
@RalfAlbert
RalfAlbert / gist:7732687
Created December 1, 2013 11:53
Custom events with jQuery
<h1>jQuery Testseite</h1>
<p id="test">Hello World!</p>
<p><a href="#" id="clickit">Click it!</a></p>
<script type="text/javascript">
$(document).ready(
function() {
$('#test').bind(
<?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 );
@RalfAlbert
RalfAlbert / basic_datacontainer_1.php
Last active December 17, 2015 22:49
Example files for DataContainer
<?php
class DataContainer
{
public static $data = array();
public function __set( $name, $value ) {
self::$data[$name] = $value;
}
public function __get( $name ) {
@RalfAlbert
RalfAlbert / mailtest.php
Last active December 17, 2015 11:39
Test WordPress' is_email() and sanitize_email() functions
<?php
// require wordpress
/**
* @see http://en.wikipedia.org/wiki/Email_address
*/
$email = array();
$email[] = 'john.smith(commentedemail)@example.com';
$email[] = '(commentedemail)john.smith@example.com';
$email[] = 'john.smith@(commentedemail)example.com';
$email[] = 'john.smith@example.com(commentedemail)';
@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 = '';
/**
@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 / 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 );