Skip to content
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
29 changes: 0 additions & 29 deletions .eslintrc.js

This file was deleted.

3 changes: 0 additions & 3 deletions .prettierrc.js

This file was deleted.

39 changes: 22 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,53 +1,58 @@
{
"name": "pluginever/wc-category-showcase",
"description": "WooCommerce extension to showcase categories in various styles and layouts like sliders, blocks, and grids.",
"homepage": "https://pluginever.com/plugins/woocommerce-category-showcase-pro/",
"type": "wordpress-plugin",
"license": "GPL-2.0-or-later",
"repositories": [
{
"type": "vcs",
"url": "git@github.com:byteever/bytekit-plugin.git"
}
],
"license": "GPL v2 or later",
"prefer-stable": true,
"minimum-stability": "dev",
"require": {
"php": ">=7.4",
"byteever/bytekit-plugin": "dev-trunk"
"byteever/plugin": "dev-trunk"
},
"require-dev": {
"byteever/byteever-sniffs": "^1.1.3"
},
"autoload": {
"psr-4": {
"WooCommerceCategoryShowcase\\": "includes/"
"PluginEver\\CategoryShowcase\\": "includes/"
}
},
"autoload-dev": {},
"config": {
"optimize-autoloader": true,
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"repositories": [
{
"type": "vcs",
"url": "git@github.com:byteever/plugin.git"
}
],
"scripts": {
"post-install-cmd": "@strauss",
"post-update-cmd": "@strauss",
"post-autoload-dump": "test -f /tmp/strauss.phar && php /tmp/strauss.phar include-autoloader || true",
"makepot": "wp --allow-root i18n make-pot . --include=*.php,assets,includes,templates --domain=wc-category-showcase",
"phpcs": "php ./vendor/bin/phpcs --standard=phpcs.xml -s -v",
"phpcbf": "php ./vendor/bin/phpcbf --standard=phpcs.xml -v",
"test:setup": "bash ./bin/setup-tests.sh wordpress_test root root localhost trunk && phpunit",
"phpcs": "@php ./vendor/bin/phpcs --standard=phpcs.xml -s -v",
"phpcbf": "@php ./vendor/bin/phpcbf --standard=phpcs.xml -v",
"test": "phpunit",
"strauss": [
"test -f /tmp/strauss.phar || curl -o /tmp/strauss.phar -L https://github.com/BrianHenryIE/strauss/releases/download/0.24.1/strauss.phar",
"@php /tmp/strauss.phar",
"@composer dump-autoload --no-scripts",
"find ./vendor/byteever -type f -name '*.php' -exec perl -i -pe \"s/'bytekit-textdomain'/'wc-category-showcase'/g\" {} +"
"@composer dump-autoload --no-scripts"
]
},
"extra": {
"strauss": {
"target_directory": "vendor",
"namespace_prefix": "WooCommerceCategoryShowcase\\",
"classmap_prefix": "WooCommerceCategoryShowcase__",
"namespace_prefix": "PluginEver\\CategoryShowcase\\",
"classmap_prefix": "PluginEver_CategoryShowcase__",
"packages": [
"byteever/bytekit-plugin"
"byteever/plugin"
]
}
}
Expand Down
91 changes: 62 additions & 29 deletions includes/Admin/Admin.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,49 @@
<?php

namespace WooCommerceCategoryShowcase\Admin;
namespace PluginEver\CategoryShowcase\Admin;

use WooCommerceCategoryShowcase\Controllers\Helpers;
use PluginEver\CategoryShowcase\B8\Component;
use PluginEver\CategoryShowcase\Controllers\Helpers;

defined( 'ABSPATH' ) || exit;

/**
* Admin class.
*
* @since 1.0.0
* @package WooCommerceCategoryShowcase
* @package PluginEver\CategoryShowcase\Admin
*/
class Admin {
class Admin extends Component {

/**
* Admin constructor.
* Child components.
*
* @since 1.0.0
* @var array<int|string, class-string>
*/
public function __construct() {
public array $components = array(
Menu::class,
Notices::class,
Feedback::class,
);

/**
* Whether to load.
*
* @since 1.0.0
* @return bool
*/
public function autoload(): bool {
return is_admin();
}

/**
* Register hooks.
*
* @since 1.0.0
* @return void
*/
public function register(): void {
add_action( 'admin_init', array( $this, 'buffer_start' ), 1 );
add_filter( 'woocommerce_screen_ids', array( $this, 'screen_ids' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
Expand Down Expand Up @@ -50,7 +74,7 @@ public function buffer_start() {
* @return array
*/
public function screen_ids( $ids ) {
return array_merge( $ids, Utilities::get_screen_ids() );
return array_merge( $ids, $this->app->get( Menu::class )->get_screen_ids() );
}

/**
Expand All @@ -62,21 +86,26 @@ public function screen_ids( $ids ) {
* @return void
*/
public function enqueue_scripts( $hook ) {
$showcase_add = isset( $_GET['add'] ) ? true : false; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Readonly check for presence.
$showcase_id = isset( $_GET['edit'] ) ? absint( wp_unslash( $_GET['edit'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Readonly check for presence.
wp_enqueue_style( 'b8-components' );
wp_enqueue_style( 'b8-layout' );

if ( in_array( $hook, Utilities::get_screen_ids(), true ) || $showcase_id || $showcase_add ) {
wc_category_showcase()->scripts->register_style( 'wccs_tailwind', '/styles/tailwind.css' );
wc_category_showcase()->scripts->register_style( 'wcc-showcase-fontawesome-icons', '/fonts/fontawesome/fontawesome-icons.css' );
wc_category_showcase()->scripts->register_style( 'wcc-showcase-happy-icons', '/fonts/happy-icons/happy-icons.css' );
wc_category_showcase()->scripts->register_style( 'wcc-showcase-vendor', '/styles/vendor.css' );
wc_category_showcase()->scripts->register_script( 'wcc-showcase-vendor', '/scripts/vendor.js', array( 'jquery' ), true );
$showcase_add = isset( $_GET['add'] ) ? true : false; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$showcase_id = isset( $_GET['edit'] ) ? absint( wp_unslash( $_GET['edit'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended

wp_enqueue_style( 'bytekit-components' );
wp_enqueue_style( 'bytekit-layout' );
$screen_ids = $this->app->get( Menu::class )->get_screen_ids();

wc_category_showcase()->scripts->enqueue_style( 'wcc_showcase-admin', '/styles/admin.css', array( 'wccs_tailwind', 'wcc-showcase-vendor', 'wcc-showcase-fontawesome-icons', 'wcc-showcase-happy-icons' ) );
wc_category_showcase()->scripts->enqueue_script( 'wcc_showcase-admin', '/scripts/admin.js', array( 'jquery', 'wp-color-picker', 'wcc-showcase-vendor' ), true );
if ( in_array( $hook, $screen_ids, true ) || $showcase_id || $showcase_add ) {
$assets = $this->app->assets_url() . '/build';
$version = $this->app->version;

wp_register_style( 'wccs_tailwind', $assets . '/styles/tailwind.css', array(), $version );
wp_register_style( 'wcc-showcase-fontawesome-icons', $assets . '/fonts/fontawesome/fontawesome-icons.css', array(), $version );
wp_register_style( 'wcc-showcase-happy-icons', $assets . '/fonts/happy-icons/happy-icons.css', array(), $version );
wp_register_style( 'wcc-showcase-vendor', $assets . '/styles/vendor.css', array(), $version );
wp_register_script( 'wcc-showcase-vendor', $assets . '/scripts/vendor.js', array( 'jquery' ), $version, true );

wp_enqueue_style( 'wcc_showcase-admin', $assets . '/styles/admin.css', array( 'wccs_tailwind', 'wcc-showcase-vendor', 'wcc-showcase-fontawesome-icons', 'wcc-showcase-happy-icons' ), $version );
wp_enqueue_script( 'wcc_showcase-admin', $assets . '/scripts/admin.js', array( 'jquery', 'wp-color-picker', 'wcc-showcase-vendor' ), $version, true );

wp_enqueue_media();

Expand Down Expand Up @@ -117,17 +146,19 @@ public function enqueue_scripts( $hook ) {
* @return string
*/
public function admin_footer_text( $text ) {
if ( in_array( get_current_screen()->id, Utilities::get_screen_ids(), true ) ) {
$screen_ids = $this->app->get( Menu::class )->get_screen_ids();

if ( in_array( get_current_screen()->id, $screen_ids, true ) ) {
$text = sprintf(
/* translators: %s: Plugin name */
__( 'Thank you for using %s!', 'wc-category-showcase' ),
'<strong>' . esc_html( wc_category_showcase()->get_name() ) . '</strong>'
'<strong>' . esc_html( $this->app->get( 'name' ) ) . '</strong>'
);
if ( wc_category_showcase()->review_url ) {
if ( $this->app->get( 'review_url' ) ) {
$text .= sprintf(
/* translators: %s: Plugin name */
__( ' Share your appreciation with a five-star review %s.', 'wc-category-showcase' ),
'<a href="' . esc_url( wc_category_showcase()->review_url ) . '" target="_blank">here</a>'
'<a href="' . esc_url( $this->app->get( 'review_url' ) ) . '" target="_blank">here</a>'
);
}
}
Expand All @@ -144,9 +175,11 @@ public function admin_footer_text( $text ) {
* @return string
*/
public function update_footer( $footer_text ) {
if ( in_array( get_current_screen()->id, Utilities::get_screen_ids(), true ) ) {
$screen_ids = $this->app->get( Menu::class )->get_screen_ids();

if ( in_array( get_current_screen()->id, $screen_ids, true ) ) {
/* translators: 1: Plugin version */
$footer_text = sprintf( esc_html__( 'Version %s', 'wc-category-showcase' ), wc_category_showcase()->get_version() );
$footer_text = sprintf( esc_html__( 'Version %s', 'wc-category-showcase' ), $this->app->version );
}

return $footer_text;
Expand Down Expand Up @@ -175,7 +208,7 @@ public static function handle_add_category_showcase() {
$settings = Helpers::get_showcase_settings();
$post_id = wp_insert_post( $args );
if ( is_wp_error( $post_id ) ) {
wc_category_showcase()->flash->error( __( 'Failed to Add Category Showcase: Please Try Again!', 'wc-category-showcase' ) );
wc_category_showcase()->app->flash->error( __( 'Failed to Add Category Showcase: Please Try Again!', 'wc-category-showcase' ) );
wp_safe_redirect( $referer );
exit();
}
Expand Down Expand Up @@ -238,7 +271,7 @@ public static function handle_add_category_showcase() {
update_post_meta( $post_id, $post_key, $meta_value );
}
}
wc_category_showcase()->flash->success( __( 'The category showcase has been successfully updated!', 'wc-category-showcase' ) );
wc_category_showcase()->app->flash->success( __( 'The category showcase has been successfully updated!', 'wc-category-showcase' ) );
$redirect_to = admin_url( 'admin.php?page=wc-category-showcase&edit=' . $post_id );
wp_safe_redirect( $redirect_to );
exit;
Expand Down Expand Up @@ -311,7 +344,7 @@ public static function get_category_details() {
}
$category_details = Helpers::get_category_details( $term_id );
$category_details['position'] = $current_position;
include WCCS_TEMPLATES_URL . 'load-category-details.php';
include WCCS_PATH . 'templates/admin/load-category-details.php';
wp_die();
}

Expand All @@ -332,7 +365,7 @@ public static function get_additional_category_details() {
}
$category_details = Helpers::get_category_details( $term_id );
$category_details['position'] = $current_position;
include WCCS_TEMPLATES_URL . 'load-additional-category-details.php';
include WCCS_PATH . 'templates/admin/load-additional-category-details.php';
wp_die();
}
}
Loading
Loading