From ab68968a2890504b4465b004aac6f51e84f230c7 Mon Sep 17 00:00:00 2001 From: Towfiqul Islam <43319312+towfiq1997@users.noreply.github.com> Date: Thu, 14 May 2026 15:22:58 +0600 Subject: [PATCH 1/8] Framework change ByteKit tO B8 --- assets/src/js/admin-common.js | 1 - composer.json | 6 +- includes/Admin/Actions.php | 2 - includes/Admin/Admin.php | 31 +++++--- includes/Admin/Menus.php | 21 +++-- includes/Admin/Notices.php | 15 +++- includes/Admin/views/notices/review.php | 2 +- includes/Admin/views/notices/upgrade.php | 3 +- includes/Donation/Donation.php | 10 ++- includes/Frontend/Cart.php | 12 +-- includes/Frontend/Frontend.php | 20 +++-- includes/Frontend/Orders.php | 8 +- includes/Frontend/Product.php | 22 +++--- includes/Installer.php | 30 ++++--- includes/Plugin.php | 99 +++++++++++++----------- wc-donation-manager.php | 13 ++++ 16 files changed, 180 insertions(+), 115 deletions(-) diff --git a/assets/src/js/admin-common.js b/assets/src/js/admin-common.js index 96f85c2..fa0eac8 100644 --- a/assets/src/js/admin-common.js +++ b/assets/src/js/admin-common.js @@ -5,7 +5,6 @@ * Copyright (c) 2025 PluginEver * Licensed under the GPLv2+ license. */ -s /*jslint browser: true */ /*global jQuery:false */ jQuery(document).ready(function ($) { diff --git a/composer.json b/composer.json index de54ed6..55e285a 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "repositories": [ { "type": "vcs", - "url": "git@github.com:byteever/bytekit-plugin.git" + "url": "git@github.com:byteever/plugin.git" }, { "type": "vcs", @@ -14,7 +14,7 @@ ], "require": { "php": ">=7.4", - "byteever/bytekit-plugin": "dev-trunk", + "byteever/plugin": "dev-trunk", "byteever/bytekit-settings": "dev-trunk" }, "require-dev": { @@ -52,7 +52,7 @@ "namespace_prefix": "WooCommerceDonationManager\\", "classmap_prefix": "WooCommerceDonationManager__", "packages": [ - "byteever/bytekit-plugin", + "byteever/plugin", "byteever/bytekit-settings" ] } diff --git a/includes/Admin/Actions.php b/includes/Admin/Actions.php index 9a96dbf..554b8a6 100644 --- a/includes/Admin/Actions.php +++ b/includes/Admin/Actions.php @@ -14,7 +14,6 @@ * @package WooCommerceDonationManager */ class Actions { - /** * Actions constructor. * @@ -108,7 +107,6 @@ public static function edit_campaign() { } else { WCDM()->flash->success( __( 'Campaign updated successfully.', 'wc-donation-manager' ) ); } - wp_safe_redirect( $referer ); exit; } diff --git a/includes/Admin/Admin.php b/includes/Admin/Admin.php index ea79ef9..b7ea66b 100644 --- a/includes/Admin/Admin.php +++ b/includes/Admin/Admin.php @@ -2,6 +2,8 @@ namespace WooCommerceDonationManager\Admin; +use WooCommerceDonationManager\Plugin; + defined( 'ABSPATH' ) || exit; // Exit if accessed directly. /** @@ -11,13 +13,20 @@ * @package WooCommerceDonationManager\Admin */ class Admin { + /** + * Plugin instance. + * + * @var Plugin + */ + protected Plugin $plugin; /** * Admin constructor. * * @since 1.0.0 */ - public function __construct() { + public function __construct( Plugin $plugin ) { + $this->plugin = $plugin; add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); add_filter( 'woocommerce_screen_ids', array( $this, 'add_screen_ids' ) ); add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), PHP_INT_MAX ); @@ -34,8 +43,8 @@ public function __construct() { */ public function enqueue_scripts( $hook ) { $screen_ids = Utilities::get_screen_ids(); - WCDM()->scripts->enqueue_style( 'wcdm-admin', 'css/admin.css', array( 'bytekit-layout', 'bytekit-components', 'woocommerce_admin_styles' ) ); - WCDM()->scripts->register_script( 'wcdm-admin', 'js/admin.js' ); + $this->plugin->scripts->enqueue_style( 'wcdm-admin', 'css/admin.css', array( 'woocommerce_admin_styles' ) ); + $this->plugin->scripts->register_script( 'wcdm-admin', 'js/admin.js' ); if ( in_array( $hook, $screen_ids, true ) ) { wp_enqueue_style( 'wcdm-admin' ); @@ -61,7 +70,7 @@ public function enqueue_scripts( $hook ) { * * @return array */ - public function add_screen_ids( $ids ) { + public function add_screen_ids( $ids ): array { return array_merge( $ids, Utilities::get_screen_ids() ); } @@ -70,10 +79,10 @@ public function add_screen_ids( $ids ) { * * @param string $text Footer text. * - * @since 1.0.0 * @return string + * @since 1.0.0 */ - public function admin_footer_text( $text ) { + public function admin_footer_text( string $text ): string { if ( in_array( get_current_screen()->id, Utilities::get_screen_ids(), true ) ) { $text = sprintf( @@ -81,11 +90,11 @@ public function admin_footer_text( $text ) { __( 'Thank you for using %s!', 'wc-donation-manager' ), '' . esc_html( WCDM()->get_name() ) . '', ); - if ( WCDM()->get_review_url() ) { + if ( $this->plugin->review_url ) { $text .= sprintf( /* translators: %s: Plugin name */ __( ' Share your appreciation with a five-star review %s.', 'wc-donation-manager' ), - 'here' + 'here' ); } } @@ -98,14 +107,14 @@ public function admin_footer_text( $text ) { * * @param string $text Footer text. * - * @since 1.0.0 * @return string + * @since 1.0.0 */ - public function update_footer( $text ) { + public function update_footer( string $text ): string { if ( in_array( get_current_screen()->id, Utilities::get_screen_ids(), true ) ) { /* translators: 1: Plugin version */ - $text = sprintf( esc_html__( 'Version %s', 'wc-donation-manager' ), WCDM()->get_version() ); + $text = sprintf( esc_html__( 'Version %s', 'wc-donation-manager' ), $this->plugin->version ); } return $text; diff --git a/includes/Admin/Menus.php b/includes/Admin/Menus.php index aceb09b..090f10c 100644 --- a/includes/Admin/Menus.php +++ b/includes/Admin/Menus.php @@ -2,6 +2,8 @@ namespace WooCommerceDonationManager\Admin; +use WooCommerceDonationManager\Plugin; + defined( 'ABSPATH' ) || exit; /** @@ -11,6 +13,12 @@ * @package WooCommerceDonationManager\Admin */ class Menus { + /** + * Plugin instance. + * + * @var Plugin + */ + protected Plugin $plugin; /** * Main menu slug. @@ -18,7 +26,7 @@ class Menus { * @since 1.0.0 * @var string */ - const PARENT_SLUG = 'wc-donation-manager'; + const string PARENT_SLUG = 'wc-donation-manager'; /** * List tables. @@ -32,14 +40,15 @@ class Menus { * * @since 1.0.0 */ - public function __construct() { + public function __construct( Plugin $plugin ) { + $this->plugin = $plugin; add_action( 'admin_menu', array( $this, 'admin_menu' ) ); add_filter( 'set-screen-option', array( $this, 'screen_option' ), 10, 3 ); add_action( 'current_screen', array( $this, 'setup_list_table' ) ); add_action( 'wc_donation_manager_campaigns_content', array( $this, 'render_campaigns_content' ) ); // Pro tabs. - if ( ! WCDM()->is_plugin_active( 'wc-donation-manager-pro' ) ) { + if ( ! $this->plugin->plugin_active( 'wc-donation-manager-pro' ) ) { add_action( 'wc_donation_manager_donors_content', array( $this, 'render_donors_content' ) ); add_action( 'wc_donation_manager_settings_emails_content', array( $this, 'render_emails_settings' ) ); add_action( 'woocommerce_admin_field_wcdm_add_to_cart_btn_text', array( $this, 'render_customizable_settings' ) ); @@ -208,7 +217,7 @@ public function render_donors_content() {

- <?php esc_attr_e( 'Donors list table', 'wc-donation-manager' ); ?> + <?php esc_attr_e( 'Donors list table', 'wc-donation-manager' ); ?> - <?php esc_attr_e( 'Customer completed emails', 'wc-donation-manager' ); ?> + <?php esc_attr_e( 'Customer completed emails', 'wc-donation-manager' ); ?> - <?php esc_attr_e( 'Add customizable settings', 'wc-donation-manager' ); ?> + <?php esc_attr_e( 'Add customizable settings', 'wc-donation-manager' ); ?> plugin = $plugin; add_action( 'admin_init', array( $this, 'admin_notices' ) ); } @@ -31,7 +40,7 @@ public function admin_notices() { $current_time = absint( wp_date( 'U' ) ); if ( ! defined( 'WCDM_PRO_VERSION' ) ) { - WCDM()->notices->add( + $this->plugin->notices->add( array( 'message' => __DIR__ . '/views/notices/upgrade.php', 'notice_id' => 'wcdm_upgrade', @@ -43,7 +52,7 @@ public function admin_notices() { // Show after 5 days. if ( $installed_time && $current_time > ( $installed_time + ( 5 * DAY_IN_SECONDS ) ) ) { - WCDM()->notices->add( + $this->plugin->notices->add( array( 'message' => __DIR__ . '/views/notices/review.php', 'dismissible' => false, diff --git a/includes/Admin/views/notices/review.php b/includes/Admin/views/notices/review.php index 575d200..3a3fc98 100644 --- a/includes/Admin/views/notices/review.php +++ b/includes/Admin/views/notices/review.php @@ -12,7 +12,7 @@ ?>
- WooCommerce Donation Manager + WooCommerce Donation Manager

diff --git a/includes/Admin/views/notices/upgrade.php b/includes/Admin/views/notices/upgrade.php index 0e0b26d..028988e 100644 --- a/includes/Admin/views/notices/upgrade.php +++ b/includes/Admin/views/notices/upgrade.php @@ -8,11 +8,10 @@ */ defined( 'ABSPATH' ) || exit; - ?>
- WooCommerce Donation Manager + WooCommerce Donation Manager

diff --git a/includes/Donation/Donation.php b/includes/Donation/Donation.php index bbe7e9f..6c77a09 100644 --- a/includes/Donation/Donation.php +++ b/includes/Donation/Donation.php @@ -2,6 +2,8 @@ namespace WooCommerceDonationManager\Donation; +use WooCommerceDonationManager\Plugin; + defined( 'ABSPATH' ) || exit; // Exist if accessed directly. /** @@ -26,10 +28,10 @@ public function __construct() { * * @param array $product_type array of product types. * - * @version 1.0.0 * @return array array of product types. + * @version 1.0.0 */ - public static function add_product_type( $product_type ) { + public static function add_product_type( array $product_type ): array { $product_type['donation'] = __( 'Donation', 'wc-donation-manager' ); return $product_type; @@ -41,10 +43,10 @@ public static function add_product_type( $product_type ) { * @param string $class_name Class name. * @param string $product_type Product type name. * - * @version 1.0.0 * @return string Class name. + * @version 1.0.0 */ - public static function product_type_class( $class_name, $product_type ) { + public static function product_type_class( string $class_name, string $product_type ): string { if ( 'donation' === $product_type ) { $class_name = 'WCDM_Donation_Product'; diff --git a/includes/Frontend/Cart.php b/includes/Frontend/Cart.php index 365465b..e9ac6ae 100644 --- a/includes/Frontend/Cart.php +++ b/includes/Frontend/Cart.php @@ -30,10 +30,10 @@ public function __construct() { * * @param array $session_data Session cart item data. * - * @since 1.0.0 * @return array + * @since 1.0.0 */ - public static function get_cart_item_from_session( $session_data ) { + public static function get_cart_item_from_session( array $session_data ): array { if ( $session_data['data']->get_type() === 'donation' && isset( $session_data['donation_amount'] ) ) { $session_data['data']->set_price( $session_data['donation_amount'] ); } @@ -48,10 +48,10 @@ public static function get_cart_item_from_session( $session_data ) { * @param array $cart_item Cart item. * @param string $cart_item_key Cart item key. * - * @since 1.0.0 * @return string + * @since 1.0.0 */ - public static function cart_item_price( $price, $cart_item, $cart_item_key ) { + public static function cart_item_price( string $price, array $cart_item, string $cart_item_key ): string { if ( ! is_cart() ) { return $price; } @@ -68,10 +68,10 @@ public static function cart_item_price( $price, $cart_item, $cart_item_key ) { * * @param bool $cart_updated weather true of false. * - * @since 1.0.0 * @return bool + * @since 1.0.0 */ - public static function update_cart( $cart_updated ) { + public static function update_cart( bool $cart_updated ): bool { wp_verify_nonce( '_wpnonce' ); if ( 'yes' !== get_option( 'wcdm_editable_cart_price', 'yes' ) ) { diff --git a/includes/Frontend/Frontend.php b/includes/Frontend/Frontend.php index 9d8786b..53de2b9 100644 --- a/includes/Frontend/Frontend.php +++ b/includes/Frontend/Frontend.php @@ -2,6 +2,8 @@ namespace WooCommerceDonationManager\Frontend; +use WooCommerceDonationManager\Plugin; + defined( 'ABSPATH' ) || exit; /** @@ -13,13 +15,21 @@ * @package WooCommerceDonationManager\Frontend */ class Frontend { + /** + * Plugin instance. + * + * @var Plugin + */ + protected Plugin $plugin; /** * Frontend constructor. * + * @param \WooCommerceDonationManager\Plugin $plugin Plugin instance. * @since 1.0.0 */ - public function __construct() { + public function __construct( Plugin $plugin ) { + $this->plugin = $plugin; add_action( 'woocommerce_before_cart', array( __CLASS__, 'remove_coupon' ) ); add_action( 'woocommerce_before_checkout_form', array( __CLASS__, 'remove_coupon' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); @@ -33,7 +43,7 @@ public function __construct() { * @since 1.0.0 * @return void */ - public static function remove_coupon() { + public static function remove_coupon(): void { if ( ! WC()->cart->is_empty() && 'yes' === get_option( 'wcdm_disabled_coupon_field', 'yes' ) ) { foreach ( WC()->cart->get_cart() as $cart_item ) { if ( 'donation' === $cart_item['data']->get_type() ) { @@ -50,8 +60,8 @@ public static function remove_coupon() { * @since 1.0.0 * @return void */ - public function enqueue_scripts() { - WCDM()->scripts->enqueue_style( 'wcdm-frontend', 'css/frontend.css' ); - WCDM()->scripts->enqueue_script( 'wcdm-frontend', 'js/frontend.js', array( 'jquery' ) ); + public function enqueue_scripts(): void { + $this->plugin->scripts->enqueue_style( 'wcdm-frontend', 'css/frontend.css' ); + $this->plugin->scripts->enqueue_script( 'wcdm-frontend', 'js/frontend.js', array( 'jquery' ) ); } } diff --git a/includes/Frontend/Orders.php b/includes/Frontend/Orders.php index 6f36867..5084b9c 100644 --- a/includes/Frontend/Orders.php +++ b/includes/Frontend/Orders.php @@ -31,10 +31,10 @@ public function __construct() { * * @param \WC_Order $order Order object. * - * @since 1.0.0 * @return void + * @since 1.0.0 */ - public static function mark_donation_order( $order ) { + public static function mark_donation_order( \WC_Order $order ): void { $order = wc_get_order( $order ); $is_type_donation = false; @@ -65,10 +65,10 @@ public static function mark_donation_order( $order ) { * @param int $order_id Order ID. * @param \WC_Order $order Order object. * - * @since 1.0.0 * @return void + * @since 1.0.0 */ - public static function order_status_completed( $order_id, $order ) { + public static function order_status_completed( int $order_id, \WC_Order $order ): void { foreach ( $order->get_items() as $item_id => $item ) { $product = $item->get_product(); diff --git a/includes/Frontend/Product.php b/includes/Frontend/Product.php index 940940d..abd4818 100644 --- a/includes/Frontend/Product.php +++ b/includes/Frontend/Product.php @@ -38,10 +38,10 @@ public function __construct() { * @param string $link Link html. * @param \WC_Product $product Product object. * - * @since 1.0.0 * @return string + * @since 1.0.0 */ - public static function add_to_cart_link( $link, $product ) { + public static function add_to_cart_link( string $link, \WC_Product $product ): string { return ( 'donation' === $product->get_type() ? str_replace( 'ajax_add_to_cart', '', $link ) : $link ); } @@ -51,10 +51,10 @@ public static function add_to_cart_link( $link, $product ) { * @param string $price product price html. * @param \WC_Product $product Product object. * - * @since 1.0.0 * @return string + * @since 1.0.0 */ - public static function get_price_html( $price, $product ) { + public static function get_price_html( string $price, \WC_Product $product ): string { if ( 'donation' === $product->get_type() ) { return ( is_admin() ? 'Variable' : '' ); } @@ -70,7 +70,7 @@ public static function get_price_html( $price, $product ) { * @since 1.0.0 * @return void */ - public static function before_add_to_cart_button() { + public static function before_add_to_cart_button(): void { global $product; if ( 'donation' === $product->get_type() ) { @@ -140,7 +140,7 @@ class="input-text text"/> * @since 1.0.0 * @return void */ - public static function add_to_cart_template() { + public static function add_to_cart_template(): void { $campaign_id = get_post_meta( get_the_ID(), 'wcdm_campaign_id', true ); $campaign_end_date = intval( str_replace( '-', '', get_post_meta( $campaign_id, '_end_date', true ) ) ); $campaign_expired_text = get_option( 'wcdm_expired_text', __( 'The campaign expired!', 'wc-donation-manager' ) ); @@ -154,16 +154,16 @@ public static function add_to_cart_template() { } /** - * Redirecting weather cart or checkout page. + * Redirecting whether cart or checkout page. * * This will only be applied for the donation products. * * @param string $url Add to cart button url. * - * @since 1.0.0 * @return string + * @since 1.0.0 */ - public static function add_to_cart_redirect( $url ) { + public static function add_to_cart_redirect( string $url ) { wp_verify_nonce( '_wpnonce' ); $product_id = (int) apply_filters( 'woocommerce_add_to_cart_product_id', ! empty( $_POST['add-to-cart'] ) ? sanitize_key( wp_unslash( $_POST['add-to-cart'] ) ) : '' ); if ( $product_id ) { @@ -225,10 +225,10 @@ public static function add_to_cart_message( $message, $product_id ) { * @param bool $passed Whether the product can be added to the cart. * @param int $product_id Product ID. * - * @since 1.0.6 * @return bool + * @since 1.0.6 */ - public static function prevent_duplicate_add_to_cart( $passed, $product_id ) { + public static function prevent_duplicate_add_to_cart( bool $passed, int $product_id ): bool { $product = wc_get_product( $product_id ); // Only donation products. diff --git a/includes/Installer.php b/includes/Installer.php index 6ccd174..59ee1f7 100644 --- a/includes/Installer.php +++ b/includes/Installer.php @@ -11,6 +11,13 @@ * @package WooCommerceDonationManager */ class Installer { + /** + * Plugin instance. + * + * @since 1.0.0 + * @var Plugin + */ + protected Plugin $plugin; /** * Update callbacks. @@ -23,7 +30,8 @@ class Installer { /** * Class constructor. */ - public function __construct() { + public function __construct( Plugin $plugin ) { + $this->plugin = $plugin; add_action( 'init', array( $this, 'check_update' ), 5 ); add_action( 'wcdm_run_update_callback', array( $this, 'run_update_callback' ), 10, 2 ); add_action( 'wcdm_update_db_version', array( $this, 'update_db_version' ) ); @@ -38,18 +46,18 @@ public function __construct() { * @return void */ public function check_update() { - $db_version = WCDM()->get_db_version(); - $current_version = WCDM()->get_version(); + $db_version = $this->plugin->options->get_db_version(); + $current_version = $this->plugin->version; $requires_update = version_compare( $db_version, $current_version, '<' ); $can_install = ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) && ! defined( 'IFRAME_REQUEST' ); if ( $can_install && $requires_update && ! WC()->queue()->get_next( 'wcdm_run_update_callback' ) ) { - static::install(); + $this->install(); $update_versions = array_keys( $this->updates ); usort( $update_versions, 'version_compare' ); if ( ! is_null( $db_version ) && version_compare( $db_version, end( $update_versions ), '<' ) ) { $this->update(); } else { - WCDM()->update_db_version( $current_version ); + $this->plugin->options->update_db_version( $current_version ); } } } @@ -61,7 +69,7 @@ public function check_update() { * @return void */ public function update() { - $db_version = WCDM()->get_db_version(); + $db_version = $this->plugin->options->get_db_version(); $loop = 0; foreach ( $this->updates as $version => $callbacks ) { $callbacks = (array) $callbacks; @@ -81,13 +89,13 @@ public function update() { ++$loop; } - if ( version_compare( WCDM()->get_db_version(), WCDM()->get_version(), '<' ) && + if ( version_compare( $this->plugin->options->get_db_version(), $this->plugin->version, '<' ) && ! WC()->queue()->get_next( 'wcdm_update_db_version' ) ) { WC()->queue()->schedule_single( time() + $loop, 'wcdm_update_db_version', array( - 'version' => WCDM()->get_version(), + 'version' => $this->plugin->version, ) ); } @@ -126,7 +134,7 @@ public function run_update_callback( $callback, $version ) { * @return void */ public function update_db_version( $version ) { - WCDM()->update_db_version( $version ); + $this->plugin->options->update_db_version( $version ); } /** @@ -135,14 +143,14 @@ public function update_db_version( $version ) { * @since 1.0.0 * @return void */ - public static function install() { + public function install() { if ( ! is_blog_installed() ) { return; } self::save_default_settings(); flush_rewrite_rules( true ); add_option( 'wcdm_installed', time() ); - WCDM()->add_db_version(); + $this->plugin->options->update_db_version( $this->plugin->version ); } /** diff --git a/includes/Plugin.php b/includes/Plugin.php index ba5afe6..98de4e0 100644 --- a/includes/Plugin.php +++ b/includes/Plugin.php @@ -2,6 +2,8 @@ namespace WooCommerceDonationManager; +use WooCommerceDonationManager\Installer; + defined( 'ABSPATH' ) || exit; // Exit if accessed directly. /** @@ -10,17 +12,13 @@ * @since 1.0.0 * @package WooCommerceDonationManager */ -final class Plugin extends \WooCommerceDonationManager\ByteKit\Plugin { - +final class Plugin extends \WooCommerceDonationManager\B8\Plugin\App { /** - * Plugin constructor. - * - * @param array $data The plugin data. + * Bootstraps the plugin. * - * @since 1.0.0 + * @return void */ - protected function __construct( $data ) { - parent::__construct( $data ); + protected function bootstrap(): void { $this->define_constants(); $this->includes(); $this->init_hooks(); @@ -32,15 +30,15 @@ protected function __construct( $data ) { * @since 1.0.0 * @return void */ - public function define_constants() { + public function define_constants(): void { $role = apply_filters( 'wc_donation_manager_role', 'manage_woocommerce' ); - $this->define( 'WCDM_VERSION', $this->get_version() ); - $this->define( 'WCDM_FILE', $this->get_file() ); - $this->define( 'WCDM_PATH', $this->get_dir_path() ); - $this->define( 'WCDM_URL', $this->get_dir_url() ); - $this->define( 'WCDM_ASSETS_URL', $this->get_assets_url() ); - $this->define( 'WCDM_ASSETS_PATH', $this->get_assets_path() ); - $this->define( 'WCDM_MANAGER_ROLE', $role ); + define( 'WCDM_VERSION', $this->version ); + define( 'WCDM_FILE', $this->file ); + define( 'WCDM_PATH', $this->plugin_path() ); + define( 'WCDM_URL', $this->plugin_url() ); + define( 'WCDM_ASSETS_URL', $this->assets_url() ); + define( 'WCDM_ASSETS_PATH', $this->assets_path() ); + define( 'WCDM_MANAGER_ROLE', $role ); } /** @@ -60,8 +58,8 @@ public function includes() { * @return void */ public function init_hooks() { - register_activation_hook( $this->get_file(), array( Installer::class, 'install' ) ); - add_filter( 'plugin_action_links_' . $this->get_basename(), array( $this, 'plugin_action_links' ) ); + register_activation_hook( $this->file, $this->callback( array( Installer::class, 'install' ) ) ); + add_filter( 'plugin_action_links_' . $this->basename(), array( $this, 'plugin_action_links' ) ); add_action( 'before_woocommerce_init', array( $this, 'on_before_woocommerce_init' ) ); add_action( 'woocommerce_init', array( $this, 'on_init' ), 0 ); } @@ -75,7 +73,7 @@ public function init_hooks() { * @return array */ public function plugin_action_links( $links ) { - if ( ! $this->is_plugin_active( 'wc-donation-manager-pro/wc-donation-manager-pro.php' ) ) { + if ( ! $this->plugin_active( 'wc-donation-manager-pro/wc-donation-manager-pro.php' ) ) { $links['go_pro'] = '' . esc_html__( 'Go Pro', 'wc-donation-manager' ) . ''; } @@ -88,10 +86,10 @@ public function plugin_action_links( $links ) { * @since 1.0.0 * @return void */ - public function on_before_woocommerce_init() { + public function on_before_woocommerce_init(): void { if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { - \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', $this->get_file(), true ); - \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', $this->get_file(), true ); + \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', $this->file, true ); + \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', $this->file, true ); } } @@ -101,7 +99,7 @@ public function on_before_woocommerce_init() { * @since 1.0.0 * @return void */ - public function on_init() { + public function on_init(): void { // Register post types. add_action( 'init', array( $this, 'register_cpt_campaigns' ) ); @@ -109,28 +107,39 @@ public function on_init() { require_once __DIR__ . '/Donation/class-donation-product.php'; // Include common classes. - $this->set( - array( - Donation\Donation::class, - Frontend\Frontend::class, - Frontend\Product::class, - Frontend\Cart::class, - Frontend\Orders::class, - ) - ); + // $this->set( + // array( + // Donation\Donation::class, + // Frontend\Frontend::class, + // Frontend\Product::class, + // Frontend\Cart::class, + // Frontend\Orders::class, + // ) + // ); + $this->make( Donation\Donation::class ); + $this->make( Frontend\Frontend::class ); + $this->make( Frontend\Product::class ); + $this->make( Frontend\Cart::class ); + $this->make( Frontend\Orders::class ); // Include Admin classes. if ( is_admin() ) { - $this->set( - array( - Admin\Admin::class, - Admin\Menus::class, - Admin\Settings::instance(), - Admin\Actions::class, - Admin\Metaboxes::class, - Admin\Notices::class, - ) - ); + // $this->set( + // array( + // Admin\Admin::class, + // Admin\Menus::class, + // Admin\Settings::instance(), + // Admin\Actions::class, + // Admin\Metaboxes::class, + // Admin\Notices::class, + // ) + // ); + $this->make( Admin\Admin::class ); + $this->make( Admin\Menus::class ); + Admin\Settings::instance(); + $this->make( Admin\Actions::class ); + $this->make( Admin\Metaboxes::class ); + $this->make( Admin\Notices::class ); } /** @@ -149,7 +158,7 @@ public function on_init() { * @since 1.0.0 * @return void */ - public function register_cpt_campaigns() { + public function register_cpt_campaigns(): void { $labels = array( 'name' => _x( 'Campaign', 'post type general name', 'wc-donation-manager' ), 'singular_name' => _x( 'Campaign', 'post type singular name', 'wc-donation-manager' ), @@ -168,7 +177,7 @@ public function register_cpt_campaigns() { ); $args = array( - 'labels' => apply_filters( 'wcdm_campaigns_post_type_labels', $labels ), + 'labels' => $this->apply_filters( 'wcdm_campaigns_post_type_labels', $labels ), 'public' => false, 'publicly_queryable' => false, 'exclude_from_search' => true, @@ -185,6 +194,6 @@ public function register_cpt_campaigns() { 'supports' => array(), ); - register_post_type( 'wcdm_campaigns', apply_filters( 'wcdm_campaigns_post_type_args', $args ) ); + register_post_type( 'wcdm_campaigns', $this->apply_filters( 'campaigns_post_type_args', $args ) ); } } diff --git a/wc-donation-manager.php b/wc-donation-manager.php index f3e03d0..ccde9f8 100644 --- a/wc-donation-manager.php +++ b/wc-donation-manager.php @@ -45,10 +45,23 @@ // Instantiate the plugin. WooCommerceDonationManager\Plugin::create( + __FILE__, array( 'file' => __FILE__, + 'version' => '1.1.2', + 'hook_prefix' => 'wcdm', 'settings_url' => admin_url( 'admin.php?page=wcdm-settings' ), 'support_url' => 'https://pluginever.com/support/', 'docs_url' => 'https://pluginever.com/docs/wc-donation-manager/', + 'text_domain' => 'wc-donation-manager', ) ); + +/** + * Main plugin instance. + * + * @return WooCommerceDonationManager\Plugin + */ +function donation_manager(): \WooCommerceDonationManager\Plugin { + return \WooCommerceDonationManager\Plugin::instance(); +} From 6621a646d48c7042c6e06c403dfd6492601232f3 Mon Sep 17 00:00:00 2001 From: Towfiqul Islam <43319312+towfiq1997@users.noreply.github.com> Date: Thu, 14 May 2026 15:34:29 +0600 Subject: [PATCH 2/8] Fix linting issuees --- includes/Admin/Admin.php | 4 +++- includes/Admin/Menus.php | 4 +++- includes/Admin/Notices.php | 4 +++- includes/Frontend/Frontend.php | 5 +++-- includes/Installer.php | 6 +++++- includes/Plugin.php | 20 -------------------- 6 files changed, 17 insertions(+), 26 deletions(-) diff --git a/includes/Admin/Admin.php b/includes/Admin/Admin.php index b7ea66b..734f000 100644 --- a/includes/Admin/Admin.php +++ b/includes/Admin/Admin.php @@ -21,9 +21,11 @@ class Admin { protected Plugin $plugin; /** - * Admin constructor. + * Admin Class constructor. * * @since 1.0.0 + * + * @param Plugin $plugin Plugin instance. */ public function __construct( Plugin $plugin ) { $this->plugin = $plugin; diff --git a/includes/Admin/Menus.php b/includes/Admin/Menus.php index 090f10c..b1b0409 100644 --- a/includes/Admin/Menus.php +++ b/includes/Admin/Menus.php @@ -36,9 +36,11 @@ class Menus { private $list_table; /** - * Menus constructor. + * Class constructor. * * @since 1.0.0 + * + * @param Plugin $plugin Plugin instance. */ public function __construct( Plugin $plugin ) { $this->plugin = $plugin; diff --git a/includes/Admin/Notices.php b/includes/Admin/Notices.php index 714a773..726c10d 100644 --- a/includes/Admin/Notices.php +++ b/includes/Admin/Notices.php @@ -20,9 +20,11 @@ class Notices { protected Plugin $plugin; /** - * Notices constructor. + * Notice Class constructor. * * @since 1.0.0 + * + * @param Plugin $plugin Plugin instance. */ public function __construct( Plugin $plugin ) { $this->plugin = $plugin; diff --git a/includes/Frontend/Frontend.php b/includes/Frontend/Frontend.php index 53de2b9..a011586 100644 --- a/includes/Frontend/Frontend.php +++ b/includes/Frontend/Frontend.php @@ -23,10 +23,11 @@ class Frontend { protected Plugin $plugin; /** - * Frontend constructor. + * Frontend Class constructor. * - * @param \WooCommerceDonationManager\Plugin $plugin Plugin instance. * @since 1.0.0 + * + * @param Plugin $plugin Plugin instance. */ public function __construct( Plugin $plugin ) { $this->plugin = $plugin; diff --git a/includes/Installer.php b/includes/Installer.php index 59ee1f7..27a4af4 100644 --- a/includes/Installer.php +++ b/includes/Installer.php @@ -28,7 +28,11 @@ class Installer { protected $updates = array(); /** - * Class constructor. + * Install Class constructor. + * + * @since 1.0.0 + * + * @param Plugin $plugin Plugin instance. */ public function __construct( Plugin $plugin ) { $this->plugin = $plugin; diff --git a/includes/Plugin.php b/includes/Plugin.php index 98de4e0..fe513f2 100644 --- a/includes/Plugin.php +++ b/includes/Plugin.php @@ -106,16 +106,6 @@ public function on_init(): void { // Including donation product type class. require_once __DIR__ . '/Donation/class-donation-product.php'; - // Include common classes. - // $this->set( - // array( - // Donation\Donation::class, - // Frontend\Frontend::class, - // Frontend\Product::class, - // Frontend\Cart::class, - // Frontend\Orders::class, - // ) - // ); $this->make( Donation\Donation::class ); $this->make( Frontend\Frontend::class ); $this->make( Frontend\Product::class ); @@ -124,16 +114,6 @@ public function on_init(): void { // Include Admin classes. if ( is_admin() ) { - // $this->set( - // array( - // Admin\Admin::class, - // Admin\Menus::class, - // Admin\Settings::instance(), - // Admin\Actions::class, - // Admin\Metaboxes::class, - // Admin\Notices::class, - // ) - // ); $this->make( Admin\Admin::class ); $this->make( Admin\Menus::class ); Admin\Settings::instance(); From 7587f57639fb87cfb2f598c2a5c2915bd6174932 Mon Sep 17 00:00:00 2001 From: Towfiqul Islam <43319312+towfiq1997@users.noreply.github.com> Date: Thu, 14 May 2026 15:46:34 +0600 Subject: [PATCH 3/8] Type declartion issue fixed --- includes/Admin/Menus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Admin/Menus.php b/includes/Admin/Menus.php index b1b0409..0fac714 100644 --- a/includes/Admin/Menus.php +++ b/includes/Admin/Menus.php @@ -26,7 +26,7 @@ class Menus { * @since 1.0.0 * @var string */ - const string PARENT_SLUG = 'wc-donation-manager'; + const PARENT_SLUG = 'wc-donation-manager'; /** * List tables. From 7224a679db8239335d2c74dbaf06d1cbad63c95c Mon Sep 17 00:00:00 2001 From: Towfiqul Islam <43319312+towfiq1997@users.noreply.github.com> Date: Thu, 14 May 2026 16:59:24 +0600 Subject: [PATCH 4/8] Added the css dependency --- includes/Admin/Admin.php | 4 +- languages/wc-donation-manager.pot | 85 ++++++++++++++++--------------- 2 files changed, 45 insertions(+), 44 deletions(-) diff --git a/includes/Admin/Admin.php b/includes/Admin/Admin.php index 734f000..c8010d5 100644 --- a/includes/Admin/Admin.php +++ b/includes/Admin/Admin.php @@ -45,7 +45,7 @@ public function __construct( Plugin $plugin ) { */ public function enqueue_scripts( $hook ) { $screen_ids = Utilities::get_screen_ids(); - $this->plugin->scripts->enqueue_style( 'wcdm-admin', 'css/admin.css', array( 'woocommerce_admin_styles' ) ); + $this->plugin->scripts->enqueue_style( 'wcdm-admin', 'css/admin.css', array( 'bytekit-layout', 'bytekit-components', 'woocommerce_admin_styles' ) ); $this->plugin->scripts->register_script( 'wcdm-admin', 'js/admin.js' ); if ( in_array( $hook, $screen_ids, true ) ) { @@ -90,7 +90,7 @@ public function admin_footer_text( string $text ): string { $text = sprintf( /* translators: %s: Plugin name */ __( 'Thank you for using %s!', 'wc-donation-manager' ), - '' . esc_html( WCDM()->get_name() ) . '', + '' . esc_html__( 'Donation Manager', 'wc-donation-manager' ) . '', ); if ( $this->plugin->review_url ) { $text .= sprintf( diff --git a/languages/wc-donation-manager.pot b/languages/wc-donation-manager.pot index 8c16f7c..4db86e0 100644 --- a/languages/wc-donation-manager.pot +++ b/languages/wc-donation-manager.pot @@ -9,13 +9,14 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"POT-Creation-Date: 2026-04-20T09:55:11+00:00\n" +"POT-Creation-Date: 2026-05-14T10:57:48+00:00\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "X-Generator: WP-CLI 2.12.0\n" "X-Domain: wc-donation-manager\n" #. Plugin Name of the plugin #: wc-donation-manager.php +#: includes/Admin/Admin.php:93 #: includes/Admin/Metaboxes.php:43 msgid "Donation Manager" msgstr "" @@ -40,36 +41,36 @@ msgstr "" msgid "https://pluginever.com/" msgstr "" -#: includes/Admin/Actions.php:63 +#: includes/Admin/Actions.php:62 msgid "Campaign created successfully." msgstr "" -#: includes/Admin/Actions.php:109 +#: includes/Admin/Actions.php:108 msgid "Campaign updated successfully." msgstr "" -#: includes/Admin/Actions.php:136 +#: includes/Admin/Actions.php:134 msgid "Suggested amounts" msgstr "" -#: includes/Admin/Admin.php:48 +#: includes/Admin/Admin.php:59 msgid "Select products" msgstr "" #. translators: %s: Plugin name -#: includes/Admin/Admin.php:81 +#: includes/Admin/Admin.php:92 #, php-format msgid "Thank you for using %s!" msgstr "" #. translators: %s: Plugin name -#: includes/Admin/Admin.php:87 +#: includes/Admin/Admin.php:98 #, php-format msgid " Share your appreciation with a five-star review %s." msgstr "" #. translators: 1: Plugin version -#: includes/Admin/Admin.php:108 +#: includes/Admin/Admin.php:119 #, php-format msgid "Version %s" msgstr "" @@ -119,46 +120,46 @@ msgstr "" msgid "Edit" msgstr "" -#: includes/Admin/Menus.php:58 -#: includes/Admin/Menus.php:59 +#: includes/Admin/Menus.php:69 +#: includes/Admin/Menus.php:70 msgid "Donations" msgstr "" -#: includes/Admin/Menus.php:153 +#: includes/Admin/Menus.php:164 msgid "Per page" msgstr "" -#: includes/Admin/Menus.php:203 +#: includes/Admin/Menus.php:214 #: includes/Admin/Utilities.php:35 #: includes/Admin/Utilities.php:36 msgid "Donors" msgstr "" -#: includes/Admin/Menus.php:204 +#: includes/Admin/Menus.php:215 msgid "The list of donors and their donation information(s)" msgstr "" -#: includes/Admin/Menus.php:208 -#: includes/Admin/Menus.php:226 -#: includes/Admin/Menus.php:244 +#: includes/Admin/Menus.php:219 +#: includes/Admin/Menus.php:237 +#: includes/Admin/Menus.php:255 msgid "Available in Pro Version" msgstr "" -#: includes/Admin/Menus.php:209 -#: includes/Admin/Menus.php:227 -#: includes/Admin/Menus.php:245 +#: includes/Admin/Menus.php:220 +#: includes/Admin/Menus.php:238 +#: includes/Admin/Menus.php:256 msgid "Upgrade to Pro Now" msgstr "" -#: includes/Admin/Menus.php:211 +#: includes/Admin/Menus.php:222 msgid "Donors list table" msgstr "" -#: includes/Admin/Menus.php:229 +#: includes/Admin/Menus.php:240 msgid "Customer completed emails" msgstr "" -#: includes/Admin/Menus.php:247 +#: includes/Admin/Menus.php:258 msgid "Add customizable settings" msgstr "" @@ -398,7 +399,7 @@ msgid "Settings" msgstr "" #: includes/Admin/views/campaigns/add.php:12 -#: includes/Plugin.php:159 +#: includes/Plugin.php:148 msgid "Add New Campaign" msgstr "" @@ -458,7 +459,7 @@ msgid "Search" msgstr "" #: includes/Admin/views/campaigns/edit.php:16 -#: includes/Plugin.php:161 +#: includes/Plugin.php:150 msgid "Edit Campaign" msgstr "" @@ -543,7 +544,7 @@ msgid "Sure, I'd love to help!" msgstr "" #: includes/Admin/views/notices/review.php:40 -#: includes/Admin/views/notices/upgrade.php:40 +#: includes/Admin/views/notices/upgrade.php:39 msgid "Maybe later" msgstr "" @@ -551,17 +552,17 @@ msgstr "" msgid "I've already left a review" msgstr "" -#: includes/Admin/views/notices/upgrade.php:18 +#: includes/Admin/views/notices/upgrade.php:17 msgid "Flash Sale Alert!" msgstr "" #. translators: %1$s: WooCommerce Donation Manager Pro plugin link, %2$s: Coupon code. -#: includes/Admin/views/notices/upgrade.php:24 +#: includes/Admin/views/notices/upgrade.php:23 #, php-format msgid "Enjoy a 10%% discount on %1$s! Use coupon code %2$s at checkout to grab the deal. Don’t miss out — this offer won’t last forever!" msgstr "" -#: includes/Admin/views/notices/upgrade.php:36 +#: includes/Admin/views/notices/upgrade.php:35 msgid "Upgrade now" msgstr "" @@ -601,7 +602,7 @@ msgstr "" msgid "View Cart" msgstr "" -#: includes/Donation/Donation.php:33 +#: includes/Donation/Donation.php:35 msgid "Donation" msgstr "" @@ -609,59 +610,59 @@ msgstr "" msgid "The campaign expired!" msgstr "" -#: includes/Plugin.php:79 +#: includes/Plugin.php:77 msgid "Go Pro" msgstr "" -#: includes/Plugin.php:154 +#: includes/Plugin.php:143 msgctxt "post type general name" msgid "Campaign" msgstr "" -#: includes/Plugin.php:155 +#: includes/Plugin.php:144 msgctxt "post type singular name" msgid "Campaign" msgstr "" -#: includes/Plugin.php:156 +#: includes/Plugin.php:145 msgctxt "admin menu" msgid "Campaign" msgstr "" -#: includes/Plugin.php:157 +#: includes/Plugin.php:146 msgctxt "add new on admin bar" msgid "Campaign" msgstr "" -#: includes/Plugin.php:158 +#: includes/Plugin.php:147 msgctxt "campaign" msgid "Add New" msgstr "" -#: includes/Plugin.php:160 +#: includes/Plugin.php:149 msgid "New Campaign" msgstr "" -#: includes/Plugin.php:162 +#: includes/Plugin.php:151 msgid "View Campaign" msgstr "" -#: includes/Plugin.php:163 +#: includes/Plugin.php:152 msgid "All Campaign" msgstr "" -#: includes/Plugin.php:164 +#: includes/Plugin.php:153 msgid "Search Campaign" msgstr "" -#: includes/Plugin.php:165 +#: includes/Plugin.php:154 msgid "Parent Campaign:" msgstr "" -#: includes/Plugin.php:166 +#: includes/Plugin.php:155 msgid "No campaigns found." msgstr "" -#: includes/Plugin.php:167 +#: includes/Plugin.php:156 msgid "No campaigns found in Trash." msgstr "" From ac4e0dc919dd71df8b97a0e646221ffb5e662368 Mon Sep 17 00:00:00 2001 From: Towfiqul Islam <43319312+towfiq1997@users.noreply.github.com> Date: Thu, 14 May 2026 17:48:54 +0600 Subject: [PATCH 5/8] Add wp editor to donation cause editor --- includes/Admin/Actions.php | 6 +++--- includes/Admin/views/campaigns/add.php | 14 +++++++++++++- includes/Admin/views/campaigns/edit.php | 14 +++++++++++++- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/includes/Admin/Actions.php b/includes/Admin/Actions.php index 554b8a6..0c14a39 100644 --- a/includes/Admin/Actions.php +++ b/includes/Admin/Actions.php @@ -36,7 +36,7 @@ public static function add_campaign() { $referer = wp_get_referer(); $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : ''; - $cause = isset( $_POST['cause'] ) ? sanitize_textarea_field( wp_unslash( $_POST['cause'] ) ) : ''; + $cause = isset( $_POST['cause'] ) ? wp_kses_post( wp_unslash( $_POST['cause'] ) ) : ''; $goal_amount = isset( $_POST['goal_amount'] ) ? floatval( wp_unslash( $_POST['goal_amount'] ) ) : floatval( '0' ); $end_date = isset( $_POST['end_date'] ) ? sanitize_text_field( wp_unslash( $_POST['end_date'] ) ) : ''; $status = isset( $_POST['status'] ) ? sanitize_key( wp_unslash( $_POST['status'] ) ) : 'pending'; @@ -46,7 +46,7 @@ public static function add_campaign() { 'ID' => $id, 'post_type' => 'wcdm_campaigns', 'post_title' => wp_strip_all_tags( $name ), - 'post_content' => wp_kses_post( $cause ), + 'post_content' => $cause, 'post_status' => $status, 'meta_input' => array( 'wcdm_goal_amount' => $goal_amount, @@ -82,7 +82,7 @@ public static function edit_campaign() { $referer = wp_get_referer(); $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : ''; - $cause = isset( $_POST['cause'] ) ? sanitize_textarea_field( wp_unslash( $_POST['cause'] ) ) : ''; + $cause = isset( $_POST['cause'] ) ? wp_kses_post( wp_unslash( $_POST['cause'] ) ) : ''; $goal_amount = isset( $_POST['goal_amount'] ) ? floatval( wp_unslash( $_POST['goal_amount'] ) ) : floatval( '0' ); $end_date = isset( $_POST['end_date'] ) ? sanitize_text_field( wp_unslash( $_POST['end_date'] ) ) : ''; $status = isset( $_POST['status'] ) ? sanitize_key( wp_unslash( $_POST['status'] ) ) : 'pending'; diff --git a/includes/Admin/views/campaigns/add.php b/includes/Admin/views/campaigns/add.php index d7f9f26..d53132f 100644 --- a/includes/Admin/views/campaigns/add.php +++ b/includes/Admin/views/campaigns/add.php @@ -30,7 +30,19 @@ - + 'cause', + 'media_buttons' => true, + 'textarea_rows' => 12, + 'teeny' => false, + 'quicktags' => true, + ) + ); + ?>

diff --git a/includes/Admin/views/campaigns/edit.php b/includes/Admin/views/campaigns/edit.php index cdcfb12..ebed76a 100644 --- a/includes/Admin/views/campaigns/edit.php +++ b/includes/Admin/views/campaigns/edit.php @@ -43,7 +43,19 @@
- + post_content ), + 'wcdm_donation_cause_editor', + array( + 'textarea_name' => 'cause', + 'media_buttons' => true, + 'textarea_rows' => 12, + 'teeny' => false, + 'quicktags' => true, + ) + ); + ?>

From 978e03771323dba685a2a1f31d8bc0858ee41b02 Mon Sep 17 00:00:00 2001 From: Towfiqul Islam <43319312+towfiq1997@users.noreply.github.com> Date: Sun, 17 May 2026 11:32:11 +0600 Subject: [PATCH 6/8] Wc deprecated function change and class type issue fix --- includes/Data/settings.php | 1 + includes/Frontend/Orders.php | 2 +- includes/Frontend/Product.php | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 includes/Data/settings.php diff --git a/includes/Data/settings.php b/includes/Data/settings.php new file mode 100644 index 0000000..b3d9bbc --- /dev/null +++ b/includes/Data/settings.php @@ -0,0 +1 @@ + Date: Tue, 19 May 2026 11:19:27 +0600 Subject: [PATCH 7/8] Fixes #35 & Donation form update --- assets/src/css/frontend-common.scss | 68 +++++++++++++++++++++++++++++ assets/src/js/frontend-common.js | 32 ++++++++++++++ includes/Frontend/Frontend.php | 35 +++++++++++++++ includes/Frontend/Product.php | 32 +++++++++++--- languages/wc-donation-manager.pot | 59 +++++++++++-------------- 5 files changed, 187 insertions(+), 39 deletions(-) diff --git a/assets/src/css/frontend-common.scss b/assets/src/css/frontend-common.scss index 722d08d..f1b33ea 100644 --- a/assets/src/css/frontend-common.scss +++ b/assets/src/css/frontend-common.scss @@ -10,6 +10,14 @@ width: 100%; } } + .campaign-cause{ + ul{ + margin-bottom: 0; + } + p{ + margin-bottom: 0; + } + } .suggested-amounts { display: grid; grid-template-columns: repeat(4, 1fr); @@ -69,3 +77,63 @@ align-self: center; } } +//Frontend donation progressbar +.wcdm-progress-bar { + width: 100%; + margin-bottom: 10px; + .donation-header { + display: flex; + align-items: center; + justify-content: space-between; + margin-bottom: 14px; + } + + .donation-title { + font-size: 16px; + font-weight: 700; + color: #1e293b; + } + + .donation-percent { + font-size: 20px; + font-weight: 700; + background: #7e7eef; + -webkit-background-clip: text; + -webkit-text-fill-color: transparent; + } + + .progress-wrapper { + width: 100%; + height: 14px; + background: #e2e8f0; + border-radius: 999px; + overflow: hidden; + position: relative; + } + + .progress-bar { + width: 0; + height: 100%; + border-radius: 999px; + transition: width 1s ease; + + background:#7e7eef; + } + + .donation-info { + display: flex; + justify-content: space-between; + margin-top: 14px; + font-size: 14px; + color: #64748b; + } + + .amount { + font-weight: 700; + color: #0f172a; + } +} +//Donation product donation button +.wcdm-donation-button{ + background-color: #10B981 !important; +} diff --git a/assets/src/js/frontend-common.js b/assets/src/js/frontend-common.js index 4756026..0d4eea1 100644 --- a/assets/src/js/frontend-common.js +++ b/assets/src/js/frontend-common.js @@ -28,5 +28,37 @@ } }); }); + + $('.wcdm-progress-bar').each(function () { + + const $progressCard = $(this); + + const raised = parseFloat($progressCard.attr('data-raised')) || 0; + const goal = parseFloat($progressCard.attr('data-goal')) || 0; + const currency = $progressCard.attr('data-currency') || '$'; + + const percentage = goal > 0 + ? Math.min((raised / goal) * 100, 100) + : 0; + + console.log(percentage); + + + $progressCard + .find('.progress-bar') + .css('width', percentage + '%'); + + $progressCard + .find('.donation-percent') + .text(Math.round(percentage) + '%'); + + $progressCard + .find('.raised-amount') + .text(currency + raised.toLocaleString()); + + $progressCard + .find('.goal-amount') + .text(currency + goal.toLocaleString()); + }); }); }(jQuery)); diff --git a/includes/Frontend/Frontend.php b/includes/Frontend/Frontend.php index a011586..acf5bc0 100644 --- a/includes/Frontend/Frontend.php +++ b/includes/Frontend/Frontend.php @@ -34,6 +34,7 @@ public function __construct( Plugin $plugin ) { add_action( 'woocommerce_before_cart', array( __CLASS__, 'remove_coupon' ) ); add_action( 'woocommerce_before_checkout_form', array( __CLASS__, 'remove_coupon' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); + add_action( 'wp_footer', array( $this, 'maybe_add_donation_button_class' ) ); } /** @@ -65,4 +66,38 @@ public function enqueue_scripts(): void { $this->plugin->scripts->enqueue_style( 'wcdm-frontend', 'css/frontend.css' ); $this->plugin->scripts->enqueue_script( 'wcdm-frontend', 'js/frontend.js', array( 'jquery' ) ); } + + /** + * Add custom class to Add to Cart button for donation products. + * + * This method checks if the current product is a donation product type + * and then injects a custom CSS class into the single product + * Add to Cart button using JavaScript. + * + * @return void + */ + public function maybe_add_donation_button_class() { + + if ( ! is_product() ) { + return; + } + + global $product; + + if ( ! $product || ! $product->is_type( 'donation' ) ) { + return; + } + + ?> + + -
-
- - +
+
+
Donation Progress
+
0%
+
+ +
+
+
+ +
+
+ Raised: + $0 +
+ +
+ Goal: + $0 +
+
- -
Date: Wed, 20 May 2026 09:56:30 +0600 Subject: [PATCH 8/8] Fixes #9 & Donation Product Validation --- assets/src/css/frontend-common.scss | 4 +-- assets/src/js/admin-common.js | 35 +++++++++++++++++++++++++ includes/Admin/Admin.php | 9 ++++--- includes/Admin/Metaboxes.php | 15 ++++++----- includes/Admin/views/notices/review.php | 2 +- includes/Frontend/Frontend.php | 11 +++++++- languages/wc-donation-manager.pot | 20 +++++++++----- 7 files changed, 77 insertions(+), 19 deletions(-) diff --git a/assets/src/css/frontend-common.scss b/assets/src/css/frontend-common.scss index f1b33ea..7d95533 100644 --- a/assets/src/css/frontend-common.scss +++ b/assets/src/css/frontend-common.scss @@ -97,7 +97,7 @@ .donation-percent { font-size: 20px; font-weight: 700; - background: #7e7eef; + background: #10B981; -webkit-background-clip: text; -webkit-text-fill-color: transparent; } @@ -117,7 +117,7 @@ border-radius: 999px; transition: width 1s ease; - background:#7e7eef; + background:#10B981; } .donation-info { diff --git a/assets/src/js/admin-common.js b/assets/src/js/admin-common.js index fa0eac8..72737a0 100644 --- a/assets/src/js/admin-common.js +++ b/assets/src/js/admin-common.js @@ -9,6 +9,7 @@ /*global jQuery:false */ jQuery(document).ready(function ($) { 'use strict'; + $.wc_donation_manager = { init: function () { $('#donation_products').select2({ @@ -44,4 +45,38 @@ jQuery(document).ready(function ($) { }; $.wc_donation_manager.init(); + + // Helper function to show admin error + function wcdm_show_admin_error(message) { + $('.wcdm-admin-error').remove(); + var $notice = $('

' + message + '

'); + $('.wrap').first().prepend($notice); + $('html, body').animate({scrollTop: $('.wrap').first().offset().top - 50}, 200); + } + + // Validate on product save + $('#post').on('submit', function (e) { + var prodType = $('#product-type').val() || $('select[name="product-type"]').val() || $('input[name="product-type"]').val(); + if (prodType !== 'donation') return true; + + var min = parseFloat($('#wcdm_min_amount').val()); + var max = parseFloat($('#wcdm_max_amount').val()); + min = isNaN(min) ? 0 : min; + max = isNaN(max) ? 0 : max; + var campaign = $('#wcdm_campaign_id').val() || $('select[name="wcdm_campaign_id"]').val(); + + if (!campaign || campaign === '0' || parseInt(campaign, 10) <= 0) { + e.preventDefault(); + wcdm_show_admin_error((typeof wcdm_admin_vars !== 'undefined' && wcdm_admin_vars.i18n && wcdm_admin_vars.i18n.select_campaign_error) ? wcdm_admin_vars.i18n.select_campaign_error : 'Please select a campaign for donation products.'); + return false; + } + + if (min > 0 && max > 0 && min > max) { + e.preventDefault(); + wcdm_show_admin_error((typeof wcdm_admin_vars !== 'undefined' && wcdm_admin_vars.i18n && wcdm_admin_vars.i18n.min_gt_max_error) ? wcdm_admin_vars.i18n.min_gt_max_error : 'Minimum amount cannot be greater than maximum amount.'); + return false; + } + + return true; + }); }); diff --git a/includes/Admin/Admin.php b/includes/Admin/Admin.php index c8010d5..3a8dce7 100644 --- a/includes/Admin/Admin.php +++ b/includes/Admin/Admin.php @@ -43,12 +43,13 @@ public function __construct( Plugin $plugin ) { * @since 1.0.0 * @return void */ - public function enqueue_scripts( $hook ) { + public function enqueue_scripts( $hook ): void { $screen_ids = Utilities::get_screen_ids(); $this->plugin->scripts->enqueue_style( 'wcdm-admin', 'css/admin.css', array( 'bytekit-layout', 'bytekit-components', 'woocommerce_admin_styles' ) ); $this->plugin->scripts->register_script( 'wcdm-admin', 'js/admin.js' ); - if ( in_array( $hook, $screen_ids, true ) ) { + if ( in_array( $hook, $screen_ids, true ) || 'post-new.php' === $hook ) { + wp_enqueue_style( 'wcdm-admin' ); wp_enqueue_script( 'wcdm-admin' ); @@ -56,7 +57,9 @@ public function enqueue_scripts( $hook ) { 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'security' => wp_create_nonce( 'wc_donation_manager' ), 'i18n' => array( - 'search_products' => esc_html__( 'Select products', 'wc-donation-manager' ), + 'search_products' => esc_html__( 'Select products', 'wc-donation-manager' ), + 'select_campaign_error' => esc_html__( 'Please select a campaign for donation products.', 'wc-donation-manager' ), + 'min_gt_max_error' => esc_html__( 'Minimum amount cannot be greater than maximum amount.', 'wc-donation-manager' ), ), ); diff --git a/includes/Admin/Metaboxes.php b/includes/Admin/Metaboxes.php index 751fba8..1f6302d 100644 --- a/includes/Admin/Metaboxes.php +++ b/includes/Admin/Metaboxes.php @@ -171,12 +171,15 @@ public static function product_data() { woocommerce_wp_select( array( - 'id' => 'wcdm_campaign_id', - 'label' => __( 'Select a campaign', 'wc-donation-manager' ), - 'description' => __( 'Select a campaign to assign this donation product. After selected a campaign, the campaign cause & the goal amount will be inherited.', 'wc-donation-manager' ), - 'desc_tip' => true, - 'options' => $campaign_options, - 'value' => ! empty( get_post_meta( get_the_ID(), 'wcdm_campaign_id', true ) ) ? get_post_meta( get_the_ID(), 'wcdm_campaign_id', true ) : '0', + 'id' => 'wcdm_campaign_id', + 'label' => __( 'Select a campaign', 'wc-donation-manager' ), + 'description' => __( 'Select a campaign to assign this donation product. After selected a campaign, the campaign cause & the goal amount will be inherited.', 'wc-donation-manager' ), + 'desc_tip' => true, + 'options' => $campaign_options, + 'value' => ! empty( get_post_meta( get_the_ID(), 'wcdm_campaign_id', true ) ) ? get_post_meta( get_the_ID(), 'wcdm_campaign_id', true ) : '0', + 'custom_attributes' => array( + 'required' => 'required', + ), ) ); diff --git a/includes/Admin/views/notices/review.php b/includes/Admin/views/notices/review.php index 3a3fc98..e946e2a 100644 --- a/includes/Admin/views/notices/review.php +++ b/includes/Admin/views/notices/review.php @@ -12,7 +12,7 @@ ?>
- WooCommerce Donation Manager + WooCommerce Donation Manager

diff --git a/includes/Frontend/Frontend.php b/includes/Frontend/Frontend.php index acf5bc0..417fea8 100644 --- a/includes/Frontend/Frontend.php +++ b/includes/Frontend/Frontend.php @@ -65,6 +65,15 @@ public static function remove_coupon(): void { public function enqueue_scripts(): void { $this->plugin->scripts->enqueue_style( 'wcdm-frontend', 'css/frontend.css' ); $this->plugin->scripts->enqueue_script( 'wcdm-frontend', 'js/frontend.js', array( 'jquery' ) ); + $this->plugin->scripts->enqueue_script( + 'wcdm-cart-block', + 'js/cart_block.js', + array( + 'wc-blocks-checkout', + 'jquery', + ), + true + ); } /** @@ -76,7 +85,7 @@ public function enqueue_scripts(): void { * * @return void */ - public function maybe_add_donation_button_class() { + public function maybe_add_donation_button_class(): void { if ( ! is_product() ) { return; diff --git a/languages/wc-donation-manager.pot b/languages/wc-donation-manager.pot index 1234506..13d1e8a 100644 --- a/languages/wc-donation-manager.pot +++ b/languages/wc-donation-manager.pot @@ -9,14 +9,14 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"POT-Creation-Date: 2026-05-19T05:15:30+00:00\n" +"POT-Creation-Date: 2026-05-20T03:31:18+00:00\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "X-Generator: WP-CLI 2.12.0\n" "X-Domain: wc-donation-manager\n" #. Plugin Name of the plugin #: wc-donation-manager.php -#: includes/Admin/Admin.php:93 +#: includes/Admin/Admin.php:96 #: includes/Admin/Metaboxes.php:43 msgid "Donation Manager" msgstr "" @@ -53,24 +53,32 @@ msgstr "" msgid "Suggested amounts" msgstr "" -#: includes/Admin/Admin.php:59 +#: includes/Admin/Admin.php:60 msgid "Select products" msgstr "" +#: includes/Admin/Admin.php:61 +msgid "Please select a campaign for donation products." +msgstr "" + +#: includes/Admin/Admin.php:62 +msgid "Minimum amount cannot be greater than maximum amount." +msgstr "" + #. translators: %s: Plugin name -#: includes/Admin/Admin.php:92 +#: includes/Admin/Admin.php:95 #, php-format msgid "Thank you for using %s!" msgstr "" #. translators: %s: Plugin name -#: includes/Admin/Admin.php:98 +#: includes/Admin/Admin.php:101 #, php-format msgid " Share your appreciation with a five-star review %s." msgstr "" #. translators: 1: Plugin version -#: includes/Admin/Admin.php:119 +#: includes/Admin/Admin.php:122 #, php-format msgid "Version %s" msgstr ""