first commit

This commit is contained in:
Yuri
2025-11-16 21:47:01 +01:00
commit 271960206c
8 changed files with 1681 additions and 0 deletions
+164
View File
@@ -0,0 +1,164 @@
<?php
/**
* Plugin Name: WHMCS Pricing
* Description: Display WHMCS product pricing via shortcodes. Lightweight, Elementor-compatible.
* Version: 1.0
* Author: ArkHost
* Author URI: https://arkhost.com
* Sponsored by: Duplika.com
* Text Domain: whmcs-pricing
* Domain Path: /languages
* Requires at least: 5.0
* Requires PHP: 7.4
* License: GPL v2 or later
*/
// Exit if accessed directly
if (!defined('ABSPATH')) {
exit;
}
// Define plugin constants
define('WHMCS_PRICING_VERSION', '1.0');
define('WHMCS_PRICING_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('WHMCS_PRICING_PLUGIN_URL', plugin_dir_url(__FILE__));
define('WHMCS_PRICING_PLUGIN_BASENAME', plugin_basename(__FILE__));
/**
* Main plugin class
*/
class WHMCS_Pricing_Plugin {
/**
* Single instance of the class
*/
private static $instance = null;
/**
* Get instance
*/
public static function get_instance() {
if (null === self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor
*/
private function __construct() {
$this->load_dependencies();
$this->init_hooks();
}
/**
* Load required files
*/
private function load_dependencies() {
require_once WHMCS_PRICING_PLUGIN_DIR . 'includes/api-handler.php';
require_once WHMCS_PRICING_PLUGIN_DIR . 'includes/shortcodes.php';
if (is_admin()) {
require_once WHMCS_PRICING_PLUGIN_DIR . 'includes/admin-settings.php';
}
}
/**
* Initialize hooks
*/
private function init_hooks() {
add_action('plugins_loaded', array($this, 'load_textdomain'));
// Add settings link on plugins page
add_filter('plugin_action_links_' . WHMCS_PRICING_PLUGIN_BASENAME, array($this, 'add_settings_link'));
// Make author link open in new tab
add_filter('plugin_row_meta', array($this, 'modify_plugin_row_meta'), 10, 2);
// Initialize components
if (is_admin()) {
WHMCS_Pricing_Admin::get_instance();
}
WHMCS_Pricing_Shortcodes::get_instance();
}
/**
* Add settings link on plugins page
*/
public function add_settings_link($links) {
$settings_link = '<a href="' . esc_url(admin_url('options-general.php?page=whmcs-pricing')) . '">' . __('Settings', 'whmcs-pricing') . '</a>';
array_unshift($links, $settings_link);
return $links;
}
/**
* Modify plugin row meta to open author link in new tab
*/
public function modify_plugin_row_meta($links, $file) {
if ($file === WHMCS_PRICING_PLUGIN_BASENAME) {
// Add target="_blank" to author link
$links = array_map(function($link) {
if (strpos($link, 'arkhost.com') !== false) {
return str_replace('<a href=', '<a target="_blank" rel="noopener noreferrer" href=', $link);
}
return $link;
}, $links);
}
return $links;
}
/**
* Load plugin textdomain
*/
public function load_textdomain() {
load_plugin_textdomain('whmcs-pricing', false, dirname(WHMCS_PRICING_PLUGIN_BASENAME) . '/languages');
}
/**
* Activate plugin
*/
public static function activate() {
// Set default options
$defaults = array(
'api_url' => '',
'api_identifier' => '',
'api_secret' => '',
'cache_duration' => 3600, // 1 hour
'default_currency' => 'USD',
'show_decimals' => true,
'debug_mode' => false
);
add_option('whmcs_pricing_settings', $defaults);
}
/**
* Deactivate plugin
*/
public static function deactivate() {
// Clear all cached data
WHMCS_Pricing_API::clear_all_cache();
}
}
/**
* Activation hook
*/
register_activation_hook(__FILE__, array('WHMCS_Pricing_Plugin', 'activate'));
/**
* Deactivation hook
*/
register_deactivation_hook(__FILE__, array('WHMCS_Pricing_Plugin', 'deactivate'));
/**
* Initialize plugin
*/
function whmcs_pricing_init() {
return WHMCS_Pricing_Plugin::get_instance();
}
// Start the plugin
whmcs_pricing_init();