File: /var/www/kevin-demo/wp-content/plugins/grocerslist/grocerslist.php
<?php
/*
Plugin Name: GRO
Plugin URI: https://gro.co
Description: GRO is a suite of tools for bloggers — monetize your site with paid memberships and Amazon deep links.
Requires at least: 4.4
Requires PHP: 7.0
Tested up to: 6.8
Version: 1.26.0
Stable tag: 1.26.0
Author: GRO Holdings, Inc
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Author URI: https://github.com/GrocersList/grocerslist-wordpress-plugin
*/
if (!defined('ABSPATH')) exit;
define('GROCERS_LIST_VERSION', '1.26.0');
define('GROCERS_LIST_PLUGIN_FILE', __FILE__);
define('GROCERS_LIST_PLUGIN_DIR', __DIR__);
// Activation hook
register_activation_hook(__FILE__, 'grocers_list_activate');
// Deactivation hook
register_deactivation_hook(__FILE__, 'grocers_list_deactivate');
/**
* Plugin activation function
*/
function grocers_list_activate() {
// Check PHP version
if (version_compare(PHP_VERSION, '7.0', '<')) {
wp_die(
__('GRO requires PHP 7.0 or higher. Your server is running PHP ' . PHP_VERSION, 'grocers-list'),
__('Plugin Activation Error', 'grocers-list'),
array('response' => 200, 'back_link' => TRUE)
);
}
// Check for required WordPress functions
if (!function_exists('add_action') || !function_exists('add_filter')) {
wp_die(
__('WordPress functions are not available. Please check your WordPress installation.', 'grocers-list'),
__('Plugin Activation Error', 'grocers-list'),
array('response' => 200, 'back_link' => TRUE)
);
}
// Check if configuration file exists, if not try to create a default one
$configFile = __DIR__ . '/includes/Support/config-constants.php';
if (!file_exists($configFile)) {
$default_config = "<?php\n/**\n * Generated configuration constants for prod environment\n * DO NOT EDIT THIS FILE DIRECTLY\n */\n\ndefine('GROCERSLIST_API_BASE_DOMAIN', 'app.grocerslist.com');\ndefine('GROCERSLIST_LINKSTA_SUBDOMAIN', '');\ndefine('GROCERSLIST_EXTERNAL_JS_URL', 'https://app.grocerslist.com/wp-plugin.js');";
// Ensure the directory exists
$config_dir = dirname($configFile);
if (!file_exists($config_dir)) {
wp_mkdir_p($config_dir);
}
// Try to create the config file
if (!file_put_contents($configFile, $default_config)) {
wp_die(
__('Could not create configuration file. Please check file permissions.', 'grocers-list'),
__('Plugin Activation Error', 'grocers-list'),
array('response' => 200, 'back_link' => TRUE)
);
}
}
// Set up autoloader for activation
spl_autoload_register(function ($class) {
if (strpos($class, 'GrocersList\\') !== 0) return;
$path = __DIR__ . '/includes/' . str_replace('GrocersList\\', '', $class);
$path = str_replace('\\', '/', $path) . '.php';
if (file_exists($path)) {
require_once $path;
}
});
// Run database installation
require_once __DIR__ . '/includes/Database/Installer.php';
GrocersList\Database\Installer::install();
// Schedule the hourly WP user cleanup cron. Handler is wired in Plugin::register().
if (!wp_next_scheduled('grocerslist_wp_user_cleanup')) {
wp_schedule_event(time(), 'hourly', 'grocerslist_wp_user_cleanup');
}
// Flush rewrite rules (useful for nginx compatibility)
flush_rewrite_rules();
}
/**
* Plugin deactivation function
*/
function grocers_list_deactivate() {
// Clean up any scheduled events if we had any
wp_clear_scheduled_hook('grocers_list_scheduled_task');
wp_clear_scheduled_hook('grocerslist_wp_user_cleanup');
// Flush rewrite rules (useful for nginx compatibility)
flush_rewrite_rules();
}
// Include configuration constants
$configFile = __DIR__ . '/includes/Support/config-constants.php';
if (!file_exists($configFile)) {
// Log error and show admin notice
error_log('GrocersList Plugin: Configuration file missing - ' . $configFile);
if (is_admin()) {
add_action('admin_notices', function() {
echo '<div class="notice notice-error"><p>GrocersList Plugin: Configuration file is missing. Please rebuild the plugin or deactivate and reactivate it.</p></div>';
});
}
return;
}
require_once $configFile;
require_once __DIR__ . '/includes/Plugin.php';
// Autoloader with error handling
spl_autoload_register(function ($class) {
if (strpos($class, 'GrocersList\\') !== 0) return;
$path = __DIR__ . '/includes/' . str_replace('GrocersList\\', '', $class);
$path = str_replace('\\', '/', $path) . '.php';
if (file_exists($path)) {
require_once $path;
} else {
error_log("GrocersList Plugin: Could not load class file: {$path}");
}
});
// Initialize plugin with error handling
try {
(new GrocersList\Plugin())->register();
} catch (Throwable $e) {
error_log('GrocersList Plugin Error: ' . $e->getMessage());
if (is_admin()) {
add_action('admin_notices', function() use ($e) {
echo '<div class="notice notice-error"><p>GrocersList Plugin Error: ' . esc_html($e->getMessage()) . '</p></div>';
});
}
}