--- /dev/null
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * PDF Output by admin-ajax
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @version 0.1
+ */
+
+require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/billingSupport.php';
+require_once GLM_MEMBERS_CONTACTS_PLUGIN_CLASS_PATH . '/data/dataContacts.php';
+/**
+ * Steve Note...
+ *
+ * You can get to this using the following URL.
+ *
+ * {host}/wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=setupQueue
+ *
+ * You should be able to do this as POST or GET and should be able to add and read additional parameters.
+ * I added a "mystuff" parameter to the URL above and it does output from the code in the
+ * modelAction() function below.
+ *
+ * To add another model under models/admin/ajax all you need to do is create it and add it to the
+ * setup/validActions.php file.
+ *
+ */
+
+// Load Members data abstract
+// require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataImages.php';
+
+/**
+ * This class performs the work of handling images passed to it via
+ * an AJAX call that goes through the WorPress AJAX Handler.
+ *
+ */
+class GlmMembersAdmin_ajax_billingFixActiveUsers
+{
+
+ /**
+ * WordPress Database Object
+ *
+ * @var $wpdb
+ * @access public
+ */
+ public $wpdb;
+ /**
+ * Plugin Configuration Data
+ *
+ * @var $config
+ * @access public
+ */
+ public $config;
+
+ public function __construct ($wpdb, $config)
+ {
+
+ // Save WordPress Database object
+ $this->wpdb = $wpdb;
+
+ // Save plugin configuration object
+ $this->config = $config;
+
+ }
+
+ public function modelAction( $actionData = false )
+ {
+
+ // echo '<pre>$actionData: ' . print_r( $actionData, true ) . '</pre>';
+ $days_after_expired = $this->config['settings']['days_after_expired'];
+ $current_date = date( 'Y-m-d' );
+ $restrictedRole = $this->config['contact_role_numb']['LogInContact'];
+ // echo '<pre>$restrictedRole: ' . print_r( $restrictedRole, true ) . '</pre>';
+
+ // Update All expired accounts so they can only be in members only not admin.
+ // Find all member contacts (by ref_dest) with accounts that are expired.
+ // With those set their contact_role to 30 (login only)
+ if ( $days_after_expired = filter_var( $days_after_expired, FILTER_VALIDATE_INT ) ) {
+ // Grab the member accounts that need to be updated
+ $members = $this->wpdb->get_results(
+ "SELECT ref_name,ref_dest
+ FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
+ WHERE renewal_date + INTERVAL 1 YEAR + INTERVAL $days_after_expired DAY > '$current_date'",
+ ARRAY_A
+ );
+ $total = count( $members );
+ echo '<pre>$total: ' . print_r( $total, true ) . '</pre>';
+ if ( isset( $members ) && $members ) {
+ foreach ( $members as $member ) {
+ echo '<pre>$member: ' . print_r( $member, true ) . '</pre>';
+ $Contact = new GlmDataContacts( $this->wpdb, $this->config );
+ $contact_id = $Contact->getContactIdByRefDest( $member['ref_dest'] );
+ $user_id = $Contact->getWpUserId( $contact_id );
+ $wpUser = get_user_by( 'id', $user_id );
+ if ( $wpUser ) {
+ echo '<pre>$wpUser-role: ' . print_r( $wpUser->roles, true ) . '</pre>';
+ $roles = $wpUser->roles;
+ if ( $roles[0] != 'glm_members_own_entity_manager' ) {
+ apply_filters(
+ 'glm_contact_update_user_role_by_ref_dest',
+ '',
+ $member['ref_dest'],
+ 'glm_members_member_contact',
+ 'glm_members_own_entity_manager'
+ );
+ }
+ }
+ }
+ }
+
+ }
+
+ }
+}