Skip to content

Instantly share code, notes, and snippets.

View alisspers's full-sized avatar

Anders Lisspers alisspers

View GitHub Profile
@alisspers
alisspers / mynewsdesk-importer.php
Last active February 8, 2016 15:20
Plugin to import from MyNewsDesk - full plugin
<?php
/*
Plugin Name: MyNewsDesk Importer
Description: Imports news via API from NyNewsDesk as post type for news
Version: 1.0
Author: Webbgaraget
Author URI: http://www.webbgaraget.se
*/
class MND_News_Importer
{
@alisspers
alisspers / flag-markup.html
Last active August 29, 2015 14:05
Exempel på loopar i SASS
<ul class="network-list">
<li class="network-node austria">
<a href="#">Austria</a>
</li>
<li class="network-node belgium">
<a href="#">Belgium</a>
</li>
<!-- […] -->
</ul>
@alisspers
alisspers / mysql-alter-collation-on-all-tables.sql
Created May 21, 2014 13:37
Altering all tables in a database to change their collation can be a tedious task if needed on a large database. This nifty little trick based on a SO answer (http://stackoverflow.com/a/19462205) returns a list of all altercommands for the tables in a database, to make your life a bit easier.
/*
Get a list of all ALTER commands needed to change collation on all tables in the given database
Note: Remember to set your database name on line 7, and change utf8_swedish_ci to the collation of your choice
Props goes to this answer on StackOverflow: http://stackoverflow.com/a/19462205
*/
SELECT CONCAT("ALTER TABLE `", TABLE_NAME,"` CONVERT TO CHARACTER SET utf8 COLLATE utf8_swedish_ci;") AS mySQL
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA="YOUR_DATABASE_NAME"
AND TABLE_TYPE="BASE TABLE"
@alisspers
alisspers / img_load_isotope_relayout.js
Created October 21, 2013 09:02
Enkelt exempel av Isotope reLayout vid image load
var $item = $(...);
var $itemList = $(...);
// [...]
$item.find('img').on('load', function ()
{
$itemList.isotope('reLayout');
});
@alisspers
alisspers / blog-heartbeat-autoreload.php
Last active December 22, 2015 10:39
Exempel på hur du med hjälp av Heartbeat API kan få din postlista att uppdateras i realtid när nya poster publiceras
<?php
function wg_add_new_posts_to_heartbeat_response( $response, $data )
{
if ( ! isset( $data['wg-posts-autoreload'] ) )
return $response; // No client of ours has requested new posts
$posts = wg_get_posts_since_timestamp( $data['wg-posts-autoreload'] );
if ( count( $posts ) === 0 )
return $response; // There were no new posts
@alisspers
alisspers / index.php
Created September 5, 2013 19:03
Using the Heartbeat API that shipped with WordPress 3.6, this sample plugin shows you how you can have your post list update for your visitors in real time when a new post is published. This code should be seen as inspiration, as it needs to be modified to work with the theme you're currently using.
<?php
/**
* Sample theme index.php to be used with WG Posts Autoreload
*/
get_header();
if ( have_posts() )
{
echo '<div id="posts">';
@alisspers
alisspers / .htaccess
Last active December 21, 2015 13:59
Kod till .htaccess för att hindra botnätens brute-force-attack mot WordPress-sajter och wp-login.php
# Undviker att botnet-attacken ska få göra inloggningsförsök.
# Se här: http://www.warriorforum.com/main-internet-marketing-discussion-forum/789591-how-botnet-attack-looks-like-what-you-can-do-about.html
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{HTTP_USER_AGENT} Mozilla/5\.0\ \(Windows\ NT\ 6\.1;\ rv\:19\.0\)\ Gecko/20100101\ Firefox/19\.0 [NC]
RewriteCond %{REQUEST_URI} wp-login\.php
RewriteRule .* - [F]
</IfModule>
@alisspers
alisspers / functions.php
Last active December 20, 2015 05:19
Exempel på hur du kan implementera alfabetisk paginering för en lista av WordPress-poster
<?php
/**
* Tar bort den transient som genererats för postlistan med
* alfabetisk paginering.
*
* @wp-hook save_post,before_delete_post
* @param int $post_id ID på posten som sparas/raderas
*/
function wg_clear_postlist_cache( $post_id )
@alisspers
alisspers / current-menu-item-for-single-cpt-functions.php
Last active December 17, 2015 20:38
Kodsnuttar från blogginlägget som visar hur du kan markera menyval som aktivt när besökaren är inne på ett enskilt inlägg i en Custom Post Type. http://www.webbgaraget.se/2013/05/30/markera-menyval-som-aktivt-nar-besokaren-ar-inne-pa-en-custom-post-type/
<?php
add_action(
'init',
function ()
{
// Vår meny
register_nav_menu( 'main-menu', 'Huvudmeny' );
// Custom Post Type för event
$labels = array(
@alisspers
alisspers / webkit-border-radius.css
Created May 8, 2013 13:32
CSS-Border Radius Webkit
button,
input[type=text],
input[type=submit],
textarea {
-webkit-appearance: none;
-webkit-border-radius: 0;
}