Refactor plugin with improved architecture and new features
All checks were successful
Create Release / build (push) Successful in 5s
All checks were successful
Create Release / build (push) Successful in 5s
- Eliminated code duplication by creating common HTTP request function - Added configurable SSL verification setting for development/production - Implemented smart caching system with 1-hour cache duration - Enhanced admin interface with cache management and better styling - Improved error handling and user experience - Added comprehensive documentation and troubleshooting guide - Updated README with new features and configuration options
This commit is contained in:
@@ -45,6 +45,14 @@ class fourthwall_settings {
|
||||
'fourthwall_settings_name_section'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'ssl_verify',
|
||||
__( 'SSL Verification', 'fourthwall_text_domain' ),
|
||||
array( $this, 'render_ssl_verify_field' ),
|
||||
'fourthwall_settings_name',
|
||||
'fourthwall_settings_name_section'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function fourthwall_page_layout() {
|
||||
@@ -54,6 +62,12 @@ class fourthwall_settings {
|
||||
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'fourthwall_text_domain' ) );
|
||||
}
|
||||
|
||||
// Handle cache clearing
|
||||
if (isset($_POST['clear_cache']) && wp_verify_nonce($_POST['_wpnonce'], 'clear_fwembed_cache')) {
|
||||
$this->clear_fwembed_cache();
|
||||
echo '<div class="notice notice-success"><p>' . __('Cache cleared successfully!', 'fourthwall_text_domain') . '</p></div>';
|
||||
}
|
||||
|
||||
// Admin Page Layout
|
||||
echo '<div class="wrap">' . "\n";
|
||||
echo ' <h1>' . get_admin_page_title() . '</h1>' . "\n";
|
||||
@@ -64,7 +78,21 @@ class fourthwall_settings {
|
||||
submit_button();
|
||||
|
||||
echo ' </form>' . "\n";
|
||||
echo ' <div><p>To use the fourthwall Embed, use the shortcode [fourthwall]</p></div>';
|
||||
|
||||
// Cache clearing form
|
||||
echo ' <form method="post" style="margin-top: 20px;">' . "\n";
|
||||
echo ' ' . wp_nonce_field('clear_fwembed_cache', '_wpnonce', true, false) . "\n";
|
||||
echo ' <input type="submit" name="clear_cache" class="button button-secondary" value="' . __('Clear Cache', 'fourthwall_text_domain') . '">' . "\n";
|
||||
echo ' <p class="description">' . __('Clear the cached Fourthwall content. Use this if products are not updating.', 'fourthwall_text_domain') . '</p>' . "\n";
|
||||
echo ' </form>' . "\n";
|
||||
|
||||
echo ' <div class="shortcode-info">' . "\n";
|
||||
echo ' <h3>' . __( 'Shortcode Usage', 'fourthwall_text_domain' ) . '</h3>' . "\n";
|
||||
echo ' <p><strong>' . __( 'Display entire store:', 'fourthwall_text_domain' ) . '</strong> <code>[fourthwall]</code></p>' . "\n";
|
||||
echo ' <p><strong>' . __( 'Display single product:', 'fourthwall_text_domain' ) . '</strong> <code>[fourthwall_single url="https://your-store.fourthwall.com/products/product-name"]</code></p>' . "\n";
|
||||
echo ' <p><strong>' . __( 'With description:', 'fourthwall_text_domain' ) . '</strong> <code>[fourthwall_single url="https://your-store.fourthwall.com/products/product-name" show_description="true"]</code></p>' . "\n";
|
||||
echo ' <p><em>' . __( 'Note: Disable SSL verification only for local development. Keep enabled for production sites.', 'fourthwall_text_domain' ) . '</em></p>' . "\n";
|
||||
echo ' </div>' . "\n";
|
||||
echo '</div>' . "\n";
|
||||
|
||||
}
|
||||
@@ -83,6 +111,43 @@ class fourthwall_settings {
|
||||
|
||||
}
|
||||
|
||||
function render_ssl_verify_field() {
|
||||
|
||||
// Retrieve data from the database.
|
||||
$options = get_option( 'fourthwall_settings_name' );
|
||||
|
||||
// Set default value.
|
||||
$value = isset( $options['ssl_verify'] ) ? $options['ssl_verify'] : '';
|
||||
|
||||
// Field output.
|
||||
echo '<input type="checkbox" name="fourthwall_settings_name[ssl_verify]" value="1" ' . checked( $value, 1, false ) . '>';
|
||||
echo '<p class="description">' . __( 'Enable SSL verification', 'fourthwall_text_domain' ) . '</p>';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all Fourthwall embed cache
|
||||
*/
|
||||
private function clear_fwembed_cache() {
|
||||
global $wpdb;
|
||||
|
||||
// Delete all transients that start with 'fwembed_'
|
||||
$wpdb->query(
|
||||
$wpdb->prepare(
|
||||
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s",
|
||||
'_transient_fwembed_%'
|
||||
)
|
||||
);
|
||||
|
||||
// Also delete transient timeouts
|
||||
$wpdb->query(
|
||||
$wpdb->prepare(
|
||||
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s",
|
||||
'_transient_timeout_fwembed_%'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
new fourthwall_settings;
|
||||
|
Reference in New Issue
Block a user