<?php
/**
 * @link              https://www.planaday.nl
 * @since             1.0.0
 * @package           Planaday_Api
 *
 * @wordpress-plugin
 * Plugin Name:       Planaday API
 * Plugin URI:        https://planaday.freshdesk.com/support/solutions/articles/11000058859-wordpress-in-website-met-publieke-api
 * Description:       Toon en boek cursussen samen met Planaday in een wordpress website. Dit kan middels een lijst, op cursussoort, label of alle cursussen en in verschillende formats met eigen opmaak
 * Version:           11.7
 * Author:            Planaday development
 * Author URI:        https://www.planaday.nl
 * License:           GPL-2.0+
 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
 * Text Domain:       planaday-api
 * Domain Path:       /languages
 */

! defined( 'ABSPATH' ) and exit;

require_once( 'src/includes/validate.php' );
require_once( 'src/includes/date.php' );
require_once( 'src/includes/functions.php' );
require_once( 'src/includes/database.php' );
require_once( 'src/api/api.php' );

function planaday_echo_warnings(): void {
	$phpVersion = explode('.', phpversion());

		if (((int)$phpVersion[0] < 8 || (int)$phpVersion[0] == 8 && (int)$phpVersion[1] < 2)) {
			echo '<div class="notice notice-error" style="display: grid; grid-template-columns: 75px calc(100% - 75px); grid-gap: 10px; min-height: 40px"><img src="/wp-content/plugins/planaday-api/assets/logobreed.png" alt="Planaday Logo" style="max-width: 100%; max-height: 100%; align-self: center"><p>De volgende plugin (Planaday Connector) zal een php versie van 8.2 of nieuwer vereisen. Jouw website gebruikt nog PHP ' . phpversion() . ', om te zien hoe je kan updaten klik <a href="https://wordpress.org/support/update-php/">hier</a>.</p></div>';
		}

	echo '
		<div class="notice notice-error" style="display: grid; grid-template-columns: 75px calc(100% - 75px); grid-gap: 10px; min-height: 40px">
			<img src="/wp-content/plugins/planaday-api/assets/logobreed.png" alt="Planaday Logo" style="max-width: 100%; max-height: 100%; align-self: center">
			<p>
				De Planaday Api plugin is verouderd en is vervangen met de Planaday Connector. Deze vind je <a href="https://wordpress.org/plugins/planaday-connector/" target="_blank" rel="noopener noreferrer">hier</a>.<br>
				Meer informatie over de nieuwe plugin kan je <a href="https://praatmee.planaday.nl/t/de-nieuwe-wordpress-plugin-is-live-planaday-connector/319" target="_blank" rel="noopener noreferrer">hier</a> vinden en een handleiding voor de installatie is <a href="https://https://planaday.freshdesk.com/a/solutions/articles/11000058859" target="_blank" rel="noopener noreferrer">hier</a> te vinden.
			</p>
		</div>
	';
}

add_action( 'plugins_loaded', [ api::planaday_api_get_instance(), 'planaday_api_plugin_setup' ] );
add_action( 'init', 'plugin_load_textdomain' );
add_action( 'init', 'register_script' );
add_action( 'wp_enqueue_scripts', 'enqueue_style' );
add_action( 'widgets_init', 'my_register_custom_widget' );
add_action( 'admin_enqueue_scripts', 'editor_scripts' );
add_action( 'paytium_after_pt_show_payment_details', 'paytium_redirect_after_payment', 10, 1 );
add_action( 'wp_enqueue_scripts', 'registreer_extra_stylesheet', 98 );
add_action( 'plugins_loaded', 'sccss_maybe_print_css2' );
add_action( 'admin_notices', 'planaday_echo_warnings' );

function pad_cron_activation(): void {
	if ( ! wp_next_scheduled( 'pad_cron_update_all_courses' ) ):
		wp_schedule_event( time(), 'hourly', 'pad_cron_update_all_courses' );
	endif;
}

add_action( 'wp', 'pad_cron_activation' );
add_action( 'pad_cron_update_all_courses', 'pad_cron_update_all_courses' );

$pluginData    = get_file_data( __FILE__, [ 'Version' => 'Version' ], false );
$pluginVersion = $pluginData['Version'];
define( 'PLANADAYAPI_CURRENT_VERSION', $pluginVersion );
define( 'PLANADAYAPI_CURRENT_VERSION_INT', str_replace( '.', '_', $pluginVersion ) );

pad_update_to_latest_version();
