diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..94f480d --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf \ No newline at end of file diff --git a/.github/workflows/phpcs.yaml b/.github/workflows/phpcs.yaml new file mode 100644 index 0000000..4e3c48e --- /dev/null +++ b/.github/workflows/phpcs.yaml @@ -0,0 +1,34 @@ +name: PHPCS Check + +on: + push: + branches: + - master + +jobs: + phpcs: + name: PHPCS Check + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.1' + + - name: Install PHPCS + run: | + composer config --global --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer true + composer require --dev squizlabs/php_codesniffer=* slevomat/coding-standard + + - name: Run PHPCS + run: | + composer phpcs --standard=phpcs.xml . + exit_status=$? + if [ $exit_status -ne 0 ]; then + echo "PHPCS check failed. Please fix the issues before merging." + exit 1 + fi \ No newline at end of file diff --git a/app/DonateBox/DonateBox.php b/app/DonateBox/DonateBox.php index 7a5416e..2df1205 100644 --- a/app/DonateBox/DonateBox.php +++ b/app/DonateBox/DonateBox.php @@ -1,11 +1,13 @@ addons->donation->addScript('main.js'); - $this->addons->donation->addStyle('main.css'); + Helpers::getAddon('donation')->addScript('main.js'); + Helpers::getAddon('donation')->addStyle('main.css'); $cryptopay = Services::preparePaymentProcess('donation', false); - return $this->addons->donation->view('donate-box', [ - 'currency' => $this->setting('donationCurrency'), - 'amounts' => $this->setting('donationDonateAmounts'), - 'theme' => $this->setting('theme'), + return Helpers::getAddon('donation')->view('donate-box', [ + 'currency' => Helpers::getSetting('donationCurrency'), + 'amounts' => Helpers::getSetting('donationDonateAmounts'), + 'theme' => Helpers::getSetting('theme'), 'cryptopay' => $cryptopay, ]); } -} \ No newline at end of file +} diff --git a/app/DonateBox/DonateBoxWidget.php b/app/DonateBox/DonateBoxWidget.php index 59f2d49..bd1274d 100644 --- a/app/DonateBox/DonateBoxWidget.php +++ b/app/DonateBox/DonateBoxWidget.php @@ -1,30 +1,42 @@ esc_html__('With this widget you can add a box to your site to receive donations with cryptocurrencies.', 'cryptopay') - ] + ] ); } - - public function widget($args, $instance) + + /** + * Widget + * + * @param array $args + * @param array $instance + * @return void + */ + // @phpcs:ignore + public function widget($args, $instance): void { $title = apply_filters('widget_title', $instance['title']); - + print($args['before_widget']); - + $title = !empty($title) ? $title : esc_html__('CryptoPay Donation Box', 'cryptopay'); print($args['before_title'] . $title . $args['after_title']); @@ -33,17 +45,32 @@ public function widget($args, $instance) print($args['after_widget']); } - - public function form($instance) + + /** + * Form + * + * @param array $instance + * @return void + */ + // @phpcs:ignore + public function form($instance) { $title = isset($instance['title']) ? $instance['title'] : null; - $this->viewEcho('widget-form', compact('title')); + Helpers::getAddon('donation')->viewEcho('widget-form', compact('title')); } - + + /** + * Update + * + * @param array $newInstance + * @param array $oldInstance + * @return array + */ + // @phpcs:ignore public function update($newInstance, $oldInstance) { $instance = []; $instance['title'] = !empty($newInstance['title']) ? sanitize_text_field($newInstance['title']) : null; return $instance; - } -} \ No newline at end of file + } +} diff --git a/app/Integrations.php b/app/Integrations.php index f9ca3c3..8c0bd0a 100644 --- a/app/Integrations.php +++ b/app/Integrations.php @@ -1,50 +1,60 @@ addons->donation->addScript('gutenberg.js', array_merge($dependencies, ['jquery', 'wp-element', 'wp-blocks'])); - }); + Helpers::getAddon('donation')->addScript( + 'gutenberg.js', + array_merge($dependencies, ['jquery', 'wp-element', 'wp-blocks']) + ); + }); // Register TinyMCE button - add_action('admin_head', function() { - add_filter('mce_external_plugins', function($pluginArray) { + add_action('admin_head', function (): void { + add_filter('mce_external_plugins', function ($pluginArray) { + // @phpcs:ignore $pluginArray['beycanpress/cryptopay-donation-box'] = plugin_dir_url('cryptopay-donation/index.php') . 'assets/js/tinymce.js'; return $pluginArray; }); - add_filter('mce_buttons', function($buttons) { + add_filter('mce_buttons', function ($buttons) { array_push($buttons, 'beycanpress/cryptopay-donation-box'); return $buttons; }); }); } else { - add_filter('the_content', function($content) { - + add_filter('the_content', function ($content) { if (function_exists('WC')) { - if (is_checkout() || is_account_page() || is_woocommerce() || is_cart()) return $content; - } + if (is_checkout() || is_account_page() || is_woocommerce() || is_cart()) { + return $content; + } + } if (is_page() || is_single()) { - $showIn = is_page() ? $this->setting('donationShowInPages') : $this->setting('donationShowInPosts'); - + $showIn = is_page() ? + Helpers::getSetting('donationShowInPages') : + Helpers::getSetting('donationShowInPosts'); + if ($showIn == 'show-in-begin') { $content = do_shortcode('[cryptopay-donation-box]') . $content; } elseif ($showIn == 'show-in-end') { @@ -56,4 +66,4 @@ public function __construct() }); } } -} \ No newline at end of file +} diff --git a/app/Lang.php b/app/Lang.php index edc3a45..e5591f3 100644 --- a/app/Lang.php +++ b/app/Lang.php @@ -1,10 +1,15 @@ + */ + public static function get(): array { return [ "orderAmount" => esc_html__('Donate amount', 'cryptopay'), @@ -19,5 +24,4 @@ public static function get() : array "paymentTimedOut" => esc_html__('Donation timed out!', 'cryptopay'), ]; } - -} \ No newline at end of file +} diff --git a/app/Loader.php b/app/Loader.php index 65b03e9..9a7b992 100644 --- a/app/Loader.php +++ b/app/Loader.php @@ -1,23 +1,26 @@ '5.0', - 'requires_php' => '7.4', - 'plugin_file' => 'cryptopay-donation/index.php', - 'plugin_version' => $this->addons->donation->getVersion(), + 'requires_php' => '8.1', + 'plugin_file' => 'cryptopay-donation/cryptopay-donation.php', + 'plugin_version' => Helpers::getAddon('donation')->getVersion(), 'icons' => [ '2x' => plugin_dir_url(dirname(__FILE__, 2) . '/index.php') . '/assets/images/icon-256x256.png', '1x' => plugin_dir_url(dirname(__FILE__, 2) . '/index.php') . '/assets/images/icon-128x128.png', @@ -25,27 +28,26 @@ public function __construct() ]); Hook::addFilter('apply_discount_donation', '__return_false'); - Hook::addFilter('models', function($models) { + Hook::addFilter('models', function ($models) { return array_merge($models, [ 'donation' => new Models\DonationTransaction() ]); }); Hook::addFilter('transaction_status_donation', fn() => 'completed'); - + if (is_admin()) { new TransactionPage( esc_html__('Donation transactions', 'cryptopay'), 'donation', 3, [], - false, ['orderId', 'status', 'updatedAt'] ); } else { new DonateBox\DonateBox(); } - + new Integrations(); } } diff --git a/app/Models/DonationTransaction.php b/app/Models/DonationTransaction.php index 29a2fe2..9a282f1 100644 --- a/app/Models/DonationTransaction.php +++ b/app/Models/DonationTransaction.php @@ -1,15 +1,20 @@ 'donate', + Setting::createSection(array( + 'id' => 'donate', 'title' => esc_html__('Donation settings', 'cryptopay'), 'icon' => 'fas fa-donate', 'fields' => array( @@ -81,4 +88,4 @@ public function __construct() ) )); } -} \ No newline at end of file +} diff --git a/composer.json b/composer.json index d6a6160..d4cf232 100644 --- a/composer.json +++ b/composer.json @@ -1,4 +1,9 @@ { + "scripts": { + "phpcs": "phpcs --standard=phpcs.xml .", + "phpcbf": "phpcbf --standard=phpcs.xml .", + "install-phpcs": "composer config --global --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer true && composer global require --dev squizlabs/php_codesniffer=* slevomat/coding-standard" + }, "autoload": { "psr-4": { "BeycanPress\\CryptoPay\\Donation\\": "app" diff --git a/cryptopay-donation.php b/cryptopay-donation.php index 0ec9560..0034b9e 100644 --- a/cryptopay-donation.php +++ b/cryptopay-donation.php @@ -1,6 +1,12 @@ -registerAddon('donation', __FILE__); - - require __DIR__ . '/vendor/autoload.php'; + Helpers::registerAddon('donation', __FILE__); - if ($this->setting('license')) { - new Donation\Loader(); - } + require __DIR__ . '/vendor/autoload.php'; - Hook::addAction("settings", function() { + new Donation\Loader(); + Hook::addAction("settings", function (): void { new Donation\Settings(); }, 90); } diff --git a/index.php b/index.php index 7e91415..1c090c1 100644 --- a/index.php +++ b/index.php @@ -1,2 +1,2 @@ -\n" "Language-Team: \n" @@ -13,7 +13,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "X-Generator: Loco https://localise.biz/\n" -"X-Loco-Version: 2.6.4; wp-6.2\n" +"X-Loco-Version: 2.6.6; wp-6.4.2\n" "X-Domain: cryptopay" #: app/DonateBox/DonateBoxWidget.php:15 @@ -29,7 +29,7 @@ msgid "Amount to be donated" msgstr "" #. Author of the plugin -msgid "BeycanPress" +msgid "BeycanPress LLC" msgstr "" #: views/donate-box.php:4 @@ -88,7 +88,7 @@ msgstr "" msgid "Donation timed out!" msgstr "" -#: app/Loader.php:31 +#: app/Loader.php:38 msgid "Donation transactions" msgstr "" @@ -97,7 +97,7 @@ msgid "https://beycanpress.com" msgstr "" #. URI of the plugin -msgid "https://beycanpress.com/" +msgid "https://beycanpress.com/cryptopay/" msgstr "" #: app/Settings.php:73 @@ -116,12 +116,16 @@ msgstr "" msgid "Not show" msgstr "" -#: views/donate-box.php:26 +#: views/donate-box.php:30 +msgid "Select currency" +msgstr "" + +#: views/donate-box.php:28 msgid "Select network" msgstr "" #: app/Settings.php:19 -msgid "Shorcode" +msgid "Shortcode" msgstr "" #: app/Settings.php:64 app/Settings.php:76 diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..a905b03 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,34 @@ + + + + + BeycanPressStandard + + ./**/*.php + + */views/* + */vendor/* + */PluginHero/templates/* + + + + + + + + + + + + + + + + + + + + + + + diff --git a/views/donate-box.php b/views/donate-box.php index 21d6dc8..8461c92 100644 --- a/views/donate-box.php +++ b/views/donate-box.php @@ -1,4 +1,7 @@ - +
@@ -24,7 +27,7 @@