Skip to content

Instantly share code, notes, and snippets.

View lloc's full-sized avatar
🏠
Working from home

Dennis Ploetner lloc

🏠
Working from home
View GitHub Profile
@lloc
lloc / my_fopen.php
Created October 1, 2011 15:59
my_fopen
<?php
function my_fopen ($url) {
$ch = curl_init ($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec ($ch);
$errno = curl_errno ($ch);
curl_close ($ch);
return (array ($errno, $content));
}
@lloc
lloc / decorator-example-old.php
Created October 2, 2011 07:23
Decorator Example Old
<?php
class Decorator {
var $_obj;
function Decorator ($obj) {
$this->_obj = $obj;
}
}
@lloc
lloc / my_refresh_plugin.php
Last active October 3, 2015 01:48
My Refresh Plugin
<?php
if ( !defined( 'MY_VERSION' ) )
define( 'MY_VERSION', 0.1 );
function my_refresh_plugin() {
if ( MY_VERSION != get_option( 'my_version' ) ) {
update_option( 'my_version', MY_VERSION );
flush_rewrite_rules( false );
}
@lloc
lloc / menu-msls-1.php
Created June 22, 2012 09:10
Code zum Artikel "Multisite Language Switcher ins Menü einbauen" Part 1
<?php
function my_custom_menu_item( $items, $args ) {
if ( class_exists( 'MslsOutput' ) && 'primary-nav' == $args->theme_location ) {
$obj = new MslsOutput;
foreach ( $obj->get( 0 ) as $item ) {
$items .= '<li>' . $item . '</li>';
}
}
return $items;
@lloc
lloc / menu-msls-2.php
Created June 22, 2012 14:43
Code zum Artikel "Multisite Language Switcher ins Menü einbauen" Part 2
<?php
function my_msls_output_get( $url, $item, $current ) {
return sprintf(
'<a href="%s" title="%s"%s>%s</a>',
$url,
$item->txt,
( $current ? ' class="current"' : '' ),
$item
);
@lloc
lloc / mxs1.php
Last active October 6, 2015 19:17
My extended sitemap
<?php
function mxs_flush_rules() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
register_activation_hook( __FILE__, 'mxs_flush_rules' );
register_deactivation_hook( __FILE__, 'mxs_flush_rules' );
@lloc
lloc / menu-msls-3.php
Created July 19, 2012 08:31
Code zum Artikel "Multisite Language Switcher ins Menü einbauen" Part 3
<?php
function my_msls_link_create() {
return new MyMenuMslsItem();
}
add_filter( 'msls_link_create', 'my_msls_link_create' );
class MyMenuMslsItem extends MslsLink {
protected $format_string = '<img src="{src}" alt="{alt}"/> <strong>{txt}</strong>';
<?php
function my_enqueue_script() {
wp_enqueue_script(
'requirejs',
plugins_url( '/js/require.js', __FILE__ ),
array( 'jquery' )
);
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_script' );
@lloc
lloc / functions.php
Last active November 19, 2015 21:24
WordPress - How to show a nav menu_item only to users who are logged in
<?php
add_filter( 'wp_setup_nav_menu_item', function ( $menu_item ) {
if ( ! is_user_logged_in() &&
in_array( 'private', $menu_item->classes )
) {
$menu_item->_invalid = true;
}
return $menu_item;
<?php
$name = 'scg_' . md5( $href );
if ( false === ( $value = get_transient( $name ) ) ) {
$response = wp_remote_get( $href );
if ( !is_wp_error( $response ) ) {
$value = trim( $response['body'] );
if ( !empty( $value ) )
set_transient( $name, $value, 86400 );
}