Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/@next #4

Merged
merged 21 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ codeception.yml
# Framework
lib


# Build
assets/dist
assets/

4 changes: 4 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ module.exports = function (grunt) {
options: {
expand: true,
text_domain: 'wc-donation-manager',
<<<<<<< HEAD
updateDomains: [ 'bytekit-textdomain', 'textdomain' ],
=======
updateDomains: ['framework-text-domain'],
>>>>>>> master
},
plugin: {
files: {
Expand Down
Empty file removed assets/src/blocks/index.js
Empty file.
50 changes: 24 additions & 26 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,24 @@
{
"name": "pluginever/wc-donation-manager",
"description": "WC Donation Manager.",
"description": "A powerful and user-friendly WordPress plugin designed to seamlessly integrate donation functionality into the WooCommerce platform. This plugin is the ultimate solution for effortlessly managing and receiving donations for a charitable organization, a non-profit, or a business looking to support a cause.",
"homepage": "https://pluginever.com/plugins/wc-donation-manager/",
"type": "wordpress-plugin",
"license": "GPL-3.0-or-later",
"prefer-stable": true,
"minimum-stability": "dev",
"repositories": [
{
"url": "[email protected]:pluginever/framework-plugin.git",
"type": "github"
},
{
"url": "[email protected]:pluginever/framework-data.git",
"type": "github"
},
{
"url": "[email protected]:pluginever/framework-settings.git",
"type": "github"
}
],
"require": {
"php": ">=7.4"
},
"require-dev": {
"byteever/byteever-sniffs": "dev-master",
"coenjacobs/mozart": "^0.7.1",
"pluginever/framework-plugin": "dev-master",
"pluginever/framework-settings": "dev-master",
"pluginever/framework-data": "dev-master"
"byteever/bytekit-plugin": "dev-master",
"byteever/bytekit-settings": "dev-master",
"coenjacobs/mozart": "^0.7.1"
},
"autoload": {
"psr-4": {
"WooCommerceDonationManager\\": ["includes/", "lib/"]
}
},
"autoload-dev": {},
"config": {
"optimize-autoloader": true,
"sort-packages": true,
Expand All @@ -38,8 +27,18 @@
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"autoload": {},
"autoload-dev": {},
"minimum-stability": "dev",
"prefer-stable": true,
"repositories": [
{
"type": "github",
"url": "[email protected]:byteever/bytekit-plugin.git"
},
{
"type": "github",
"url": "[email protected]:byteever/bytekit-settings.git"
}
],
"scripts": {
"post-install-cmd": [
"\"vendor/bin/mozart\" compose",
Expand All @@ -60,9 +59,8 @@
"classmap_prefix": "WooCommerceDonationManager_",
"delete_vendor_directories": true,
"packages": [
"pluginever/framework-plugin",
"pluginever/framework-settings",
"pluginever/framework-data"
"byteever/bytekit-plugin",
"byteever/bytekit-settings"
]
}
}
Expand Down
144 changes: 144 additions & 0 deletions includes/Admin/Actions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?php

namespace WooCommerceDonationManager\Admin;

defined( 'ABSPATH' ) || exit;

/**
* Actions class.
*
* All actions related to the admin area
* should be added here.
*
* @since 1.0.0
* @package WooCommerceDonationManager
*/
class Actions {

/**
* Actions constructor.
*
* @since 1.0.0
*/
public function __construct() {
add_action( 'admin_post_wcdm_add_campaign', array( __CLASS__, 'add_campaign' ) );
add_action( 'admin_post_wcdm_edit_campaign', array( __CLASS__, 'edit_campaign' ) );
add_action( 'woocommerce_process_product_meta_donation', array( __CLASS__, 'save_donation_meta' ) );
}

/**
* Add a campaign.
*
* @since 1.0.0
* @return void
*/
public static function add_campaign() {
check_admin_referer( 'wcdm_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'] ) ) : '';
$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';
$id = isset( $_POST['id'] ) ? intval( wp_unslash( $_POST['id'] ) ) : intval( '0' );

$args = array(
'ID' => $id,
'post_type' => 'wcdm_campaigns',
'post_title' => wp_strip_all_tags( $name ),
'post_content' => wp_kses_post( $cause ),
'post_status' => $status,
'meta_input' => array(
'_goal_amount' => $goal_amount,
'_end_date' => $end_date,
),
);

$campaign = wp_insert_post( $args );

if ( is_wp_error( $campaign ) ) {
WCDM()->flash->error( $campaign->get_error_message() );
} else {
WCDM()->flash->success( __( 'Campaign created successfully.', 'wc-donation-manager' ) );

$referer = add_query_arg(
array( 'edit' => absint( $campaign ) ),
remove_query_arg( 'add', $referer )
);
}

wp_safe_redirect( $referer );
exit;
}

/**
* Edit a campaign.
*
* @since 1.0.0
* @return void
*/
public static function edit_campaign() {
check_admin_referer( 'wcdm_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'] ) ) : '';
$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';
$id = isset( $_POST['id'] ) ? intval( wp_unslash( $_POST['id'] ) ) : intval( '0' );

$args = array(
'ID' => $id,
'post_type' => 'wcdm_campaigns',
'post_title' => wp_strip_all_tags( $name ),
'post_content' => wp_kses_post( $cause ),
'post_status' => $status,
'meta_input' => array(
'_goal_amount' => $goal_amount,
'_end_date' => $end_date,
),
);

$campaign = wp_insert_post( $args );

if ( is_wp_error( $campaign ) ) {
WCDM()->flash->error( $campaign->get_error_message() );
} else {
WCDM()->flash->success( __( 'Campaign updated successfully.', 'wc-donation-manager' ) );
}

wp_safe_redirect( $referer );
exit;
}

/**
* Save donation product meta.
* The method only callable while adding/editing donation products type.
*
* @param int $product_id Donation product id.
*
* @version 1.0.0
* @return void
*/
public static function save_donation_meta( $product_id ) {
wp_verify_nonce( '_wpnonce' );
$price = isset( $_POST['wcdm_amount'] ) ? floatval( wp_unslash( $_POST['wcdm_amount'] ) ) : '';
$goal_amounts = isset( $_POST['_goal_amount'] ) ? sanitize_text_field( wp_unslash( $_POST['_goal_amount'] ) ) : '';
$predefined_amounts = ! empty( $_POST['_predefined_amounts'] ) ? explode( ',', preg_replace( '/\s*/m', '', sanitize_text_field( wp_unslash( $_POST['_predefined_amounts'] ) ) ) ) : array();
$predefined_amounts = array_filter( array_unique( $predefined_amounts ) );

update_post_meta( $product_id, '_price', $price );
update_post_meta( $product_id, '_regular_price', $price );
update_post_meta( $product_id, '_goal_amount', $goal_amounts );
update_post_meta( $product_id, '_is_predefined_amounts', isset( $_POST['_is_predefined_amounts'] ) ? sanitize_text_field( wp_unslash( $_POST['_is_predefined_amounts'] ) ) : '' );
update_post_meta( $product_id, '_predefined_amounts_title', ( ! empty( $_POST['_predefined_amounts_title'] ) ? sanitize_text_field( wp_unslash( $_POST['_predefined_amounts_title'] ) ) : __( 'Suggested amounts', 'wc-donation-manager' ) ) );
update_post_meta( $product_id, '_predefined_amounts', $predefined_amounts );
update_post_meta( $product_id, '_is_custom_amount', isset( $_POST['_is_custom_amount'] ) ? sanitize_text_field( wp_unslash( $_POST['_is_custom_amount'] ) ) : 'no' );
update_post_meta( $product_id, '_amount_increment_steps', ( ! empty( $_POST['_amount_increment_steps'] ) && is_numeric( $_POST['_amount_increment_steps'] ) ? number_format( wp_unslash( $_POST['_amount_increment_steps'] ), 2, '.', '' ) : 0.01 ) );
update_post_meta( $product_id, '_wcdm_min_amount', ( ! empty( $_POST['_wcdm_min_amount'] ) && is_numeric( $_POST['_wcdm_min_amount'] ) ? floatval( wp_unslash( $_POST['_wcdm_min_amount'] ) ) : get_option( 'wcdm_minimum_amount' ) ) );
update_post_meta( $product_id, '_wcdm_max_amount', ( ! empty( $_POST['_wcdm_max_amount'] ) && is_numeric( $_POST['_wcdm_max_amount'] ) ? floatval( wp_unslash( $_POST['_wcdm_max_amount'] ) ) : get_option( 'wcdm_maximum_amount' ) ) );
update_post_meta( $product_id, '_wcdm_campaign_id', ( ! empty( $_POST['_wcdm_campaign_id'] ) ? sanitize_text_field( wp_unslash( $_POST['_wcdm_campaign_id'] ) ) : '' ) );
}
}
144 changes: 144 additions & 0 deletions includes/Admin/Admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?php

namespace WooCommerceDonationManager\Admin;

defined( 'ABSPATH' ) || exit(); // Exit if accessed directly.

/**
* Admin class.
*
* @since 1.0.0
* @package WooCommerceDonationManager\Admin
*/
class Admin {

/**
* Admin constructor.
*
* @since 1.0.0
*/
public function __construct() {
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 );
add_filter( 'update_footer', array( $this, 'update_footer' ), PHP_INT_MAX );
}

/**
* Enqueue admin scripts.
*
* @param string $hook The current admin page.
*
* @since 1.0.0
* @return void
*/
public function enqueue_scripts( $hook ) {
// TODO: Need to finalized the enqueue codes.
// $is_order_page = ( in_array( $hook, array( 'post.php', 'post-new.php' ), true ) && in_array( get_post_type(), array( 'shop_order' ), true ) ) || 'woocommerce_page_wc-orders' === $hook;
// $is_product_page = in_array( $hook, array( 'post.php', 'post-new.php' ), true ) && in_array( get_post_type(), array( 'product' ), true );
// $is_settings_page = Menus::PARENT_SLUG . '_page_wcdm-settings' === $hook;
// 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' );
//
// if ( ! in_array( $hook, Utilities::get_screen_ids(), true ) && ! $is_product_page && ! $is_order_page ) {
// return;
// }
//
// $localize = array(
// 'ajaxurl' => admin_url( 'admin-ajax.php' ),
// 'security' => wp_create_nonce( 'wc_key_manager' ),
// 'i18n' => array(
// 'search_products' => esc_html__( 'Select products', 'wc-donation-manager' ),
// 'search_orders' => esc_html__( 'Select orders', 'wc-donation-manager' ),
// 'search_customers' => esc_html__( 'Select customers', 'wc-donation-manager' ),
// ),
// 'key_settings' => array(
// 'pattern' => get_option( 'wcdm_key_pattern', '####-####-####-####' ),
// 'chars' => get_option( 'wcdm_key_characters', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ),
// ),
// );
//
// wp_enqueue_style( 'jquery-ui-style' );
// wp_enqueue_script( 'jquery-ui-datepicker' );
// wp_localize_script( 'wcdm-admin', 'wcdm_admin_vars', $localize );
// wp_enqueue_script( 'wcdm-admin' );
// wp_enqueue_style( 'wcdm-admin' );

$screen_ids = Utilities::get_screen_ids();
WCDM()->scripts->enqueue_style( 'wcdm-admin', 'css/wcdm-admin.css', array( 'bytekit-layout', 'bytekit-components', 'woocommerce_admin_styles' ) );
WCDM()->scripts->register_script( 'wcdm-admin', 'js/wcdm-admin.js' );

if ( in_array( $hook, $screen_ids, true ) ) {
wp_enqueue_style( 'wcdm-admin' );
wp_enqueue_script( 'wcdm-admin' );

$localize = array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'security' => wp_create_nonce( 'wc_donation_manager' ),
'i18n' => array(
'search_products' => esc_html__( 'Select products', 'wc-donation-manager' ),
),
);

wp_localize_script( 'wcdm-admin', 'wcdm_admin_vars', $localize );
}
}

/**
* Add the plugin screens to the WooCommerce screens.
* This will load the WooCommerce admin styles and scripts.
*
* @param array $ids Screen ids.
*
* @return array
*/
public function add_screen_ids( $ids ) {
return array_merge( $ids, Utilities::get_screen_ids() );
}

/**
* Request review.
*
* @param string $text Footer text.
*
* @since 1.0.0
* @return string
*/
public function admin_footer_text( $text ) {

if ( in_array( get_current_screen()->id, Utilities::get_screen_ids(), true ) ) {
$text = sprintf(
/* translators: %s: Plugin name */
__( 'Thank you for using %s!', 'wc-donation-manager' ),
'<strong>' . esc_html( WCDM()->get_name() ) . '</strong>',
);
if ( WCDM()->get_review_url() ) {
$text .= sprintf(
/* translators: %s: Plugin name */
__( ' Share your appreciation with a five-star review %s.', 'wc-donation-manager' ),
'<a href="' . esc_url( WCDM()->get_review_url() ) . '" target="_blank">here</a>'
);
}
}

return $text;
}

/**
* Update footer.
*
* @param string $text Footer text.
*
* @since 1.0.0
* @return string
*/
public function update_footer( $text ) {

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() );
}

return $text;
}
}
Loading
Loading