addon = $addon; } public function handleRemoveAll(): bool { $nonce = isset( $_GET['nonce'] ) ? sanitize_text_field( $_GET['nonce'] ) : false; if ( ! wp_verify_nonce( $nonce, self::REMOVE_ALL_CUSTOM_COLUMNS ) ) { $this->getContainer()->getAdminNotifier()->flash( __( 'Invalid nonce, please try again', 'tier-pricing-table' ), AdminNotifier::ERROR ); return wp_safe_redirect( wp_get_referer() ); } foreach ( $this->addon->columnsManager->getColumns() as $column ) { $column->remove(); } $this->addon->columnsManager->updateRawColumns( array() ); $this->getContainer()->getAdminNotifier()->flash( __( 'Columns were deleted successfully.', 'tier-pricing-table' ) ); return wp_safe_redirect( wp_get_referer() ); } public function handleRemove(): bool { $nonce = isset( $_GET['nonce'] ) ? sanitize_text_field( $_GET['nonce'] ) : false; if ( ! wp_verify_nonce( $nonce, self::REMOVE_COLUMN_ACTION ) ) { $this->getContainer()->getAdminNotifier()->flash( __( 'Invalid nonce, please try again', 'tier-pricing-table' ), AdminNotifier::ERROR ); return wp_safe_redirect( wp_get_referer() ); } $slug = ! empty( $_GET['slug'] ) ? sanitize_text_field( $_GET['slug'] ) : false; if ( ! $slug ) { $this->getContainer()->getAdminNotifier()->flash( __( 'Invalid column.', 'tier-pricing-table' ), AdminNotifier::ERROR ); } else { if ( $this->addon->columnsManager->removeColumn( $slug ) ) { $this->getContainer()->getAdminNotifier()->flash( __( 'Column removed successfully.', 'tier-pricing-table' ) ); } else { $this->getContainer()->getAdminNotifier()->flash( __( 'Something went wrong. Please try again.', 'tier-pricing-table' ), AdminNotifier::ERROR ); } } return wp_safe_redirect( wp_get_referer() ); } public function handleAddNew(): bool { $nonce = isset( $_GET['nonce'] ) ? sanitize_text_field( $_GET['nonce'] ) : false; if ( ! wp_verify_nonce( $nonce, self::ADD_NEW_ACTION ) ) { $this->getContainer()->getAdminNotifier()->flash( __( 'Invalid nonce, please try again', 'tier-pricing-table' ), AdminNotifier::ERROR ); return wp_safe_redirect( wp_get_referer() ); } $name = ! empty( $_GET['name'] ) ? sanitize_text_field( $_GET['name'] ) : false; $type = ! empty( $_GET['type'] ) ? sanitize_text_field( $_GET['type'] ) : false; $dataType = ! empty ( $_GET['data_type'] ) ? sanitize_text_field( $_GET['data_type'] ) : false; $slug = strtolower( wp_generate_password( 10, false ) ); $columnInstance = $this->addon->columnsManager->getColumnInstance( $slug, array( 'name' => $name, 'type' => $type, 'data_type' => $dataType, ) ); try { if ( $columnInstance && $columnInstance->save() ) { $this->getContainer()->getAdminNotifier()->flash( __( 'Column added successfully.', 'tier-pricing-table' ) ); } else { $this->getContainer()->getAdminNotifier()->flash( __( 'Something went wrong. Please try again.', 'tier-pricing-table' ), AdminNotifier::ERROR ); } } catch ( \Exception $e ) { $this->getContainer()->getAdminNotifier()->flash( __( 'Invalid column data.', 'tier-pricing-table' ), AdminNotifier::ERROR ); } return wp_safe_redirect( wp_get_referer() ); } public function handleUpdate(): bool { $nonce = isset( $_GET['nonce'] ) ? sanitize_text_field( $_GET['nonce'] ) : false; if ( ! wp_verify_nonce( $nonce, self::UPDATE_ACTION ) ) { $this->getContainer()->getAdminNotifier()->flash( __( 'Invalid nonce, please try again', 'tier-pricing-table' ), AdminNotifier::ERROR ); return wp_safe_redirect( wp_get_referer() ); } $slug = ! empty( $_GET['slug'] ) ? sanitize_text_field( $_GET['slug'] ) : false; $name = ! empty( $_GET['name'] ) ? sanitize_text_field( $_GET['name'] ) : false; $type = ! empty( $_GET['type'] ) ? sanitize_text_field( $_GET['type'] ) : false; $dataType = ! empty ( $_GET['data_type'] ) ? sanitize_text_field( $_GET['data_type'] ) : false; $columnInstance = $this->addon->columnsManager->getColumnInstance( $slug, array( 'name' => $name, 'type' => $type, 'data_type' => $dataType, ) ); try { if ( $columnInstance && $columnInstance->save() ) { $this->getContainer()->getAdminNotifier()->flash( __( 'Column edited successfully.', 'tier-pricing-table' ) ); } else { $this->getContainer()->getAdminNotifier()->flash( __( 'Something went wrong. Please try again.', 'tier-pricing-table' ), AdminNotifier::ERROR ); } } catch ( \Exception $e ) { $this->getContainer()->getAdminNotifier()->flash( __( 'Invalid column data.', 'tier-pricing-table' ), AdminNotifier::ERROR ); } return wp_safe_redirect( wp_get_referer() ); } public function renderButton() { ?> addon->columnsManager->getColumns() as $column ) : ?>