$num_days ) { $bill_day = $num_days; } else { $bill_day = $status['bill_day']; } if ( $bill_day == 0 ) { $reset_date .= '' . __( 'Never', 'datafeedr-api' ) . ''; } 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'] = "

" . __( "This is an automated message generated by: ", 'datafeedr-api' ) . get_bloginfo( 'wpurl' ) . "

"; if ( $percentage >= 100 && empty( $tracker['100_percent'] ) ) { $params['subject'] = get_bloginfo( 'name' ) . __( ': Datafeedr API Usage (Critical)', 'datafeedr-api' ); $params['message'] .= "

" . __( "You have used 100% of your allocated Datafeedr API requests for this period. You are no longer able to query the Datafeedr API to get product information.", 'datafeedr-api' ) . "

"; $params['message'] .= "

" . __( "What to do next?", 'datafeedr-api' ) . "

"; $params['message'] .= "

" . __( "We strongly recommend that you upgrade to prevent your product information from becoming outdated.", 'datafeedr-api' ) . "

"; $params['message'] .= "

" . __( "UPGRADE NOW", 'datafeedr-api' ) . "

"; $params['message'] .= "

" . __( "Upgrading only takes a minute. You will have instant access to more API requests. Any remaining credit for your current plan will be applied to your new plan.", 'datafeedr-api' ) . "

"; $params['message'] .= "

" . __( "You are under no obligation to upgrade. You may continue using your current plan for as long as you would like.", 'datafeedr-api' ) . "

"; $params['message'] .= "

" . __( "If you have any questions about your account, please ", 'datafeedr-api' ); $params['message'] .= "" . __( "contact us", 'datafeedr-api' ) . ".

"; $params['message'] .= "

" . __( "Thanks,
Eric & Stefan
The Datafeedr Team", 'datafeedr-api' ) . "

"; $params['message'] .= "

"; $params['message'] .= "" . __( "Account Information", 'datafeedr-api' ) . " | "; $params['message'] .= "" . __( "Upgrade Account", 'datafeedr-api' ) . ""; $params['message'] .= "

"; $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)', 'datafeedr-api' ); $params['message'] .= "

" . __( "You have used 90% of your allocated Datafeedr API requests for this period.", 'datafeedr-api' ) . "

"; $params['message'] .= "

" . __( "API Usage", 'datafeedr-api' ) . "

"; $params['message'] .= ""; $params['message'] .= "

" . __( "What to do next?", 'datafeedr-api' ) . "

"; $params['message'] .= "

" . __( "We recommend that you upgrade to prevent your product information from becoming outdated.", 'datafeedr-api' ) . "

"; $params['message'] .= "

" . __( "UPGRADE NOW", 'datafeedr-api' ) . "

"; $params['message'] .= "

" . __( "Upgrading only takes a minute. You will have instant access to more API requests. Any remaining credit for your current plan will be applied to your new plan.", 'datafeedr-api' ) . "

"; $params['message'] .= "

" . __( "You are under no obligation to upgrade. You may continue using your current plan for as long as you would like.", 'datafeedr-api' ) . "

"; $params['message'] .= "

" . __( "If you have any questions about your account, please ", 'datafeedr-api' ); $params['message'] .= "" . __( "contact us", 'datafeedr-api' ) . ".

"; $params['message'] .= "

" . __( "Thanks,
Eric & Stefan
The Datafeedr Team", 'datafeedr-api' ) . "

"; $params['message'] .= "

"; $params['message'] .= "" . __( "Account Information", 'datafeedr-api' ) . " | "; $params['message'] .= "" . __( "Upgrade Account", 'datafeedr-api' ) . ""; $params['message'] .= "

"; $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' ); } } add_action( 'init', 'dfrapi_email_user_about_usage' );