/** * This stores messages to be displayed using the 'admin_notices' action. */ function dfrapi_admin_messages($key = false) { $messages = array('missing_api_keys' => array('class' => 'update-nag', 'message' => __('Your Datafeedr API Keys are missing.', DFRAPI_DOMAIN), 'url' => 'admin.php?page=dfrapi', 'button_text' => __('Add Your API Keys', DFRAPI_DOMAIN)), 'missing_network_ids' => array('class' => 'update-nag', 'message' => __('You haven\'t selected any affiliate networks yet.', DFRAPI_DOMAIN), 'url' => 'admin.php?page=dfrapi_networks', 'button_text' => __('Select Networks', DFRAPI_DOMAIN)), 'missing_merchant_ids' => array('class' => 'update-nag', 'message' => __('You haven\'t selected any merchants yet.', DFRAPI_DOMAIN), 'url' => 'admin.php?page=dfrapi_merchants', 'button_text' => __('Select Merchants', DFRAPI_DOMAIN)), 'usage_over_90_percent' => array('class' => 'update-nag', 'message' => __('You have used ', DFRAPI_DOMAIN) . dfrapi_get_api_usage_percentage() . __('% of your total Datafeedr API requests this month. ', DFRAPI_DOMAIN), 'url' => 'admin.php?page=dfrapi_account', 'button_text' => __('View Account', DFRAPI_DOMAIN)), 'missing_affiliate_ids' => array('class' => 'update-nag', 'message' => __('You are missing affiliate IDs. ', DFRAPI_DOMAIN), 'url' => 'admin.php?page=dfrapi_networks', 'button_text' => __('Enter your Affiliate IDs', DFRAPI_DOMAIN)), 'database_rotation' => array('class' => 'update-nag', 'message' => __('<strong>Datafeedr API Message:</strong> We are currently refreshing our database of 270 million products. This process starts daily at 8:00am GMT and runs for about 20 minutes. During this time you may be unable to query our database.', DFRAPI_DOMAIN), 'url' => '', 'button_text' => __('', DFRAPI_DOMAIN)), 'unapproved_zanox_merchants' => array('class' => 'update-nag', 'message' => '<strong>' . __('Unapproved Zanox Merchant(s):', DFRAPI_DOMAIN) . '</strong> ' . __('It appears you are not approved by one or more Zanox merchants you have selected. Please remove unapproved Zanox merchants from your ', DFRAPI_DOMAIN) . '<a href="' . admin_url('admin.php?page=dfrapi_merchants') . '" target="_blank">' . __('Zanox merchant selection', DFRAPI_DOMAIN) . '</a>' . __(' then delete your cached API data ', DFRAPI_DOMAIN) . '<a href="' . admin_url('admin.php?page=dfrapi_tools') . '" target="_blank">' . __('here', DFRAPI_DOMAIN) . '</a>.', 'url' => '', 'button_text' => __('', DFRAPI_DOMAIN))); if (isset($messages[$key])) { dfrapi_admin_notices($key, $messages); } }
static function usage_over_90_percent() { $percentage = dfrapi_get_api_usage_percentage(); if ($percentage >= 90) { return true; } return false; }
function dfrapi_email_user_about_usage() { $percentage = dfrapi_get_api_usage_percentage(); $status = get_option('dfrapi_account', array()); $request_count = isset($status['request_count']) ? number_format($status['request_count']) : 0; $remaining_requests = isset($status['max_requests']) ? number_format($status['max_requests'] - $request_count) : 0; $reset_date = ''; if (isset($status['bill_day'])) { $today = date('j'); $num_days = date('t'); if ($status['bill_day'] > $num_days) { $bill_day = $num_days; } else { $bill_day = $status['bill_day']; } if ($bill_day == 0) { $reset_date .= '<em>' . __('Never', DFRAPI_DOMAIN) . '</em>'; } elseif ($today >= $bill_day) { $reset_date .= date('F', strtotime('+1 month')) . ' ' . $bill_day . ', ' . date('Y', strtotime('+1 month')); } else { $reset_date .= date('F') . ' ' . $bill_day . ', ' . date('Y'); } } $default = array('90_percent' => '', '100_percent' => ''); // Don't do anything if less than 90%. if ($percentage < 90) { update_option('dfrapi_usage_notification_tracker', $default); return; } $tracker = get_option('dfrapi_usage_notification_tracker', $default); $params = array(); $params['to'] = get_bloginfo('admin_email'); $params['message'] = "<p>" . __("This is an automated message generated by: ", DFRAPI_DOMAIN) . get_bloginfo('wpurl') . "</p>"; if ($percentage >= 100 && empty($tracker['100_percent'])) { $params['subject'] = get_bloginfo('name') . __(': Datafeedr API Usage (Critical)', DFRAPI_DOMAIN); $params['message'] .= "<p>" . __("You have used <strong>100%</strong> of your allocated Datafeedr API requests for this period. <u>You are no longer able to query the Datafeedr API to get product information.</u>", DFRAPI_DOMAIN) . "</p>"; $params['message'] .= "<p><strong>" . __("What to do next?", DFRAPI_DOMAIN) . "</strong></p>"; $params['message'] .= "<p>" . __("We strongly recommend that you upgrade to prevent your product information from becoming outdated.", DFRAPI_DOMAIN) . "</p>"; $params['message'] .= "<p><a href=\"" . dfrapi_user_pages('change') . "?utm_source=email&utm_medium=link&utm_campaign=upgrade100percentnotice\"><strong>" . __("UPGRADE NOW", DFRAPI_DOMAIN) . "</strong></a></p>"; $params['message'] .= "<p>" . __("Upgrading only takes a minute. You will have <strong>instant access</strong> to more API requests. Any remaining credit for your current plan will be applied to your new plan.", DFRAPI_DOMAIN) . "</p>"; $params['message'] .= "<p>" . __("You are under no obligation to upgrade. You may continue using your current plan for as long as you would like.", DFRAPI_DOMAIN) . "</p>"; $params['message'] .= "<p>" . __("If you have any questions about your account, please ", DFRAPI_DOMAIN); $params['message'] .= "<a href=\"" . DFRAPI_EMAIL_US_URL . "?utm_source=email&utm_medium=link&utm_campaign=upgrade100percentnotice\">" . __("contact us", DFRAPI_DOMAIN) . "</a>.</p>"; $params['message'] .= "<p>" . __("Thanks,<br />Eric & Stefan<br />The Datafeedr Team", DFRAPI_DOMAIN) . "</p>"; $params['message'] .= "<p>"; $params['message'] .= "<a href=\"" . admin_url('admin.php?page=dfrapi_account') . "\">" . __("Account Information", DFRAPI_DOMAIN) . "</a> | "; $params['message'] .= "<a href=\"" . dfrapi_user_pages('change') . "?utm_source=email&utm_medium=link&utm_campaign=upgrade100percentnotice\">" . __("Upgrade Account", DFRAPI_DOMAIN) . "</a>"; $params['message'] .= "</p>"; $tracker['100_percent'] = 1; update_option('dfrapi_usage_notification_tracker', $tracker); add_filter('wp_mail_content_type', 'dfrapi_set_html_content_type'); wp_mail($params['to'], $params['subject'], $params['message']); remove_filter('wp_mail_content_type', 'dfrapi_set_html_content_type'); } elseif ($percentage >= 90 && $percentage < 100 && empty($tracker['90_percent'])) { $params['subject'] = get_bloginfo('name') . __(': Datafeedr API Usage (Warning)', DFRAPI_DOMAIN); $params['message'] .= "<p>" . __("You have used <strong>90%</strong> of your allocated Datafeedr API requests for this period.", DFRAPI_DOMAIN) . "</p>"; $params['message'] .= "<p><strong>" . __("API Usage", DFRAPI_DOMAIN) . "</strong></p>"; $params['message'] .= "<ul>"; $params['message'] .= "<li>" . __("API requests used: ", DFRAPI_DOMAIN) . $request_count . "</li>"; $params['message'] .= "<li>" . __("API requests remaining: ", DFRAPI_DOMAIN) . $remaining_requests . "</li>"; $params['message'] .= "<li>" . __("API requests will reset on: ", DFRAPI_DOMAIN) . $reset_date . "</li>"; $params['message'] .= "</ul>"; $params['message'] .= "<p><strong>" . __("What to do next?", DFRAPI_DOMAIN) . "</strong></p>"; $params['message'] .= "<p>" . __("We recommend that you upgrade to prevent your product information from becoming outdated.", DFRAPI_DOMAIN) . "</p>"; $params['message'] .= "<p><a href=\"" . dfrapi_user_pages('change') . "?utm_source=email&utm_medium=link&utm_campaign=upgrade90percentnotice\"><strong>" . __("UPGRADE NOW", DFRAPI_DOMAIN) . "</strong></a></p>"; $params['message'] .= "<p>" . __("Upgrading only takes a minute. You will have <strong>instant access</strong> to more API requests. Any remaining credit for your current plan will be applied to your new plan.", DFRAPI_DOMAIN) . "</p>"; $params['message'] .= "<p>" . __("You are under no obligation to upgrade. You may continue using your current plan for as long as you would like.", DFRAPI_DOMAIN) . "</p>"; $params['message'] .= "<p>" . __("If you have any questions about your account, please ", DFRAPI_DOMAIN); $params['message'] .= "<a href=\"" . DFRAPI_EMAIL_US_URL . "?utm_source=email&utm_medium=link&utm_campaign=upgrade90percentnotice\">" . __("contact us", DFRAPI_DOMAIN) . "</a>.</p>"; $params['message'] .= "<p>" . __("Thanks,<br />Eric & Stefan<br />The Datafeedr Team", DFRAPI_DOMAIN) . "</p>"; $params['message'] .= "<p>"; $params['message'] .= "<a href=\"" . admin_url('admin.php?page=dfrapi_account') . "\">" . __("Account Information", DFRAPI_DOMAIN) . "</a> | "; $params['message'] .= "<a href=\"" . dfrapi_user_pages('change') . "?utm_source=email&utm_medium=link&utm_campaign=upgrade90percentnotice\">" . __("Upgrade Account", DFRAPI_DOMAIN) . "</a>"; $params['message'] .= "</p>"; $tracker['90_percent'] = 1; update_option('dfrapi_usage_notification_tracker', $tracker); add_filter('wp_mail_content_type', 'dfrapi_set_html_content_type'); wp_mail($params['to'], $params['subject'], $params['message']); remove_filter('wp_mail_content_type', 'dfrapi_set_html_content_type'); } return; }