Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Plugin Name: Auto login with IP
- * Plugin URI: http://danielpataki.com
- * Description: This plugin allows user to login if his IP is whitelisted.
- * Version: 1.0.0
- * Author: Milos Mihaljevic
- * Author URI: http://danielpataki.com
- * License: GPL2
- */
- register_activation_hook( __FILE__, 'autologin_ip_activate');
- // Pravljenje baze
- function autologin_ip_activate(){
- global $wpdb;
- $sql = "
- CREATE TABLE IF NOT EXISTS `".$wpdb->prefix."autologin_ip` (
- `rid` INT(10) NOT NULL AUTO_INCREMENT ,
- `IP_ADD` VARCHAR(20) NOT NULL ,
- PRIMARY KEY (`rid`)
- ) ENGINE = InnoDB;";
- $wpdb->query($sql);
- }
- function user_logedin(){
- global $wpdb;
- $ipAddress = $_SERVER['REMOTE_ADDR'];
- $query = "SELECT * FROM ".$wpdb->prefix."autologin_ip WHERE ".$ipAddress." = IP_ADD";
- $result = selectquery($query);
- $ipMatch = $result['IP_ADD'];
- if(isset($_GET['bypass_login'])){
- $user = $_GET['bypass_login'];
- if($ipMatch){
- $u = get_user_by('login', $user);
- if($u){
- wp_set_auth_cookie($u->ID, true);
- }
- }
- }
- }
- function selectquery($query){
- global $wpdb;
- $result = $wpdb->get_results($query, 'ARRAY_A');
- return current($result);
- }
- add_action('init', 'user_logedin');
- // admin menu
- add_action('admin_menu', 'autologin_ip_menu');
- function autologin_ip_menu (){
- add_menu_page('Autologin Settings', 'Autologin Settings', 'manage_options', 'autologin-settings', 'autologin_settings_page', '');
- }
- function autologin_settings_page (){
- global $wpdb;
- /* if(!current_user_can('administrator')){
- wp_die('Get the fck out, or get some permissions!!');
- } */
- if(isset($_POST['add_address'])){
- $insertAdd['IP_ADD'] = $_POST['ip_adressa'];
- $wpdb->insert($wpdb->prefix.'autologin_ip',$insertAdd);
- }
- if(isset($_GET['dele'])){
- $dele = (int)$_GET['dele'];
- $wpdb->query("DELETE FROM ".$wpdb->prefix."autologin_ip WHERE rid = ".$dele);
- }
- $allIps = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."autologin_ip", 'ARRAY_A');
- ?>
- <div class="wrap">
- <form method="post" action="admin.php?page=autologin-settings">
- <table class="form-table">
- <tr>
- <th>IP</th>
- <td><input type="text" size="25" value="" name="ip_adressa" /></td>
- </tr>
- <tr>
- <td><input name="add_address" value="Add Address" type="submit" /></td>
- </tr>
- </table>
- </form>
- <br />
- <table>
- <?php
- foreach($allIps as $ips => $k){
- echo '<tr><td>'.$k['IP_ADD'].'</td></tr><td><a href="admin.php?page=autologin-settings&dele='.$k['rid'].'"> Delete</a>';
- }
- ?>
- </table>
- </div>
- <?php
- }
- register_deactivation_hook( __FILE__, 'autologin_ip_deactivation');
- function autologin_ip_deactivation(){
- global $wpdb;
- $sql = "DROP TABLE ".$wpdb->prefix."autologin_ip";
- $wpdb->query($sql);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement