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

Add Software Licensing to the Plugin #29

Merged
merged 3 commits into from
Feb 18, 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
2 changes: 1 addition & 1 deletion pattern-wrangler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

define( 'DLX_PATTERN_WRANGLER_VERSION', '1.0.0' );
define( 'DLX_PATTERN_WRANGLER_FILE', __FILE__ );
define( 'DLX_PATTERN_WRANGLER_PRODUCT_ID', 36631 );
define( 'DLX_PATTERN_WRANGLER_PRODUCT_ID', 37029 );

// Support for site-level autoloading.
if ( file_exists( __DIR__ . '/lib/autoload.php' ) ) {
Expand Down
4 changes: 2 additions & 2 deletions php/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function ajax_save_license() {
// Get latest options.
$options = Options::get_options( true );
$options['licenseKey'] = $license_key;
$options['licenseData'] = get_site_transient( 'dlxgbhacks_core_license_check', array() );
$options['licenseData'] = get_site_transient( 'dlxpw_core_license_check', array() );
wp_send_json_success( $options );
}

Expand Down Expand Up @@ -218,7 +218,7 @@ public function ajax_license_get_options() {
);
}
$options = Options::get_options( true );
$options['licenseData'] = get_site_transient( 'dlxgbhacks_core_license_check', array() );
$options['licenseData'] = get_site_transient( 'dlxpw_core_license_check', array() );
wp_send_json_success( $options );
}

Expand Down
10 changes: 10 additions & 0 deletions php/Patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public function run() {
// Add a featured image to the wp_block post type.
add_action( 'init', array( $this, 'add_featured_image_support' ) );

// Add an author to the wp_block post type.
add_action( 'init', array( $this, 'add_post_author_support' ) );

// Change post type label for featured image.
add_filter( 'post_type_labels_wp_block', array( $this, 'change_featured_image_label' ) );

Expand Down Expand Up @@ -190,6 +193,13 @@ public function add_featured_image_support() {
add_post_type_support( 'wp_block', 'thumbnail' );
}

/**
* Add post author support to wp_block post type.
*/
public function add_post_author_support() {
add_post_type_support( 'wp_block', 'author' );
}

/**
* Remove core patterns.
*/
Expand Down
36 changes: 18 additions & 18 deletions php/Plugin_License.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function perform_action( string $action, string $license = '', bool $forc
private function perform_license_action( string $action, bool $force ) {

$options = Options::get_options();
$maybe_check = get_site_transient( 'dlxgbhacks_core_license_check' );
$maybe_check = get_site_transient( 'dlxpw_core_license_check' );

if ( 'check_license' === $action && ! $force && $maybe_check ) {
return $maybe_check;
Expand All @@ -91,7 +91,7 @@ private function perform_license_action( string $action, bool $force ) {
'license_errors' => true,
'license' => $this->license,
'license_valid' => false,
'message' => __( 'It appears the license key is blank.', 'dlx-gb-hacks' ),
'message' => __( 'It appears the license key is blank.', 'dlx-pattern-wrangler' ),
'data' => array(),
'action' => $action,
);
Expand All @@ -102,7 +102,7 @@ private function perform_license_action( string $action, bool $force ) {
$api_params = array(
'edd_action' => $action,
'license' => $this->license,
'item_id' => GB_HACKS_PRODUCT_ID,
'item_id' => DLX_PATTERN_WRANGLER_PRODUCT_ID,
'url' => home_url(),
);
// Call the custom API.
Expand All @@ -120,7 +120,7 @@ private function perform_license_action( string $action, bool $force ) {
return $response;
}
if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
return new \WP_Error( 'sce_license_communications_error', __( 'We could not communicate with the update server. Please try again later.', 'dlx-gb-hacks' ) );
return new \WP_Error( 'sce_license_communications_error', __( 'We could not communicate with the update server. Please try again later.', 'dlx-pattern-wrangler' ) );
}
// Succeeded, let's check the response.
$response = $this->get_response( json_decode( wp_remote_retrieve_body( $response ), ARRAY_A ), $action );
Expand Down Expand Up @@ -155,7 +155,7 @@ private function perform_license_action( string $action, bool $force ) {

// Add query flag for checking the license so we don't ping the API every time.
if ( 'check_license' === $action || 'activate_license' === $action ) {
set_site_transient( 'dlxgbhacks_core_license_check', $response, 12 * HOUR_IN_SECONDS );
set_site_transient( 'dlxpw_core_license_check', $response, 12 * HOUR_IN_SECONDS );
}

/**
Expand All @@ -166,10 +166,10 @@ private function perform_license_action( string $action, bool $force ) {
* @param string $action Can be: check_license, activate_license, deactivate_license
* @param array $response Response of the action.
*/
do_action( 'dlx_gb_hacks_core_license_' . $action, $response );
do_action( 'dlx_pw_core_license_' . $action, $response );

// Return any custom data.
$data = apply_filters( 'dlx_gb_hacks_core_license_data_' . $action, $response );
$data = apply_filters( 'dlx_pw_core_license_data_' . $action, $response );

return $data;
}
Expand Down Expand Up @@ -214,8 +214,8 @@ private function get_response( array $response, string $action ) {
if ( ! empty( $expires ) ) {

if ( 'lifetime' === $expires ) {
$return_defaults['expires_human_time_diff'] = esc_html__( 'Lifetime', 'dlx-gb-hacks' );
$return_defaults['expires'] = esc_html__( 'Lifetime', 'dlx-gb-hacks' );
$return_defaults['expires_human_time_diff'] = esc_html__( 'Lifetime', 'dlx-pattern-wrangler' );
$return_defaults['expires'] = esc_html__( 'Lifetime', 'dlx-pattern-wrangler' );
} else {
$return_defaults['expires_human_time_diff'] = human_time_diff( time(), strtotime( $expires ) );
$return_defaults['expires'] = date_i18n( 'F jS, Y', strtotime( $expires ) );
Expand All @@ -226,54 +226,54 @@ private function get_response( array $response, string $action ) {
if ( 'deactivate_license' === $action ) {
return wp_parse_args(
array(
'message' => __( 'Your license key has been deactivated.', 'dlx-gb-hacks' ),
'message' => __( 'Your license key has been deactivated.', 'dlx-pattern-wrangler' ),
),
$return_defaults
);
}
if ( 'activate_license' === $action || 'check_license' === $action ) {
return wp_parse_args(
array(
'message' => __( 'Your license key is active and valid.', 'dlx-gb-hacks' ),
'message' => __( 'Your license key is active and valid.', 'dlx-pattern-wrangler' ),
),
$return_defaults
);
}
}

// There are errors.
$error_message = __( 'An error occurred, please try again.', 'dlx-gb-hacks' );
$error_message = __( 'An error occurred, please try again.', 'dlx-pattern-wrangler' );
$errors = $response['error'] ?? false;
if ( $errors ) {
switch ( $errors ) {
case 'expired':
$error_message = sprintf(
/* Translators: %s is a date format placeholder */
__( 'Your license key expired on %s.', 'dlx-gb-hacks' ),
__( 'Your license key expired on %s.', 'dlx-pattern-wrangler' ),
date_i18n( get_option( 'date_format' ), strtotime( $response['expires'], current_time( 'timestamp' ) ) ) // phpcs:ignore
);
break;

case 'disabled':
case 'revoked':
$error_message = __( 'Your license key has been disabled.', 'dlx-gb-hacks' );
$error_message = __( 'Your license key has been disabled.', 'dlx-pattern-wrangler' );
break;

case 'missing':
$error_message = __( 'The license entered is not valid.', 'dlx-gb-hacks' );
$error_message = __( 'The license entered is not valid.', 'dlx-pattern-wrangler' );
break;
case 'invalid':
case 'site_inactive':
$error_message = __( 'Your license is not active for this URL.', 'dlx-gb-hacks' );
$error_message = __( 'Your license is not active for this URL.', 'dlx-pattern-wrangler' );
break;

case 'item_name_mismatch':
/* Translators: %s is the plugin name */
$error_message = sprintf( __( 'This appears to be an invalid license key for %s.', 'dlx-gb-hacks' ), 'Toggl Plan for Gravity Forms' );
$error_message = sprintf( __( 'This appears to be an invalid license key for %s.', 'dlx-pattern-wrangler' ), 'Toggl Plan for Gravity Forms' );
break;

case 'no_activations_left':
$error_message = __( 'Your license key has reached its activation limit.', 'dlx-gb-hacks' );
$error_message = __( 'Your license key has reached its activation limit.', 'dlx-pattern-wrangler' );
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/js/blocks/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ const GBCommands = () => {
context: 'block-editor',
} );
useCommand( {
name: 'dlx-gb-hacks-Settings',
name: 'dlx-pattern-wrangler-Settings',
label: 'Go to GenerateBlocks (GB) Hacks Settings',
icon: settings,
callback: () => {
document.location.href = 'admin.php?page=dlx-gb-hacks';
document.location.href = 'admin.php?page=dlx-pattern-wrangler';
},
context: 'block-editor',
} );
Expand Down
19 changes: 18 additions & 1 deletion src/scss/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,20 @@ html {
scroll-behavior: smooth;
}

/* Lucide React Icons Styles */
svg.lucide {
color: inherit;
fill: none !important;

path,
circle,
rect,
line {
fill: unset !important;
color: currentColor !important;
}
}

/* Table Styles when rows are sections */
.form-table-row-sections {
tr {
Expand Down Expand Up @@ -498,9 +512,12 @@ html {
border-left-color: var(--dlx-pw-admin--color-notice--warning-alt);
}

svg path {
svg:not(.lucide) path {
fill: var(--dlx-pw-admin--color-notice--warning-alt);
}
svg.lucide {
color: var(--dlx-pw-admin--color-notice--warning-alt);
}
}
}

Expand Down
Loading