init_settings(); $this->get_active(); add_action('init', array($this, 'after_init')); add_action('init', array($this, 'profile_start')); add_action('admin_menu', array($this, 'profile_menu_add')); add_filter( "manage_athenaprofile_posts_columns", array($this, 'profile_column') ); add_action( "manage_athenaprofile_posts_custom_column", array($this, 'profile_column_content'), 10, 2 ); add_action('wp_ajax_athena_settings', array($this,'setting_save')); add_action('wp_ajax_nopriv_athena_settings', array($this,'setting_save')); Athena_Cron::init( self::$_settings, self::$_active_posts, self::$_active_profiles ); Athena_Post_Delete::init( self::$_active_profiles ); Athena_Shortcode::init( self::$_settings ); new Athena_Meta_Gen($this->profile_meta(), self::$_settings, self::$_active_profiles); add_filter('the_content', array($this, 'content_display')); add_action( 'wp_insert_post', array($this, 'auto_enabled_check'), 10, 3 ); }//end __construct method public static function init(){ if(!self::$_instance instanceof self){ self::$_instance = new Athena(); } return self::$_instance; }//end init method public function after_init(){ $this->get_post_types(); Athena_Settings::init( self::$_settings, $this->_post_types, $this->settings_fields_options() ); foreach($this->_post_types as $post){ if(isset(self::$_settings['enable_posttype_'.$post->name]) && self::$_settings['enable_posttype_'.$post->name] == true){ new Athena_Meta_Gen($this->setup_post_type_meta( $post->name ), self::$_settings, self::$_active_posts); } } }//end after_init method private function init_settings(){ self::$_settings = get_option( self::ATHENA_OPT ); if(self::$_settings === false){ $info = array(); foreach($this->settings_fields_options()['general'] as $value){ if(!empty($value['default'])){ $info[$value['id']] = $value['default']; } } update_option(self::ATHENA_OPT, $info, false); } return; } private function get_active(){ self::$_active_posts = get_option(self::ATHENA_POST, false); self::$_active_profiles = get_option(self::ATHENA_PROFILE, false); }//end get_active method public function profile_start(){ $labels = array( 'name' => _x( 'Profiles', 'Post Type General Name', 'athena-post-expiration' ), 'singular_name' => _x( 'Profile', 'Post Type Singular Name', 'athena-post-expiration' ), 'menu_name' => __( 'Profiles', 'athena-post-expiration' ), 'name_admin_bar' => __( 'Profiles', 'athena-post-expiration' ), 'archives' => __( 'Profile Archives', 'athena-post-expiration' ), 'attributes' => __( 'Profile Attributes', 'athena-post-expiration' ), 'parent_item_colon' => __( 'Parent Item:', 'athena-post-expiration' ), 'all_items' => __( 'All Profiles', 'athena-post-expiration' ), 'add_new_item' => __( 'Add New Profile', 'athena-post-expiration' ), 'add_new' => __( 'Add Profile', 'athena-post-expiration' ), 'new_item' => __( 'New Profile', 'athena-post-expiration' ), 'edit_item' => __( 'Edit Profile', 'athena-post-expiration' ), 'update_item' => __( 'Update Profile', 'athena-post-expiration' ), 'view_item' => __( 'View Profile', 'athena-post-expiration' ), 'view_items' => __( 'View Profiles', 'athena-post-expiration' ), 'search_items' => __( 'Search Profiles', 'athena-post-expiration' ), 'not_found' => __( 'Not found', 'athena-post-expiration' ), 'not_found_in_trash' => __( 'Not found in Trash', 'athena-post-expiration' ), 'featured_image' => __( 'Featured Image', 'athena-post-expiration' ), 'set_featured_image' => __( 'Set featured image', 'athena-post-expiration' ), 'remove_featured_image' => __( 'Remove featured image', 'athena-post-expiration' ), 'use_featured_image' => __( 'Use as featured image', 'athena-post-expiration' ), 'insert_into_item' => __( 'Insert into item', 'athena-post-expiration' ), 'uploaded_to_this_item' => __( 'Uploaded to this item', 'athena-post-expiration' ), 'items_list' => __( 'Items list', 'athena-post-expiration' ), 'items_list_navigation' => __( 'Items list navigation', 'athena-post-expiration' ), 'filter_items_list' => __( 'Filter items list', 'athena-post-expiration' ), ); $args = array( 'label' => __( 'Profile', 'athena-post-expiration' ), 'description' => __( 'Profiles', 'athena-post-expiration' ), 'labels' => $labels, 'supports' => array( 'title'), 'hierarchical' => false, 'public' => false, 'show_ui' => true, 'show_in_menu' => false, 'menu_position' => 5, 'show_in_admin_bar' => false, 'show_in_nav_menus' => false, 'can_export' => true, 'has_archive' => false, 'exclude_from_search' => false, 'publicly_queryable' => true, 'capability_type' => 'post', ); register_post_type( 'athenaprofile', $args ); }//end profile_start method public function profile_menu_add(){ add_submenu_page('athena', 'Profiles', 'Profiles', 'administrator', 'edit.php?post_type=athenaprofile', null); }//end profile_menu_add method public function profile_column( $columns ){ $new = array(); foreach($columns as $key => $value){ if($key == 'date'){ $new['athena_timestamp'] = __( 'Expiration', 'athena-post-expiration' ); }else{ $new[$key] = $value; } } return $new; }//end profile_column method public function profile_column_content( $column_name, $post_id ){ $date = get_post_meta($post_id, '_post_expiration_timestamp', true); if(empty($date)){ echo 'No Expiration Set'; return; }else{ $current_time = current_time( 'timestamp', 1 ); } $date_formatted = athena_date_timezone($date, self::$_settings); if($current_time > $date){ $date_formatted = '' . $date_formatted . ''; } echo $date_formatted; }//end profile_column_content method private function profile_meta(){ $timestamp = strtotime('+1 week', current_time('timestamp')); $settings['config'] = array( 'title' => 'Profile Settings', 'id' => 'athena-profile-settings', 'pages' => array( 'athenaprofile' ), 'callback' => '', 'context' => 'normal', 'priority' => 'high' ); $settings['options'] = array( array( 'type' => 'date_box', 'name' => __('Expiration Date & Time', 'athena-post-expiration'), 'desc' => __('Choose the date and time that you would like for this profile to apply.', 'athena-post-expiration'), 'id' => '_post_expiration', 'default' => date((isset(self::$_settings['date_time_format'])?self::$_settings['date_time_format']:'F jS, Y g:ia'), $timestamp) ), array( 'type' => 'select', 'name' => __('Expiration Action', 'athena-post-expiration'), 'desc' => __('Choose the action to take on the expiring post type', 'athena-post-expiration'), 'id' => '_post_type_ex', 'default' => 'draft', 'options' => array( 'delete' => 'Delete', 'draft' => 'Draft', 'private' => 'Private', 'password' => 'Password Protected', 'category' => 'Change Category' ), 'onChange' => true, 'class' => 'athena-ex-type' ), array( 'type' => 'text', 'name' => __('Post Password', 'athena-post-expiration'), 'desc' => __('Adds a password to the post', 'athena-post-expiration'), 'id' => '_post_password', 'default' => '', 'activate' => 'athena-ex-type', 'select' => 'password', 'required' => true, 'max' => 20 ), array( 'type' => 'category', 'name' => __('Post Category', 'athena-post-expiration'), 'desc' => __('Select the Categories to assign to the post', 'athena-post-expiration'), 'id' => '_post_category', 'default' => '', 'activate' => 'athena-ex-type', 'select' => 'category', 'required' => true ), array( 'type' => 'checkbox', 'name' => __('Enable Email Notification', 'athena-post-expiration'), 'desc' => __('Send email prior to your profile expiring.', 'athena-post-expiration'), 'default' => '', 'id' => 'enable_email' ), array( 'type' => 'future_date', 'name' => __('Email Notification Time', 'athena-post-expiration'), 'desc' => __('The amount of time prior to your profile expiring to send email notification.', 'athena-post-expiration'), 'default' => array('count' => 1, 'type' => 'h'), 'id' => 'email_time', 'times' => 'hour' ), array( 'type' => 'textarea', 'name' => __('Append To Footer', 'athena-post-expiration'), 'desc' => __('Text that will be added to the bottom of the post', 'athena-post-expiration'), 'id' => '_post_footer_append', 'default' => '', 'legend' => __('

%DATETIME% - Displays the date the post expires

') ) ); return $settings; }//end profile_meta method private function settings_fields_options(){ $settings['general'] = array( array( 'type' => 'text', 'name' => __('Set date and time format.', 'athena-post-expiration'), 'desc' => __('This is how the date and time will be displayed.', 'athena-post-expiration'), 'id' => 'date_time_format', 'default' => 'F jS, Y g:ia', 'legend' => __('See all of your format options here.', 'athena-post-expiration'), 'required' => false, 'display' => true ), array( 'type' => 'text', 'name' => __('Email Address', 'athena-post-expiration'), 'desc' => __('This is the email address to use for notifications.', 'athena-post-expiration'), 'id' => 'notify_email', 'default' => get_option('admin_email'), 'display' => false, 'required' => true ), array( 'type' => 'checkbox', 'name' => __('Bypass Trash', 'athena-post-expiration'), 'desc' => __('Enabling this will permanently delete posts that are set to delete on post expiration bypasing the trash.', 'athena-post-expiration'), 'id' => 'trash_bypass', 'default' => '' ), array( 'type' => 'checkbox', 'name' => __('Enable', 'athena-post-expiration'), 'desc' => __('This will enable the post footer on all active posts not using a profile', 'athena-post-expiration'), 'default' => '', 'id' => 'enable_general_footer' ), array( 'type' => 'textarea', 'name' => __('Append To Footer', 'athena-post-expiration'), 'desc' => __('Text that will be added to the bottom of the post', 'athena-post-expiration'), 'id' => 'post_general_footer', 'default' => '', 'legend' => __('

%DATETIME% - Displays the date the post expires

') ) ); $settings['schedule'] = array( array( 'type' => 'cron', ) ); return $settings; }//end fields_options method public function setting_save(){ //Check to make sure that the request is valid: if($_SERVER['REQUEST_METHOD'] !== 'POST' || empty($_POST)){ // Return this message to JS script and exit: echo 'You cannot access this script in this manner.'; exit(); } foreach($_POST['info'] as $value){ //Assign the name value pair to the array: if(($array_start = strpos($value['name'],'[')) !== false){ $name = stristr($value['name'], '[', true); $sub = substr($value['name'], $array_start + 1, strpos($value['name'], ']') - ++$array_start ); $final[$name][$sub] = $value['value']; }else{ $final[$value['name']] = $value['value']; } } if($final === self::$_settings){ echo '1'; exit(); } if(update_option(self::ATHENA_OPT, $final) !== false){ echo '1'; exit(); } echo '0'; exit(); }//end setting_save method public function get_post_types(){ $args = array( 'exclude_from_search' => false, 'show_ui' => true, 'show_in_nav_menus' => true ); $this->_post_types = get_post_types($args, 'objects'); }//end get_post_types private function setup_post_type_meta( $post_type ){ $settings['config'] = array( 'title' => 'Athena Post Expirations', 'id' => 'athena-post-settings', 'pages' => $post_type, 'callback' => '', 'context' => 'side', 'priority' => 'low' ); $settings['options'] = array( array( 'type' => 'post_meta', 'id' => '_athena_options', 'default' => '' ), array( 'type' => 'select', 'name' => __('Expiration Action', 'athena-post-expiration'), 'desc' => '', 'id' => '_athena_ex_type', 'default' => 'draft', 'options' => array( 'delete' => 'Delete', 'draft' => 'Draft', 'private' => 'Private', 'password' => 'Password Protected', 'category' => 'Change Category' ), 'onChange' => true, 'class' => 'athena-ex-type', 'required' => 'false' ), array( 'type' => 'text', 'name' => __('Post Password', 'athena-post-expiration'), 'desc' => '', 'id' => '_athena_password', 'default' => '', 'activate' => 'athena-ex-type', 'select' => 'password', 'required' => true, 'max' => 20 ), array( 'type' => 'category', 'name' => __('Post Category', 'athena-post-expiration'), 'desc' => '', 'id' => '_athena_category', 'default' => '', 'activate' => 'athena-ex-type', 'select' => 'category', 'required' => true ) ); return $settings; }//end setup_post_type_meta method public function content_display( $content ){ $athena_settings = self::$_settings; $post_meta = get_post_meta($GLOBALS['post']->ID); $post_meta = isset($post_meta['_athena_options']) ? unserialize($post_meta['_athena_options'][0]) : false; if($post_meta !== false && $post_meta['enabled'] == true){ if(isset($post_meta['profile']) && !empty($post_meta['profile'])){ $profile = get_post_meta($post_meta['profile']); if(isset($profile['_post_footer_append'][0])){ $athena_footer = str_replace('%DATETIME%', athena_date_timezone($profile['_post_expiration_timestamp'][0], $athena_settings), $profile['_post_footer_append'][0]); $athena_footer = wpautop($athena_footer); return $content . $athena_footer; } }else if(isset($athena_settings['enable_general_footer'])){ if(isset($athena_settings['post_general_footer'])){ $athena_footer = str_replace('%DATETIME%', athena_date_timezone($post_meta['timestamp'], $athena_settings), $athena_settings['post_general_footer']); $athena_footer = wpautop( $athena_footer ); return $content . $athena_footer; } } } return $content; }//end content_display public function auto_enabled_check( $post_id, $post, $update){ if(!$update){ if( (isset(self::$_settings['enable_posttype_' . $post->post_type]) && self::$_settings['enable_posttype_'. $post->post_type] == true ) && ( isset(self::$_settings['auto_apply_'. $post->post_type]) && self::$_settings['auto_apply_'. $post->post_type] == true ) ){ $options = array( array( 'id' => '_athena_options' ), array( 'id' => '_athena_ex_type' ), array( 'id' => '_athena_password' ), array( 'id' => '_athena_category' ) ); $count = self::$_settings['future_date_'.$post->post_type]['count']; $type = athena_date_time($count); $value['_athena_options']['enabled'] = '1'; $value['_athena_options']['timestamp'] = strtotime('+'. $count .' ' . $type[self::$_settings['future_date_'.$post->post_type]['type']]); $value['_athena_ex_type'] = self::$_settings['expire_action_'.$post->post_type]; switch($value['_athena_ex_type']){ case 'password' : $value['_athena_password'] = self::$_settings['post_password_'.$post->post_type]; break; case 'category' : $value['_athena_category'] = self::$_settings['post_category_'.$post->post_type]; break; } new Athena_Save($options, $post_id, $post->post_type, $value); } }//end conditional if update }//end auto_enabled_check method public static function deactivate(){ global $wpdb, $table_prefix; $meta = $wpdb->get_results('SELECT * FROM '.$table_prefix.'postmeta WHERE meta_key LIKE "%athena%"', ARRAY_A); $profiles = self::$_active_profiles; $posts = self::$_active_posts; if(!empty($profiles) && is_array($profiles)){ foreach($profiles as $p){ wp_clear_scheduled_hook( 'athena_profile_ex_'.$p['id'], array($p['id']) ); if(isset($p['email']) && $p['email'] === true){ wp_clear_scheduled_hook( 'athena_profile_email_'.$p['id'], array($p['id'])); } } } if(!empty($posts) && is_array($posts)){ foreach($posts as $p){ wp_clear_scheduled_hook( 'athena_post_ex_'.$p, array($p) ); } } if(is_array($meta)){ foreach($meta as $value){ delete_post_meta($value['post_id'], $value['meta_key']); } }//end check if variable is array $args = array( 'post_type' => 'athenaprofile', 'posts_per_page' => -1 ); $profiles = get_posts( $args ); foreach($profiles as $key){ delete_option('athena_profile_' . $key->ID); wp_delete_post( $key->ID ); } delete_option(self::ATHENA_OPT); delete_option(self::ATHENA_POST); delete_option(self::ATHENA_PROFILE); }//end deactivate method }//end Athena class }//end class_exists