2024-12-27 14:10:25 -08:00
< ? php
class fourthwall_settings {
public function __construct () {
add_action ( 'admin_menu' , array ( $this , 'add_admin_menu' ) );
add_action ( 'admin_init' , array ( $this , 'init_settings' ) );
}
public function add_admin_menu () {
add_menu_page (
esc_html__ ( 'Fourthwall Store Embed' , 'fourthwall_text_domain' ),
esc_html__ ( 'FourthWall Embed' , 'fourthwall_text_domain' ),
'manage_options' ,
'fwembed' ,
array ( $this , 'fourthwall_page_layout' ),
'dashicons-store' ,
10
);
}
public function init_settings () {
register_setting (
'fourthwall_settings_group' ,
'fourthwall_settings_name'
);
add_settings_section (
'fourthwall_settings_name_section' ,
'' ,
false ,
'fourthwall_settings_name'
);
add_settings_field (
'fourth_url' ,
__ ( 'Store URL' , 'fourthwall_text_domain' ),
array ( $this , 'render_fourth_url_field' ),
'fourthwall_settings_name' ,
'fourthwall_settings_name_section'
);
2025-06-24 11:21:04 -07:00
add_settings_field (
'ssl_verify' ,
__ ( 'SSL Verification' , 'fourthwall_text_domain' ),
array ( $this , 'render_ssl_verify_field' ),
'fourthwall_settings_name' ,
'fourthwall_settings_name_section'
);
2024-12-27 14:10:25 -08:00
}
public function fourthwall_page_layout () {
// Check required user capability
if ( ! current_user_can ( 'manage_options' ) ) {
wp_die ( esc_html__ ( 'You do not have sufficient permissions to access this page.' , 'fourthwall_text_domain' ) );
}
2025-06-24 11:21:04 -07:00
// 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>' ;
}
2024-12-27 14:10:25 -08:00
// Admin Page Layout
echo '<div class="wrap">' . " \n " ;
echo ' <h1>' . get_admin_page_title () . '</h1>' . " \n " ;
echo ' <form action="options.php" method="post">' . " \n " ;
settings_fields ( 'fourthwall_settings_group' );
do_settings_sections ( 'fourthwall_settings_name' );
submit_button ();
echo ' </form>' . " \n " ;
2025-06-24 11:21:04 -07:00
// 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 " ;
2025-06-24 11:40:08 -07:00
echo ' <p><strong>' . __ ( 'Display random products:' , 'fourthwall_text_domain' ) . '</strong> <code>[fourthwall_random count="5"]</code></p>' . " \n " ;
echo ' <p><strong>' . __ ( 'Random from specific URLs:' , 'fourthwall_text_domain' ) . '</strong> <code>[fourthwall_random count="3" urls="https://store.com/product1,https://store.com/product2,https://store.com/product3"]</code></p>' . " \n " ;
echo ' <p><strong>' . __ ( 'Random from different store:' , 'fourthwall_text_domain' ) . '</strong> <code>[fourthwall_random count="2" store_url="https://different-store.fourthwall.com"]</code></p>' . " \n " ;
2025-06-24 11:21:04 -07:00
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 " ;
2024-12-27 14:10:25 -08:00
echo '</div>' . " \n " ;
}
function render_fourth_url_field () {
// Retrieve data from the database.
$options = get_option ( 'fourthwall_settings_name' );
// Set default value.
$value = isset ( $options [ 'fourth_url' ] ) ? $options [ 'fourth_url' ] : '' ;
// Field output.
echo '<input type="url" name="fourthwall_settings_name[fourth_url]" class="regular-text fourth_url_field" placeholder="' . esc_attr__ ( 'https://some-shop.fourthwall.com' , 'fourthwall_text_domain' ) . '" value="' . esc_attr ( $value ) . '">' ;
echo '<p class="description">' . __ ( 'The fourth wall URL' , 'fourthwall_text_domain' ) . '</p>' ;
}
2025-06-24 11:21:04 -07:00
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_%'
)
);
}
2024-12-27 14:10:25 -08:00
}
new fourthwall_settings ;