Skip to content

Instantly share code, notes, and snippets.

@nikolov-tmw
nikolov-tmw / .htaccess
Last active December 28, 2015 00:09
WordPress login lock - try to prevent automated brute force attacks. Just place the login-lock.php file in /wp-content/mu-plugins/ and add the code in .htaccess to your root's .htaccess file. Note that if you have WordPress in a sub-directory, you would have to change the RewriteBase on line 8.
# Add this code to the .htaccess in your root WordPress directory
# If your wordpress files are in a sub-directory, just change the RewriteBase
# to something like:
# RewriteBase /wordpress/
# If your wordpress files are in a sub-directory called "wordpress"
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Redirect to home page upon log-out
@nikolov-tmw
nikolov-tmw / multiple-roles-per-user.php
Last active October 5, 2021 03:56
Multiple roles per user WordPress plugin.
<?php
/**
* Plugin Name: Multiple Roles per User
* Description: Allows anyone who can edit users to set multiple roles per user. In a default WordPress environment that wouldn't have much of an effect, since the user would have the privileges of the top-privileged role that you assign to him. But if you have custom roles with custom privileges, this might be helpful.
* Version: 1
* Author: nikolov.tmw
* Author URI: http://paiyakdev.com/
* License: GPL2
*/
/*
@nikolov-tmw
nikolov-tmw / custom-menu-panel.php
Last active February 22, 2024 21:29
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…
<?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' );
/**
@nikolov-tmw
nikolov-tmw / projects-restriction.php
Created February 4, 2014 12:25
Simple plugin that requires users to be logged-in to see any posts from a "projects" custom post type.
<?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: http://paiyakdev.com/
* License: GPL2
*/
/*
@nikolov-tmw
nikolov-tmw / gsmg-media.php
Created February 16, 2014 12:17
Extension to the Google XML Sitemaps plugin(version 4.0+) that lists all media attachments in the sitemap
<?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: http://paiyakdev.com/
*/
if ( ! defined( 'ABSPATH' ) ) {
@nikolov-tmw
nikolov-tmw / README
Last active August 29, 2015 13:56
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
nikolov-tmw / shipping-awd.php
Created March 13, 2014 23:31
AWD Weight/Country WooCommerce add-on plugin fix. Props to @PozHonks(http://wordpress.org/support/profile/pozhonks) - just keeping the code safe here.
<?php
/**
* Plugin Name: AWD Weight/Country Shipping
* Plugin URI: http://www.andyswebdesign.ie/blog/free-woocommerce-weight-and-country-based-shipping-extension-plugin/
* Description: Unofficial update for WooCommerce 2.1. Weight and Country based shipping method for Woocommerce.
* Version: 1.0.2b
* Author: Andy_P
/* Copyright 2012 andyswebdesign.ie
This program is free software; you can redistribute it and/or modify
<?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
nikolov-tmw / disable-social.php
Created July 18, 2014 15:42
Disables displaying of the social sharing buttons by the "Tweet, Like, Google +1 and Share" plugin on specific page templates
<?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 );
}
}