false, 'customer_reviews' => false, 'auto_subscription' => false, 'recommend_plan' => false, ]; $pricing_active = adqs_is_pricing_addon_available(); if ( ! $pricing_active ) { return $permissions; } // Get the pricing package ID from the order $pricing_id = 0; if ( $pricing_active === 'self' && function_exists( 'adp_get_query_order' ) ) { $order = adp_get_query_order( $order_id, 'pricing_id' ); $pricing_id = $order->pricing_id ?? 0; } elseif ( $pricing_active === 'wc' && function_exists( 'adp_wc_get_query_order' ) ) { $order = function_exists( 'adp_wc_get_query_order' ) ? adp_wc_get_query_order( $order_id ) : null; $pricing_id = $order->pricing_id ?? 0; } if ( empty( $pricing_id ) ) { return $permissions; } // Get pricing package permissions if ( $pricing_active === 'self' && function_exists( 'adp_get_query_pricing_meta' ) ) { $permissions['contact_owner'] = adp_get_query_pricing_meta( $pricing_id, 'cl_owner', true ) === 'yes'; $permissions['customer_reviews'] = adp_get_query_pricing_meta( $pricing_id, 'at_cusreview', true ) === 'yes'; $permissions['auto_subscription'] = adp_get_query_pricing_meta( $pricing_id, 'at_subsc', true ) === 'yes'; $permissions['recommend_plan'] = adp_get_query_pricing_meta( $pricing_id, 'recm_plan', true ) === 'yes'; } elseif ( $pricing_active === 'wc' && function_exists( 'adp_wc_get_meta' ) ) { $permissions['contact_owner'] = adp_wc_get_meta( $pricing_id, 'cl_owner' ) === 'yes'; $permissions['customer_reviews'] = adp_wc_get_meta( $pricing_id, 'cs_review' ) === 'yes'; $permissions['auto_subscription'] = adp_wc_get_meta( $pricing_id, 'at_subsc' ) === 'yes'; $permissions['recommend_plan'] = adp_wc_get_meta( $pricing_id, 'recm_plan' ) === 'yes'; } return $permissions; } /** * Check if a listing has specific pricing package permission * * @param int $post_id Listing post ID * @param string $permission Permission to check (contact_owner, customer_reviews, etc.) * @return bool Whether the listing has the permission */ function adqs_listing_has_pricing_permission( $post_id, $permission ) { $post_id = absint( $post_id ); if ( empty( $post_id ) ) { return false; } $pricing_active = adqs_is_pricing_addon_available(); // If no pricing addon is active, allow all features if ( ! $pricing_active ) { return true; } // 1) Prefer LIVE permission from the purchaser's current active order // so that toggling a plan feature affects all purchasers immediately. $package_info = adqs_get_listing_pricing_package_info( $post_id ); if ( ! empty( $package_info ) && ! empty( $package_info['permissions'] ) && is_array( $package_info['permissions'] ) ) { if ( array_key_exists( $permission, $package_info['permissions'] ) ) { return (bool) $package_info['permissions'][ $permission ]; } } // 2) Fallback to listing-stored permissions (saved at creation/upgrade) $pricing_permissions = get_post_meta( $post_id, '_pricing_permissions', true ); if ( is_array( $pricing_permissions ) && array_key_exists( $permission, $pricing_permissions ) ) { return (bool) $pricing_permissions[ $permission ]; } // 3) Sensible defaults when addon is active but nothing stored // Use main plugin setting if available; otherwise allow filter override $default = adqs_get_default_permission_for_feature( $permission, $post_id ); return (bool) $default; } /** * Get default permission when a plan doesn't define its own setting * Attempts to read main plugin settings; falls back to filters and safe defaults */ function adqs_get_default_permission_for_feature( $permission, $post_id = 0 ) { $permission = (string) $permission; // Try to read from main settings if available $from_setting = null; if ( function_exists( 'adqs_get_setting_option' ) ) { if ( $permission === 'customer_reviews' ) { // Common keys seen in installs; treat truthy as enabled $possible_keys = [ 'enable_reviews', 'enable_review', 'enable_review_comments' ]; foreach ( $possible_keys as $key ) { $v = adqs_get_setting_option( $key ); if ( $v !== null && $v !== '' ) { $from_setting = (bool) $v; break; } } } if ( $permission === 'contact_owner' ) { $possible_keys = [ 'enable_contact_owner', 'contact_owner' ]; foreach ( $possible_keys as $key ) { $v = adqs_get_setting_option( $key ); if ( $v !== null && $v !== '' ) { $from_setting = (bool) $v; break; } } } } // Default allow for core UX unless a site setting overrides $default = ( $from_setting !== null ) ? (bool) $from_setting : in_array( $permission, [ 'contact_owner', 'customer_reviews' ], true ); /** * Filter: allow themes/plugins to override default permission per feature */ return (bool) apply_filters( 'adqs_default_permission_' . $permission, $default, $post_id ); } /** * Get pricing package information for a listing * * @param int $post_id Listing post ID * @param int $specified_order_id Optional. Specific order ID to use. If not provided, will find most recent. * @return array Pricing package information */ function adqs_get_listing_pricing_package_info( $post_id, $specified_order_id = 0 ) { $post_id = absint( $post_id ); if ( empty( $post_id ) ) { return []; } $pricing_active = adqs_is_pricing_addon_available(); if ( ! $pricing_active ) { return []; } $author_id = get_post_field( 'post_author', $post_id ); $directory_id = adqs_get_term_id_by_post_type_slug( get_post_type( $post_id ) ); // Use specified order ID if provided, otherwise get the most recent order $order_id = absint( $specified_order_id ); if ( empty( $order_id ) ) { // Get the most recent order for this user and directory if ( $pricing_active === 'self' && function_exists( 'adp_get_order_by_user_id' ) ) { $orders = adp_get_order_by_user_id( $author_id, 'id', 'completed', true, [ 'directory_id' => $directory_id ] ); if ( ! empty( $orders ) ) { $order_id = $orders[0]->id ?? 0; } } elseif ( $pricing_active === 'wc' && function_exists( 'adp_wc_get_order_by_user_id' ) ) { $orders = function_exists( 'adp_wc_get_order_by_user_id' ) ? adp_wc_get_order_by_user_id( $author_id, 'id', 'completed', true, [ 'directory_id' => $directory_id ] ) : []; if ( ! empty( $orders ) ) { $order_id = $orders[0]->id ?? 0; } } } if ( empty( $order_id ) ) { return []; } // Get pricing package details $pricing_id = 0; if ( $pricing_active === 'self' && function_exists( 'adp_get_query_order' ) ) { $order = adp_get_query_order( $order_id, 'pricing_id' ); $pricing_id = $order->pricing_id ?? 0; } elseif ( $pricing_active === 'wc' && function_exists( 'adp_wc_get_query_order' ) ) { $order = function_exists( 'adp_wc_get_query_order' ) ? adp_wc_get_query_order( $order_id ) : null; $pricing_id = $order->pricing_id ?? 0; } if ( empty( $pricing_id ) ) { return []; } $package_info = [ 'order_id' => $order_id, 'pricing_id' => $pricing_id, 'pricing_active' => $pricing_active, 'permissions' => adqs_get_pricing_package_permissions( $author_id, $directory_id, $order_id ), ]; return $package_info; } function adqs_get_purchase_expiry_date( $post_id = 0 ) { if ( empty( $post_id ) ) { return false; } $expiry_type = ! empty( adqs_get_setting_option( '_expiry_duration_type' ) ) ? adqs_get_setting_option( '_expiry_duration_type' ) : ''; $selectExpiry_type = ( $expiry_type === 'by_post_date' ) ? true : false; if ( ! $selectExpiry_type ) { return false; } $author_id = get_post_field( 'post_author', $post_id ); $post_date = get_post_field( 'post_date', $post_id ); $post = get_post( $post_id ); $directory_id = 0; if ( $post ) { $directory_id = adqs_get_directory_id_by_post_type( $post->post_type ); } if ( ! empty( $_REQUEST['adqs_listing_type'] ?? '' ) ) { $directory_id = absint( $_REQUEST['adqs_listing_type'] ); } $pricing_active = adqs_is_pricing_addon_available(); if ( $pricing_active === 'self' ) { $getAllOrders = adp_get_order_by_user_id( $author_id, 'id,pricing_id', 'completed', true, [ 'directory_id' => $directory_id ] ); $longest_expiry = false; if ( ! empty( $getAllOrders ) ) { foreach ( $getAllOrders as $order ) { $getDate = get_user_meta( absint( $author_id ), "adp_order_expire_{$order->id}", true ); if ( ! empty( $getDate ) && ( $getDate !== 'never_expire' ) ) { if ( $expiry_type === 'by_post_date' ) { $pricing = adp_get_query_pricing( $order->pricing_id, 'duration' ); $duration = $pricing->duration ?? ''; if ( ! empty( $duration ) ) { $calculated_expiry = wp_date( 'Y-m-d H:i:s', strtotime( "+{$duration}", strtotime( $post_date ) ) ); // Keep the longest expiry date if ( ! $longest_expiry || strtotime( $calculated_expiry ) > strtotime( $longest_expiry ) ) { $longest_expiry = $calculated_expiry; } } } } } } if ( $longest_expiry ) { return $longest_expiry; } } elseif ( $pricing_active === 'wc' ) { // code for woocommerce $query = new WC_Order_Query( [ 'status' => 'wc-completed', 'limit' => -1, 'customer_id' => $author_id, ] ); $longest_expiry = false; if ( ! empty( $query->get_orders() ) ) { foreach ( $query->get_orders() as $order ) { $order_id = $order->get_id(); $getDate = get_user_meta( absint( $author_id ), "adp_wc_order_expire_{$order_id}", true ); if ( ! empty( $order->get_items() ) && ! empty( $getDate ) && ( $getDate !== 'never_expire' ) ) { foreach ( $order->get_items() as $item ) { $product = $item->get_product(); $id = $product->get_id(); $term = get_term_by( 'slug', get_post_meta( $id, '_directory_type', true ) ?? '', 'adqs_listing_types' ); if ( absint( $term->term_id ?? 0 ) !== absint( $directory_id ) ) { continue; } if ( $expiry_type === 'by_post_date' ) { $duration = adp_wc_get_meta( $id, 'duration' ); if ( ! empty( $duration ) ) { $calculated_expiry = wp_date( 'Y-m-d H:i:s', strtotime( "+{$duration}", strtotime( $post_date ) ) ); // Keep the longest expiry date if ( ! $longest_expiry || strtotime( $calculated_expiry ) > strtotime( $longest_expiry ) ) { $longest_expiry = $calculated_expiry; } } } } } } } if ( $longest_expiry ) { return $longest_expiry; } } return false; } /** * Get expiry date for a listing * * @param int $post_id The post ID * @return string|false Expiry date in Y-m-d H:i:s format or false if none */ function adqs_convert_expiry_date( $post_id = 0 ) { $post_id = absint( $post_id ); if ( empty( $post_id ) ) { return false; } // Check if listing is set to never expire $expiryNever = AD()->Helper->meta_val( $post_id, '_expiry_never', '' ); if ( $expiryNever === 'yes' ) { return false; } // First, check if explicit expiry date is set $value = AD()->Helper->meta_val( $post_id, '_expiry_date', '' ); if ( ! empty( $value ) ) { return wp_date( 'Y-m-d H:i:s', strtotime( $value ) ); } // Check if this is a guest listing $is_guest_listing = get_post_meta( $post_id, '_is_guest_listing', true ); // For logged-in users, check if they have purchase-based expiry if ( $is_guest_listing !== 'yes' ) { $purchase_expiry_date = adqs_get_purchase_expiry_date( $post_id ); if ( ! empty( $purchase_expiry_date ) ) { return $purchase_expiry_date; } } // Use default expiry setting with package-specific override $expireDays = absint( adqs_get_setting_option( 'listing_expiry_date' ) ); // Check for package-specific listing expire days if user has active packages $post = get_post( $post_id ); if ( $post && $post->post_author > 0 ) { $author_id = $post->post_author; $directory_id = function_exists( 'adqs_get_term_id_by_post_type_slug' ) ? adqs_get_term_id_by_post_type_slug( $post->post_type ) : 0; if ( $directory_id > 0 ) { $package_expire_days = null; // Check regular pricing package addon first (has priority) if ( function_exists( 'adqs_get_user_package_listing_expire_days' ) ) { $package_expire_days = adqs_get_user_package_listing_expire_days( $author_id, $directory_id ); } // Only check WooCommerce pricing if regular pricing is not available elseif ( function_exists( 'adqs_get_wc_user_package_listing_expire_days' ) ) { $package_expire_days = adqs_get_wc_user_package_listing_expire_days( $author_id, $directory_id ); } if ( $package_expire_days !== null && $package_expire_days > 0 ) { $expireDays = $package_expire_days; } } } if ( empty( $expireDays ) ) { $expireDays = 365; // Default fallback } $post_date = get_post_field( 'post_date', $post_id ); if ( ! empty( $post_date ) ) { return wp_date( 'Y-m-d H:i:s', strtotime( "+{$expireDays} days", strtotime( $post_date ) ) ); } return false; } function adqs_save_listing_expiry_date( $post_id ) { $post_id = absint( $post_id ); // IMPORTANT: Don't update expiry date when editing existing listings // Only set expiry for NEW listings. Cron jobs handle expiry management for existing listings. if ( ! empty( $_GET['postid'] ) && absint( $_GET['postid'] ) === $post_id ) { return; // Skip entirely for updates } $getData = AD()->Helper->post_data( $_POST, '_expiry_date', [] ); if ( ! empty( $getData ) && is_array( $getData ) ) { $sanitized_data = array_map( 'sanitize_text_field', array_values( $getData ) ); list($mm, $jj, $aa, $hh, $mn) = $sanitized_data; if ( ! empty( $aa ?? '' ) && ! empty( $mm ?? '' ) && ! empty( $jj ?? '' ) ) { $expireDates = sprintf( '%04d-%02d-%02d %02d:%02d:00', $aa, $mm, $jj, $hh, $mn ); update_post_meta( $post_id, '_expiry_date', $expireDates ); } } else { // Check if this is a logged-in user listing (not guest) $is_guest_listing = get_post_meta( $post_id, '_is_guest_listing', true ); // For logged-in users, check if they have purchase-based expiry if ( $is_guest_listing !== 'yes' ) { $purchase_expiry_date = adqs_get_purchase_expiry_date( $post_id ); if ( ! empty( $purchase_expiry_date ) ) { update_post_meta( $post_id, '_expiry_date', $purchase_expiry_date ); } else { // Use package-specific or default expiry for logged-in users without purchase $author_id = get_post_field( 'post_author', $post_id ); $post = get_post( $post_id ); $directory_id = 0; if ( $post ) { $directory_id = adqs_get_term_id_by_post_type_slug( $post->post_type ); } // Check if user has package-specific expiry settings $expireDays = 365; // Default fallback if ( function_exists( 'adqs_get_user_package_setting' ) ) { $package_expiry = adqs_get_user_package_setting( 'listing_expire_days', $author_id, $directory_id, $post->post_type ); if ( ! empty( $package_expiry ) ) { $expireDays = $package_expiry; } else { $expireDays = ! empty( adqs_get_setting_option( 'listing_expiry_date' ) ) ? adqs_get_setting_option( 'listing_expiry_date' ) : 365; } } elseif ( function_exists( 'adqs_get_wc_user_package_settings' ) ) { // Check WooCommerce package settings $wc_settings = adqs_get_wc_user_package_settings( $author_id, $directory_id ); if ( ! empty( $wc_settings['listing_expire_days'] ) ) { $expireDays = $wc_settings['listing_expire_days']; } else { $expireDays = ! empty( adqs_get_setting_option( 'listing_expiry_date' ) ) ? adqs_get_setting_option( 'listing_expiry_date' ) : 365; } } else { $expireDays = ! empty( adqs_get_setting_option( 'listing_expiry_date' ) ) ? adqs_get_setting_option( 'listing_expiry_date' ) : 365; } if ( ! empty( $expireDays ) && get_post_field( 'post_date', $post_id ) ) { $expireDates = wp_date( 'Y-m-d H:i:s', strtotime( "+{$expireDays} days", strtotime( get_post_field( 'post_date', $post_id ) ) ) ); update_post_meta( $post_id, '_expiry_date', $expireDates ); } } } else { // Use default expiry for guest listings $expireDays = ! empty( adqs_get_setting_option( 'listing_expiry_date' ) ) ? adqs_get_setting_option( 'listing_expiry_date' ) : 365; if ( ! empty( $expireDays ) && get_post_field( 'post_date', $post_id ) ) { $expireDates = wp_date( 'Y-m-d H:i:s', strtotime( "+{$expireDays} days", strtotime( get_post_field( 'post_date', $post_id ) ) ) ); update_post_meta( $post_id, '_expiry_date', $expireDates ); } } } // Handle "Never Expire" option $getExpData = AD()->Helper->post_data( $_POST, '_expiry_never', '' ); update_post_meta( $post_id, '_expiry_never', sanitize_text_field( $getExpData ) ); // If set to never expire, and listing is currently expired, restore to publish if ( $getExpData === 'yes' && get_post_status( $post_id ) === 'expired' ) { wp_update_post( [ 'ID' => $post_id, 'post_status' => 'publish', ] ); } } add_action( 'adqs_frontend_after_save_metabox_data', 'adqs_save_listing_expiry_date' ); add_action( 'adqs_after_save_metabox_data', 'adqs_save_listing_expiry_date' ); /** * Check if a listing is from a guest user * * @param int $post_id The post ID * @return bool True if guest listing, false if logged-in user */ function adqs_is_guest_listing( $post_id ) { $is_guest_listing = get_post_meta( $post_id, '_is_guest_listing', true ); return $is_guest_listing === 'yes'; } /** * Check if a listing is expired * * @param int $post_id The post ID * @return bool True if expired, false otherwise */ function adqs_is_listing_expired( $post_id ) { $post_id = absint( $post_id ); if ( empty( $post_id ) ) { return false; } // Check post status first $post_status = get_post_status( $post_id ); if ( $post_status === 'expired' ) { return true; } // Check expiry date $expiry_date = adqs_convert_expiry_date( $post_id ); if ( empty( $expiry_date ) ) { return false; // No expiry date means not expired } $current_time = current_time( 'timestamp' ); $expiry_timestamp = strtotime( $expiry_date ); return $current_time > $expiry_timestamp; } /** * Check if a listing is expiring soon * * @param int $post_id The post ID * @param int $days Number of days to check (default: from settings) * @return bool True if expiring within specified days, false otherwise */ function adqs_is_listing_expiring_soon( $post_id, $days = null ) { $post_id = absint( $post_id ); if ( empty( $post_id ) ) { return false; } // Don't show warning for already expired listings if ( adqs_is_listing_expired( $post_id ) ) { return false; } $expiry_date = adqs_convert_expiry_date( $post_id ); if ( empty( $expiry_date ) ) { return false; // No expiry means not expiring } // Get notification days from settings if not provided if ( $days === null ) { $days = absint( adqs_get_setting_option( '_expiry_notification' ) ); if ( empty( $days ) ) { $days = 7; } } $current_time = current_time( 'timestamp' ); $expiry_timestamp = strtotime( $expiry_date ); $warning_timestamp = $expiry_timestamp - ( $days * DAY_IN_SECONDS ); return $current_time >= $warning_timestamp && $current_time < $expiry_timestamp; } /** * Get days remaining until expiry * * @param int $post_id The post ID * @return int|false Number of days remaining, 0 if expired, false if no expiry */ function adqs_get_days_until_expiry( $post_id ) { $post_id = absint( $post_id ); if ( empty( $post_id ) ) { return false; } $expiry_date = adqs_convert_expiry_date( $post_id ); if ( empty( $expiry_date ) ) { return false; } $current_time = current_time( 'timestamp' ); $expiry_timestamp = strtotime( $expiry_date ); if ( $current_time > $expiry_timestamp ) { return 0; // Already expired } $diff_seconds = $expiry_timestamp - $current_time; return absint( ceil( $diff_seconds / DAY_IN_SECONDS ) ); } function adqs_delete_purchase_expiry_date() { $pricing_active = adqs_is_pricing_addon_available(); $expireNotifDay = ! empty( adqs_get_setting_option( '_expiry_notification' ) ) ? adqs_get_setting_option( '_expiry_notification' ) : 7; // Skip notification if set to 0 (disabled) if ( $expireNotifDay <= 0 ) { return; } if ( $pricing_active === 'self' ) { $getAllOrders = adp_get_query_orders( [ 'number' => '' ] ); if ( ! empty( $getAllOrders ) ) { foreach ( $getAllOrders as $order ) { $getDate = get_user_meta( absint( $order->customer_id ?? 0 ), "adp_order_expire_{$order->id}", true ); if ( ! empty( $getDate ) && ( $getDate !== 'never_expire' ) ) { $userNotifyDate = wp_date( 'Y-m-d', strtotime( $getDate . " -{$expireNotifDay} days" ) ); $currentDate = wp_date( 'Y-m-d' ); if ( $currentDate === $userNotifyDate ) { $order_url = $order->id ?? ''; if ( ! empty( get_option( 'adp_view_page_id' ) ) ) { $order_url = get_permalink( absint( get_option( 'adp_view_page_id' ) ) ); $order_url = esc_url( "{$order_url}ad-order/{$order->id}" ); } do_action( 'adqs_expire_listing_notification', $getDate, absint( $order->customer_id ?? 0 ), $order_url ); } if ( time() > strtotime( $getDate ) ) { $customer_id = absint( $order->customer_id ?? 0 ); // Check if we've already processed this expiration $processed_flag = get_user_meta( $customer_id, "_adqs_package_expired_{$order->id}", true ); if ( $processed_flag !== 'yes' ) { // Get pricing details for this order $pricing = adp_get_query_pricing( $order->pricing_id ?? 0 ); if ( $pricing && isset( $pricing->directory_type ) ) { $directory_slug = $pricing->directory_type; // Expire author's listings for this package $expire_results = adqs_snapshot_and_expire_author_listings( $customer_id, $order->id, $order->pricing_id, $directory_slug ); // Mark as processed if successful if ( ! empty( $expire_results['success_count'] ) ) { update_user_meta( $customer_id, "_adqs_package_expired_{$order->id}", 'yes' ); } } } // Delete the expiry meta after processing delete_user_meta( $customer_id, "adp_order_expire_{$order->id}" ); delete_user_meta( $customer_id, "adp_order_reg_listing_{$order->id}" ); delete_user_meta( $customer_id, "adp_order_fea_listing_{$order->id}" ); } } } } } elseif ( $pricing_active === 'wc' ) { // code for woocommerce $query = new WC_Order_Query( [ 'status' => array_keys( wc_get_order_statuses() ), 'limit' => -1, ] ); if ( ! empty( $query->get_orders() ) ) { foreach ( $query->get_orders() as $order ) { $order_id = $order->get_id(); $customer_id = $order->get_user_id(); $getDate = get_user_meta( absint( $customer_id ), "adp_wc_order_expire_{$order_id}", true ); if ( ! empty( $getDate ) && ( $getDate !== 'never_expire' ) ) { $userNotifyDate = wp_date( 'Y-m-d', strtotime( $getDate . " -{$expireNotifDay} days" ) ); $currentDate = wp_date( 'Y-m-d' ); if ( $currentDate === $userNotifyDate ) { $order_url = $order_id ?? ''; if ( ! empty( $order->get_view_order_url() ) ) { $order_url = $order->get_view_order_url(); } do_action( 'adqs_expire_listing_notification', $getDate, absint( $customer_id ), $order_url ); } if ( time() > strtotime( $getDate ) ) { // Check if we've already processed this expiration $processed_flag = get_user_meta( $customer_id, "_adqs_wc_package_expired_{$order_id}", true ); if ( $processed_flag !== 'yes' ) { // Get WooCommerce order and find directory type foreach ( $order->get_items() as $item ) { $product = $item->get_product(); if ( $product && $product->get_type() === 'ad_pricing' ) { $directory_type = adp_wc_get_meta( $product->get_id(), 'directory_type' ); if ( ! empty( $directory_type ) ) { // Get directory term to get slug $directory_term = get_term( $directory_type, 'adqs_listing_types' ); if ( $directory_term && ! is_wp_error( $directory_term ) ) { // Use WooCommerce-specific snapshot function $expire_results = function_exists( 'adqs_wc_snapshot_and_expire_author_listings' ) ? adqs_wc_snapshot_and_expire_author_listings( $customer_id, $order_id, $product->get_id(), $directory_term->slug ) : adqs_snapshot_and_expire_author_listings( $customer_id, $order_id, $product->get_id(), $directory_term->slug ); // Mark as processed if successful if ( ! empty( $expire_results['success_count'] ) ) { update_user_meta( $customer_id, "_adqs_wc_package_expired_{$order_id}", 'yes' ); } } } } } } delete_user_meta( $customer_id, "adp_wc_order_expire_{$order_id}" ); delete_user_meta( $customer_id, "adp_wc_order_reg_listing_{$order_id}" ); delete_user_meta( $customer_id, "adp_wc_order_fea_listing_{$order_id}" ); } } } } } } /** * Mark a listing as expired if expiry date has passed * * @param int $post_id The post ID * @return bool True if listing was expired, false otherwise */ function adqs_expire_listing_action( $post_id ) { $post_id = absint( $post_id ); // Verify post exists and is one of our dynamic post types $post = get_post( $post_id ); if ( ! $post || ! in_array( $post->post_type, adqs_get_directory_post_types() ) ) { return false; } // Check if listing is set to never expire $expiryNever = AD()->Helper->meta_val( $post_id, '_expiry_never', '' ); if ( $expiryNever === 'yes' ) { return false; } // Only process published listings if ( $post->post_status !== 'publish' ) { return false; } $expiry_date = adqs_convert_expiry_date( $post_id ); if ( ! empty( $expiry_date ) ) { $current_time = current_time( 'timestamp' ); $expiry_timestamp = strtotime( $expiry_date ); if ( $current_time > $expiry_timestamp ) { // Update post status to expired $updated = wp_update_post( [ 'ID' => $post_id, 'post_status' => 'expired', ], true ); if ( ! is_wp_error( $updated ) ) { // Clear notification flag so it can be sent again if renewed delete_post_meta( $post_id, '_expiry_notification_sent' ); // Fire action hook for extensions do_action( 'adqs_listing_expired', $post_id, $expiry_date ); return true; } } } return false; } /** * Schedule expiry cron event on init */ function adqs_schedule_expiry_cron() { if ( ! wp_next_scheduled( 'adqs_daily_expire_listings' ) ) { wp_schedule_event( time(), 'daily', 'adqs_daily_expire_listings' ); } } add_action( 'init', 'adqs_schedule_expiry_cron' ); /** * Send expiry notifications for individual listings */ /** * Send expiry notifications for individual listings */ function adqs_send_listing_expiry_notifications() { $dynamic_post_types = adqs_get_directory_post_types(); if ( empty( $dynamic_post_types ) ) { return; } $notification_days = absint( adqs_get_setting_option( '_expiry_notification' ) ); // If notification is disabled (0), skip if ( $notification_days === 0 ) { return; } // Default to 7 days if not set if ( empty( $notification_days ) ) { $notification_days = 7; } foreach ( $dynamic_post_types as $post_type ) { $args = [ 'post_type' => $post_type, 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => [ [ 'key' => '_expiry_notification_sent', 'compare' => 'NOT EXISTS', ], ], ]; $query = new WP_Query( $args ); if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); $post_id = get_the_ID(); // Skip if set to never expire $expiryNever = get_post_meta( $post_id, '_expiry_never', true ); if ( $expiryNever === 'yes' ) { continue; } $expiry_date = adqs_convert_expiry_date( $post_id ); if ( ! empty( $expiry_date ) ) { $notification_date = wp_date( 'Y-m-d', strtotime( $expiry_date . " -{$notification_days} days" ) ); $current_date = wp_date( 'Y-m-d' ); $expiry_timestamp = strtotime( $expiry_date ); $notification_timestamp = strtotime( $notification_date ); $current_timestamp = strtotime( $current_date ); // Check if we're at or past the notification date but before expiry if ( $current_timestamp >= $notification_timestamp && $current_timestamp < $expiry_timestamp ) { // Send notification $is_guest_listing = adqs_is_guest_listing( $post_id ); if ( $is_guest_listing ) { // For guest listings, get email from meta $guest_email = get_post_meta( $post_id, '_guest_email', true ); if ( ! empty( $guest_email ) ) { do_action( 'adqs_expire_listing_notification', $expiry_date, 0, get_permalink( $post_id ), $guest_email ); // Mark notification as sent update_post_meta( $post_id, '_expiry_notification_sent', 'yes' ); } } else { // For logged-in users, get user data $author_id = get_post_field( 'post_author', $post_id ); if ( $author_id ) { do_action( 'adqs_expire_listing_notification', $expiry_date, $author_id, get_permalink( $post_id ), '' ); // Mark notification as sent update_post_meta( $post_id, '_expiry_notification_sent', 'yes' ); } } } } } wp_reset_postdata(); } } } /** * Permanently delete expired listings after the specified number of days * * This function is called by the daily cron job. * It deletes listings that have been in 'expired' status for the configured number of days or longer. * When deleting, all post meta entries are automatically removed by WordPress. * * @return void */ function adqs_permanently_delete_expired_listings() { // Get all dynamic post types $dynamic_post_types = adqs_get_directory_post_types(); if ( empty( $dynamic_post_types ) ) { return; } $deleted_count = 0; foreach ( $dynamic_post_types as $post_type ) { // Query for expired listings with performance optimizations $args = [ 'post_type' => $post_type, 'post_status' => 'expired', 'posts_per_page' => 100, // Process in batches to avoid memory issues 'fields' => 'ids', // Only get IDs for better performance 'no_found_rows' => true, // Skip pagination count 'update_post_meta_cache' => false, // Don't cache meta 'update_post_term_cache' => false, // Don't cache terms ]; $query = new WP_Query( $args ); if ( $query->have_posts() ) { foreach ( $query->posts as $post_id ) { // Absolute safeguard: listings marked as never expire should never be removed if ( get_post_meta( $post_id, '_expiry_never', true ) === 'yes' ) { continue; } // Get the expiry date $expiry_date = get_post_meta( $post_id, '_expiry_date', true ); // Skip if no expiry date is set if ( empty( $expiry_date ) ) { continue; } // Get post author and directory information for package-specific settings $post = get_post( $post_id ); if ( ! $post ) { continue; } $author_id = $post->post_author; $directory_id = function_exists( 'adqs_get_term_id_by_post_type_slug' ) ? adqs_get_term_id_by_post_type_slug( $post_type ) : 0; // Get package-specific delete days from ORIGINAL package used for this listing $delete_days = 0; $saved_order_id = get_post_meta( $post_id, 'adqs_pricing_order_no', true ); if ( ! empty( $saved_order_id ) ) { // Get delete days from THE SPECIFIC package used for this listing if ( function_exists( 'adqs_get_package_settings_from_order' ) ) { $package_settings = adqs_get_package_settings_from_order( $saved_order_id ); $delete_days = absint( $package_settings['permanent_delete_days'] ?? 0 ); } elseif ( function_exists( 'adqs_get_wc_package_settings_from_order' ) ) { $package_settings = adqs_get_wc_package_settings_from_order( $saved_order_id ); $delete_days = absint( $package_settings['permanent_delete_days'] ?? 0 ); } } // Fallback to user's active packages if no saved order (for listings created before this fix) if ( $delete_days === 0 && function_exists( 'adqs_get_user_package_setting' ) ) { $delete_days = adqs_get_user_package_setting( 'permanent_delete_days', $author_id, $directory_id, $post_type, 0 ); } // Only check WooCommerce pricing if regular pricing is not available and delete_days is still 0 elseif ( $delete_days === 0 && function_exists( 'adqs_get_wc_user_package_setting' ) ) { $delete_days = adqs_get_wc_user_package_setting( 'permanent_delete_days', $author_id, $directory_id, $post_type, 0 ); } // If still 0, use main plugin setting if ( $delete_days === 0 ) { $admin_settings = get_option( 'adqs_admin_settings', [] ); $delete_days = absint( $admin_settings['_permanent_delete_days'] ?? 15 ); } // If delete days is 0, skip permanent deletion for this listing if ( $delete_days === 0 ) { continue; } // Calculate the cutoff timestamp for this specific listing $current_time = current_time( 'timestamp' ); $delete_timestamp = $current_time - ( $delete_days * DAY_IN_SECONDS ); $expiry_timestamp = strtotime( $expiry_date ); // Validate timestamp if ( ! $expiry_timestamp ) { continue; } // Check if listing has been expired for the exact number of days or longer // Using <= to include listings that are exactly X days old if ( $expiry_timestamp <= $delete_timestamp ) { // Allow filtering before deletion $should_delete = apply_filters( 'adqs_should_permanently_delete_listing', true, $post_id, $expiry_date, $delete_days ); if ( $should_delete ) { $deleted = wp_delete_post( $post_id, true ); if ( $deleted ) { ++$deleted_count; // Fire action after deletion for logging/cleanup do_action( 'adqs_listing_permanently_deleted', $post_id, $expiry_date ); } } } } } } // Log the deletion count if any deletions occurred if ( $deleted_count > 0 ) { do_action( 'adqs_after_permanent_deletion_batch', $deleted_count ); } } function adqs_daily_run_cron_job() { // delete the expiry purchase date of a listing adqs_delete_purchase_expiry_date(); // Send expiry notifications for individual listings adqs_send_listing_expiry_notifications(); // Permanently delete expired listings if enabled adqs_permanently_delete_expired_listings(); // Expire all listings action - use all dynamic post types $dynamic_post_types = adqs_get_directory_post_types(); if ( ! empty( $dynamic_post_types ) ) { foreach ( $dynamic_post_types as $post_type ) { $args = [ 'post_type' => $post_type, 'post_status' => 'publish', 'posts_per_page' => -1, ]; $query = new WP_Query( $args ); if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); adqs_expire_listing_action( get_the_ID() ); } wp_reset_postdata(); } } } } // Hook the Cron Event add_action( 'adqs_daily_expire_listings', 'adqs_daily_run_cron_job' ); function adqs_unschedule_cron_job() { $timestamp = wp_next_scheduled( 'adqs_daily_expire_listings' ); if ( $timestamp ) { wp_unschedule_event( $timestamp, 'adqs_daily_expire_listings' ); } } /** * Check for expired pricing packages and expire author listings * This function runs daily to detect expired packages and expire associated listings * * @return array Results with processed packages and any errors */ function adqs_check_and_expire_package_listings() { $results = [ 'processed_packages' => 0, 'expired_listings' => 0, 'errors' => [], ]; // Check if pricing package addon is available $pricing_active = adqs_is_pricing_addon_available(); if ( ! $pricing_active ) { return $results; // No pricing addon active } $current_time = current_time( 'timestamp' ); if ( $pricing_active === 'self' && function_exists( 'adp_get_all_orders' ) ) { // Handle standalone pricing package addon $all_orders = adp_get_all_orders( 'completed' ); foreach ( $all_orders as $order ) { $customer_id = $order->customer_id ?? 0; $order_id = $order->id ?? 0; $pricing_id = $order->pricing_id ?? 0; if ( empty( $customer_id ) || empty( $order_id ) || empty( $pricing_id ) ) { continue; } // Check if this order has expired $expire_date = get_user_meta( $customer_id, "adp_order_expire_{$order_id}", true ); // Skip if no expiry date or never expires if ( empty( $expire_date ) || $expire_date === 'never_expire' ) { continue; } $expire_timestamp = strtotime( $expire_date ); if ( ! $expire_timestamp ) { continue; // Invalid date format } // Check if expired (current time is greater than expiry time) if ( $current_time <= $expire_timestamp ) { continue; // Not expired yet } // Check if we've already processed this expiration $processed_flag = get_user_meta( $customer_id, "_adqs_package_expired_{$order_id}", true ); if ( $processed_flag === 'yes' ) { continue; // Already processed } // Get pricing details to find directory type if ( function_exists( 'adp_get_query_pricing' ) ) { $pricing = adp_get_query_pricing( $pricing_id ); if ( $pricing && isset( $pricing->directory_type ) ) { $directory_slug = $pricing->directory_type; // Expire author's listings for this directory type $expire_results = adqs_snapshot_and_expire_author_listings( $customer_id, $order_id, $pricing_id, $directory_slug ); if ( ! empty( $expire_results['success_count'] ) ) { $results['expired_listings'] += $expire_results['success_count']; // Mark this package as processed to avoid re-processing update_user_meta( $customer_id, "_adqs_package_expired_{$order_id}", 'yes' ); // Fire action hook for logging/extensions do_action( 'adqs_package_expired_listings_processed', $customer_id, $order_id, $pricing_id, $directory_slug, $expire_results ); } if ( ! empty( $expire_results['errors'] ) ) { $results['errors'] = array_merge( $results['errors'], $expire_results['errors'] ); } ++$results['processed_packages']; } } } } elseif ( $pricing_active === 'wc' && class_exists( 'WC_Order_Query' ) ) { // Handle WooCommerce pricing package addon $query = new WC_Order_Query( [ 'status' => 'wc-completed', 'limit' => -1, ] ); $orders = $query->get_orders(); foreach ( $orders as $wc_order ) { $customer_id = $wc_order->get_customer_id(); $order_id = $wc_order->get_id(); if ( empty( $customer_id ) || empty( $order_id ) ) { continue; } // Check WooCommerce order expiry (placeholder for future WC addon implementation) // Note: WooCommerce pricing package addon would need to implement these functions $is_wc_order_expired = false; $wc_directory_type = ''; if ( function_exists( 'adp_wc_check_order_expired' ) ) { $is_wc_order_expired = call_user_func( 'adp_wc_check_order_expired', $order_id ); } if ( function_exists( 'adp_wc_get_order_directory_type' ) ) { $wc_directory_type = call_user_func( 'adp_wc_get_order_directory_type', $order_id ); } if ( $is_wc_order_expired && ! empty( $wc_directory_type ) ) { // Check if we've already processed this expiration $processed_flag = get_user_meta( $customer_id, "_adqs_wc_package_expired_{$order_id}", true ); if ( $processed_flag === 'yes' ) { continue; } $expire_results = adqs_snapshot_and_expire_author_listings( $customer_id, $order_id, 0, // WC doesn't use pricing_id the same way $wc_directory_type ); if ( ! empty( $expire_results['success_count'] ) ) { $results['expired_listings'] += $expire_results['success_count']; update_user_meta( $customer_id, "_adqs_wc_package_expired_{$order_id}", 'yes' ); } if ( ! empty( $expire_results['errors'] ) ) { $results['errors'] = array_merge( $results['errors'], $expire_results['errors'] ); } ++$results['processed_packages']; } } } // Log the results if ( $results['processed_packages'] > 0 || ! empty( $results['errors'] ) ) { do_action( 'adqs_package_expiry_check_completed', $results ); } return $results; } /** * Snapshot and expire all listings for an author when their pricing package expires * * @param int $author_id User ID of the author * @param int $purchase_id Purchase/Order ID (for tracking) * @param int $package_id Package/Pricing ID * @param string $directory_type Directory type slug * @return array Results with success count and errors */ function adqs_snapshot_and_expire_author_listings( $author_id, $purchase_id, $package_id, $directory_type ) { $author_id = absint( $author_id ); $purchase_id = absint( $purchase_id ); $package_id = absint( $package_id ); $directory_type = sanitize_text_field( $directory_type ); $results = [ 'success_count' => 0, 'errors' => [], 'processed_listings' => [], ]; if ( empty( $author_id ) || empty( $purchase_id ) || empty( $directory_type ) ) { $results['errors'][] = 'Invalid parameters provided'; return $results; } // Get the directory term to find the post type $directory_term = get_term_by( 'slug', $directory_type, 'adqs_listing_types' ); if ( ! $directory_term || is_wp_error( $directory_term ) ) { $results['errors'][] = 'Invalid directory type: ' . $directory_type; return $results; } $post_type = get_term_meta( $directory_term->term_id, 'adqs_directory_post_type', true ); if ( empty( $post_type ) ) { $results['errors'][] = 'No post type found for directory: ' . $directory_type; return $results; } // Find all published listings by this author for this directory type $listings = get_posts( [ 'author' => $author_id, 'post_type' => $post_type, 'post_status' => [ 'publish', 'pending', 'draft' ], // Any non-expired status 'posts_per_page' => -1, 'fields' => 'ids', 'meta_query' => [ [ 'key' => '_adqs_prev_status_' . $purchase_id, 'compare' => 'NOT EXISTS', ], ], ] ); foreach ( $listings as $listing_id ) { $current_status = get_post_status( $listing_id ); // Skip if already expired or if set to never expire if ( $current_status === 'expired' ) { continue; } $expiry_never = get_post_meta( $listing_id, '_expiry_never', true ); if ( $expiry_never === 'yes' ) { continue; } // Save current status for restoration $snapshot_key = '_adqs_prev_status_' . $purchase_id; $snapshot_data = [ 'previous_status' => $current_status, 'package_id' => $package_id, 'directory_type' => $directory_type, 'expired_at' => current_time( 'mysql' ), 'author_id' => $author_id, ]; update_post_meta( $listing_id, $snapshot_key, $snapshot_data ); // Change status to expired $updated = wp_update_post( [ 'ID' => $listing_id, 'post_status' => 'expired', ], true ); if ( ! is_wp_error( $updated ) ) { ++$results['success_count']; $results['processed_listings'][] = $listing_id; // Fire action hook for extensions do_action( 'adqs_author_listing_expired_by_package', $listing_id, $author_id, $purchase_id, $package_id, $directory_type ); } else { $results['errors'][] = 'Failed to expire listing ' . $listing_id . ': ' . $updated->get_error_message(); } } // Log the action do_action( 'adqs_author_listings_expired_by_package', $author_id, $purchase_id, $package_id, $directory_type, $results ); return $results; } /** * Restore author listings after renewal or purchase of same plan type * * @param int $author_id User ID of the author * @param int $purchase_id Purchase/Order ID (for tracking) * @param int $package_id Package/Pricing ID * @param string $directory_type Directory type slug * @return array Results with success count and errors */ function adqs_restore_author_listings_after_renewal( $author_id, $purchase_id, $package_id, $directory_type ) { $author_id = absint( $author_id ); $purchase_id = absint( $purchase_id ); $package_id = absint( $package_id ); $directory_type = sanitize_text_field( $directory_type ); $results = [ 'success_count' => 0, 'errors' => [], 'restored_listings' => [], ]; if ( empty( $author_id ) || empty( $directory_type ) ) { $results['errors'][] = 'Invalid parameters provided'; return $results; } // Get the directory term to find the post type $directory_term = get_term_by( 'slug', $directory_type, 'adqs_listing_types' ); if ( ! $directory_term || is_wp_error( $directory_term ) ) { $results['errors'][] = 'Invalid directory type: ' . $directory_type; return $results; } $post_type = get_term_meta( $directory_term->term_id, 'adqs_directory_post_type', true ); if ( empty( $post_type ) ) { $results['errors'][] = 'No post type found for directory: ' . $directory_type; return $results; } // Find all expired listings by this author for this directory type that have snapshots $expired_listings = get_posts( [ 'author' => $author_id, 'post_type' => $post_type, 'post_status' => 'expired', 'posts_per_page' => -1, 'fields' => 'ids', 'meta_query' => [ [ 'key' => '_adqs_prev_status_' . $purchase_id, 'compare' => 'EXISTS', ], ], ] ); // Also check for any other purchase IDs for this directory type (in case of multiple expired packages) if ( empty( $expired_listings ) ) { $all_expired_listings = get_posts( [ 'author' => $author_id, 'post_type' => $post_type, 'post_status' => 'expired', 'posts_per_page' => -1, 'fields' => 'ids', ] ); foreach ( $all_expired_listings as $listing_id ) { $all_meta = get_post_meta( $listing_id ); foreach ( $all_meta as $meta_key => $meta_value ) { if ( strpos( $meta_key, '_adqs_prev_status_' ) === 0 ) { $snapshot_data = maybe_unserialize( $meta_value[0] ); if ( isset( $snapshot_data['directory_type'] ) && $snapshot_data['directory_type'] === $directory_type ) { $expired_listings[] = $listing_id; break; } } } } } foreach ( $expired_listings as $listing_id ) { $snapshot_key = '_adqs_prev_status_' . $purchase_id; $snapshot_data = get_post_meta( $listing_id, $snapshot_key, true ); // If no snapshot for this purchase ID, look for any snapshot for this directory type if ( empty( $snapshot_data ) ) { $all_meta = get_post_meta( $listing_id ); foreach ( $all_meta as $meta_key => $meta_value ) { if ( strpos( $meta_key, '_adqs_prev_status_' ) === 0 ) { $temp_snapshot = maybe_unserialize( $meta_value[0] ); if ( isset( $temp_snapshot['directory_type'] ) && $temp_snapshot['directory_type'] === $directory_type ) { $snapshot_data = $temp_snapshot; $snapshot_key = $meta_key; break; } } } } if ( empty( $snapshot_data ) || ! isset( $snapshot_data['previous_status'] ) ) { $results['errors'][] = 'No snapshot data found for listing ' . $listing_id; continue; } // Restore to previous status $previous_status = sanitize_text_field( $snapshot_data['previous_status'] ); $updated = wp_update_post( [ 'ID' => $listing_id, 'post_status' => $previous_status, ], true ); if ( ! is_wp_error( $updated ) ) { // Remove the snapshot meta delete_post_meta( $listing_id, $snapshot_key ); // Update expiry date based on new package adqs_save_listing_expiry_date( $listing_id ); ++$results['success_count']; $results['restored_listings'][] = $listing_id; // Fire action hook for extensions do_action( 'adqs_author_listing_restored_by_package', $listing_id, $author_id, $purchase_id, $package_id, $directory_type, $previous_status ); } else { $results['errors'][] = 'Failed to restore listing ' . $listing_id . ': ' . $updated->get_error_message(); } } // Log the action do_action( 'adqs_author_listings_restored_by_package', $author_id, $purchase_id, $package_id, $directory_type, $results ); return $results; } /** * Clean up old snapshot metadata for expired listings that are no longer needed * This function should be called periodically to prevent database bloat * * @param int $days_old Number of days old snapshots to clean up (default: 90) * @return int Number of cleaned up snapshots */ function adqs_cleanup_old_listing_snapshots( $days_old = 90 ) { $days_old = absint( $days_old ); if ( $days_old < 7 ) { $days_old = 7; // Minimum 7 days to prevent accidental cleanup } $cleanup_count = 0; $cutoff_date = wp_date( 'Y-m-d H:i:s', strtotime( "-{$days_old} days" ) ); // Use direct database query for better performance with large datasets global $wpdb; $post_types = adqs_get_directory_post_types(); if ( empty( $post_types ) ) { return 0; } $post_types_placeholders = implode( ',', array_fill( 0, count( $post_types ), '%s' ) ); $posts_with_snapshots = $wpdb->get_col( $wpdb->prepare( " SELECT DISTINCT pm.post_id FROM {$wpdb->postmeta} pm INNER JOIN {$wpdb->posts} p ON pm.post_id = p.ID WHERE (pm.meta_key LIKE %s OR pm.meta_key LIKE %s) AND p.post_type IN ({$post_types_placeholders}) AND p.post_status IN ('expired', 'publish', 'pending', 'draft') LIMIT 1000 ", '_adqs_prev_status_%', '_adqs_wc_prev_status_%', ...$post_types ) ); foreach ( $posts_with_snapshots as $post_id ) { $all_meta = get_post_meta( $post_id ); foreach ( $all_meta as $meta_key => $meta_value ) { // Clean up both regular and WooCommerce snapshots if ( strpos( $meta_key, '_adqs_prev_status_' ) === 0 || strpos( $meta_key, '_adqs_wc_prev_status_' ) === 0 ) { $snapshot_data = maybe_unserialize( $meta_value[0] ); if ( isset( $snapshot_data['expired_at'] ) ) { $expired_at = $snapshot_data['expired_at']; // If snapshot is older than cutoff date, clean it up if ( strtotime( $expired_at ) < strtotime( $cutoff_date ) ) { delete_post_meta( $post_id, $meta_key ); ++$cleanup_count; // Log the cleanup do_action( 'adqs_snapshot_cleaned_up', $post_id, $meta_key, $snapshot_data ); } } } } } // Log the total cleanup do_action( 'adqs_snapshots_cleanup_completed', $cleanup_count, $days_old ); return $cleanup_count; } /** * Schedule cleanup of old snapshots to run weekly */ function adqs_schedule_snapshot_cleanup() { if ( ! wp_next_scheduled( 'adqs_weekly_cleanup_snapshots' ) ) { wp_schedule_event( time(), 'weekly', 'adqs_weekly_cleanup_snapshots' ); } } add_action( 'init', 'adqs_schedule_snapshot_cleanup' ); /** * Hook the weekly cleanup event */ add_action( 'adqs_weekly_cleanup_snapshots', 'adqs_cleanup_old_listing_snapshots' ); /** * Unschedule cleanup event on deactivation */ function adqs_unschedule_snapshot_cleanup() { $timestamp = wp_next_scheduled( 'adqs_weekly_cleanup_snapshots' ); if ( $timestamp ) { wp_unschedule_event( $timestamp, 'adqs_weekly_cleanup_snapshots' ); } } // Unschedule Cron Events on Deactivation register_deactivation_hook( ADQS_DIRECTORY_FILE, 'adqs_unschedule_cron_job' ); register_deactivation_hook( ADQS_DIRECTORY_FILE, 'adqs_unschedule_snapshot_cleanup' );