'0', 'can-see-submission-data' => 'manage_options', 'datetimeformat-use-wordpress' => '0', 'preferred-mail-format' => 'html', 'display-host' => '0', 'display-attachments' => '0', 'log-rotation-limit-amout' => '0', 'log-rotation-limit-amout-keep' => '75', 'log-rotation-delete-time' => '0', 'log-rotation-delete-time-days' => '30', 'top-level-menu' => '1', ]; /** * Only instance of this object. * * @since 1.11.0 * * @var SettingsTab */ private static $instance = null; /** * Nonce action in saving the settings. * * @since 1.11.0 * * @var string */ const SAVE_SETTINGS_NONCE_ACTION = 'wp-mail-logging-admin-save-settings'; /** * Option name of the settings. * * @since 1.11.0 * * @var string */ const OPTIONS_NAME = 'wpml_settings'; /** * Constructor * * @since 1.11.0 */ private function __construct() { } /** * Get the only instance of this object. * * @since 1.11.0 * * @return SettingsTab */ public static function get_instance() { if ( is_null( self::$instance ) ) { self::$instance = new self; } return self::$instance; } /** * Hooks that are fired earlier. * * @since 1.11.0 * * @return void */ public function hooks() { // Perform save early in `admin_menu` action so it'll know where to put the settings in the admin menu. add_action( 'admin_menu', [ $this, 'save_settings'], 5 ); } /** * Only add hooks here that are invoked after `current_screen` action hook. * * @since 1.11.0 * * @return void */ public function screen_hooks() { add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); add_action( 'admin_notices', [ 'No3x\WPML\WPML_Utils', 'display_admin_notices' ] ); add_action( 'wp_mail_logging_admin_tab_content', [ $this, 'display_tab_content' ] ); add_filter( 'screen_options_show_screen', '__return_false' ); } /** * Save settings from $_POST. * * @since 1.11.0 * * @return void */ public function save_settings() { // Check if we need to save data. $data = filter_input( INPUT_POST, 'wp-mail-logging-setting', FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_REQUIRE_ARRAY ); if ( empty( $data ) || empty( $_POST[ self::SAVE_SETTINGS_NONCE_ACTION ] ) || ! wp_verify_nonce( $_POST[ self::SAVE_SETTINGS_NONCE_ACTION ], self::SAVE_SETTINGS_NONCE_ACTION ) ) { return; } if ( ! current_user_can( 'manage_options' ) ) { return; } $default = self::DEFAULT_SETTINGS; // Use the default if we need to reset. if ( ! empty( $_POST['wp-mail-logging-setting-reset'] ) ) { if ( update_option( self::OPTIONS_NAME, self::DEFAULT_SETTINGS ) ) { WPML_Utils::add_admin_notice( esc_html__( 'Settings saved!', 'wp-mail-logging' ), WPML_Utils::ADMIN_NOTICE_SUCCESS, true ); } return; } $save_data = wp_parse_args( $data, $default ); if ( empty( $data['top-level-menu'] ) ) { $save_data['top-level-menu'] = '0'; } // Sanitize the data. $save_data['log-rotation-limit-amout-keep'] = absint( $save_data['log-rotation-limit-amout-keep'] ); $save_data['log-rotation-delete-time-days'] = absint( $save_data['log-rotation-delete-time-days'] ); if ( update_option( self::OPTIONS_NAME, $save_data ) ) { WPML_Utils::add_admin_notice( esc_html__( 'Settings saved!', 'wp-mail-logging' ), WPML_Utils::ADMIN_NOTICE_SUCCESS, true ); } } /** * Enqueue settings tab scripts. * * @since 1.11.0 * * @return void * * @throws Exception */ public function enqueue_scripts() { $assets_url = WPML_Init::getInstance()->getService( 'plugin' )->get_assets_url(); $plugin_meta = WPML_Init::getInstance()->getService( 'plugin-meta' ); if ( empty( $plugin_meta['version'] ) ) { return; } wp_enqueue_script( 'wp-mail-logging-admin-settings', $assets_url . '/js/wp-mail-logging-admin-settings.js', [ 'jquery', 'wp-mail-logging-jquery-confirm' ], $plugin_meta['version'] ); } /** * Display Settings form. * * @since 1.11.0 * * @return void */ public function display_tab_content() { $saved_settings = self::get_settings( self::DEFAULT_SETTINGS ); ?>