Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / .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