plugin updates

This commit is contained in:
Tony Volpe
2024-06-17 15:33:26 -04:00
parent 3751a5a1a6
commit e4e274a9a7
2674 changed files with 0 additions and 507851 deletions

View File

@@ -1,156 +0,0 @@
<?php
/**
* Functions to register client-side assets (scripts and stylesheets) for the
* Gutenberg block.
*
* @author StoreApps
* @since 4.0.0
* @version 1.0
*
* @package woocommerce-smart-coupons/includes/blocks
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'WC_SC_Gutenberg_Coupon_Block' ) ) {
/**
* Class for handling Smart Coupons Shortcode
*/
class WC_SC_Gutenberg_Coupon_Block {
/**
* Variable to hold instance of WC_SC_Gutenberg_Coupon_Block
*
* @var $instance
*/
private static $instance = null;
/**
* Constructor
*/
private function __construct() {
global $wp_version;
if ( ! function_exists( 'is_plugin_active' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
if ( is_plugin_active( 'gutenberg/gutenberg.php' ) || version_compare( $wp_version, '5.0', '>=' ) ) {
add_action( 'init', array( $this, 'gutenberg_coupon_block_init' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'gutenberg_coupon_add_inline_css' ) );
}
}
/**
* Get single instance of WC_SC_Gutenberg_Coupon_Block
*
* @return WC_SC_Gutenberg_Coupon_Block Singleton object of WC_SC_Gutenberg_Coupon_Block
*/
public static function get_instance() {
// Check if instance is already exists.
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Handle call to functions which is not available in this class
*
* @param string $function_name The function name.
* @param array $arguments Array of arguments passed while calling $function_name.
* @return result of function call
*/
public function __call( $function_name, $arguments = array() ) {
global $woocommerce_smart_coupon;
if ( ! is_callable( array( $woocommerce_smart_coupon, $function_name ) ) ) {
return;
}
if ( ! empty( $arguments ) ) {
return call_user_func_array( array( $woocommerce_smart_coupon, $function_name ), $arguments );
} else {
return call_user_func( array( $woocommerce_smart_coupon, $function_name ) );
}
}
/**
* Registers all block assets so that they can be enqueued through Gutenberg in
* the corresponding context.
*
* @see https://wordpress.org/gutenberg/handbook/blocks/writing-your-first-block-type/#enqueuing-block-scripts
*/
public function gutenberg_coupon_block_init() {
// Skip block registration if Gutenberg is not enabled/merged.
if ( ! function_exists( 'register_block_type' ) ) {
return;
}
$dir = dirname( __FILE__ );
$index_js = 'sc-gutenberg-block.js';
wp_register_script(
'coupon-block-editor-js',
plugins_url( $index_js, __FILE__ ),
array(
'wp-blocks',
'wp-i18n',
'wp-element',
'wp-components',
),
filemtime( "$dir/$index_js" ),
true
);
if ( shortcode_exists( 'smart_coupons' ) ) {
register_block_type(
'woocommerce-smart-coupons/coupon',
array(
'editor_script' => 'coupon-block-editor-js',
'attributes' => array(
'coupon_code' => array( 'type' => 'string' ),
),
'render_callback' => array( WC_SC_Shortcode::get_instance(), 'execute_smart_coupons_shortcode' ),
)
);
}
}
/**
* Our componenet is referring to smart-coupon.css as main css file.
* We cannot add register/enqueue a new CSS file to render coupon design in Gutenberg.
* And hence we are adding necessary files via wp_add_inline_style.
*/
public function gutenberg_coupon_add_inline_css() {
if ( ! wp_style_is( 'smart-coupon' ) ) {
wp_enqueue_style( 'smart-coupon' );
}
$coupon_style_attributes = WC_Smart_Coupons::get_instance()->get_coupon_style_attributes();
$gutenberg_active_coupon_style = '
.gb-active-coupon {
' . $coupon_style_attributes . '
}
';
// Add the above custom CSS via wp_add_inline_style.
wp_add_inline_style( 'smart-coupon', $gutenberg_active_coupon_style );
}
}
}
WC_SC_Gutenberg_Coupon_Block::get_instance();

View File

@@ -1,120 +0,0 @@
/**
* WooCommerce Smart Coupons Gutenberg
*
* @author StoreApps
* @since 4.0.0
* @version 1.0
*
* @package woocommerce-smart-coupons/includes/blocks
*/
( function( wp ) {
/**
* Registers a new block provided a unique name and an object defining its behavior.
*
* @see https://github.com/WordPress/gutenberg/tree/master/blocks#api
*/
const {registerBlockType} = wp.blocks;
/**
* Returns a new element of given type. Element is an abstraction layer atop React.
*
* @see https://github.com/WordPress/gutenberg/tree/master/element#element
*/
const createElement = wp.element.createElement;
/**
* Retrieves the translation of text.
*
* @see https://github.com/WordPress/gutenberg/tree/master/i18n#api
*/
const {__} = wp.i18n;
/**
* Every block starts by registering a new block type definition.
*
* @see https://wordpress.org/gutenberg/handbook/block-api/
*/
registerBlockType(
'woocommerce-smart-coupons/coupon',
{
/**
* This is the display title for our block, which can be translated with `i18n` functions.
* The block inserter will show this name.
*/
title: __( 'Smart Coupons', 'woocommerce-smart-coupons' ),
/**
* This is the block description for our block, which can be translated with `il8n` functions.
*/
description: __( 'Show any WooCommerce coupon with Smart Coupons.' ),
/**
* Blocks are grouped into categories to help users browse and discover them.
* The categories provided by core are `common`, `embed`, `formatting`, `layout` and `widgets`.
*/
category: 'embed',
/**
* Define block icon for our block.
*/
icon: 'heart',
/**
* This are the block keywords using which our block can be searched.
*/
keywords: [
__( 'Smart' ),
__( 'Coupons' ),
__( 'Store Credit' ),
],
/**
* Optional block extended support features.
*/
supports: {
// Removes support for an HTML mode.
html: false,
// align: [ 'wide', 'full' ],.
},
attributes: {
coupon_code: {
type: 'string',
},
},
/**
* The edit function describes the structure of your block in the context of the editor.
* This represents what the editor will render when the block is used.
*
* @see https://wordpress.org/gutenberg/handbook/block-edit-save/#edit
*
* @param {Object} [props] Properties passed from the editor.
* @return {Element} Element to render.
*/
edit: function( props ){
return createElement(
wp.editor.RichText,
{
className: 'coupon-container gb-active-coupon',
value: props.attributes.coupon_code,
onChange: function( coupon_code ) {
props.setAttributes( { coupon_code: coupon_code } );
}
}
);
},
/**
* The save function defines the way in which the different attributes should be combined
* into the final markup, which is then serialized by Gutenberg into `post_content`.
*
* @see https://wordpress.org/gutenberg/handbook/block-edit-save/#save
*
* @return {Element} Element to render.
*/
save:function( props ){
return null;
}
}
);
} )( window.wp );