Advertisement
Guest User

Untitled

a guest
Oct 8th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 48.86 KB | None | 0 0
  1. <?php
  2. /** This file holds the functions for the Absolute Privacy plugin.
  3.  *
  4.  * By John Kolbert
  5.  * http://www.johnkolbert.com/
  6.  *
  7.  * email: j[at]johnkolbert[dot]com
  8.  */
  9.  
  10. /**
  11.  *    abpr_installOptionsMenu function
  12.  *
  13.  *    Hooks the settings page into add_options_page
  14.  *
  15.  * @return void
  16.  */
  17. function abpr_installOptionsMenu() { // install the options menu
  18.     add_options_page( __( 'Absolute Privacy', 'absprivacy' ), __( 'Absolute Privacy', 'absprivacy' ), 'manage_options', __FILE__, 'abpr_optionsPage' );
  19. }
  20.  
  21.  
  22. /**
  23.  * abpr_optionsPage function.
  24.  *
  25.  * Displays the settings page. Called by abpr_installOptionsMenu
  26.  *
  27.  * @return void
  28.  */
  29. function abpr_optionsPage() {
  30.  
  31.     global $wpdb;
  32.  
  33.     if ( isset( $_GET['db_update'] ) && abpr_needsUpgrade() ) {
  34.         abpr_doUpgrade(); //upgrade DB
  35.         echo '<div class="updated"><p>' . __( 'Absolute Privacy database settings upgraded successfully. Carry on.', 'absprivacy' ) . '</p></div>';
  36.     }
  37.  
  38.     if ( isset( $_POST['update_options'] ) ) { //we're updating
  39.         $options['member_lockdown']   = trim( $_POST['member_lockdown'], '{}' );
  40.         $options['redirect_page']     = trim( $_POST['redirect_page'], '{}' );
  41.         $options['allowed_pages']     = trim( $_POST['allowed_pages'], '{}' );
  42.         $options['admin_block']       = isset( $_POST['admin_block'] ) ? trim( $_POST['admin_block'], '{}' ) : null;
  43.         $options['rss_control']       = trim( $_POST['rss_control'], '{}' );
  44.         $options['rss_characters']    = trim( $_POST['rss_characters'], '{}' );
  45.         $options['members_only_page'] = trim( $_POST['members_only_page'], '{}' );
  46.         $options['profile_page']      = trim( $_POST['profile_page'], '{}' );
  47.  
  48.         $options['pending_welcome_email_subject']  = trim( stripslashes( $_POST['pending_welcome_email_subject'] ), '{}' );
  49.         $options['pending_welcome_message']        = trim( stripslashes( $_POST['pending_welcome_message'] ), '{}' );
  50.         $options['account_approval_email_subject'] = trim( stripslashes( $_POST['account_approval_email_subject'] ), '{}' );
  51.         $options['account_approval_message']       = trim( stripslashes( $_POST['account_approval_message'] ), '{}' );
  52.         $options['admin_approval_email_subject']   = trim( stripslashes( $_POST['admin_approval_email_subject'] ), '{}' );
  53.         $options['admin_approval_message']         = trim( stripslashes( $_POST['admin_approval_message'] ), '{}' );
  54.  
  55.         update_option( ABSPRIVACY_OPTIONS, $options );
  56.  
  57.         // Show a message to say we've done something
  58.         echo '<div class="updated"><p>' . __( 'Options saved', 'absprivacy' ) . '</p> </div>';
  59.  
  60.     } else {
  61.         $options = get_option( ABSPRIVACY_OPTIONS );
  62.     }
  63.  
  64.     //notify user that registrations are not enabled. Hopefully this will save me some support emails.
  65.     if ( 1 !== get_option( 'users_can_register' ) ) {
  66.         echo '<div class="updated"> <p>' . sprintf( __( '<strong>Notice:</strong> Your settings do not currently allow users to register themselves. If you want to allow the Absolute Privacy plugin to handle user moderation, please check <em>anyone can register</em> on the <a href="%s">general settings page</a>.', 'absprivacy' ), home_url( 'wp-admin/options-general.php' ) ) . '</p></div>';
  67.     }
  68.  
  69.     ?>
  70.     <div class="wrap">
  71.         <div id="icon-plugins" class="icon32"></div>
  72.         <h2><?php _e( 'Absolute Privacy: Options Page', 'absprivacy' ); ?></h2>
  73.         <?php if ( abpr_needsUpgrade() ) : ?>
  74.  
  75.             <p><?php _e( 'Absolute Privacy requires that your database settings be upgraded.', 'absprivacy' ); ?></p>
  76.             <a class="button-secondary" href="<?php echo get_admin_url() . 'options-general.php?page=absolute-privacy/functions.php&db_update'; ?>"><?php _e( 'Upgrade Settings', 'absprivacy' ); ?></a>
  77.  
  78.             <?php return; ?>
  79.         <?php endif; ?>
  80.  
  81.         <?php if (is_multisite()) : ?>
  82.             <p><?php _e( 'Sorry, Absolute Privacy does not currently support multi-site enabled installations. This is planned for a future release, but a timeline is not available.', 'absprivacy' ); ?></p>
  83.         <?php else : ?>
  84.  
  85.         <form method="post" action="">
  86.             <div class="submit" style="display: block; margin-bottom: -30px;">
  87.                 <input type="submit" name="update_options" value="<?php _e( 'Update Settings', 'absprivacy' ); ?>" style="font-weight:bold;"/>
  88.             </div>
  89.  
  90.             <br clear="all"/>
  91.  
  92.             <div style="float: left; width: 65%; margin: 5px;">
  93.  
  94.                 <table class="widefat" cellspacing="0">
  95.                 <thead>
  96.                 <tr class="thead">
  97.                     <th scope="col" style="width: 100px;" colspan="2"><?php _e( 'Privacy Method', 'absprivacy' ); ?></th>
  98.                     <th></th>
  99.                     <th></th>
  100.                     <th></th>
  101.                     <th></th>
  102.                     <th></th>
  103.                 </tr>
  104.                 </thead>
  105.  
  106.                 <tbody id="users" class="list:user user-list">
  107.                 <tr valign="top">
  108.                     <th style="width: 30px;"><?php _e( 'Off', 'absprivacy' ); ?></th>
  109.                     <td style="padding-top: 7px;"><input type="radio" name="member_lockdown" value="off"
  110.                                                          class="radio_class" <?php if ( $options['member_lockdown'] == "off" ) echo " checked "; ?> />
  111.                     </td>
  112.                     <th style="width: 140px;"><?php _e( 'Complete Lockdown:', 'absprivacy' ); ?></th>
  113.                     <td style="padding-top: 7px;"><input type="radio" name="member_lockdown" value="lockdown"
  114.                                                          class="radio_class" <?php if ( $options['member_lockdown'] == "lockdown" ) echo " checked "; ?> />
  115.                     </td>
  116.                     <th style="width: 120px;"><?php _e( 'Members Area:', 'absprivacy' ); ?></th>
  117.                     <td style="padding-top: 7px;"><input type="radio" name="member_lockdown" value="members_area"
  118.                                                          class="radio_class" <?php if ( $options['member_lockdown'] == "members_area" ) echo " checked "; ?> />
  119.                     </td>
  120.                 </tr>
  121.  
  122.                 <tr>
  123.                     <td colspan="6"
  124.                         id="members_off" <?php if ( 'off' !== $options['member_lockdown'] ) echo "style='display: none;'"; ?> >
  125.                         <p><?php _e( 'Privacy is currently <code>off</code>', 'absprivacy' ); ?></p>
  126.  
  127.                         <p><?php _e( 'What does this mean? Users may view your website as normal. However, user moderation is still enabled, meaning users can register, choose a username and password, but their account will not be active until you approve it. To disable user moderation, please deactivate the Absolute Privacy plugin.', 'absprivacy' ); ?></p>
  128.                     </td>
  129.                 </tbody>
  130.             </table>
  131.  
  132.                 <table id="lockdown_settings" class="widefat"
  133.                    style="margin-top: 15px; <?php if ( 'lockdown' !== $options['member_lockdown'] ) echo 'display: none;'; ?>"
  134.                    cellspacing="0">
  135.                 <thead>
  136.                 <tr class="thead">
  137.                     <th scope="col" style="width: 100px;" colspan="2"><?php _e( 'Lockdown Settings', 'absprivacy' ); ?></th>
  138.                     <th scope="col"><?php _e( 'Setting Description:', 'absprivacy' ); ?></th>
  139.                 </tr>
  140.                 </thead>
  141.  
  142.                 <tbody id="users" class="list:user user-list">
  143.                 <tr>
  144.                     <td colspan="3">
  145.                         <p><?php _e( 'Enabling <code>Complete Lockdown</code> means that only logged in users will be able to access any part of your website (except the pages you specify below). This is ideal for private family, personal, or business blogs. User moderation is also enabled, meaning you must approve user accounts before they will be activated.', 'absprivacy' ); ?></p>
  146.                     </td>
  147.                 </tr>
  148.  
  149.                 <tr>
  150.                     <th style="width: 120px;"><?php _e( 'Allowed Pages:', 'absprivacy' ); ?></th>
  151.                     <td><input type="text" name="allowed_pages" id="allowed_pages" style="width: 58px;"
  152.                                value="<?php echo isset( $options['allowed_pages'] ) ? $options['allowed_pages'] : ''; ?>"/></td>
  153.                     <td><?php _e( 'These pages will be accessible to non-logged in users. List page IDs separated by a comma (eg: <code>0,19,12</code>). <em>Tip:</em> Enter <code>0</code> to allow access to the home page.', 'absprivacy' ); ?></td>
  154.                 </tr>
  155.                 <tr>
  156.                     <th><?php _e( 'RSS Control:', 'absprivacy' ); ?></th>
  157.                     <td colspan="2">
  158.                         <input type="radio" name="rss_control"
  159.                                value="off" <?php if ( $options['rss_control'] == "off" ) echo 'checked'; ?> /><?php _e( 'RSS Disabled &nbsp; &nbsp;', 'absprivacy' ); ?>
  160.                         <input type="radio" name="rss_control"
  161.                                value="on" <?php if ( $options['rss_control'] == "on" ) echo 'checked'; ?> /><?php _e( ' RSS On &nbsp; &nbsp;', 'absprivacy' ); ?>
  162.                         <br/>
  163.                         <input type="radio" name="rss_control"
  164.                                value="headline" <?php if ( $options['rss_control'] == "headline" ) echo 'checked'; ?> /><?php _e( ' Limited to headlines &nbsp; &nbsp;', 'absprivacy' ); ?>
  165.                         <input type="radio" name="rss_control"
  166.                                value="excerpt" <?php if ( $options['rss_control'] == "excerpt" ) echo 'checked'; ?> /><?php echo sprintf( __( ' Limited to <input type="text" name="rss_characters" id="rss_characters" value="%s" style="width: 32px;" />&nbsp;Characters', 'absprivacy' ), isset( $options['rss_characters'] ) ? $options['rss_characters'] : '' ); ?>
  167.                         <br/><?php _e( 'Viewing your website\'s RSS feed does not require the user to login. Thus your RSS feed is publicly accessible if it is enabled. You may disable or limit the RSS feed above.', 'absprivacy' ); ?>
  168.                     </td>
  169.  
  170.                 </tr>
  171.  
  172.                 </tbody>
  173.             </table>
  174.  
  175.                 <table id="members_settings" class="widefat"
  176.                    style="margin-top: 15px; <?php if ( $options['member_lockdown'] != "members_area" ) echo 'display: none;'; ?>"
  177.                    cellspacing="0">
  178.                 <thead>
  179.                 <tr class="thead">
  180.                     <th scope="col" style="width: 100px;" colspan="2"><?php _e( 'Members Area Settings', 'absprivacy' ); ?></th>
  181.                     <th scope="col"><?php _e( 'Setting Description:', 'absprivacy' ); ?></th>
  182.                 </tr>
  183.                 </thead>
  184.  
  185.                 <tbody id="users" class="list:user user-list">
  186.                 <tr>
  187.                     <td colspan="3">
  188.                         <p>
  189.                             <?php _e( 'Enabling <code>Members Area</code> means that your site will be accessible to visitors as normal, except the members page that you specify below. The members page (and <em>all</em> subpages) will be accessible to logged in users only. User moderation is also enabled, meaning you must approve user accounts before they will be activated.', 'absprivacy' ); ?>
  190.                         </p>
  191.                     </td>
  192.                 </tr>
  193.  
  194.                 <tr>
  195.                     <th style="width: 150px;"><?php _e( 'Members Only Page:', 'absprivacy' ); ?></th>
  196.                     <td><input type="text" name="members_only_page" id="members_only_page" style="width: 58px;"
  197.                                value="<?php echo isset( $options['members_only_page'] ) ? $options['members_only_page'] : ''; ?>"/>
  198.                     </td>
  199.                     <td><?php _e( 'Enter the ID of your main members only page <code>Eg: 42</code> This page and all child pages will be accessible only to logged in members.', 'absprivacy' ); ?></td>
  200.                 </tr>
  201.  
  202.                 </tbody>
  203.             </table>
  204.  
  205.                 <script type="text/javascript">
  206.                 jQuery( document ).ready( function ( $ ) {
  207.                     $( ".radio_class" ).on( 'click', function () {
  208.                         var $this = $( this );
  209.  
  210.                         if ( $this.val() === "lockdown" ) {
  211.                             $( "#members_settings" ).fadeOut( 100 );
  212.                             $( "#members_off" ).fadeOut( 100 );
  213.                             $( "#lockdown_settings" ).fadeIn( 1000 );
  214.                             $( "#general_settings" ).fadeIn( 1000 );
  215.                         } else if ( $this.val() === "members_area" ) {
  216.                             $( "#lockdown_settings" ).fadeOut( 100 );
  217.                             $( "#members_off" ).fadeOut( 100 );
  218.                             $( "#members_settings" ).fadeIn( 1000 );
  219.                             $( "#general_settings" ).fadeIn( 1000 );
  220.                         } else {
  221.                             $( "#lockdown_settings" ).fadeOut( 100 );
  222.                             $( "#members_settings" ).fadeOut( 100 );
  223.                             $( "#general_settings" ).fadeOut( 100 );
  224.                             $( "#members_off" ).fadeIn( 1000 );
  225.                         }
  226.                     } );
  227.                 } )
  228.             </script>
  229.  
  230.                 <br clear="all"/>
  231.  
  232.                 <table class="widefat" cellspacing="0"
  233.                    id="general_settings" <?php if ( $options['member_lockdown'] == 'off' ) echo "style='display: none;'"; ?> >
  234.                 <thead>
  235.                 <tr class="thead">
  236.                     <th scope="col" style="width: 100px;" colspan="2" class=""
  237.                         style=""><?php _e( 'General Settings', 'absprivacy' ); ?></th>
  238.                     <th scope="col"><?php _e( 'Setting Description:', 'absprivacy' ); ?></th>
  239.                 </tr>
  240.                 </thead>
  241.  
  242.                 <tbody id="users" class="list:user user-list">
  243.                 <tr>
  244.                     <th><?php _e( 'Redirect Non-logged in Users To:', 'absprivacy' ); ?></th>
  245.                     <td style="padding-top: 2.5%;">
  246.                         <input type="text" name="redirect_page" id="redirect_page" style="width: 28px;" value="<?php echo isset( $options['redirect_page'] ) ? $options['redirect_page'] : ''; ?>"/>
  247.                     </td>
  248.                     <td><?php _e( 'By default, non-logged in users will be redirected to the login form. Alternatively, you can enter a page ID here that you want non-logged in users to be redirected to instead.', 'absprivacy' ); ?></td>
  249.                 </tr>
  250.  
  251.                 <tr>
  252.                     <th style="padding-top: 1%;"><?php _e( 'Block Admin Access:', 'absprivacy' ); ?></th>
  253.                     <td style="padding-top: 3%;"><input type="checkbox" name="admin_block" value="yes" <?php if ( isset( $options['admin_block'] ) && $options['admin_block'] == "yes" ) echo " checked "; ?> />
  254.                         <?php _e( 'Yes', 'absprivacy' ); ?>
  255.                     </td>
  256.                     <td><?php _e( 'This blocks subscribers from viewing any administrative pages, such as their wp-admin profile page or the dashboard. If they try to access an administrative page they will be redirected to the homepage.', 'absprivacy' ); ?></td>
  257.                 </tr>
  258.  
  259.                 </tbody>
  260.             </table>
  261.  
  262.                 <br clear="all"/>
  263.  
  264.                 <table class="widefat" cellspacing="0">
  265.  
  266.                 <thead>
  267.                 <tr class="thead">
  268.                     <th scope="col" style="width: 100px;" colspan="2" class=""
  269.                         style=""><?php _e( 'Message Settings', 'absprivacy' ); ?></th>
  270.                     <th scope="col"></th>
  271.                 </tr>
  272.                 </thead>
  273.  
  274.                 <tbody id="users" class="list:user user-list">
  275.                 <tr>
  276.                     <td colspan="3">
  277.                         <p><?php _e( 'You may use the following variables in your emails: %username%, %name%, %blogname%, %blogurl%, %approval_url%, %login_url%. You are not able to send the users password in clear text.', 'absprivacy' ); ?></p>
  278.                     </td>
  279.                 </tr>
  280.                 <tr>
  281.                     <th><?php _e( 'Profile Edit Page', 'absprivacy' ); ?></th>
  282.                     <td style="padding-top: 2%;">
  283.                         <input type="text" size="10" name="profile_page" id="profile_page" value="<?php echo isset( $options['profile_page'] ) ? $options['profile_page'] : ''; ?>"/>
  284.                     <td><?php _e( "If you've created a page for the user to edit their profile, enter its ID here <code>(eg: 42)</code>. If a user uses the password recovery tool, they will be given a temporary password with a link to this page to change it. <em>Tip:</em> Use the <code>[profilepage]</code> shortcode to create a profile page.", 'absprivacy' ); ?></td>
  285.                 </tr>
  286.  
  287.                 <tr valign="top">
  288.                     <th style="width: 150px; padding-top: 2%;"><?php _e( 'Pending Welcome Message:', 'absprivacy' ); ?>
  289.                         <br/><br/><span style="font-weight: lighter; font-size: 10px;"><?php _e( 'This message is sent to the user immediately after they register & prior to approval.', 'absprivacy' ); ?></span>
  290.                     </th>
  291.                     <td colspan="2">
  292.                         <?php _e( 'Email Subject:', 'absprivacy' ); ?><br/>
  293.                         <input type="text" name="pending_welcome_email_subject" id="pending_welcome_email_subject"
  294.                                value="<?php echo stripslashes( $options['pending_welcome_email_subject'] ); ?>"
  295.                                style="width: 100%;"/><br/>
  296.                         <?php _e( 'Email Message:', 'absprivacy' ); ?><br/>
  297.                         <textarea name="pending_welcome_message" id="pending_welcome_message" style="width: 100%;"
  298.                                   rows="5"><?php echo stripslashes( $options['pending_welcome_message'] ); ?></textarea>
  299.                     </td>
  300.                 </tr>
  301.  
  302.                 <tr valign="top">
  303.                     <th style="width: 150px; padding-top: 2%;"><?php _e( 'Account Approval Message:', 'absprivacy' ); ?>
  304.                         <br/><br/><span
  305.                             style="font-weight: lighter; font-size: 10px;"><?php _e( 'This message is sent to the user immediately after their account has been approved.', 'absprivacy' ); ?></span>
  306.                     </th>
  307.                     <td colspan="2">
  308.                         <?php _e( 'Email Subject:', 'absprivacy' ); ?><br/>
  309.                         <input type="text" name="account_approval_email_subject" id="account_approval_email_subject"
  310.                                value="<?php echo stripslashes( $options['account_approval_email_subject'] ); ?>"
  311.                                style="width: 100%;"/><br/>
  312.                         <?php _e( 'Email Message:', 'absprivacy' ); ?><br/>
  313.                         <textarea name="account_approval_message" id="account_approval_message" style="width: 100%;"
  314.                                   rows="5"><?php echo stripslashes( $options['account_approval_message'] ); ?></textarea>
  315.                     </td>
  316.                 </tr>
  317.  
  318.                 <tr valign="top">
  319.                     <th style="width: 150px; padding-top: 2%;"><?php _e( 'Admin Notification Message:', 'absprivacy' ); ?> <br/><br/><span
  320.                             style="font-weight: lighter; font-size: 10px;"><?php _e( 'This message is sent to the administrator after a new registration is waiting approval.', 'absprivacy' ); ?></span>
  321.                     </th>
  322.                     <td colspan="2">
  323.                         <?php _e( 'Email Subject:', 'absprivacy' ); ?><br/>
  324.                         <input type="text" name="admin_approval_email_subject" id="admin_approval_email_subject"
  325.                                value="<?php echo stripslashes( $options['admin_approval_email_subject'] ); ?>"
  326.                                style="width: 100%;"/><br/>
  327.                         <?php _e( 'Email Message:', 'absprivacy' ); ?><br/>
  328.                         <textarea name="admin_approval_message" id="admin_approval_message" style="width: 100%;"
  329.                                   rows="5"><?php echo stripslashes( $options['admin_approval_message'] ); ?></textarea>
  330.                     </td>
  331.                 </tr>
  332.                 </tbody>
  333.             </table>
  334.  
  335.                 <div class="clear"></div>
  336.  
  337.                 <div class="submit">
  338.                 <input type="submit" name="update_options" value="<?php _e( 'Update Settings', 'absprivacy' ); ?>" style="font-weight:bold;"/>
  339.             </div>
  340.  
  341.             </div>
  342.  
  343.             <div style="float: left; width: 30%; margin: 5px; ">
  344.  
  345.                 <table name="pl_donate" class="widefat fixed" style="margin-bottom: 10px;" cellspacing="0">
  346.                 <thead>
  347.                 <tr class="thead">
  348.                     <th scope="col" style="width: 100px;">
  349.                         <img style="margin-top: -5px; margin-right: 3px; float: left;" src="<?php echo ABSPRIVACY_URL; ?>/img/LinkBack.png" alt=""/>
  350.                         <?php _e(' How To Support This Plugin', 'absprivacy' ); ?>
  351.                     </th>
  352.                 </tr>
  353.                 </thead>
  354.  
  355.                 <tbody>
  356.                 <tr>
  357.                     <td>
  358.                         <ul style="font-size: 1.0em;">
  359.                             <li><a href="http://www.wordpress.org/extend/plugins/absolute-privacy/" title="<?php _e( 'Rate', 'absprivacy' ); ?>"><?php _e( 'Rate this plugin on WP.org', 'absprivacy' ); ?></a></li>
  360.                         </ul>
  361.                     </td>
  362.                 </tr>
  363.                 </tbody>
  364.             </table>
  365.                 <!-- #pl_donate -->
  366.  
  367.                 <table name="pl_help" class="widefat fixed" style="margin-bottom: 10px;" cellspacing="0">
  368.                 <thead>
  369.                 <tr class="thead">
  370.                     <th scope="col" class="" style="">
  371.                         <img style="margin-top: -5px; margin-right: 3px; float: left;" src="<?php echo ABSPRIVACY_URL; ?>/img/help.png" alt=""/>
  372.                         <?php _e( 'Plugin Help', 'absprivacy' ); ?>
  373.                     </th>
  374.                 </tr>
  375.                 </thead>
  376.  
  377.                 <tbody>
  378.                 <tr>
  379.                     <td>
  380.                         <ul style="font-size: 1.0em;">
  381.                             <li>
  382.                                 <a href="http://www.johnkolbert.com/portfolio/wp-plugins/absolute-privacy/" title="<?php _e( 'Go to Plugin Homepage', 'absprivacy' ); ?>"><?php _e( 'Plugin Homepage', 'absprivacy' ); ?>'</a>
  383.                             </li>
  384.                         </ul>
  385.                     </td>
  386.                 </tr>
  387.                 </tbody>
  388.             </table>
  389.                 <!-- #pl_help -->
  390.  
  391.                 <table name="pl_author" class="widefat fixed" cellspacing="0">
  392.                 <thead>
  393.                 <tr class="thead">
  394.                     <th scope="col" style="width: 100px;" class="" style="">
  395.                         <img style="margin-top: -5px; margin-right: 3px; float: left;" src="<?php echo ABSPRIVACY_URL; ?>/img/info.png" alt=""/>
  396.                         <?php _e( 'Plugin Author', 'absprivacy' ); ?>
  397.                     </th>
  398.                 </tr>
  399.                 </thead>
  400.  
  401.                 <tbody>
  402.                 <tr>
  403.                     <td>
  404.                         <p style="text-align: center; font-size: 1.2em;">
  405.                             <?php echo sprintf( __( 'Plugin created by <a href="%s" title="John Kolbert">John Kolbert</a>', 'absprivacy' ), 'http://www.johnkolbert.com/' ); ?><br/>
  406.                             <span style="font-size: 0.8em;">
  407.                                 <?php _e( 'Need Help?', 'absprivacy' ); ?> <a href="http://www.mammothapps.com/contact/" title="<?php _e( 'Hire Me', 'absprivacy' ); ?>"><?php _e( 'Hire me', 'absprivacy' ); ?>.</a>
  408.                                 <br/>
  409.                                 <a href="http://www.twitter.com/johnkolbert" title="<?php _e( 'Follow Me!', 'absprivacy' ); ?>"><?php _e( 'Follow me on Twitter!', 'absprivacy' ); ?></a><br/>
  410.                             </span>
  411.                         </p>
  412.  
  413.                         <p style="text-align: center; font-size: 1.2em;">
  414.                             <?php echo sprintf( __( 'Plugin maintained by <a href="%s" title="Eric Mann">Eric Mann</a>', 'absprivacy' ), 'http://eamann.com' ); ?><br/>
  415.                             <span style="font-size: 0.8em;">
  416.                                 <a href="http://www.twitter.com/ericmann" title="<?php _e( 'Follow Me!', 'absprivacy' ); ?>"><?php _e( 'Follow me on Twitter!', 'absprivacy' ); ?></a><br/>
  417.                             </span>
  418.                         </p>
  419.                     </td>
  420.                 </tr>
  421.                 </tbody>
  422.             </table>
  423.                 <!-- #pl_author -->
  424.  
  425.             </div>
  426.  
  427.             <div class="clear"></div>
  428.  
  429.         </form>
  430.  
  431.         <?php endif; ?>
  432.     </div>
  433. <?php
  434.  
  435. }
  436.  
  437. /**
  438.  * abpr_moderateMenu function.
  439.  *
  440.  * installs the "Moderate Users" page, which displays all users currently not approved on the blog
  441.  *
  442.  * @return void
  443.  */
  444. function abpr_moderateMenu() {
  445.     add_submenu_page( 'users.php', __( 'Moderate Users', 'absprivacy' ), __( 'Moderate Users', 'absprivacy' ), 'manage_options', basename( __FILE__ ), 'abpr_moderateUsers' );
  446. }
  447.  
  448. /**
  449.  * abpr_moderateUsers function.
  450.  *
  451.  * Allows for management of unapproved users. Called by
  452.  * abpr_moderateMeni
  453.  *
  454.  * @return void
  455.  */
  456. function abpr_moderateUsers() {
  457.     global $wpdb, $current_user;
  458.     $options = get_option( ABSPRIVACY_OPTIONS );
  459.  
  460.     if ( ! current_user_can( 'manage_options' ) )
  461.         wp_die( __( 'You are not able to do that', 'absprivacy' ) );
  462.  
  463.     if ( isset( $_GET['u_id'] ) && ! empty( $_GET['u_id'] ) ) { //we're querying just one user
  464.         $unapproved[0] = $_GET['u_id']; //make this an array to satisfy the foreach() further down
  465.  
  466.         $check_user = get_userdata( $unapproved[0] );
  467.         $cap        = $wpdb->prefix . "capabilities";
  468.  
  469.         if ( ! $check_user ) {
  470.             echo '<div class="error"><p>' . __( 'No such user exists. Check ID and try again.', 'absprivacy' ) . '</p></div>';
  471.  
  472.             return;
  473.         } elseif ( ! array_key_exists( ABSPRIVACY_ROLEREF, $check_user->$cap ) ) {
  474.             echo '<div class="updated"><p>' . __( 'This user has already been approved.', 'absprivacy' ) . '</p></div>';
  475.  
  476.             return;
  477.         }
  478.  
  479.     } else { // otherwise get all unapproved users
  480.  
  481.         $query      = "SELECT user_id FROM " . $wpdb->usermeta . " WHERE meta_key = '" . $wpdb->prefix . 'capabilities' . "' AND meta_value LIKE '%" . ABSPRIVACY_ROLEREF . "%';";
  482.         $unapproved = $wpdb->get_col( $query );
  483.     }
  484.  
  485.     if ( isset( $_POST['update_options'] ) ) {
  486.  
  487.         if ( $_POST['update_options'] === __( "Delete Selected Users", 'absprivacy' ) ) {
  488.             foreach ( $_POST['users'] as $user ) {
  489.                 if ( ! current_user_can( 'delete_user', $user ) ) {
  490.                     wp_die( __( 'You cannot delete that user.', 'absprivacy' ) );
  491.                 }
  492.                 if ( $user == $current_user->ID ) {
  493.                     wp_die( __( 'You cannot delete yourself.', 'absprivacy' ) );
  494.                 }
  495.  
  496.                 wp_delete_user( $user );
  497.             }
  498.             // Show a message to say we've done something
  499.             echo '<div class="updated"><p>' . __( 'User(s) deleted', 'absprivacy' ) . '</p></div>';
  500.  
  501.             return;
  502.         }
  503.  
  504.         if ( $_POST['update_options'] === __( "Approve Selected Users", 'absprivacy' ) ) {
  505.             foreach ( $_POST['users'] as $user ) {
  506.                 $user      = get_userdata( $user );
  507.                 $user_role = new WP_User( $user->ID );
  508.  
  509.                 $user_role->set_role( get_option( 'default_role' ) );
  510.  
  511.                 abpr_handleEmail( $user->ID, $type = 'account_approved' );
  512.  
  513.             }
  514.             // Show a message to say we've done something
  515.             echo '<div class="updated"><p>' . __( 'User(s) Approved. Notifications sent via email.', 'absprivacy' ) . '</p></div>';
  516.  
  517.             return;
  518.         }
  519.     }
  520.  
  521.     $output = '<div class="wrap">
  522.                 <h2>' . __( 'Absolute Privacy: Moderate Users', 'absprivacy' ) . '</h2>
  523.                 <form method="post" action="">
  524.                 <table id="tablo" class="widefat fixed" cellspacing="0">
  525.             <p id="tablo_para">' . __( 'The following users have registered but not been approved to login.', 'absprivacy' ) . '</p>
  526.  
  527.             <thead>
  528.             <tr class="thead">
  529.             <th scope="col"  class="manage-column column-cb check-column" style=""><input type="checkbox" /></th>
  530.             <th scope="col" id="cb" class="manage-column column-cb check-column" style="">' . __( 'ID', 'absprivacy' ) . '</th>
  531.             <th scope="col" id="username" class="manage-column column-username" style="">' . __( 'Username', 'absprivacy' ) . '</th>
  532.             <th scope="col" id="name" class="manage-column column-name" style="">' . __( 'Name', 'absprivacy' ) . '</th>
  533.             <th scope="col" id="email" class="manage-column column-email" style="">' . __( 'E-mail', 'absprivacy' ) . '</th>
  534.             <th scope="col" id="role" class="manage-column column-role" style="">' . __( 'Status', 'absprivacy' ) . '</th>
  535.             <th scope="col" id="role" class="manage-column column-role" style="">' . __( 'Registration Date', 'absprivacy' ) . '</th>
  536.             </tr>
  537.             </thead>
  538.  
  539.             <tfoot>
  540.             <tr class="thead">
  541.             <th scope="col"  class="manage-column column-cb check-column" style=""><input type="checkbox" /></th>
  542.             <th scope="col" id="cb" class="manage-column column-cb check-column" style="">' . __( 'ID', 'absprivacy' ) . '</th>
  543.             <th scope="col" id="username" class="manage-column column-username" style="">' . __( 'Username', 'absprivacy' ) . '</th>
  544.             <th scope="col" id="name" class="manage-column column-name" style="">' . __( 'Name', 'absprivacy' ) . '</th>
  545.             <th scope="col" id="email" class="manage-column column-email" style="">' . __( 'E-mail', 'absprivacy' ) . '</th>
  546.             <th scope="col" id="role" class="manage-column column-role" style="">' . __( 'Status', 'absprivacy' ) . '</th>
  547.             <th scope="col" id="role" class="manage-column column-role" style="">' . __( 'Registration Date', 'absprivacy' ) . '</th>
  548.         </tr>
  549.         </tfoot>
  550.         <tbody id="users" class="list:user user-list">';
  551.  
  552.     echo $output;
  553.  
  554.     $i     = 0;
  555.     $state = "class='alternate'";
  556.  
  557.     foreach ( $unapproved as $user_id ) {
  558.         $user = get_userdata( $user_id );
  559.         $i ++;
  560.  
  561.         echo "<tr id='user-$i' $state>
  562.           <th scope='row' class='check-column'><input type='checkbox' name='users[]' id='$user_id' class='administrator' value='$user_id' /></th>
  563.           <th scope='row' class='check-column'>$user_id</th>
  564.           <td class='username column-username'><strong><a href='user-edit.php?user_id=$user_id'>{$user->user_login}</a></strong></td>
  565.           <td class='name column-name'>{$user->user_firstname} {$user->user_lastname} </td><td class='email column-email'><a href='mailto:{$user->user_email}' title='e-mail: {$user->user_email}'>{$user->user_email}</a></td>
  566.           <td class='role column-role'>" . ABSPRIVACY_ROLENAME . "</td>
  567.           <td class='column-name'>{$user->user_registered}</td>
  568.           </tr>";
  569.  
  570.         if ( $state == "class='alternate'" ) {
  571.             $state = '';
  572.             continue;
  573.         }
  574.         if ( $state == '' ) {
  575.             $state = "class='alternate'";
  576.             continue;
  577.         }
  578.     }
  579.  
  580.     if ( $i == 0 ) {
  581.         echo "</table><script type='text/javascript'>document.getElementById('tablo').style.display = 'none'; document.getElementById('tablo_para').style.display = 'none';</script><p><strong>" . __( 'No users are waiting moderation', 'absprivacy' ) . "</strong></p>";
  582.         echo "</table></form></div>";
  583.  
  584.         return;
  585.     }
  586.  
  587.     $output = '</table>
  588.                 <p style="margin-bottom: 0px;">' . __( 'Approved users will receive an email notification of their approval.', 'absprivacy' ) . '</p>
  589.                 <div class="submit" style="float: left;"><input type="submit" name="update_options" value="' . __( 'Delete Selected Users', 'absprivacy' ) . '"  onClick="return confirm(\'' . __( 'Really Delete? (This cannot be undone)', 'absprivacy' ) . '\')" style="font-weight:bold; color: red; float: left;" /> </div>
  590.                 <div class="submit" style="float: left;"><input type="submit" name="update_options" value="' . __( 'Approve Selected Users', 'absprivacy' ) . '"  style="font-weight:bold; float: left;" /> </div>
  591.                 </form>';
  592.     echo $output;
  593. }
  594.  
  595.  
  596. /**
  597.  * abpr_handleEmail function.
  598.  *
  599.  * handles email notifications
  600.  *
  601.  * @param $user_id:    the integer ID of the user being acted upon (newly registered, approved, etc)
  602.  * @param $type:        pending_welcome, account_approve, or admin_notification
  603.  * @return bool
  604.  */
  605. function abpr_handleEmail( $user_id, $type ) {
  606.  
  607.     $options = get_option( ABSPRIVACY_OPTIONS );
  608.     $user    = get_userdata( $user_id ); //object with user info
  609.  
  610.     switch ( $type ) {
  611.         case( 'pending_welcome' ):
  612.             $to_email = $user->user_email;
  613.             $subject  = $options['pending_welcome_email_subject'];
  614.             $message  = $options['pending_welcome_message'];
  615.             break;
  616.  
  617.         case( 'account_approved' ):
  618.             $to_email = $user->user_email;
  619.             $subject  = $options['account_approval_email_subject'];
  620.             $message  = $options['account_approval_message'];
  621.             break;
  622.  
  623.         case( 'admin_notification' ):
  624.             $to_email = get_bloginfo( 'admin_email' );
  625.             $subject  = $options['admin_approval_email_subject'];
  626.             $message  = $options['admin_approval_message'];
  627.             break;
  628.  
  629.         default : //an invalid response has been given
  630.             return false;
  631.     }
  632.  
  633.     $login_url = ( isset( $options['redirect_page'] ) && $options['redirect_page'] != '' ) ? get_permalink( $options['redirect_page'] ) : wp_login_url();
  634.  
  635.     $replace = array(
  636.         '%username%'     => $user->user_login,
  637.         '%name%'         => $user->display_name,
  638.         '%blogname%'     => get_bloginfo( 'name' ),
  639.         '%blogurl%'      => get_bloginfo( 'url' ),
  640.         '%approval_url%' => get_bloginfo( 'url' ) . '/wp-admin/users.php?page=functions.php&u_id=' . $user_id,
  641.         '%login_url%'    => $login_url
  642.     );
  643.  
  644.     $email_body = strtr( stripslashes( $message ), $replace ); //get email body and replace variables
  645.  
  646.     $headers = "MIME-Version: 1.0\n" .
  647.         "From: " . get_option( 'blogname' ) . " <" . get_option( 'admin_email' ) . ">";
  648.  
  649.     wp_mail( $to_email, $subject, $email_body, $headers );
  650.  
  651. }
  652.  
  653.  
  654. /**
  655.  * abpr_check_is_feed function.
  656.  *
  657.  * handles filtering the content based on the value the user selected on the options page.
  658.  * Only runs if user has enabled "Lockdown Mode"
  659.  *
  660.  * @param $content:    The post content passed from the action
  661.  * @return string
  662.  */
  663. function abpr_check_is_feed( $content ) {
  664.     $options = get_option( ABSPRIVACY_OPTIONS );
  665.     if ( $options['member_lockdown'] == "lockdown" && is_feed() ) :
  666.         switch ( $options['rss_control'] ) {
  667.             case "on":
  668.                 //allow full RSS
  669.                 break;
  670.             case "headline":
  671.                 $content = '';
  672.                 break;
  673.             case "excerpt":
  674.                 $content = substr( strip_tags( get_the_content() ), 0, $options['rss_characters'] ) . "...";
  675.                 break;
  676.         }
  677.     endif;
  678.  
  679.     return $content;
  680. }
  681.  
  682.  
  683. /**
  684.  * abpr_lockDown function.
  685.  *
  686.  * Checks if plugin is enabled, on lockdown mode, or in member area mode
  687.  * and restricts non-logged in users accordingly.
  688.  *
  689.  * @return void
  690.  */
  691. function abpr_lockDown() {
  692.  
  693.     $options = get_option( ABSPRIVACY_OPTIONS );
  694.  
  695.     if ( $options['member_lockdown'] == 'off' || is_user_logged_in() ) {
  696.         return; //plugin is activated but disabled or user is logged in
  697.     } elseif ( $options['member_lockdown'] == "lockdown" ) {
  698.  
  699.         if ( is_feed() && $options['rss_control'] != "off" ) return; //allow RSS feed to be handled by check_is_feed() function unless the RSS feed is disabled.
  700.  
  701.         if ( isset( $options['allowed_pages'] ) && $options['allowed_pages'] != '' ) {
  702.             $allowed_pages = explode( ',', $options['allowed_pages'] );
  703.  
  704.             if ( in_array( 0, $allowed_pages ) && is_front_page() )
  705.                 return;
  706.  
  707.             if ( is_page( $allowed_pages ) || is_single( $allowed_pages ) )
  708.                 return; //let them visit the allowed pages
  709.         }
  710.  
  711.         $http             = ( ! empty( $_SERVER['HTTPS'] ) && strtolower( $_SERVER['HTTPS'] != 'off' ) ) ? 'https://' : 'http://'; //Thanks to Brian L. for this fix
  712.         $original_request = $http . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; //this is where the user was trying to go
  713.  
  714.  
  715.         if ( isset( $options['redirect_page'] ) && $options['redirect_page'] != '' ) { //redirect page setting has been set
  716.  
  717.             if ( is_single( $options['redirect_page'] ) || is_page( $options['redirect_page'] ) )
  718.                 return; //end the function if the visitor is already on the redirect_page page
  719.  
  720.             $redirect_url = get_permalink( $options['redirect_page'] );
  721.             $url          = $redirect_url . '?req=' . urlencode( $original_request );
  722.  
  723.         } else {
  724.  
  725.             $url = wp_login_url( $original_request );
  726.         }
  727.  
  728.         wp_redirect( $url, 302 );
  729.         exit();
  730.  
  731.     } elseif ( $options['member_lockdown'] == 'members_area' ) {
  732.  
  733.         if ( abpr_is_members_page() ) {
  734.  
  735.             $http             = ( ! empty( $_SERVER['HTTPS'] ) && strtolower( $_SERVER['HTTPS'] != 'off' ) ) ? 'https://' : 'http://'; //Thanks to Brian L. for this fix
  736.             $original_request = $http . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; //this is where the user was trying to go
  737.  
  738.             if ( isset( $options['redirect_page'] ) && $options['redirect_page'] != '' ) {
  739.  
  740.                 if ( is_single( $options['redirect_page'] ) || is_page( $options['redirect_page'] ) )
  741.                     return; //end the function if the visitor is already on the redirect_page page
  742.  
  743.                 $redirect_url = get_permalink( $options['redirect_page'] );
  744.                 $url          = $redirect_url . '?req=' . urlencode( $original_request );
  745.  
  746.             } else {
  747.                 $url = wp_login_url( $original_request );
  748.             }
  749.  
  750.             wp_redirect( $url, 302 ); //send them there
  751.             exit();
  752.         } else {
  753.             return; //not a members page, so let it go
  754.         }
  755.     }
  756.  
  757.     return;
  758. }
  759.  
  760. /**
  761.  * abpr_adminLockDown function.
  762.  *
  763.  * Blocks subscribers from their admin profile page if enabled
  764.  * in the plugin settings
  765.  *
  766.  * @return void
  767.  */
  768. function abpr_adminLockDown() {
  769.     global $userdata, $wpdb;
  770.  
  771.     $options = get_option( ABSPRIVACY_OPTIONS );
  772.  
  773.     if ( ! is_admin() || ! ( is_user_logged_in() ) || ( isset( $options['member_lockdown'] ) && $options['member_lockdown'] == 'off' ) ) return;
  774.     //if it's not an admin page or the user isn't logged in at all, we don't need this
  775.  
  776.     $user_role    = new WP_User( $userdata->ID );
  777.     $capabilities = $wpdb->prefix . 'capabilities';
  778.  
  779.     if ( isset( $options['admin_block'] ) && $options['admin_block'] == "yes" && array_key_exists( 'subscriber', $user_role->$capabilities ) ) {
  780.         $url = get_bloginfo( 'url' );
  781.         wp_redirect( $url, 302 );
  782.         exit();
  783.     }
  784. }
  785.  
  786. /**
  787.  * abpr_regCSS function.
  788.  *
  789.  * Adds CSS for registration form
  790.  *
  791.  * @return void
  792.  */
  793. function abpr_regCSS() {
  794.     echo '<style type="text/css">
  795.    #invite_code, #first_name, #last_name, #pswd1, #pswd2{
  796.         font-size: 24px;
  797.         width: 97%;
  798.         padding: 3px;
  799.         margin-top: 2px;
  800.         margin-right: 6px;
  801.         margin-bottom: 16px;
  802.         border: 1px solid #e5e5e5;
  803.         background: #fbfbfb;
  804.    }
  805.    #reg_passmail{
  806.         display:none;
  807.    }
  808.    </style>';
  809. }
  810.  
  811.  
  812. /**
  813.  * abpr_registrationBox function.
  814.  *
  815.  * Echos input boxes for first name, last name, and password to
  816.  * the registration box.
  817.  *
  818.  * Todo: allow users to add custom boxes via filter/action
  819.  * @return void
  820.  */
  821. function abpr_registrationBox() {
  822.  
  823.     $output = '<p><label>' . __( 'First Name:', 'absprivacy' ) . '<br />
  824.                 <input type="text" name="first_name" id="first_name" class="input" value="' . ( isset( $_POST['first_name'] ) ? esc_attr( stripslashes( $_POST['first_name'] ) ) : '' ) . '" size="25" tabindex="70" /></label></p>
  825.                 <p><label>' . __( 'Last Name:', 'absprivacy' ) . '<br />
  826.                 <input type="text" name="last_name" id="last_name" class="input" value="' . ( isset( $_POST['last_name'] ) ? esc_attr( stripslashes( $_POST['last_name'] ) ) : '' ) . '" size="25" tabindex="80" /></label></p>
  827.            
  828.                 <p><label>' . __( 'Password:', 'absprivacy' ) . '<br />
  829.                 <input type="password" name="pswd1" id="pswd1" class="input" size="25" tabindex="91"/></label></p>
  830.                 <p><label>' . __( 'Repeat Password:', 'absprivacy' ) . '<br />
  831.                 <input type="password" name="pswd2" id="pswd2" class="input" size="25" tabindex="92" /></label></p>';
  832.  
  833.     $output .= "\n" . '<p class="message register" style="margin-bottom: 8px;">' . __( 'Your account must be approved before you will be able to log in. You will be emailed once it is approved.', 'absprivacy' ) . '</p>';
  834.  
  835.     // echo apply_filter( 'abpr_regbox', $output );
  836.  
  837.     // do_action( 'abpor_add_regbox' );
  838.  
  839.     echo $output;
  840. }
  841.  
  842. /**
  843.  * abpr_checkRegErrors function.
  844.  *
  845.  * Adds error checks to registration form
  846.  *
  847.  * @param $errors:    contains other errors passed to the function
  848.  * @return mixed
  849.  */
  850. function abpr_checkRegErrors( $errors ) {
  851.  
  852.     if ( empty( $_POST['first_name'] ) || empty( $_POST['last_name'] ) ) {
  853.         $errors->add( 'name', __( '<strong>ERROR</strong>: You must enter a first and last name', 'absprivacy' ) );
  854.     }
  855.     if ( empty( $_POST['pswd1'] ) || empty( $_POST['pswd2'] ) || $_POST['pswd1'] == '' || $_POST['pswd2'] == '' ) {
  856.         $errors->add( 'password', __( '<strong>ERROR</strong>: Please enter a password in both password boxes.', 'absprivacy' ) );
  857.     } elseif ( $_POST['pswd1'] != $_POST['pswd2'] ) {
  858.         $errors->add( 'password', __( '<strong>ERROR</strong>: Passwords do not match.', 'absprivacy' ) );
  859.     }
  860.  
  861.     return $errors;
  862. }
  863.  
  864. /**
  865.  * abpr_addNewUser function.
  866.  *
  867.  * Adds new registrants name and password to the database
  868.  *
  869.  * @param $user_id:    the integer ID of the newly added user
  870.  * @return void
  871.  */
  872. function abpr_addNewUser( $user_id ) {
  873.  
  874.     update_user_meta( $user_id, 'first_name', esc_attr( stripslashes( $_POST['first_name'] ) ) );
  875.     update_user_meta( $user_id, 'last_name', esc_attr( stripslashes( $_POST['last_name'] ) ) );
  876.  
  877.     $user_role = new WP_User( $user_id );
  878.     $user_role->set_role( ABSPRIVACY_ROLEREF ); //for some reason this role isn't being set. Need to look into it
  879.  
  880.     if ( ! empty( $_POST['pswd1'] ) ) {
  881.         wp_set_password( esc_attr( stripslashes( $_POST['pswd1'] ) ), $user_id );
  882.     }
  883.  
  884.     unset( $_POST['pswd1'] );
  885.     unset( $_POST['pswd2'] );
  886. }
  887.  
  888. /**
  889.  * abpr_add_error_code function.
  890.  *
  891.  * Adds 'unapproved' $wp_error to the list of shake codes for the login box
  892.  *
  893.  * @param $shake_codes:    other shake error codes passed to the function
  894.  * @return array
  895.  */
  896. function abpr_add_error_code( $shake_codes ) {
  897.     $shake_codes[] = 'unapproved';
  898.  
  899.     return $shake_codes;
  900.  
  901. }
  902.  
  903. /**
  904.  * abpr_authenticateUser function.
  905.  *
  906.  * Adds additional authentication when logging in. Checks that the
  907.  * user trying to log in isn't an 'Unapproved User'
  908.  *
  909.  * @param $user:        NULL
  910.  * @param $username:    username of attempted login
  911.  * @param $password:    password of attempted login
  912.  *
  913.  * @return WP_User
  914.  */
  915. function abpr_authenticateUser( $user, $username, $password ) {
  916.     global $wpdb;
  917.  
  918.     $tempUser = get_user_by( 'login', $username );
  919.  
  920.     $cap = $wpdb->prefix . "capabilities";
  921.     if ( $tempUser && array_key_exists( ABSPRIVACY_ROLEREF, $tempUser->$cap ) ) { //if the user's role is listed as "unapproved"
  922.         $user = new WP_Error( 'unapproved', __( "<strong>ERROR</strong>: The administrator of this site must approve your account before you can login. You will be notified via email when it has been approved.", 'absprivacy' ) );
  923.         add_filter( 'shake_error_codes', 'abpr_add_error_code' ); //make the login box shake
  924.         remove_action( 'authenticate', 'wp_authenticate_username_password', 20 ); //prevent authentication of user
  925.     }
  926.  
  927.     return $user;
  928. }
  929.  
  930. /**
  931.  * abpr_profileRecoveryLink function.
  932.  *
  933.  * If the profile page has been set in the options, this
  934.  * adds a link in the password recovery email to allow the
  935.  * user to change their password.
  936.  *
  937.  * @param $message:    The original password recovery message
  938.  * @param $key:        The users unique key. Not used in this function
  939.  * @return bool
  940.  */
  941. function abpr_profileRecoveryLink( $message, $key ) {
  942.  
  943.     $options = get_option( ABSPRIVACY_OPTIONS );
  944.  
  945.     $message = sprintf( __( "Here is your temporary password for %s\n \n%s", 'absprivacy' ), get_option( 'blogname' ), $message );
  946.  
  947.     if ( isset( $options['profile_page'] ) && $options['profile_page'] != '' ) {
  948.  
  949.         $message .= sprintf( __( "\n \n After logging in, you may change this temporary password here: %s", 'absprivacy' ), get_permalink( $options['profile_page'] ) );
  950.     }
  951.  
  952.     return $message;
  953.  
  954. }
  955.  
  956. /**
  957.  * abpr_is_ancestor function.
  958.  *
  959.  * Checks if the given $post_id is an ancestor of the currently
  960.  * queried post
  961.  *
  962.  * Thanks to http://www.kevinleary.net/wordpress-is_child-for-advanced-navigation/ for this
  963.  * $post_id:    ID of post/page to check
  964.  * @return bool
  965.  */
  966. function abpr_is_ancestor( $post_id ) {
  967.     global $wp_query;
  968.  
  969.     $ancestors = $wp_query->post->ancestors;
  970.  
  971.     if ( in_array( $post_id, $ancestors ) ) {
  972.         $return = true;
  973.     } else {
  974.         $return = false;
  975.     }
  976.  
  977.     return $return;
  978. }
  979.  
  980. /**
  981.  * abpr_is_members_page function.
  982.  *
  983.  * Checks if the current page is the members page or a subpage of it. Calls abpr_is_ancestor()
  984.  *
  985.  * @return bool
  986.  */
  987. function abpr_is_members_page() {
  988.     global $wpdb;
  989.  
  990.     $options      = get_option( ABSPRIVACY_OPTIONS );
  991.     $members_page = $options['members_only_page'];
  992.  
  993.     if ( is_single( $members_page ) || is_page( $members_page ) ) {
  994.         $return = true;
  995.     } elseif ( is_page() && abpr_is_ancestor( $members_page ) ) {
  996.         $return = true;
  997.     } else {
  998.         $return = false;
  999.     }
  1000.  
  1001.     return $return; //true = is member page; false = not member page
  1002. }
  1003.  
  1004. /**
  1005.  * wp_new_user_notification function
  1006.  *
  1007.  * Overwrites wp_new_user_notification() function found in pluggable.php
  1008.  * Handles emails when a new user registers.
  1009.  *
  1010.  * @return void
  1011.  */
  1012. if ( ! function_exists( 'wp_new_user_notification' ) ) {
  1013.     function wp_new_user_notification( $user_id, $plaintext_pass = '' ) {
  1014.  
  1015.         $user = get_userdata( $user_id ); //object with user info
  1016.  
  1017.         abpr_handleEmail( $user_id, $type = 'admin_notification' ); //send admin email
  1018.  
  1019.         if ( empty( $plaintext_pass ) )
  1020.             return;
  1021.  
  1022.         abpr_handleEmail( $user_id, $type = 'pending_welcome' ); //send new user pending message email
  1023.  
  1024.     }
  1025. }
  1026.  
  1027. /**
  1028.  * abpr_loginShortcode function.
  1029.  *
  1030.  * Handles the [loginform] shortcode. This displays a login form
  1031.  * via wp_login_form() if the user is not logged in. Otherwise it
  1032.  * displays the useraname and a logout link.
  1033.  *
  1034.  * The shortcode takes the standard inputs of wp_login_form()
  1035.  */
  1036. function abpr_loginShortcode( $atts ) {
  1037.     global $userdata;
  1038.  
  1039.     extract(
  1040.         shortcode_atts(
  1041.             array(
  1042.                  'redirect'       => null,
  1043.                  'form_id'        => 'loginform',
  1044.                  'label_username' => __( 'Username', 'absprivacy' ),
  1045.                  'label_password' => __( 'Password', 'absprivacy' ),
  1046.                  'label_remember' => __( 'Remember Me', 'absprivacy' ),
  1047.                  'label_log_in'   => __( 'Log In', 'absprivacy' ),
  1048.                  'id_username'    => 'user_login',
  1049.                  'id_password'    => 'user_pass',
  1050.                  'id_remember'    => 'rememberme',
  1051.                  'id_submit'      => 'wp-submit',
  1052.                  'remember'       => true,
  1053.                  'value_username' => '',
  1054.                  'value_remember' => false,
  1055.                  'loggedin_id'    => 'logged-in',
  1056.                  'logout_url'     => home_url(),
  1057.                  'lostpassword'   => null
  1058.             ),
  1059.             $atts
  1060.         )
  1061.     );
  1062.  
  1063.     switch ( $redirect ) {
  1064.  
  1065.         case null :
  1066.         case 'same' :
  1067.             if ( null === $redirect && isset( $options['redirect_page'] ) && $options['redirect_page'] != '' ) {
  1068.                 $redirect_to = get_permalink( $options['redirect_page'] );
  1069.                 break;
  1070.             }
  1071.             $http        = ( ! empty( $_SERVER['HTTPS'] ) && strtolower( $_SERVER['HTTPS'] != 'off' ) ) ? 'https://' : 'http://';
  1072.             $redirect_to = $http . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; //this is where the user was trying to go
  1073.             break;
  1074.  
  1075.         case 'home' :
  1076.             $redirect_to = home_url();
  1077.             break;
  1078.  
  1079.         default :
  1080.             $redirect_to = $redirect;
  1081.     }
  1082.  
  1083.     $redirect_to = ( empty( $_GET['req'] ) ? $redirect_to : $_GET['req'] ); //a get request trumps the user input for now
  1084.  
  1085.     if ( is_user_logged_in() ) {
  1086.         echo '<p id="' . $loggedin_id . '"> ' . sprintf( __( 'You are currently logged in as %s', 'absprivacy' ), $userdata->user_login ) . '. <a href="' . wp_logout_url( $logout_url ) . '" title="' . __( 'Logout', 'absprivacy' ) . '">' . __( 'Log out?', 'absprivacy' ) . '</a></p>';
  1087.     } else {
  1088.         $return = wp_login_form(
  1089.             array(
  1090.                  'echo'           => false,
  1091.                  'redirect'       => $redirect_to,
  1092.                  'label_username' => $label_username,
  1093.                  'label_password' => $label_password,
  1094.                  'label_remember' => $label_remember,
  1095.                  'label_log_in'   => $label_log_in,
  1096.                  'id_username'    => $id_username,
  1097.                  'id_password'    => $id_password,
  1098.                  'id_remember'    => $id_remember,
  1099.                  'id_submit'      => $id_submit,
  1100.                  'remember'       => $remember,
  1101.                  'value_username' => $value_username,
  1102.                  'value_remember' => $value_remember
  1103.             )
  1104.         );
  1105.     }
  1106.  
  1107.     return $return;
  1108. }
  1109.  
  1110. /**
  1111.  * abpr_profileShortcode function.
  1112.  *
  1113.  * Handles the [profilepage] shortcode. This displays a login form
  1114.  * via wp_login_form() if the user is not logged in. Otherwise it
  1115.  * displays the useraname and a logout link, and a form where the user
  1116.  * can chagne their name, email, and password. The code is found in
  1117.  * profile_page.php
  1118.  *
  1119.  */
  1120. function abpr_profileShortcode() {
  1121.  
  1122.     include( 'profile_page.php' );
  1123.  
  1124. }
  1125.  
  1126. function abpr_needsUpgrade() {
  1127.  
  1128.     $db_version = get_option( ABSPRIVACY_DBOPTION );
  1129.     $options    = get_option( ABSPRIVACY_OPTIONS );
  1130.  
  1131.     if ( ! $db_version || $db_version < ABSPRIVACY_DBVERSION || ! $options ) {
  1132.         return true;
  1133.     }
  1134.  
  1135.     return false;
  1136. }
  1137.  
  1138. function abpr_adminnotice() {
  1139.     echo '<div class="error"><p>' . __( 'Absolute Privacy database update needed. Your site may not be protected until you update.', 'absprivacy' ) . ' <a href="' . admin_url() . 'wp-admin/options-general.php?page=absolute-privacy/functions.php' . '">' . __( 'More information', 'absprivacy' ) . '</a></p></div>';
  1140. }
  1141.  
  1142.  
  1143. /**
  1144.  *    abpr_doUpgrade function
  1145.  *
  1146.  *    Runs when plugin is first activated or if a database/settings update
  1147.  *    is needed. Handles
  1148.  *
  1149.  * @return void
  1150.  */
  1151. function abpr_doUpgrade() {
  1152.  
  1153.     global $wp_roles;
  1154.  
  1155.     /* First lets make sure the absolute privacy role is set */
  1156.     $role = get_role( ABSPRIVACY_ROLEREF );
  1157.     if ( ! $role ) add_role( ABSPRIVACY_ROLEREF, ABSPRIVACY_ROLENAME ); //create the unapproved role
  1158.  
  1159.     $options = get_option( ABSPRIVACY_OPTIONS );
  1160.  
  1161.     if ( ! $options ) { // no options set so set default
  1162.  
  1163.         $legacy_options = get_option( 'absolute_privacy' ); // options term used prior to 2.0
  1164.  
  1165.         if ( $legacy_options ) { // user is upgrading from legacy version
  1166.             $options['member_lockdown']                = ( $legacy_options['members_enabled'] == 'yes' ) ? 'lockdown' : 'off';
  1167.             $options['allowed_pages']                  = $legacy_options['allowed_pages'];
  1168.             $options['pending_welcome_email_subject']  = $legacy_options['pending_welcome_email_subject'];
  1169.             $options['pending_welcome_message']        = $legacy_options['pending_welcome_message'];
  1170.             $options['account_approval_email_subject'] = $legacy_options['account_approval_email_subject'];
  1171.             $options['account_approval_message']       = $legacy_options['account_approval_message'];
  1172.             $options['admin_approval_email_subject']   = $legacy_options['admin_approval_email_subject'];
  1173.             $options['admin_approval_message']         = $legacy_options['admin_approval_message'];
  1174.             $options['redirect_page']                  = $legacy_options['redirect_page'];
  1175.             $options['admin_block']                    = $legacy_options['admin_block'];
  1176.             $options['rss_control']                    = $legacy_options['rss_control'];
  1177.             $options['rss_characters']                 = $legacy_options['rss_characters'];
  1178.  
  1179.  
  1180.             delete_option( 'absolute_privacy' ); // delete legacy options from database
  1181.             delete_option( 'absolute_privacy_default' );
  1182.  
  1183.             /* prior to 2.0 Absolute Privacy changed the default role. 2.0+ no longer does this
  1184.              * so we need to change the default role back. For now we'll just change this to subscriber
  1185.              */
  1186.             $default_role = get_option( 'default_role' );
  1187.             if ( $default_role == 'unapproved' ) {
  1188.                 update_option( 'default_role', 'subscriber' );
  1189.             }
  1190.  
  1191.         } else { // user must be installing fresh since no options were found
  1192.  
  1193.             $options['member_lockdown']                = 'off';
  1194.             $options['rss_control']                    = 'off';
  1195.             $options['pending_welcome_email_subject']  = sprintf( __( 'Your account with %s is under review', 'absprivacy' ), stripslashes( get_option( 'blogname' ) ) );
  1196.             $options['pending_welcome_message']        = __( "Hi %name%, \n \n Thanks for registering for %blogname%! Your registration is currently being reviewed. You will not be able to login until it has been approved. You will receive an email at that time. Thanks for your patience. \n \n Sincerely, \n \n %blogname%", 'absprivacy' );
  1197.             $options['account_approval_email_subject'] = __( "Your account has been approved!", 'absprivacy' );
  1198.             $options['account_approval_message']       = __( "Your registration with %blogname% has been approved! \n \n You may login using the following information: \n Username: %username% \n Password: (hidden) \n URL: %login_url%", 'absprivacy' );
  1199.             $options['admin_approval_email_subject']   = __( "A new user is waiting approval", 'absprivacy' );
  1200.             $options['admin_approval_message']         = __( "A new user has registered for %blogname% and is waiting your approval. You may approve or delete them here: %approval_url% \n \n This user cannot log in until you approve them.", 'absprivacy' );
  1201.  
  1202.         }
  1203.  
  1204.         update_option( ABSPRIVACY_OPTIONS, $options ); // set option values
  1205.         update_option( ABSPRIVACY_DBOPTION, ABSPRIVACY_DBVERSION );
  1206.     } else { // there are $options already in the database
  1207.  
  1208.         if ( abpr_needsUpgrade() ) {
  1209.             /* Run options upgrade script here */
  1210.  
  1211.             // for now lets just enter the DB version
  1212.             update_option( ABSPRIVACY_DBOPTION, ABSPRIVACY_DBVERSION );
  1213.         }
  1214.     }
  1215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement