<?php
/**
 * Display Category and Taxonomy List
 *
 * @package           display-category-and-taxonomy-list
 * @author            Nishan
 * @copyright         2026 Nishan
 * @license           GPL-2.0-or-later
 *
 * @wordpress-plugin
 * Plugin Name:       Display Category and Taxonomy List
 * Plugin URI:        https://dcatl.diviaccessories.com/
 * Description:       Display WordPress categories or taxonomies in a responsive grid with images, counters, and styling options—great for blogs and shops.
 * Version:           2.0.0
 * Requires at least: 6.5
 * Requires PHP:      8.2
 * Author:            Nishan Mazumder
 * Author URI:        https://github.com/nishanmazumder
 * Text Domain:       display-category-and-taxonomy-list
 * Domain Path:       /languages
 * License:           GPLv2 or later
 * License URI:       https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 */

use DCATL\Core\Manager;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Define Plugins Constants.
 *
 * @since 1.0.0
 */

define( 'DCATL_PATH', plugin_dir_path( __FILE__ ) );
define( 'DCATL_URL', plugin_dir_url( __FILE__ ) );
define( 'DCATL_NAME', 'display-category-and-taxonomy-list' );
define( 'DCATL_VERSION', '2.0.0' );

/**
 * Loader class.
 *
 * @since 1.0.0
 */
require DCATL_PATH . 'includes/class-manager.php';

$dcatl = new Manager();
$dcatl->kick_dcatl();

register_activation_hook( __FILE__, 'initialize_dcatl' );
register_deactivation_hook( __FILE__, 'halt_dcatl' );
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'dcatl_action_links' );

/**
 * The code that runs during plugin activation.
 *
 * @since 1.0.0
 *
 * @return void
 */
function initialize_dcatl() {

	// Set plugin install date.
	update_user_meta( get_current_user_id(), 'dcatl_install_time', time() );

	// Set a transient to display the welcome message.
	set_transient( 'dcatl_active_notice', true, 5 );
}

/**
 * The code that runs during plugin deactivation.
 *
 * @since 1.0.0
 */
function halt_dcatl() {}

/**
 * Core plugin action links.
 * Includes interface, documentation, and settings.
 *
 * @param string[] $actions An array containing the plugin's action links.
 *
 * @since 1.0.0
 */
function dcatl_action_links( $actions ) {
	$settings_link = sprintf(
		'<a href="%1$s">%2$s</a>',
		esc_url( admin_url( 'admin.php?page=display-category-and-taxonomy-list' ) ),
		esc_html__( 'Settings', 'display-category-and-taxonomy-list' )
	);

	array_unshift( $actions, $settings_link );

	return $actions;
}
