Advertisement
Hypnotic

plugin

Mar 1st, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.13 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  
  5.     Plugin Name: WP User Control
  6.     Plugin URI: http://oaktondata.com/wp-user-control/
  7.     Version: 1.1.1
  8.     Author: Bill Edgar
  9.     Author URI: http://oaktondata.com
  10.     Text Domain: wp-uc-widget
  11.     Description: WP User Control adds a sidebar widget that allows a user to login, register, retrieve lost passwords, etc. without leaving a page/post within your site.
  12.     Package: wp-uc-widget
  13.     License: BSD New (3-CLause License)
  14.    
  15.     Copyright (c) 2012, Oakton Data LLC
  16.     All rights reserved.
  17.  
  18.     Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  19.        
  20.         * Redistributions of source code must retain the above copyright
  21.           notice, this list of conditions and the following disclaimer.
  22.         * Redistributions in binary form must reproduce the above copyright
  23.           notice, this list of conditions and the following disclaimer in the
  24.           documentation and/or other materials provided with the distribution.
  25.         * Neither the name of the Oakton Data LLC nor the
  26.           names of its contributors may be used to endorse or promote products
  27.           derived from this software without specific prior written permission.
  28.  
  29.     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  30.     ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  31.     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  32.     DISCLAIMED. IN NO EVENT SHALL Oakton Data LLC BE LIABLE FOR ANY
  33.     DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  34.     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  35.     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  36.     ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  37.     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38.     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39.    
  40.     This is the main PHP class file for the WP User Control Widget plugin.
  41.    
  42. */
  43.  
  44. // define constants
  45. define( 'WP_USER_CONTROL_WIDGET_VERSION', '1.1' );
  46. define( 'WP_USER_CONTROL_WIDGET_BASE_URL', network_site_url() );
  47.  
  48. // directory locations
  49. define( 'WP_USER_CONTROL_WIDGET_DIR', plugin_dir_url(__FILE__) );
  50. define( 'WP_USER_CONTROL_WIDGET_CSS', WP_USER_CONTROL_WIDGET_DIR . 'css/' );
  51. define( 'WP_USER_CONTROL_WIDGET_INCLUDES', dirname(__FILE__) . '/' . 'inc/' );
  52. define( 'WP_USER_CONTROL_WIDGET_JS', WP_USER_CONTROL_WIDGET_DIR . 'js/' );
  53. define( 'WP_USER_CONTROL_WIDGET_HTML', WP_USER_CONTROL_WIDGET_DIR . 'html/' );
  54.  
  55. // php class files
  56. define( 'WP_USER_CONTROL_WIDGET_SIDEBAR_CLASS', 'SidebarWidget' );
  57. define( 'WP_USER_CONTROL_WIDGET_CLASS', 'WPUserControlWidget' );
  58. define( 'WP_USER_CONTROL_WIDGET_EXCEPTION_CLASS', 'Exception' );
  59. define( 'WP_USER_CONTROL_WIDGET_UTILITIES_CLASS', 'Utilities' );
  60.  
  61. // definition and configuration files
  62. define( 'WP_USER_CONTROL_WIDGET_STYLE', 'style.css' );
  63.  
  64. // generic include method
  65. function wp_uc__autoinclude( $class_name ) {
  66.     try {
  67.         include_once( WP_USER_CONTROL_WIDGET_INCLUDES . $class_name . '.php' );
  68.     } catch ( Exception $e ) {
  69.         echo "<p>" . $e->getMessage() . "</p>";
  70.     }
  71. }
  72.  
  73. // generic getter method
  74. function wp_uc__get( $property, $obj ) { // generic getter
  75.     if ( array_key_exists( $property, get_class_vars( get_class( $obj ) ) ) ) {
  76.         return $obj->$property;
  77.     } else {
  78.         die("<p>$property does not exist in " . get_class( $obj ) . "</p>");
  79.     }
  80. }
  81.  
  82. // generic setter method
  83. function wp_uc__set( $property, $value, $obj ) { // generic setter
  84.     if ( array_key_exists( $property, get_class_vars( get_class( $obj ) ) ) ) {
  85.         $obj->$property = $value;
  86.     } else {
  87.         die( "<p>$property does not exist in " . get_class( $obj ) . "</p>" );
  88.     }
  89. }
  90.  
  91. // generic toString method
  92. function wp_uc__toString( $obj ) { // generic object toString
  93.     $attributes = get_class_vars( get_class( $obj ) );
  94.     $str = 'Class = ' . get_class( $obj ) . '\n';
  95.     foreach ( $attributes as $name => $value ) {
  96.         $str .= $name . ' = ' . $value . '\n';
  97.     }
  98.     return $str;
  99. }
  100.  
  101. if ( !class_exists( 'wp_uc_widget' ) ) {
  102.  
  103.     // wp_uc_widget class
  104.     class wp_uc_widget {
  105.        
  106.         // public constructor method
  107.         function wp_uc_widget() {
  108.             $this->__construct();
  109.         }
  110.        
  111.         // hidden constructor method
  112.         function __construct() {
  113.            
  114.             wp_uc__autoinclude( WP_USER_CONTROL_WIDGET_EXCEPTION_CLASS );
  115.             wp_uc__autoinclude( WP_USER_CONTROL_WIDGET_SIDEBAR_CLASS ); // must be loaded first... base class
  116.             wp_uc__autoinclude( WP_USER_CONTROL_WIDGET_UTILITIES_CLASS );
  117.             wp_uc__autoinclude( WP_USER_CONTROL_WIDGET_CLASS );
  118.            
  119.             // verify we're on admin pages
  120.             if ( is_admin() ) {
  121.  
  122.                 // runs when plugin is activated
  123.                 register_activation_hook( __FILE__, array( &$this, 'activate' ) );
  124.                 // runs when plugin is deactivated
  125.                 register_deactivation_hook( __FILE__, array( &$this, 'deactivate' ) );
  126.                
  127.             }
  128.        
  129.         }
  130.        
  131.         // activate method
  132.         function activate() {
  133.             // call setup function
  134.             $this->setup();
  135.         }
  136.        
  137.         // deactivate method
  138.         function deactivate() {
  139.            
  140.             // remove action and filter hooks          
  141.             remove_action(
  142.                 $tag = 'wp_login_failed',
  143.                 $function_to_remove = 'wp_user_control_login_fail_action',
  144.                 $priority = 10,
  145.                 $accepted_args = 1
  146.                 ); // remove action hook for failed login
  147.            
  148.             remove_filter(
  149.                 $tag = 'registration_errors',
  150.                 $function_to_remove = 'wp_user_control_registration_errors_filter',
  151.                 $priority = 10,
  152.                 $accepted_args = 3
  153.                 ); // remove filter for registration errors
  154.                
  155.             remove_filter(
  156.                 $tag = 'login_url',
  157.                 $function_to_remove = 'wp_user_control_login_url_filter',
  158.                 $priority = 10,
  159.                 $accepted_args = 2
  160.                 ); // remove filter for custom login url
  161.            
  162.         }
  163.        
  164.         // setup method
  165.         function setup() {
  166.            
  167.         }
  168.        
  169.         // uninstall method
  170.         function uninstall() {
  171.             if ( !defined( 'ABSPATH' ) || !defined( 'WP_UNINSTALL_PLUGIN' ) ) {
  172.                 exit();
  173.             }
  174.         }
  175.        
  176.         // validate method
  177.         function validate( $rawinput ) {
  178.             return $rawinput;
  179.         }
  180.        
  181.     }
  182.    
  183. } // end class wp_uc_widget
  184.  
  185. // instantiate new wp_uc_widget object
  186. if ( class_exists( 'wp_uc_widget' ) ) {
  187.     new wp_uc_widget();
  188. }
  189. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement