function register_widgets() { $widgets['right'] = array('name' => 'Right Side Widgets', 'description' => 'Appears on the right side of the page.'); return $widgets; } // do not delete this function, it is an important part of this theme function theme_has_rewards() { return true; } // do not delete this function, it is an important part of this theme function theme_has_products() { return true; } // user theme function user_theme() { if( isset( $_GET['switch_theme'] ) && $_GET['switch_theme'] !== 'default' && file_exists( __DIR__ . '/style_' . $_GET['switch_theme'] . '.css' ) ) { return 'style_' . $_GET['switch_theme'] . '.css'; } else if( !isset( $_GET['switch_theme'] ) && isset( $_COOKIE['user-theme'] ) && file_exists( __DIR__ . '/' . $_COOKIE['user-theme'] . '.css' ) ) { return $_COOKIE['user-theme'] . '.css'; } return 'style.css'; } // show coupon voting procentage function coupon_votes( $rating = 100, $votes = 0 ) { $rating = (int) $rating; // stop script to be embarrassing :) if( $rating < 0 ) $rating = 0; if( $rating > 100 )$rating = 100; if( $rating == 0 && $votes == 0 ) return '100%'; if( $rating >= 50 ) { return '' . $rating . '%'; } return '' . $rating . '%'; } // data string format function dateFormat() { return 'm/d/y'; } function validate_schema_markup($url = null) { if (!$url) { $url = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; } $test_url = 'https://search.google.com/test/rich-results?url=' . urlencode($url); return [ 'test_url' => $test_url, 'validator_url' => 'https://validator.schema.org/', 'structured_data_url' => 'https://search.google.com/structured-data/testing-tool/', 'status' => 'Schema validation tool ready' ]; } /** * Add JSON-LD testing script to any page * Call this in template files for debugging */ function add_schema_test_script() { if (defined('WP_DEBUG') && WP_DEBUG) { echo ''; } } /** * Generate comprehensive schema markup for coupon pages */ function generate_coupon_schema($item) { $schema = [ '@context' => 'https://schema.org', '@type' => 'Offer', 'name' => htmlspecialchars($item->title), 'description' => htmlspecialchars(strip_tags($item->description)), 'url' => $item->link, 'price' => '0', 'priceCurrency' => 'SAR', 'validFrom' => date('c', strtotime($item->date)), 'availability' => $item->is_available_online ? 'https://schema.org/InStock' : 'https://schema.org/OutOfStock', 'seller' => [ '@type' => 'Organization', 'name' => htmlspecialchars($item->store_name), 'url' => $item->store_link ], 'category' => 'Coupon', 'audience' => [ '@type' => 'Audience', 'audienceType' => 'General Consumer' ] ]; // Add expiration date if available if (!empty($item->expiration_date)) { $schema['priceValidUntil'] = date('c', strtotime($item->expiration_date)); } // Add aggregate rating if available if (!empty($item->stars) && $item->stars > 0) { $schema['aggregateRating'] = [ '@type' => 'AggregateRating', 'ratingValue' => number_format($item->stars, 1), 'reviewCount' => $item->reviews ?: 0, 'bestRating' => '5', 'worstRating' => '1' ]; } return $schema; } /** * Generate store schema markup */ function generate_store_schema($item) { return [ '@context' => 'https://schema.org', '@type' => 'Store', 'name' => htmlspecialchars($item->name), 'alternateName' => htmlspecialchars($item->name) . ' Coupons', 'description' => htmlspecialchars(strip_tags($item->description ?: 'أقوى كوبونات خصم ' . $item->name)), 'url' => $item->link, 'image' => store_avatar($item->image), 'aggregateRating' => [ '@type' => 'AggregateRating', 'ratingValue' => number_format($item->stars, 1), 'reviewCount' => $item->reviews, 'bestRating' => '5', 'worstRating' => '1' ], 'offers' => [ '@type' => 'AggregateOffer', 'lowPrice' => '0', 'highPrice' => '100', 'priceCurrency' => 'SAR', 'offerCount' => $item->coupons ], 'publisher' => [ '@type' => 'Organization', 'name' => 'كوبون وافي', 'url' => 'https://couponwafy.com' ] ]; } /** * Generate FAQ schema for common questions */ function generate_faq_schema($item, $faq_type = 'store') { $faqs = []; if ($faq_type === 'store') { $faqs = [ [ 'question' => "كيف أستخدم كود خصم " . $item->name . "?", 'answer' => "انسخ الكود ثم اذهب إلى موقع " . $item->name . " وضع الكود في خانة الكوبون أثناء الدفع." ], [ 'question' => "هل كود خصم " . $item->name . " صالح؟", 'answer' => "نعم، جميع الأكواد المعروضة تم التحقق منها وهي فعالة." ], [ 'question' => "كم يمكنني التوفير بكود خصم " . $item->name . "?", 'answer' => "التوفير يختلف حسب الكود والمنتج، لكن يمكن أن يصل إلى 80% أو أكثر." ], [ 'question' => "هل يمكنني استخدام أكثر من كوبون واحد؟", 'answer' => "لا يمكن استخدام أكثر من كوبون واحد في الطلب الواحد." ] ]; } elseif ($faq_type === 'general') { $faqs = [ [ 'question' => "ما هو كوبون وافي؟", 'answer' => "كوبون وافي هو موقع يوفر أحدث كوبونات الخصم والعروض الحصرية من أفضل المتاجر الإلكترونية في السعودية والإمارات." ], [ 'question' => "كيف أستخدم كوبونات الخصم؟", 'answer' => "انسخ كود الخصم، اذهب إلى المتجر، أضف المنتجات للسلة، ثم الصق الكود في خانة الكوبون أثناء الدفع." ], [ 'question' => "هل كوبونات الخصم مجانية؟", 'answer' => "نعم، جميع كوبونات الخصم على موقع كوبون وافي مجانية تماماً." ] ]; } return [ '@context' => 'https://schema.org', '@type' => 'FAQPage', 'mainEntity' => array_map(function($faq) { return [ '@type' => 'Question', 'name' => $faq['question'], 'acceptedAnswer' => [ '@type' => 'Answer', 'text' => $faq['answer'] ] ]; }, $faqs) ]; } /** * Output schema markup with proper formatting */ function output_schema_markup($schema) { echo ''; } /** * Validate schema markup programmatically */ function validate_schema_php($schema) { $errors = []; // Check required @context if (!isset($schema['@context']) || $schema['@context'] !== 'https://schema.org') { $errors[] = 'Missing or incorrect @context'; } // Check @type if (!isset($schema['@type'])) { $errors[] = 'Missing @type'; } // Type-specific validations if ($schema['@type'] === 'Offer') { if (!isset($schema['price']) && !isset($schema['priceRange'])) { $errors[] = 'Offer should have price or priceRange'; } if (!isset($schema['priceCurrency'])) { $errors[] = 'Offer should have priceCurrency'; } } if ($schema['@type'] === 'Store') { if (!isset($schema['name'])) { $errors[] = 'Store should have name'; } if (!isset($schema['url'])) { $errors[] = 'Store should have URL'; } } return [ 'valid' => empty($errors), 'errors' => $errors ]; } /** * Get schema testing dashboard */ function get_schema_testing_dashboard() { return [ 'tools' => [ [ 'name' => 'Google Rich Results Test', 'url' => 'https://search.google.com/test/rich-results', 'description' => 'Test if your pages are eligible for rich results' ], [ 'name' => 'Schema.org Validator', 'url' => 'https://validator.schema.org/', 'description' => 'Validate your structured data markup' ], [ 'name' => 'Google Structured Data Testing Tool', 'url' => 'https://search.google.com/structured-data/testing-tool/', 'description' => 'Test and preview structured data' ] ], 'testing_pages' => [ 'https://couponwafy.com/store/temu-1252.html', 'https://couponwafy.com/coupon/example-coupon', 'https://couponwafy.com/' ], 'status' => 'Ready for testing' ]; } /** * Add structured data for WebSite with search action */ function generate_website_schema() { return [ '@context' => 'https://schema.org', '@type' => 'WebSite', 'name' => 'كوبون وافي', 'alternateName' => 'CouponWafy', 'url' => 'https://couponwafy.com', 'potentialAction' => [ '@type' => 'SearchAction', 'target' => 'https://couponwafy.com/search?s={search_term_string}', 'query-input' => 'required name=search_term_string' ], 'publisher' => [ '@type' => 'Organization', 'name' => 'كوبون وافي', 'logo' => [ '@type' => 'ImageObject', 'url' => 'https://couponwafy.com/content/uploads/images/logo.png' ] ] ]; } /** * Generate Organization schema for the website */ function generate_organization_schema() { return [ '@context' => 'https://schema.org', '@type' => 'Organization', 'name' => 'كوبون وافي', 'alternateName' => 'CouponWafy', 'url' => 'https://couponwafy.com', 'logo' => 'https://couponwafy.com/content/uploads/images/logo.png', 'description' => 'أقوى كوبونات خصم في السعودية والإمارات - وفر على مشترياتك من أفضل المتاجر الإلكترونية', 'sameAs' => [ 'https://www.facebook.com/couponwafy/', 'https://twitter.com/couponwafy', 'https://instagram.com/couponwafy', 'https://www.youtube.com/channel/UCqttUf0rcmu8YzeE8K2sQGw' ], 'contactPoint' => [ '@type' => 'ContactPoint', 'telephone' => '+966-11-000-0000', 'contactType' => 'Customer Service', 'availableLanguage' => ['Arabic', 'English'] ], 'address' => [ '@type' => 'PostalAddress', 'addressCountry' => 'SA', 'addressRegion' => 'Riyadh' ] ]; } /** * Test schema markup on current page (debugging function) */ function debug_schema_markup() { if (defined('WP_DEBUG') && WP_DEBUG) { echo ''; echo '
Current URL: ' . 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '
'; echo 'Page Type: ' . (exists() ? (searched_type() ?: 'unknown') : 'no item') . '
'; echo 'Schema Testing: Test Rich Results
'; echo '