include_files(); $this->init_hooks(); $this->register_post_types(); $this->register_taxonomies(); } private function include_files() { require_once PPP_PATH . 'includes/class-subscription-manager.php'; require_once PPP_PATH . 'includes/class-payment-handler.php'; require_once PPP_PATH . 'includes/class-odds-manager.php'; require_once PPP_PATH . 'includes/class-livescore-api.php'; require_once PPP_PATH . 'includes/class-elementor-widgets.php'; require_once PPP_PATH . 'includes/class-ajax-handlers.php'; require_once PPP_PATH . 'includes/class-shortcodes.php'; require_once PPP_PATH . 'includes/class-widgets.php'; require_once PPP_PATH . 'includes/class-admin.php'; require_once PPP_PATH . 'includes/class-install.php'; } private function init_hooks() { register_activation_hook(__FILE__, ['PPP_Install', 'activate']); register_deactivation_hook(__FILE__, ['PPP_Install', 'deactivate']); add_action('init', [$this, 'init']); add_action('plugins_loaded', [$this, 'load_textdomain']); add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts']); add_action('admin_enqueue_scripts', [$this, 'admin_enqueue_scripts']); add_action('rest_api_init', [$this, 'register_rest_routes']); add_shortcode('ppp_daily_predictions', [$this, 'daily_predictions_shortcode']); add_shortcode('ppp_premium_predictions', [$this, 'premium_predictions_shortcode']); add_shortcode('ppp_subscription_plans', [$this, 'subscription_plans_shortcode']); add_shortcode('ppp_payment_form', [$this, 'payment_form_shortcode']); add_shortcode('ppp_live_scores', [$this, 'live_scores_shortcode']); } public function init() { new PPP_Subscription_Manager(); new PPP_Payment_Handler(); new PPP_Odds_Manager(); new PPP_LiveScore_API(); new PPP_Elementor_Widgets(); new PPP_Ajax_Handlers(); new PPP_Shortcodes(); new PPP_Widgets(); new PPP_Admin(); } public function register_post_types() { register_post_type('daily_prediction', [ 'labels' => [ 'name' => __('Daily Predictions', 'premium-predictions-pro'), 'singular_name' => __('Daily Prediction', 'premium-predictions-pro'), 'add_new' => __('Add New Prediction', 'premium-predictions-pro'), 'add_new_item' => __('Add New Daily Prediction', 'premium-predictions-pro'), 'edit_item' => __('Edit Daily Prediction', 'premium-predictions-pro'), 'new_item' => __('New Daily Prediction', 'premium-predictions-pro'), 'view_item' => __('View Daily Prediction', 'premium-predictions-pro'), 'search_items' => __('Search Daily Predictions', 'premium-predictions-pro'), 'not_found' => __('No daily predictions found', 'premium-predictions-pro'), 'not_found_in_trash' => __('No daily predictions found in Trash', 'premium-predictions-pro'), 'all_items' => __('All Daily Predictions', 'premium-predictions-pro'), 'menu_name' => __('Daily Predictions', 'premium-predictions-pro'), ], 'public' => true, 'has_archive' => true, 'supports' => ['title', 'editor', 'thumbnail', 'excerpt', 'custom-fields'], 'menu_icon' => 'dashicons-calendar-alt', 'menu_position' => 5, 'rewrite' => ['slug' => 'daily-predictions'], 'show_in_rest' => true, ]); register_post_type('premium_prediction', [ 'labels' => [ 'name' => __('Premium Predictions', 'premium-predictions-pro'), 'singular_name' => __('Premium Prediction', 'premium-predictions-pro'), 'add_new' => __('Add New Premium Prediction', 'premium-predictions-pro'), 'add_new_item' => __('Add New Premium Prediction', 'premium-predictions-pro'), 'edit_item' => __('Edit Premium Prediction', 'premium-predictions-pro'), 'new_item' => __('New Premium Prediction', 'premium-predictions-pro'), 'view_item' => __('View Premium Prediction', 'premium-predictions-pro'), 'search_items' => __('Search Premium Predictions', 'premium-predictions-pro'), 'not_found' => __('No premium predictions found', 'premium-predictions-pro'), 'not_found_in_trash' => __('No premium predictions found in Trash', 'premium-predictions-pro'), 'all_items' => __('All Premium Predictions', 'premium-predictions-pro'), 'menu_name' => __('Premium Predictions', 'premium-predictions-pro'), ], 'public' => true, 'has_archive' => true, 'supports' => ['title', 'editor', 'custom-fields'], 'menu_icon' => 'dashicons-star-filled', 'menu_position' => 6, 'rewrite' => ['slug' => 'premium-predictions'], 'show_in_rest' => true, ]); } public function register_taxonomies() { register_taxonomy('prediction_league', ['daily_prediction', 'premium_prediction'], [ 'labels' => [ 'name' => __('Leagues', 'premium-predictions-pro'), 'singular_name' => __('League', 'premium-predictions-pro'), 'search_items' => __('Search Leagues', 'premium-predictions-pro'), 'all_items' => __('All Leagues', 'premium-predictions-pro'), 'edit_item' => __('Edit League', 'premium-predictions-pro'), 'update_item' => __('Update League', 'premium-predictions-pro'), 'add_new_item' => __('Add New League', 'premium-predictions-pro'), 'new_item_name' => __('New League Name', 'premium-predictions-pro'), 'menu_name' => __('Leagues', 'premium-predictions-pro'), ], 'hierarchical' => true, 'public' => true, 'rewrite' => ['slug' => 'league'], 'show_in_rest' => true, ]); } public function enqueue_scripts() { wp_enqueue_style('ppp-main', PPP_URL . 'assets/css/style.css', [], PPP_VERSION); wp_enqueue_style('ppp-responsive', PPP_URL . 'assets/css/responsive.css', [], PPP_VERSION); wp_enqueue_style('font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css', [], '6.4.0'); wp_enqueue_style('google-fonts', 'https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&display=swap', [], null); wp_enqueue_script('ppp-main', PPP_URL . 'assets/js/main.js', ['jquery'], PPP_VERSION, true); wp_enqueue_script('ppp-livescore', PPP_URL . 'assets/js/livescore.js', ['jquery'], PPP_VERSION, true); wp_enqueue_script('ppp-payment', PPP_URL . 'assets/js/payment.js', ['jquery'], PPP_VERSION, true); wp_localize_script('ppp-main', 'ppp_ajax', [ 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('ppp_ajax_nonce'), 'rest_url' => rest_url('premium-predictions/v1/'), 'site_url' => home_url(), 'is_user_logged_in' => is_user_logged_in(), 'currency' => 'USD', 'currency_symbol' => '$', ]); } public function admin_enqueue_scripts($hook) { if (strpos($hook, 'premium-predictions') !== false) { wp_enqueue_style('ppp-admin', PPP_URL . 'assets/css/admin.css', [], PPP_VERSION); wp_enqueue_script('ppp-admin', PPP_URL . 'assets/js/admin.js', ['jquery'], PPP_VERSION, true); } } public function register_rest_routes() { register_rest_route('premium-predictions/v1', '/livescores', [ 'methods' => 'GET', 'callback' => [$this, 'get_live_scores'], 'permission_callback' => '__return_true', ]); register_rest_route('premium-predictions/v1', '/predictions/daily', [ 'methods' => 'GET', 'callback' => [$this, 'get_daily_predictions'], 'permission_callback' => '__return_true', ]); } public function get_live_scores() { $api = new PPP_LiveScore_API(); return rest_ensure_response($api->get_live_matches()); } public function get_daily_predictions($request) { $args = [ 'post_type' => 'daily_prediction', 'posts_per_page' => $request->get_param('per_page') ?: 10, 'paged' => $request->get_param('page') ?: 1, ]; $predictions = get_posts($args); $data = []; foreach ($predictions as $prediction) { $data[] = [ 'id' => $prediction->ID, 'title' => $prediction->post_title, 'content' => $prediction->post_content, 'excerpt' => $prediction->post_excerpt, 'link' => get_permalink($prediction), 'odds' => get_post_meta($prediction->ID, '_odds', true), ]; } return rest_ensure_response($data); } public function daily_predictions_shortcode($atts) { ob_start(); include PPP_PATH . 'templates/daily-predictions.php'; return ob_get_clean(); } public function premium_predictions_shortcode($atts) { ob_start(); include PPP_PATH . 'templates/premium-predictions.php'; return ob_get_clean(); } public function subscription_plans_shortcode($atts) { ob_start(); include PPP_PATH . 'templates/subscription-plans.php'; return ob_get_clean(); } public function payment_form_shortcode($atts) { ob_start(); include PPP_PATH . 'templates/payment-form.php'; return ob_get_clean(); } public function live_scores_shortcode($atts) { ob_start(); include PPP_PATH . 'templates/live-scores.php'; return ob_get_clean(); } public function load_textdomain() { load_plugin_textdomain('premium-predictions-pro', false, dirname(PPP_BASENAME) . '/languages'); } } function PremiumPredictionsPro() { return PremiumPredictionsPro::get_instance(); } PremiumPredictionsPro(); function ppp_create_directories() { $directories = [ PPP_PATH . 'templates', PPP_PATH . 'assets/css', PPP_PATH . 'assets/js', PPP_PATH . 'assets/images', PPP_PATH . 'includes', PPP_PATH . 'admin', PPP_PATH . 'languages', ]; foreach ($directories as $dir) { if (!file_exists($dir)) { wp_mkdir_p($dir); } } } add_action('plugins_loaded', 'ppp_create_directories'); PHP; file_put_contents($temp_dir . '/premium-football-predictions.php', $main_file); // Create all the include files $include_files = [ 'class-subscription-manager.php' => 'init_plans(); } private function init_plans() { $settings = get_option(\'ppp_settings\', []); $this->plans = [ \'daily\' => [ \'key\' => \'daily\', \'label\' => __(\'Daily\', \'premium-predictions-pro\'), \'price\' => isset($settings[\'daily_plan_price\']) ? floatval($settings[\'daily_plan_price\']) : 9.99, \'duration\' => 1, \'features\' => [__(\'Access to all daily predictions\', \'premium-predictions-pro\')], ], \'weekly\' => [ \'key\' => \'weekly\', \'label\' => __(\'Weekly\', \'premium-predictions-pro\'), \'price\' => isset($settings[\'weekly_plan_price\']) ? floatval($settings[\'weekly_plan_price\']) : 29.99, \'duration\' => 7, \'features\' => [__(\'Access to all daily predictions\', \'premium-predictions-pro\')], ], \'monthly\' => [ \'key\' => \'monthly\', \'label\' => __(\'Monthly\', \'premium-predictions-pro\'), \'price\' => isset($settings[\'monthly_plan_price\']) ? floatval($settings[\'monthly_plan_price\']) : 79.99, \'duration\' => 30, \'features\' => [__(\'Access to all predictions\', \'premium-predictions-pro\')], ], \'six_months\' => [ \'key\' => \'six_months\', \'label\' => __(\'6 Months\', \'premium-predictions-pro\'), \'price\' => isset($settings[\'six_months_plan_price\']) ? floatval($settings[\'six_months_plan_price\']) : 399.99, \'duration\' => 180, \'features\' => [__(\'Access to all predictions\', \'premium-predictions-pro\')], ], \'yearly\' => [ \'key\' => \'yearly\', \'label\' => __(\'Yearly\', \'premium-predictions-pro\'), \'price\' => isset($settings[\'yearly_plan_price\']) ? floatval($settings[\'yearly_plan_price\']) : 699.99, \'duration\' => 365, \'features\' => [__(\'Access to all predictions\', \'premium-predictions-pro\')], ], ]; } public function get_plans() { return $this->plans; } public function get_plan($key) { return isset($this->plans[$key]) ? $this->plans[$key] : null; } public function get_plan_price($key) { $plan = $this->get_plan($key); return $plan ? $plan[\'price\'] : 0; } public function activate_subscription($user_id, $plan_key, $payment_id = \'\', $payment_gateway = \'\') { global $wpdb; $plan = $this->get_plan($plan_key); if (!$plan) { return false; } $table_name = $wpdb->prefix . \'ppp_subscriptions\'; $wpdb->update($table_name, [\'status\' => \'expired\'], [\'user_id\' => $user_id, \'status\' => \'active\']); $start_date = current_time(\'mysql\'); $end_date = date(\'Y-m-d H:i:s\', strtotime("+{$plan[\'duration\']} days")); return $wpdb->insert($table_name, [ \'user_id\' => $user_id, \'plan\' => $plan_key, \'status\' => \'active\', \'amount\' => $plan[\'price\'], \'start_date\' => $start_date, \'end_date\' => $end_date, \'payment_id\' => $payment_id, \'payment_gateway\' => $payment_gateway, ]); } public function check_access($user_id = null) { if (!$user_id) $user_id = get_current_user_id(); if (!$user_id || user_can($user_id, \'manage_options\')) return true; global $wpdb; $table_name = $wpdb->prefix . \'ppp_subscriptions\'; $subscription = $wpdb->get_row($wpdb->prepare( "SELECT * FROM $table_name WHERE user_id = %d AND status = \'active\' AND end_date > NOW() ORDER BY id DESC LIMIT 1", $user_id )); return !empty($subscription); } }', 'class-payment-handler.php' => 'settings = get_option(\'ppp_settings\', []); add_action(\'wp_ajax_ppp_process_payment\', [$this, \'process_payment_ajax\']); add_action(\'wp_ajax_nopriv_ppp_process_payment\', [$this, \'process_payment_ajax\']); } public function process_payment_ajax() { check_ajax_referer(\'ppp_ajax_nonce\', \'nonce\'); $gateway = sanitize_text_field($_POST[\'gateway\']); $plan = sanitize_text_field($_POST[\'plan\']); $email = sanitize_email($_POST[\'email\']); if (empty($email) || !is_email($email)) { wp_send_json_error([\'message\' => __(\'Invalid email address\', \'premium-predictions-pro\')]); } $subscription_manager = new PPP_Subscription_Manager(); $plan_data = $subscription_manager->get_plan($plan); $user_id = is_user_logged_in() ? get_current_user_id() : $this->create_temporary_user($email); $response = $this->process_payment($gateway, $plan_data, $user_id, $email); if ($response[\'success\']) { wp_send_json_success($response[\'data\']); } else { wp_send_json_error([\'message\' => $response[\'message\']]); } } private function process_payment($gateway, $plan_data, $user_id, $email) { switch ($gateway) { case \'paystack\': return $this->process_paystack_payment($plan_data, $user_id, $email); case \'flutterwave\': return $this->process_flutterwave_payment($plan_data, $user_id, $email); case \'stripe\': return $this->process_stripe_payment($plan_data, $user_id, $email); default: return [\'success\' => false, \'message\' => __(\'Invalid payment gateway\', \'premium-predictions-pro\')]; } } private function process_paystack_payment($plan_data, $user_id, $email) { if (empty($this->settings[\'paystack_secret_key\'])) { return [\'success\' => false, \'message\' => __(\'Paystack is not configured\', \'premium-predictions-pro\')]; } $amount = $plan_data[\'price\'] * 100; $callback_url = home_url(\'/payment-return?gateway=paystack&plan=\' . $plan_data[\'key\']); $url = \'https://api.paystack.co/transaction/initialize\'; $response = wp_remote_post($url, [ \'headers\' => [ \'Authorization\' => \'Bearer \' . $this->settings[\'paystack_secret_key\'], \'Content-Type\' => \'application/json\', ], \'body\' => json_encode([ \'amount\' => $amount, \'email\' => $email, \'callback_url\' => $callback_url, \'metadata\' => [\'user_id\' => $user_id, \'plan\' => $plan_data[\'key\']], ]), \'timeout\' => 30, ]); if (is_wp_error($response)) { return [\'success\' => false, \'message\' => $response->get_error_message()]; } $body = json_decode(wp_remote_retrieve_body($response), true); if ($body[\'status\']) { return [\'success\' => true, \'data\' => [\'authorization_url\' => $body[\'data\'][\'authorization_url\']]]; } return [\'success\' => false, \'message\' => $body[\'message\'] ?? __(\'Payment failed\', \'premium-predictions-pro\')]; } private function process_flutterwave_payment($plan_data, $user_id, $email) { if (empty($this->settings[\'flutterwave_secret_key\'])) { return [\'success\' => false, \'message\' => __(\'Flutterwave is not configured\', \'premium-predictions-pro\')]; } $reference = \'tx_\' . uniqid() . \'_\' . time(); $url = \'https://api.flutterwave.com/v3/payments\'; $response = wp_remote_post($url, [ \'headers\' => [ \'Authorization\' => \'Bearer \' . $this->settings[\'flutterwave_secret_key\'], \'Content-Type\' => \'application/json\', ], \'body\' => json_encode([ \'tx_ref\' => $reference, \'amount\' => $plan_data[\'price\'], \'currency\' => \'USD\', \'redirect_url\' => home_url(\'/payment-return?gateway=flutterwave&plan=\' . $plan_data[\'key\']), \'customer\' => [\'email\' => $email], \'meta\' => [\'user_id\' => $user_id, \'plan\' => $plan_data[\'key\']], ]), \'timeout\' => 30, ]); if (is_wp_error($response)) { return [\'success\' => false, \'message\' => $response->get_error_message()]; } $body = json_decode(wp_remote_retrieve_body($response), true); if ($body[\'status\'] === \'success\') { return [\'success\' => true, \'data\' => [\'redirect_url\' => $body[\'data\'][\'link\']]]; } return [\'success\' => false, \'message\' => $body[\'message\'] ?? __(\'Payment failed\', \'premium-predictions-pro\')]; } private function process_stripe_payment($plan_data, $user_id, $email) { return [\'success\' => false, \'message\' => __(\'Stripe integration coming soon\', \'premium-predictions-pro\')]; } private function create_temporary_user($email) { $username = \'user_\' . uniqid(); $password = wp_generate_password(); $user_id = wp_create_user($username, $password, $email); if (!is_wp_error($user_id)) { wp_set_password($password, $user_id); } return $user_id; } }', 'class-odds-manager.php' => ' \'1.95\', \'draw\' => \'3.40\', \'away_win\' => \'3.80\']; } return $odds; } }', 'class-livescore-api.php' => 'api_key = isset($settings[\'livescore_api_key\']) ? $settings[\'livescore_api_key\'] : \'\'; } public function get_live_matches() { if (empty($this->api_key)) { return $this->get_mock_data(); } $response = wp_remote_get($this->api_url, [ \'headers\' => [\'X-Auth-Token\' => $this->api_key], ]); if (is_wp_error($response)) { return $this->get_mock_data(); } $data = json_decode(wp_remote_retrieve_body($response), true); return $this->format_response($data); } private function format_response($data) { $matches = []; if (isset($data[\'matches\'])) { foreach ($data[\'matches\'] as $match) { $matches[] = [ \'home_team\' => $match[\'homeTeam\'][\'name\'] ?? \'Team A\', \'away_team\' => $match[\'awayTeam\'][\'name\'] ?? \'Team B\', \'home_score\' => $match[\'score\'][\'fullTime\'][\'home\'] ?? 0, \'away_score\' => $match[\'score\'][\'fullTime\'][\'away\'] ?? 0, \'status\' => $match[\'status\'] ?? \'SCHEDULED\', \'league\' => $match[\'competition\'][\'name\'] ?? \'League\', ]; } } return $matches; } private function get_mock_data() { return [ [\'home_team\' => \'Manchester United\', \'away_team\' => \'Liverpool\', \'home_score\' => 2, \'away_score\' => 1, \'status\' => \'LIVE\', \'league\' => \'Premier League\'], [\'home_team\' => \'Real Madrid\', \'away_team\' => \'Barcelona\', \'home_score\' => 1, \'away_score\' => 1, \'status\' => \'LIVE\', \'league\' => \'La Liga\'], [\'home_team\' => \'Bayern Munich\', \'away_team\' => \'Borussia Dortmund\', \'home_score\' => 3, \'away_score\' => 0, \'status\' => \'HALF\', \'league\' => \'Bundesliga\'], ]; } }', 'class-elementor-widgets.php' => ' 'get_live_matches()); } public function update_odds() { check_ajax_referer(\'ppp_ajax_nonce\', \'nonce\'); $post_id = intval($_POST[\'post_id\']); $odds = array_map(\'sanitize_text_field\', $_POST[\'odds\']); update_post_meta($post_id, \'_odds\', $odds); wp_send_json_success([\'message\' => __(\'Odds updated successfully\', \'premium-predictions-pro\')]); } }', 'class-shortcodes.php' => ' \'daily_prediction\', \'posts_per_page\' => 10]); ?>
\' . __(\'Subscribe to access premium predictions\', \'premium-predictions-pro\') . \'
\' . __(\'Subscribe Now\', \'premium-predictions-pro\') . \'__(\'Display recent predictions\', \'premium-predictions-pro\')]); } public function widget($args, $instance) { $count = isset($instance[\'count\']) ? $instance[\'count\'] : 5; $predictions = get_posts([\'post_type\' => [\'daily_prediction\', \'premium_prediction\'], \'posts_per_page\' => $count]); if (empty($predictions)) return; echo $args[\'before_widget\']; echo $args[\'before_title\'] . __(\'Recent Predictions\', \'premium-predictions-pro\') . $args[\'after_title\']; echo \'
'
Welcome to Premium Football Predictions Pro
\'daily_prediction\', \'posts_per_page\' => -1])); ?>
Coming Soon