Skip to content

Instantly share code, notes, and snippets.

Ralf Albert RalfAlbert

Block or report user

Report or block RalfAlbert

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@RalfAlbert
RalfAlbert / columns_and_pages.php
Created Feb 11, 2014
WordPress: Zerlegt einen Text in zwei Spalten und verteilt die SApalten auf Seiten.
View columns_and_pages.php
<?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 Feb 7, 2014
Insert a cc license by a custom field.
View cc-license_custom_fields.php
<?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"><
View 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 Dec 1, 2013
Custom events with jQuery
View gist:7732687
<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(
View onetime_nonce.php
<?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 Dec 17, 2015
Example files for DataContainer
View basic_datacontainer_1.php
<?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 Dec 17, 2015
Test WordPress' is_email() and sanitize_email() functions
View mailtest.php
<?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
WordPress: Simple class to handle file uploads to the wp-content directory and creating an attachment post
View file_upload.php
<?php
class File_Upload
{
/**
* Index key from upload form
* @var string
*/
public $index_key = '';
/**
@RalfAlbert
RalfAlbert / autoimporter.php
Created Apr 27, 2013
WordPress: Class to allow automatically import posts/pages
View autoimporter.php
<?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 Apr 12, 2013
PHP execution shortcode for WordPress Usage: [php]<?php echo 'Hello World!'; ?>[/php]
View gist:5372635
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 );
You can’t perform that action at this time.