_settings = $settings; $this->_active_posts = $post; $this->_active_profiles = $profile; if(is_array($this->_active_posts)){ foreach($this->_active_posts as $id){ add_action('athena_post_ex_' . $id[0], array($this, 'post_cron'), 10, 1); } } if(is_array($this->_active_profiles)){ foreach($this->_active_profiles as $id){ add_action('athena_profile_ex_' . $id['id'], array($this, 'profile_cron'), 10, 1); if(isset($id['email']) && $id['email'] === true){ add_action('athena_profile_email_' . $id['id'], array($this, 'email_cron'), 10, 1); } } } } public static function init( $settings, $post, $profile ){ if(!self::$_instance instanceof self){ self::$_instance = new Athena_Cron( $settings, $post, $profile ); } return self::$_instance; }//end init method public function profile_cron( $post_id ){ $profile_actions = get_post_meta( $post_id ); $attached_posts = get_option('athena_profile_' . $post_id); if($attached_posts !== false){ foreach($attached_posts as $post){ $action['id'] = $post; $action['action'] = $profile_actions['_post_type_ex'][0]; if(isset($profile_actions['_post_password'][0]) && !empty($profile_actions['_post_password'][0])){ $action['password'] = $profile_actions['_post_password'][0]; } if(isset($profile_actions['_post_category'][0]) && !empty($profile_actions['_post_category'][0])){ $action['category'] = unserialize($profile_actions['_post_category'][0]); } $this->post_action( $action ); }//end foreach } }//end profile_cron method public function post_cron( $post_id ){ $post_actions = get_post_meta( $post_id ); $action['id'] = $post_id; $action['action'] = $post_actions['_athena_ex_type'][0]; if(isset($post_actions['_athena_password'][0]) && !empty($post_actions['_athena_password'][0])){ $action['password'] = $post_actions['_athena_password'][0]; } if(isset($post_actions['_athena_category'][0]) && !empty($post_actions['_athena_category'][0])){ $action['category'] = unserialize($post_actions['_athena_category'][0]); } $this->post_action( $action ); }//end post_cron method private function post_action( $action ){ switch( $action['action'] ){ case 'delete' : $bypass = (isset($this->_settings['trash_bypass']) && $this->_settings['trash_bypass'] == true)? true : false; wp_delete_post($action['id'], $bypass); break; case 'draft' : $args = array( 'ID' => $action['id'], 'post_status' => 'draft' ); wp_update_post( $args ); break; case 'private' : $args = array( 'ID' => $action['id'], 'post_status' => 'private' ); wp_update_post( $args ); break; case 'password' : $args = array( 'ID' => $action['id'], 'post_status' => 'publish', 'post_password' => $action['password'] ); wp_update_post( $args ); break; case 'category' : $args = array( 'ID' => $action['id'], 'post_category' => $action['category'] ); wp_update_post( $args ); break; }//end switch conditional }//end post_action method public function email_cron( $post_id ){ add_filter('wp_mail_content_type', function(){return 'text/html';} ); $profile = get_post($post_id, OBJECT); $profile_time = get_post_meta($post_id, '_post_expiration_timestamp', true); $sitename = strtolower( $_SERVER['SERVER_NAME'] ); if ( substr( $sitename, 0, 4 ) == 'www.' ) { $sitename = substr( $sitename, 4 ); } $from_email = 'noreply@' . $sitename; $email = wp_remote_get(ATHENA_URI . 'view/assets/email_temp/template1.html'); $email = wp_remote_retrieve_body($email); $subject = 'Athena Profile Expiring Soon!'; $headers = 'From: '.get_option('blogname') .' <' . $from_email .'>'; $body = '
Up To Logo
'; $body .= '
'; $body .= '

Hello,

'; $body .= '

You\'re Athena profile '. $profile->post_title .' will be expiring soon. If you need to make a change to your profile you should do so prior to it\'s expiration date of ' . athena_date_timezone($profile_time, $this->_settings) . '.'; $body .= '

Sincerely,
The Athena Team

'; $body .= '
'; $body = str_replace('%ATHENACONTENT%', $body, $email); wp_mail($this->_settings['notify_email'], $subject, $body, $headers); add_filter('wp_mail_content_type', function(){return 'text/plain';}); }//end email_cron method }//end Athena_Cron class }//end class_exists conditional