array( $this, 'sanitize_settings' ) ) ); 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' ); add_settings_field( 'cache_ttl', __( 'Cache Lifetime', 'fourthwall_text_domain' ), array( $this, 'render_cache_ttl_field' ), 'fourthwall_settings_name', 'fourthwall_settings_name_section' ); } /** * Sanitize settings before they are stored. * * @param array $input Raw submitted values * @return array Cleaned values */ public function sanitize_settings( $input ) { $input = is_array( $input ) ? $input : array(); $output = array(); if ( isset( $input['fourth_url'] ) ) { $output['fourth_url'] = esc_url_raw( trim( $input['fourth_url'] ) ); } $ttl = isset( $input['cache_ttl'] ) ? intval( $input['cache_ttl'] ) : 60; $output['cache_ttl'] = $ttl < 1 ? 60 : $ttl; return $output; } 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' ) ); } // Handle cache clearing if (isset($_POST['clear_cache']) && wp_verify_nonce($_POST['_wpnonce'], 'clear_fwembed_cache')) { $this->clear_fwembed_cache(); echo '
' . __('Cache cleared successfully!', 'fourthwall_text_domain') . '
' . __( 'Display entire store:', 'fourthwall_text_domain' ) . ' [fourthwall]
' . __( 'Display single product:', 'fourthwall_text_domain' ) . ' [fourthwall_single url="https://your-store.fourthwall.com/products/product-name"]
' . __( 'With description:', 'fourthwall_text_domain' ) . ' [fourthwall_single url="https://your-store.fourthwall.com/products/product-name" show_description="true"]
' . __( 'Display random products:', 'fourthwall_text_domain' ) . ' [fourthwall_random count="5"]
' . __( 'Random from specific URLs:', 'fourthwall_text_domain' ) . ' [fourthwall_random count="3" urls="https://store.com/product1,https://store.com/product2,https://store.com/product3"]
' . __( 'Random from different store:', 'fourthwall_text_domain' ) . ' [fourthwall_random count="2" store_url="https://different-store.fourthwall.com"]
' . __( 'Random from the store page instead of the sitemap:', 'fourthwall_text_domain' ) . ' [fourthwall_random count="3" source="page"]
' . __( 'Random products are drawn from your store sitemap, which covers your whole catalog. Set source="page" to only use products shown on the store page itself.', 'fourthwall_text_domain' ) . '
' . "\n"; echo '' . __( 'Tip: point the Store URL at your /collections/all page to list every product with [fourthwall].', 'fourthwall_text_domain' ) . '
' . "\n"; echo '' . __( 'The fourth wall URL', 'fourthwall_text_domain' ) . '
'; } function render_cache_ttl_field() { // Retrieve data from the database. $options = get_option( 'fourthwall_settings_name' ); // Set default value. $value = isset( $options['cache_ttl'] ) ? intval( $options['cache_ttl'] ) : 60; if ( $value < 1 ) { $value = 60; } // Field output. echo ' ' . esc_html__( 'minutes', 'fourthwall_text_domain' ); echo '' . __( 'How long store content stays fresh before it is refreshed (default: 60). Expired content is still shown instantly while it refreshes in the background, so raising this does not slow your pages down.', 'fourthwall_text_domain' ) . '
'; } /** * 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;