| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Knit Pay |
| 4 |
* Plugin URI: https://www.knitpay.org |
| 5 |
* Description: Seamlessly integrates 500+ payment gateways, including Cashfree, Instamojo, Razorpay, PayPal, Stripe, UPI QR, and SSLCommerz, with over 100 WordPress plugins. |
| 6 |
* |
| 7 |
* Version: 9.6.2.0-beta.2 |
| 8 |
* Requires at least: 6.2 |
| 9 |
* Requires PHP: 8.1 |
| 10 |
* |
| 11 |
* Author: KnitPay |
| 12 |
* Author URI: https://www.knitpay.org/ |
| 13 |
* |
| 14 |
* Text Domain: knit-pay-lang |
| 15 |
* Domain Path: /languages/ |
| 16 |
* |
| 17 |
* License: GPL-3.0-or-later |
| 18 |
* |
| 19 |
* @author KnitPay |
| 20 |
* @license GPL-3.0-or-later |
| 21 |
* @package KnitPay |
| 22 |
* @copyright 2020-2026 Knit Pay |
| 23 |
*/ |
| 24 |
|
| 25 |
if ( ! defined( 'ABSPATH' ) ) { |
| 26 |
exit; |
| 27 |
} |
| 28 |
|
| 29 |
if ( ! defined( 'KNIT_PAY_DEBUG' ) ) { |
| 30 |
define( 'KNIT_PAY_DEBUG', false ); |
| 31 |
} |
| 32 |
if ( ! defined( 'PRONAMIC_PAY_DEBUG' ) ) { |
| 33 |
define( 'PRONAMIC_PAY_DEBUG', false ); |
| 34 |
} |
| 35 |
|
| 36 |
define( 'KNITPAY_URL', plugins_url( '', __FILE__ ) ); |
| 37 |
define( 'KNITPAY_DIR', plugin_dir_path( __FILE__ ) ); |
| 38 |
define( 'KNITPAY_PATH', __FILE__ ); |
| 39 |
|
| 40 |
/** |
| 41 |
* Autoload. |
| 42 |
*/ |
| 43 |
require_once __DIR__ . '/vendor/autoload_packages.php'; |
| 44 |
|
| 45 |
require_once KNITPAY_DIR . 'include.php'; |
| 46 |
|
| 47 |
/** |
| 48 |
* Bootstrap. |
| 49 |
*/ |
| 50 |
$knit_pay_plugin = \Pronamic\WordPress\Pay\Plugin::instance( |
| 51 |
[ |
| 52 |
'file' => __FILE__, |
| 53 |
'rest_base' => 'knit-pay', |
| 54 |
/* |
| 55 |
'options' => [ |
| 56 |
'about_page_file' => __DIR__ . '/admin/page-about.php', |
| 57 |
]*/ |
| 58 |
'action_scheduler' => __DIR__ . '/packages/woocommerce/action-scheduler/action-scheduler.php', |
| 59 |
] |
| 60 |
); |
| 61 |
define( 'KNITPAY_VERSION', $knit_pay_plugin->get_version() ); |
| 62 |
|
| 63 |
// Knit Pay Reports Module. |
| 64 |
\KnitPay\Reports\ReportsModule::instance()->setup(); |
| 65 |
|
| 66 |
add_filter( |
| 67 |
'pronamic_pay_modules', |
| 68 |
function ( $modules ) { |
| 69 |
if ( defined( 'KNIT_PAY_RAZORPAY_SUBSCRIPTION' ) ) { |
| 70 |
$modules[] = 'subscriptions'; |
| 71 |
} |
| 72 |
|
| 73 |
return $modules; |
| 74 |
} |
| 75 |
); |
| 76 |
|
| 77 |
add_filter( |
| 78 |
'pronamic_pay_plugin_integrations', |
| 79 |
function ( $integrations ) { |
| 80 |
// BookingPress. |
| 81 |
$integrations[] = new \KnitPay\Extensions\BookingPress\Extension(); |
| 82 |
|
| 83 |
// Camptix. |
| 84 |
$integrations[] = new \KnitPay\Extensions\Camptix\Extension(); |
| 85 |
|
| 86 |
// Charitable. |
| 87 |
$integrations[] = new \KnitPay\Extensions\Charitable\Extension(); |
| 88 |
|
| 89 |
// Contact Form 7. |
| 90 |
$integrations[] = new \KnitPay\Extensions\ContactForm7\Extension(); |
| 91 |
|
| 92 |
// Easy Digital Downloads. |
| 93 |
$integrations[] = new \KnitPay\Extensions\EasyDigitalDownloads\Extension(); |
| 94 |
|
| 95 |
// Give. |
| 96 |
$integrations[] = new \KnitPay\Extensions\Give\Extension(); |
| 97 |
|
| 98 |
// Gravity Forms. |
| 99 |
if ( ! defined( 'KNIT_PAY_GRAVITY_FORMS' ) ) { |
| 100 |
$integrations[] = new \Pronamic\WordPress\Pay\Extensions\GravityForms\Extension(); |
| 101 |
} |
| 102 |
|
| 103 |
// Knit Pay - Payment Button. |
| 104 |
$integrations[] = new \KnitPay\Extensions\KnitPayPaymentButton\Extension(); |
| 105 |
|
| 106 |
// Knit Pay - Payment Link. |
| 107 |
$integrations[] = new \KnitPay\Extensions\KnitPayPaymentLink\Extension(); |
| 108 |
|
| 109 |
// LatePoint. |
| 110 |
$integrations[] = new \KnitPay\Extensions\LatePoint\Extension(); |
| 111 |
|
| 112 |
// LearnDash. |
| 113 |
if ( ! defined( 'KNIT_PAY_LEARN_DASH' ) ) { |
| 114 |
$integrations[] = new \KnitPay\Extensions\LearnDash\Extension(); |
| 115 |
} |
| 116 |
|
| 117 |
// LearnPress. |
| 118 |
$integrations[] = new \KnitPay\Extensions\LearnPress\Extension(); |
| 119 |
|
| 120 |
// LifterLMS. |
| 121 |
$integrations[] = new \KnitPay\Extensions\LifterLMS\Extension(); |
| 122 |
|
| 123 |
// NinjaForms. |
| 124 |
$integrations[] = new \Pronamic\WordPress\Pay\Extensions\NinjaForms\Extension(); |
| 125 |
|
| 126 |
// Paid Memberships Pro. |
| 127 |
$integrations[] = new \KnitPay\Extensions\PaidMembershipsPro\Extension(); |
| 128 |
|
| 129 |
// Profile Press. |
| 130 |
$integrations[] = new \KnitPay\Extensions\ProfilePress\Extension(); |
| 131 |
|
| 132 |
// Tourmaster. |
| 133 |
$integrations[] = new \KnitPay\Extensions\TourMaster\Extension(); |
| 134 |
|
| 135 |
// Tutor LMS. |
| 136 |
$integrations[] = new \KnitPay\Extensions\TutorLMS\Extension(); |
| 137 |
|
| 138 |
// WP Travel. |
| 139 |
$integrations[] = new \KnitPay\Extensions\WPTravel\Extension(); |
| 140 |
|
| 141 |
// WP Travel Engine. |
| 142 |
$integrations[] = new \KnitPay\Extensions\WPTravelEngine\Extension(); |
| 143 |
|
| 144 |
// WooCommerce. |
| 145 |
$integrations[] = new \Pronamic\WordPress\Pay\Extensions\WooCommerce\Extension( |
| 146 |
[ |
| 147 |
'db_version_option_name' => 'knit_pay_woocommerce_db_version', |
| 148 |
] |
| 149 |
); |
| 150 |
|
| 151 |
// Uncanny Automator. |
| 152 |
$integrations['uncanny-automator'] = new \KnitPay\Extensions\UncannyAutomator\Extension(); |
| 153 |
|
| 154 |
// Return integrations. |
| 155 |
return $integrations; |
| 156 |
} |
| 157 |
); |
| 158 |
|
| 159 |
add_filter( |
| 160 |
'pronamic_pay_gateways', |
| 161 |
function ( $gateways ) { |
| 162 |
// Cashfree. |
| 163 |
$gateways[] = new \KnitPay\Gateways\Cashfree\Integration(); |
| 164 |
|
| 165 |
// Instamojo. |
| 166 |
$gateways[] = new \KnitPay\Gateways\Instamojo\Integration(); |
| 167 |
|
| 168 |
// Manual. |
| 169 |
$gateways[] = new \KnitPay\Gateways\Manual\Integration(); |
| 170 |
|
| 171 |
// Open Money. |
| 172 |
if ( defined( 'KNIT_PAY_OPEN_MONEY' ) ) { |
| 173 |
$gateways[] = new \KnitPay\Gateways\OpenMoney\Integration(); |
| 174 |
} |
| 175 |
|
| 176 |
// Easebuzz. |
| 177 |
if ( defined( 'KNIT_PAY_EASEBUZZ' ) ) { |
| 178 |
$gateways[] = new \KnitPay\Gateways\Easebuzz\Integration(); |
| 179 |
} |
| 180 |
|
| 181 |
// RazorPay. |
| 182 |
$gateways[] = new \KnitPay\Gateways\Razorpay\Integration(); |
| 183 |
|
| 184 |
// SSLCommerz. |
| 185 |
$gateways[] = new \KnitPay\Gateways\SSLCommerz\Integration(); |
| 186 |
|
| 187 |
// Stripe Connect. |
| 188 |
$gateways['stripe-connect'] = new \KnitPay\Gateways\Stripe\Connect\Integration(); |
| 189 |
|
| 190 |
// Test. |
| 191 |
$gateways[] = new \KnitPay\Gateways\Test\Integration(); |
| 192 |
|
| 193 |
// UPI QR. |
| 194 |
$gateways[] = new \KnitPay\Gateways\UpiQR\Integration(); |
| 195 |
|
| 196 |
// Multi Gateway. |
| 197 |
$gateways[] = new \KnitPay\Gateways\MultiGateway\Integration(); |
| 198 |
|
| 199 |
// Orderbox. |
| 200 |
$gateways[] = new \KnitPay\Gateways\OrderBox\Integration(); |
| 201 |
|
| 202 |
// Other Gateways. |
| 203 |
$gateways[] = new \KnitPay\Gateways\Other\Integration(); |
| 204 |
|
| 205 |
// PayPal. |
| 206 |
$gateways[] = new \KnitPay\Gateways\PayPal\Integration(); |
| 207 |
|
| 208 |
// Return gateways. |
| 209 |
return $gateways; |
| 210 |
} |
| 211 |
); |
| 212 |
|
| 213 |
// Show Error If no configuration Found |
| 214 |
function knitpay_admin_no_config_error() { |
| 215 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 216 |
return; |
| 217 |
} |
| 218 |
|
| 219 |
if ( 0 === wp_count_posts( 'pronamic_gateway' )->publish ) { |
| 220 |
$class = 'notice notice-error'; |
| 221 |
$url = admin_url() . 'post-new.php?post_type=pronamic_gateway'; |
| 222 |
$link = '<a href="' . $url . '">' . __( 'Knit Pay >> Configurations', 'knit-pay-lang' ) . '</a>'; |
| 223 |
$supported_gateways = '<br><a href="https://www.knitpay.org/indian-payment-gateways-supported-in-knit-pay/">' . __( 'Check the list of Supported Payment Gateways', 'knit-pay-lang' ) . '</a>'; |
| 224 |
$message = sprintf( __( '<b>Knit Pay:</b> No Payment Gateway configuration was found. %1$s and visit %2$s to add the first configuration before start using Knit Pay.', 'knit-pay-lang' ), $supported_gateways, $link ); |
| 225 |
|
| 226 |
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), $message ); |
| 227 |
} |
| 228 |
} |
| 229 |
add_action( 'admin_notices', 'knitpay_admin_no_config_error' ); |
| 230 |
|
| 231 |
|
| 232 |
// Add custom link on plugin page |
| 233 |
function knitpay_filter_plugin_action_links( array $actions ) { |
| 234 |
return array_merge( |
| 235 |
[ |
| 236 |
'configurations' => '<a href="edit.php?post_type=pronamic_gateway">' . esc_html__( 'Configurations', 'knit-pay-lang' ) . '</a>', |
| 237 |
'payments' => '<a href="admin.php?page=knit-pay-reports&tab=transactions">' . esc_html__( 'Payments', 'knit-pay-lang' ) . '</a>', |
| 238 |
], |
| 239 |
$actions |
| 240 |
); |
| 241 |
} |
| 242 |
$plugin = plugin_basename( __FILE__ ); |
| 243 |
add_filter( "plugin_action_links_$plugin", 'knitpay_filter_plugin_action_links' ); |
| 244 |
|
| 245 |
|
| 246 |
// Fix URLs with multiple question marks by converting extras to ampersands. |
| 247 |
function knitpay_fix_get_url() { |
| 248 |
if ( ! ( filter_has_var( INPUT_SERVER, 'REQUEST_METHOD' ) && 'GET' === $_SERVER['REQUEST_METHOD'] ) ) { |
| 249 |
return; |
| 250 |
} |
| 251 |
|
| 252 |
$current_url = home_url( esc_url_raw( $_SERVER['REQUEST_URI'] ) ); |
| 253 |
|
| 254 |
// Only process if there are multiple question marks |
| 255 |
if ( substr_count( $current_url, '?' ) > 1 ) { |
| 256 |
// Split URL at first question mark |
| 257 |
list($base, $query) = explode( '?', $current_url, 2 ); |
| 258 |
|
| 259 |
// Replace remaining question marks with ampersands and fix encoded ampersands |
| 260 |
$query = str_replace( [ '?', '&' ], [ '&', '&' ], $query ); |
| 261 |
|
| 262 |
wp_safe_redirect( $base . '?' . $query ); |
| 263 |
exit; |
| 264 |
} |
| 265 |
} |
| 266 |
add_action( 'init', 'knitpay_fix_get_url', 0 ); |
| 267 |
|
| 268 |
add_action( 'plugins_loaded', 'knit_pay_engine_themes_init', -10 ); |
| 269 |
function knit_pay_engine_themes_init() { |
| 270 |
if ( \defined( 'KNIT_PAY_ENGINE_THEMES' ) ) { |
| 271 |
require_once KNITPAY_DIR . 'extensions/EngineThemes/init.php'; |
| 272 |
} |
| 273 |
} |
| 274 |
|