Skip to content

Commit 6274a64

Browse files
authored
Merge pull request #59 from wpgaurav/claude/add-fluent-cart-licensing-xpEAZ
Add Fluent Cart licensing (product ID 1150934) and auto-install SCF
2 parents 9ab902e + 8d6919a commit 6274a64

2 files changed

Lines changed: 59 additions & 6 deletions

File tree

acf-blocks.php

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: ACF Blocks
44
* Plugin URI: https://github.com/wpgaurav/acf-blocks-plugin
55
* Description: A collection of ACF Pro blocks for the WordPress block editor with automatic field group registration.
6-
* Version: 2.0.6
6+
* Version: 2.1.0
77
* Requires at least: 6.0
88
* Requires PHP: 7.4
99
* Author: Gaurav Tiwari
@@ -19,7 +19,7 @@
1919
}
2020

2121
// Plugin constants
22-
define( 'ACF_BLOCKS_VERSION', '2.0.6' );
22+
define( 'ACF_BLOCKS_VERSION', '2.1.0' );
2323
define( 'ACF_BLOCKS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
2424
define( 'ACF_BLOCKS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
2525
define( 'ACF_BLOCKS_PLUGIN_FILE', __FILE__ );
@@ -36,12 +36,12 @@ function acf_blocks_check_requirements() {
3636
}
3737

3838
/**
39-
* Admin notice for missing ACF Pro.
39+
* Admin notice for missing ACF Pro / SCF.
4040
*/
4141
function acf_blocks_missing_acf_notice() {
4242
?>
4343
<div class="notice notice-error">
44-
<p><?php esc_html_e( 'ACF Blocks requires Advanced Custom Fields Pro to be installed and activated.', 'acf-blocks' ); ?></p>
44+
<p><?php esc_html_e( 'ACF Blocks requires Advanced Custom Fields Pro or Secure Custom Fields (SCF) to be installed and activated.', 'acf-blocks' ); ?></p>
4545
</div>
4646
<?php
4747
}
@@ -69,11 +69,64 @@ function acf_blocks_init() {
6969
$acf_blocks_license = new ACF_Blocks_License_Manager( __FILE__ );
7070
$acf_blocks_license->hook();
7171

72+
/**
73+
* Check if ACF Pro or SCF is installed (not necessarily active).
74+
*
75+
* @return bool
76+
*/
77+
function acf_blocks_has_acf_or_scf_installed() {
78+
if ( ! function_exists( 'get_plugins' ) ) {
79+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
80+
}
81+
$plugins = get_plugins();
82+
foreach ( $plugins as $plugin_file => $plugin_data ) {
83+
// ACF Pro
84+
if ( strpos( $plugin_file, 'advanced-custom-fields-pro/' ) === 0 ) {
85+
return true;
86+
}
87+
// SCF (Secure Custom Fields)
88+
if ( strpos( $plugin_file, 'secure-custom-fields/' ) === 0 ) {
89+
return true;
90+
}
91+
}
92+
return false;
93+
}
94+
95+
/**
96+
* Install and activate SCF (Secure Custom Fields) from WordPress.org.
97+
*/
98+
function acf_blocks_install_scf() {
99+
if ( acf_blocks_has_acf_or_scf_installed() ) {
100+
return;
101+
}
102+
103+
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
104+
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
105+
require_once ABSPATH . 'wp-admin/includes/file.php';
106+
require_once ABSPATH . 'wp-admin/includes/misc.php';
107+
108+
$api = plugins_api( 'plugin_information', array(
109+
'slug' => 'secure-custom-fields',
110+
'fields' => array( 'sections' => false ),
111+
) );
112+
113+
if ( is_wp_error( $api ) ) {
114+
return;
115+
}
116+
117+
$upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
118+
$result = $upgrader->install( $api->download_link );
119+
120+
if ( ! is_wp_error( $result ) && $result ) {
121+
activate_plugin( 'secure-custom-fields/secure-custom-fields.php' );
122+
}
123+
}
124+
72125
/**
73126
* Activation hook.
74127
*/
75128
function acf_blocks_activate() {
76-
// Flush rewrite rules on activation
129+
acf_blocks_install_scf();
77130
flush_rewrite_rules();
78131
}
79132
register_activation_hook( __FILE__, 'acf_blocks_activate' );

includes/license-manager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
class ACF_Blocks_License_Manager {
1616

1717
const LICENSE_SERVER = 'https://gauravtiwari.org/';
18-
const ITEM_ID = 0; // Set after creating FluentCart product
18+
const ITEM_ID = 1150934;
1919
const OPTION_KEY = 'acf_blocks_license';
2020
const LAST_CHECK_KEY = 'acf_blocks_license_last_check';
2121
const UPDATE_TRANSIENT = 'acf_blocks_update_info';

0 commit comments

Comments
 (0)