Skip to content

Instantly share code, notes, and snippets.

View palpalani's full-sized avatar

Palaniappan P palpalani

View GitHub Profile
@palpalani
palpalani / functions.php
Last active December 26, 2015 13:19
Log in a WordPress user programmatically
<?php
/*
* Here is the function, drop it in your functions.php file
*/
function auto_login( $user ) {
$username = $user;
if ( !is_user_logged_in() ) {
$user = get_userdatabylogin( $username );
@palpalani
palpalani / functions.php
Created October 25, 2013 12:26
Limit number of posts an user can create in WordPress admin panel
<?php
/*
* If you, by any chance, want to limit the number of posts an user can create in your multi author WordPress blog, there is a nice way to do it. Add the following code in your theme’s functions.php file
*/
add_action("load-post-new.php","limit_user_by_post_count");
function limit_user_by_post_count(){
$user = get_current_user_id();
if (!current_user_can( 'manage_options')) {
//not an admin - so impose the limit
@palpalani
palpalani / files-backup.sh
Last active December 28, 2020 19:55
Linux / UNIX Tar Full and Incremental Tape Backup Shell Script#!/bin/bash
# A UNIX / Linux shell script to backup dirs to tape device like /dev/st0 (linux)
# This script make both full and incremental backups.
# You need at two sets of five tapes. Label each tape as Mon, Tue, Wed, Thu and Fri.
# You can run script at midnight or early morning each day using cronjons.
# The operator or sys admin can replace the tape every day after the script has done.
# Script must run as root or configure permission via sudo.
# -------------------------------------------------------------------------
# Copyright (c) 1999 Vivek Gite <vivek@nixcraft.com>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
@palpalani
palpalani / mysql-backup.sh
Last active December 23, 2015 04:09
Shell Script To Backup MySql Database Server
#!/bin/bash
# Shell script to backup MySql database
# To backup MySql databases file to /backup directory and later pick up by your
# script. You can skip few databases from backup too.
# For more info please see (Installation info):
# http://www.cyberciti.biz/nixcraft/vivek/blogger/2005/01/mysql-backup-script.html
# Last updated: Nov - 2013
# --------------------------------------------------------------------
# This is a free shell script under GNU GPL version 2.0 or above
# Copyright (C) 2004, 2005 nixCraft project
@palpalani
palpalani / wordpress-sandbox.sh
Last active December 22, 2015 22:09
WordPress sandbox install
#!/bin/sh
# WordPress Sandbox
# palPalani
# m3webware.com
# requires wp-cli
# usage: wordpress-sandbox
# or: ./wordpress-sandbox.sh
# Download WordPress
@palpalani
palpalani / monitrc.sh
Last active December 22, 2015 21:49
Monitor centminmod (http://centminmod.com) powered VPS or dedicated server using Moint (http://mmonit.com/monit).
//Monitor CentMinMod (https://community.centminmod.com/) server using Monit
//Mmonit 5.14 - http://mmonit.com/monit/
//How to: http://mmonit.com/wiki/Monit/HowTo
//Real-world configuration examples - http://mmonit.com/wiki/Monit/ConfigurationExamples
//Pushover notifications - http://mmonit.com/wiki/MMonit/Notification
//About Monit
Monit is a helpful program that automatically monitors and manages server programs to ensure that they not only stay online consistently, but that the file size, checksum, or permissions are always correct. Additionally monit comes with a basic web interface through which all of the processes can be set up. This tutorial will cover the most basic setup and configuration.
//Install Monit on CentOS 6.x
@palpalani
palpalani / wp-admin.sql
Last active December 22, 2015 18:09
Creating WordPress admin account using PhpMyAdmin
/*
Creating admin user account for WordPress using PhpMyAdmin.
Please make the following changes and then run this SQL.
*** Change the Database name 'yourdbname'.
*** Change table names 'wp_users' and 'wp_usermeta' and also change 'wp_capabilities' and 'wp_user_level' according to table prefix.
*** Change username 'palpalani' and password 'password'
*** Change ID to whatever you need
*/
@palpalani
palpalani / wpconnect.php
Last active April 2, 2019 04:32
PliggConnect for WordPress WordPress and Pligg bridge plugin.
<?php
/*
* 1. create wp plugin for pligg
* 2. create file wpconnect.php at pligg root
*/
$pligg_url = '';
$pligg_path = '';
/*
@palpalani
palpalani / wp-pligg-connect.php
Last active November 21, 2019 21:34
PliggConnect for WordPress Integrating Pligg with WordPress
<?php
/*
I've managed to get Pligg to use WordPress authentication and user database.
I recently got Pligg using Pubcookie and that formed the basis of this work, however they are very different.
I've only tested this with Pligg. I believe future versions may have a better approach for external authentication so I can't guarantee this will work with future versions.
This approach is very "hacky". I've also been slightly lazy. It assumes that you will use WordPress' login, logout and register pages. This will break the existing login, logout and register forms in Pligg. The ultimate solution would allow the Pligg forms to login and logout also on WordPress and the register form to create new users in WordPress.
@palpalani
palpalani / Course_Tree.php
Last active December 21, 2015 17:29
MPTT for course
<?php
/**
* Course_Tree is a PHP class that provides an implementation of the modified preorder tree traversal algorithm making
* it easy for you to use MPTT in your PHP applications.
*
* It provides methods for adding nodes anywhere in the tree, deleting nodes, moving and copying nodes around the tree
* and methods for retrieving various information about the nodes.
*
* Course_Tree uses {@link http://dev.mysql.com/doc/refman/5.0/en/ansi-diff-transactions.html MySQL transactions} making