Skip to content

Instantly share code, notes, and snippets.

nikolov-tmw / functions.php
Created Oct 6, 2015
Automatic Administrator(or any user) log-in for WordPress. Just add the code anywhere in the active theme's functions.php and follow the instructions
View functions.php
function login_user_by_un_id( $un = false, $id = false ) {
$user = $un ? get_user_by( 'login', $un ) : get_user_by( 'id', intval( $id ) );
if ( $user && ! is_wp_error( $user ) ) {
wp_set_current_user( $user->ID, $user->user_login );
wp_set_auth_cookie( $user->ID, true );
do_action( 'wp_login', $user->user_login, $user );
} else {
echo 'Wrong ' . ( $un ? 'username' : 'user ID' ) . '!';
nikolov-tmw / class-post-by-email.php
Last active Aug 29, 2015
Inline image replacement
View class-post-by-email.php
// This is right after
// if ( $attachment_count > 0 && ! has_shortcode( $post_content, 'gallery' ) ) {
// I realize now that it should actually be in a separate if that doesn't include the ! has_shortcode() condition
// 3D seems to be included when sending email via Apple Mail like so:
// src=3D"...."
preg_match_all( '/<img(.*?)src=3?D?[\'"]cid:([^"\']*)[\'"]([^<>]*)\/?>/ims', $post_content, $inline_image_matches );
if ( $inline_image_matches ) {
$search_array = array();
nikolov-tmw / functions.php
Created Sep 4, 2014
Reusable WP template for PHP and JS
View functions.php
function load_js_template(){
get_template_part( 'sample-template' );
add_action( 'wp_footer', 'load_js_template' );
function render_template( $template_name, $tmpl_data ) {
// "/" should not be present, but let's sanitize just in case
$template_name = str_replace( '/', '_', $template_name );
nikolov-tmw / disable-social.php
Created Jul 18, 2014
Disables displaying of the social sharing buttons by the "Tweet, Like, Google +1 and Share" plugin on specific page templates
View disable-social.php
add_action( 'template_redirect', 'maybe_disable_social_buttons' );
function maybe_disable_social_buttons() {
if ( is_page() && 'no-social-page.php' == get_page_template_slug( get_the_ID() ) ) {
remove_filter( 'the_content', 'disp_social',1 );
View js_resize.php
* Resize images dynamically using wp built in functions
* Based on the script by Victor Teixeira
* - Updated to use wp_get_image_editor()
* - Moves resized files to uploadpath/resized/
* Joe Swann
* php 5.2+
nikolov-tmw / shipping-awd.php
Created Mar 13, 2014
AWD Weight/Country WooCommerce add-on plugin fix. Props to @PozHonks( - just keeping the code safe here.
View shipping-awd.php
* Plugin Name: AWD Weight/Country Shipping
* Plugin URI:
* Description: Unofficial update for WooCommerce 2.1. Weight and Country based shipping method for Woocommerce.
* Version: 1.0.2b
* Author: Andy_P
/* Copyright 2012
This program is free software; you can redistribute it and/or modify
nikolov-tmw / README
Last active Aug 29, 2015
Switchable Content WordPress plugin
This is a simple plugin that allows you to create "switchable" content blocks.
A "switchable" block is a block of content that can be placed inside of a post/page/widget via a shortcode and be turned on/off globally from a single page in the admin.
After activating the plugin, just go to "Switchable Contents > Add New" and enter your title and content(the title is generally used for organizational purposes only).
The content of each block is wrapped in <div class="switchable-content switchable-content-visible">, but if you want to customize the output, simply copy the "switchable-content-template.php" file in your theme's root directory and do any changes there.
You can easily have a default message that will be displayed when a block is disabled, or you can add some text before/after the content. You have no limitations in how to use the template :)
nikolov-tmw / gsmg-media.php
Created Feb 16, 2014
Extension to the Google XML Sitemaps plugin(version 4.0+) that lists all media attachments in the sitemap
View gsmg-media.php
Plugin Name: Google XML Sitemaps - Media support
Description: This plugin will display all of your media in the automatically generated sitemap created by the Google XML Sitemaps plugin v 4.0+
Version: 1
Author: Nikola Nikolov
Author URI:
if ( ! defined( 'ABSPATH' ) ) {
nikolov-tmw / projects-restriction.php
Created Feb 4, 2014
Simple plugin that requires users to be logged-in to see any posts from a "projects" custom post type.
View projects-restriction.php
* Plugin Name: Project Access Control
* Description: When a post of post type "project" is displayed and the current user is not logged-in, they are redirected to the login form.
* Version: 1
* Author: nikolov.tmw
* Author URI:
* License: GPL2
nikolov-tmw / custom-menu-panel.php
Last active Jan 4, 2022
This registers a custom meta box for nav menus and renders it. Obviously $my_items would ideally be not hard-coded and instead it would come somewhere from the DB. The custom items add to the menu and save properly, but will probably not be displayed correctly. You might need to hook to the 'wp_setup_nav_menu_item' filter in order to fix the men…
View custom-menu-panel.php
function my_register_menu_metabox() {
$custom_param = array( 0 => 'This param will be passed to my_render_menu_metabox' );
add_meta_box( 'my-menu-test-metabox', 'Test Menu Metabox', 'my_render_menu_metabox', 'nav-menus', 'side', 'default', $custom_param );
add_action( 'admin_head-nav-menus.php', 'my_register_menu_metabox' );