<?php
/**
 * filters.php
 *
 * @since      1.0.0
 * @author     alfiopiccione <alfio.piccione@gmail.com>
 * @license    http://opensource.org/licenses/gpl-2.0.php GPL v2
 *
 * Copyright (C) 2025 POP
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

if (! defined('ABSPATH')) {
    exit; // Exit if accessed directly.
}

// include filters.php for WooCommerce
include_once \WcElectronInvoice\Plugin::getPluginDirPath('/inc/wc/filters.php');

$optionPage = \WcElectronInvoice\Admin\Settings\OptionPage::init();

//
//  array(
//      'filter'        => ''
//      'callback'      => ''
//      'priority'      => ''
//      'accepted_args' => ''
//  )
//
$filters = array(
    'inc' => array(
        'action' => array(
            /**
             * Options
             *
             * - adminToolbar @since 1.0.0
             */
            array(
                'filter'   => 'admin_bar_menu',
                'callback' => array($optionPage, 'adminToolbar'),
                'priority' => 100,
            ),

            /**
             * Remove temp Xml files @since 1.0.0
             */
            array(
                'filter'   => 'wp_loaded',
                'callback' => 'WcElectronInvoice\\Xml\\CreateXml::deleteTempXmlFiles',
                'priority' => 20,
            ),

            /**
             * Remove temp Zip files @since 1.0.0
             */
            array(
                'filter'   => 'wp_loaded',
                'callback' => 'WcElectronInvoice\\Xml\\CreateXml::deleteTempZipFiles',
                'priority' => 100,
            ),

            /**
             * Protected diagnostic log viewer.
             */
            array(
                'filter'   => 'admin_post_wc_el_inv_view_log',
                'callback' => 'WcElectronInvoice\\Functions\\viewDiagnosticLog',
                'priority' => 10,
            ),
        ),
        'filter' => array(
            /**
             * Support w3tc
             *
             * - w3tc_can_print_comment - delete comments from XML
             */
            array(
                'filter'   => 'w3tc_can_print_comment',
                'callback' => function ($can_print) {
                    if (defined('IS_POP_XML_RESPONSE') && IS_POP_XML_RESPONSE === true) {
                        return false;
                    }

                    return $can_print;
                },
                'priority' => 10,
            ),

        ),
    ),
);

return apply_filters('wc_el_inv-filters', $filters);
