get_logger()->debug( 'Fetching parameters', [ 'plugin' => 'double-opt-in', 'class' => __CLASS__, 'method' => __METHOD__, 'post_id' => $postID, ] ); $data = [ 'enable' => 0, 'sender' => get_bloginfo( 'admin_email' ), 'sender_name' => '', 'subject' => '', 'body' => '', 'recipient' => '', 'page' => - 1, 'conditions' => 'disabled', 'template' => '', 'category' => 0, ]; $data = apply_filters( 'f12_cf7_doubleoptin_get_parameter', $data ); if ( ! $postID ) { $this->get_logger()->debug( 'No postID provided, returning defaults', [ 'plugin' => 'double-opt-in', ] ); return $data; } $options = get_post_meta( $postID, 'f12-cf7-doubleoptin', true ); if ( ! $options ) { $this->get_logger()->debug( 'No options found for postID, returning defaults', [ 'plugin' => 'double-opt-in', 'post_id' => $postID, ] ); return $data; } $this->get_logger()->debug( 'Options merged with defaults', [ 'plugin' => 'double-opt-in', 'post_id' => $postID, ] ); return array_merge( $data, $options ); } /** * Private constructor to prevent direct instantiation. */ private function __construct() { $this->logger = Logger::getInstance(); if ( ! get_option( 'f12_cf7_doubleoptin_installed_at' ) ) { update_option( 'f12_cf7_doubleoptin_installed_at', time() ); } $this->get_logger()->info( 'Initialization of Forge12 Double Opt-In started', [ 'plugin' => 'double-opt-in', 'class' => __CLASS__, 'method' => __METHOD__, ] ); load_plugin_textdomain( 'double-opt-in', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); $this->get_logger()->debug( 'Textdomain loaded', [ 'plugin' => 'double-opt-in', 'domain' => 'double-opt-in', ] ); do_action( 'f12_cf7_doubleoptin_init', $this ); $this->get_logger()->debug( 'Action f12_cf7_doubleoptin_init executed', [ 'plugin' => 'double-opt-in', ] ); $this->TemplateHandler = TemplateHandler::getInstance(); $this->get_logger()->debug( 'TemplateHandler initialized', [ 'plugin' => 'double-opt-in', ] ); $UI = new UI( $this->get_logger(), $this->TemplateHandler, FORGE12_OPTIN_SLUG, 'Forge12 Double Opt-In', 'manage_options' ); $this->get_logger()->debug( 'UI initialized', [ 'plugin' => 'double-opt-in', ] ); add_action( 'after_setup_theme', array( $this, 'init' ) ); $this->get_logger()->debug( 'Hook after_setup_theme registered', [ 'plugin' => 'double-opt-in', ] ); $Compatibility = new Compatibility( $this ); $this->get_logger()->debug( 'Compatibility initialized', [ 'plugin' => 'double-opt-in', ] ); $CleanUp = new CleanUp( $this->get_logger() ); $this->get_logger()->debug( 'CleanUp initialized', [ 'plugin' => 'double-opt-in', ] ); // Pagination Pagination::getInstance(); $this->get_logger()->debug( 'Pagination initialized', [ 'plugin' => 'double-opt-in', ] ); // initialize filter CategoryOptions::getInstance(); $this->get_logger()->debug( 'CategoryOptions initialized', [ 'plugin' => 'double-opt-in', ] ); OptInLimitFilter::getInstance(); $this->get_logger()->debug( 'OptInLimitFilter initialized', [ 'plugin' => 'double-opt-in', ] ); OptInSearchFilter::getInstance(); $this->get_logger()->debug( 'OptInSearchFilter initialized', [ 'plugin' => 'double-opt-in', ] ); $this->get_logger()->info( 'Initialization of Forge12 Double Opt-In completed', [ 'plugin' => 'double-opt-in', 'class' => __CLASS__, 'method' => __METHOD__, ] ); } public function get_logger() { return $this->logger; } /** * Retrieve the template handler instance. * * @return TemplateHandler The template handler instance. */ public function get_template_handler() { $this->get_logger()->debug( 'TemplateHandler retrieved', [ 'plugin' => 'double-opt-in', 'class' => __CLASS__, 'method' => __METHOD__, ] ); return $this->TemplateHandler; } /** * @private WordPress Hook */ public function init() { $this->get_logger()->debug( 'Init started', [ 'plugin' => 'double-opt-in', 'class' => __CLASS__, 'method' => __METHOD__, ] ); do_action( 'f12_cf7_doubleoptin_register_implementations' ); $this->get_logger()->debug( 'Action f12_cf7_doubleoptin_register_implementations executed', [ 'plugin' => 'double-opt-in', ] ); } /** * Return the settings for the optin. * * @param string $single The Key of the setting to return only the required setting * * @formatter:off * @return { * // Returns the Settings for the DOI * * @type string $optout_subject The Subject for the OptOut Mail * @type string $optout_body The Content for the OptOut Mail * @type int $optout_page The Post ID for the OptOut Page * @type int $support Defines if the Support link will be added to the footer * @type int $delete An integer from 1 to 30 * @type int $delete_unconfirmed An integer from 1 to 30 * @type string $delete_period The time period, either months, days, years * @type string $delete_unconfirmed_period The time period, either months, days, years * } * @formatter:on */ public function getSettings( $single = '', $container = null ) { $this->get_logger()->debug( 'Fetching settings', [ 'plugin' => 'double-opt-in', 'class' => __CLASS__, 'method' => __METHOD__, 'single' => $single, 'container' => $container, ] ); $default = array(); $default = apply_filters( 'f12_cf7_doubleoptin_settings', $default ); $settings = get_option( 'f12-doi-settings' ); if ( ! is_array( $settings ) ) { $this->get_logger()->debug( 'No settings found in options, using empty array', [ 'plugin' => 'double-opt-in', ] ); $settings = array(); } foreach ( $default as $key => $data ) { if ( isset( $settings[ $key ] ) ) { if ( is_array( $default[ $key ] ) ) { $default[ $key ] = array_merge( $default[ $key ], $settings[ $key ] ); } else { $default[ $key ] = $settings[ $key ]; } $this->get_logger()->debug( 'Merged settings for key', [ 'plugin' => 'double-opt-in', 'key' => $key, ] ); } } $settings = $default; if ( ! empty( $single ) ) { if ( $container != null ) { if ( isset( $settings[ $container ] ) && isset( $settings[ $container ][ $single ] ) ) { $this->get_logger()->debug( 'Returning single setting from container', [ 'plugin' => 'double-opt-in', 'container' => $container, 'single' => $single, ] ); $settings = $settings[ $container ][ $single ]; } } } else { if ( isset( $settings[ $single ] ) ) { $this->get_logger()->debug( 'Returning single setting', [ 'plugin' => 'double-opt-in', 'single' => $single, ] ); $settings = $settings[ $single ]; } } return $settings; } } add_action( 'plugins_loaded', function () { add_cron_jobs(); CF7DoubleOptIn::getInstance(); } ); }