init(); } /** * Admin actions * * @since 1.0 */ public function admin_actions() { add_action( 'admin_menu', array( $this, 'register_settings_page' ) ); add_action( 'admin_init', array( $this, 'register_settings' ) ); add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) ); if ( isset( $_GET['page'] ) && $_GET['page'] == 'authorized-digital-sellers-txt' ) { add_action( 'admin_head', array( $this, 'settings_page_css' ) ); } } /** * Init * * @since 1.0 */ public function init() { if ( is_admin() ) { $this->admin_actions(); } } /** * Load textdomain * * @since 1.0 */ public function load_textdomain() { load_plugin_textdomain( 'authorized-digital-sellers-txt', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' ); } /** * Register settings page * * @since 1.0 */ public function register_settings_page() { add_options_page( __( 'ADS.txt options', 'authorized-digital-sellers-txt' ), __( 'ADS.txt', 'authorized-digital-sellers-txt' ), 'manage_options', 'authorized-digital-sellers-txt', array( $this, 'settings_page_callback' ) ); } /** * Settings page css. * * @since 1.0 */ public function settings_page_css() { $css = ''; echo $css; } /** * Settings page html * * @since 1.0 */ public function settings_page_callback() { if ( isset( $_POST['authorized_digital_sellers_txt'] ) && current_user_can( 'manage_options' ) ) { if ( wp_verify_nonce( $_POST['_wpnonce'], 'authorized_digital_sellers_txt_nonce' ) ) { $this->write_txt_file( filter_input( INPUT_POST, 'authorized_digital_sellers_txt', FILTER_SANITIZE_STRING ) ); } } $file = get_home_path() . 'ads.txt'; $file_content = file_get_contents( $file ); $txt_content = filter_var( $file_content, FILTER_SANITIZE_STRING ); include 'partials/admin-settings-page.php'; } /** * Write txt file * * @since 1.0 */ public function write_txt_file( $txt ) { $file = get_home_path() . 'ads.txt'; if ( is_writable ( $file ) ) { file_put_contents( $file, filter_var( $txt, FILTER_SANITIZE_STRING ), LOCK_EX ); } else { wp_die( __( 'Not able to write the ads.txt file in the WordPress root directory. Please add it manually or edit the permissions of the folder.', 'authorized-digital-sellers-txt' ) ); exit; } } } new Authorized_Digital_Sellers_Txt(); }