public function _notify_expiring_listings() { if (wpbdp_get_option('payment-abandonment')) { $this->payments->notify_abandoned_payments(); } wpbdp_log('Running expirations hook.'); $now = current_time('timestamp'); $api = wpbdp_listings_api(); $api->notify_expiring_listings(0, $now); // notify already expired listings first if (!wpbdp_get_option('listing-renewal')) { return; } $api->notify_expiring_listings(wpbdp_get_option('renewal-email-threshold', 5), $now); // notify listings expiring soon if (wpbdp_get_option('renewal-reminder')) { $threshold = -max(1, intval(wpbdp_get_option('renewal-reminder-threshold'))); $api->notify_expiring_listings($threshold, $now); } }
function wpbdp_log_deprecated() { wpbdp_log('Deprecated function called.', 'deprecated'); }
function _wpbdp_resize_image_if_needed($id) { require_once ABSPATH . 'wp-admin/includes/image.php'; $metadata = wp_get_attachment_metadata($id); if (!$metadata) { return; } $crop = (bool) wpbdp_get_option('thumbnail-crop'); $def_width = absint(wpbdp_get_option('thumbnail-width')); $width = absint(isset($metadata['width']) ? $metadata['width'] : 0); if ($width < $def_width) { return; } $thumb_info = isset($metadata['sizes']['wpbdp-thumb']) ? $metadata['sizes']['wpbdp-thumb'] : false; if (!$width) { return; } if ($thumb_info) { $thumb_width = absint($thumb_info['width']); $def_width = absint(wpbdp_get_option('thumbnail-width')); // 10px of tolerance. if (abs($thumb_width - $def_width) < 10) { return; } } $filename = get_attached_file($id, true); $attach_data = wp_generate_attachment_metadata($id, $filename); wp_update_attachment_metadata($id, $attach_data); wpbdp_log(sprintf('Resized image "%s" [ID: %d] to match updated size constraints.', $filename, $id)); }
function license_check() { if (!$this->modules) { return; } wpbdp_log('Performing (scheduled) license check.'); $data = get_transient('wpbdp-license-check-data'); if (!$data) { $data = array('date' => current_time('mysql'), 'warning-dismissed' => false); foreach ($this->modules as $module) { if (null == ($status = $this->check_module_license($module['id']))) { continue; } if (!isset($data[$status])) { $data[$status] = array(); } $data[$status][$module['id']] = $module['license']; update_option('wpbdp-license-status-' . $module['id'], $status); } set_transient('wpbdp-license-check-data', $data, 1 * WEEK_IN_SECONDS); } }
public function tracking() { global $wpdb; wpbdp_log('Performing (scheduled) site tracking.'); $site_hash = $this->site_hash(); $data = get_transient('wpbdp-site_tracking_data'); if (!$data) { wpbdp_log('Gathering site tracking metrics.'); $data = array(); // General site info. $data['hash'] = $site_hash; $data['site-info'] = array('title' => get_bloginfo('name'), 'wp-version' => get_bloginfo('version'), 'bd-version' => WPBDP_VERSION, 'lang' => get_locale(), 'users' => count(get_users())); // Plugins info. if (!function_exists('get_plugin_data')) { require_once ABSPATH . 'wp-admin/includes/admin.php'; } $data['plugins'] = array(); foreach (get_option('active_plugins') as $path) { $plugin = get_plugin_data(WP_PLUGIN_DIR . '/' . $path); $data['plugins'][] = array('id' => str_replace('/' . basename($path), '', $path), 'name' => wpbdp_getv($plugin, 'Name', ''), 'version' => wpbdp_getv($plugin, 'Version', ''), 'plugin_uri' => wpbdp_getv($plugin, 'PluginURI', ''), 'author' => wpbdp_getv($plugin, 'AuthorName', ''), 'author_uri' => wpbdp_getv($plugin, 'AuthorURI', '')); } // Theme info. $data['theme'] = array(); if (function_exists('wp_get_theme')) { $theme = wp_get_theme(); foreach (array('Name', 'ThemeURI', 'Version', 'Author', 'AuthorURI') as $k) { $data['theme'][strtolower($k)] = $theme->display($k, false, false); } $data['theme']['parent'] = array(); if ($theme_parent = $theme->parent()) { foreach (array('Name', 'ThemeURI', 'Version', 'Author', 'AuthorURI') as $k) { $data['theme']['parent'][strtolower($k)] = $theme_parent->display($k, false, false); } } else { $data['theme']['parent'] = null; } } else { $theme = (object) get_theme_data(get_stylesheet_directory() . '/style.css'); foreach (array('Name', 'Version', 'Author') as $k) { $data['theme'][strtolower($k)] = wpbdp_getv($theme, $k, ''); } } // Posts. $data['posts'] = array(); foreach (get_post_types(array('public' => true)) as $post_type) { $count = wp_count_posts($post_type); $data['posts'][$post_type] = intval($count->publish); } // Taxonomies. $data['taxonomies'] = array(); foreach (get_taxonomies(array('public' => true), 'objects') as $tax) { $data['taxonomies'][$tax->name] = array('name' => $tax->name, 'label' => $tax->label, 'terms' => intval(wp_count_terms($tax->name, array('hide_empty' => 0)))); } // Environment. $data['environment'] = array(); $data['environment']['os'] = php_uname('s') . ' ' . php_uname('r') . ' ' . php_uname('m'); $data['environment']['php'] = phpversion(); $data['environment']['mysql'] = $wpdb->get_var('SELECT @@version'); $data['environment']['server-software'] = $_SERVER['SERVER_SOFTWARE']; wp_remote_post(self::TRACKING_URL, array('method' => 'POST', 'blocking' => false, 'body' => $data)); set_transient('wpbdp-site_tracking_data', true, 7 * 60 * 60 * 24); } // delete_transient( 'wpbdp-site_tracking_data' ); }
public function upgrade_to_2_5() { global $wpdb; wpbdp_log('Updating payment/sticky status values.'); $wpdb->query($wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_key = %s WHERE meta_key = %s", '_wpbdp[sticky]', '_wpbdp_sticky')); $wpdb->query($wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_value = %s WHERE meta_key = %s AND meta_value = %s", 'sticky', '_wpbdp[sticky]', 'approved')); $wpdb->query($wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_value = %s WHERE meta_key = %s AND meta_value != %s", 'pending', '_wpbdp[sticky]', 'approved')); $wpdb->query($wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_key = %s WHERE meta_key = %s", '_wpbdp[payment_status]', '_wpbdp_paymentstatus')); $wpdb->query($wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_value = %s WHERE meta_key = %s AND meta_value != %s", 'not-paid', '_wpbdp[payment_status]', 'paid')); // Misc updates $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE meta_key = %s", '_wpbdp_totalallowedimages')); $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE meta_key = %s", '_wpbdp_termlength')); $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE meta_key = %s", '_wpbdp_costoflisting')); $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE meta_key = %s", '_wpbdp_listingfeeid')); wpbdp_log('Updating listing images to new framework.'); $old_images = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->postmeta} WHERE meta_key = %s", '_wpbdp_image')); foreach ($old_images as $old_image) { require_once ABSPATH . 'wp-admin/includes/file.php'; require_once ABSPATH . 'wp-admin/includes/image.php'; $filename = ABSPATH . 'wp-content/uploads/wpbdm/' . $old_image->meta_value; $wp_filetype = wp_check_filetype(basename($filename), null); $attachment_id = wp_insert_attachment(array('post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename($filename)), 'post_content' => '', 'post_status' => 'inherit'), $filename, $old_image->post_id); $attach_data = wp_generate_attachment_metadata($attachment_id, $filename); wp_update_attachment_metadata($attachment_id, $attach_data); } $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE meta_key = %s", '_wpbdp_image')); $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE meta_key = %s", '_wpbdp_thumbnail')); }