Astra_Ext_Advanced_Hooks_Meta::sanitize_hook_actions( mixed $rows )

Sanitize the multi-hook placement rows.


Description

Each row is { action, custom }; custom only matters when action is custom_hook. Rows without a usable hook name are dropped and duplicates (by resolved hook name) are removed.


Parameters

$rows

(Required) Raw rows from the request.


Return

(array) Clean rows.


Source

File: addons/advanced-hooks/classes/class-astra-ext-advanced-hooks-meta.php

		public static function sanitize_hook_actions( $rows ) {
			$clean = array();
			$seen  = array();

			if ( ! is_array( $rows ) ) {
				return $clean;
			}

			foreach ( $rows as $row ) {
				if ( ! is_array( $row ) ) {
					continue;
				}
				$action = isset( $row['action'] ) ? sanitize_text_field( $row['action'] ) : '';
				$custom = isset( $row['custom'] ) ? sanitize_text_field( $row['custom'] ) : '';

				if ( '' === $action || '0' === $action ) {
					continue;
				}
				if ( 'custom_hook' !== $action ) {
					$custom = '';
				} elseif ( '' === $custom ) {
					continue;
				}

				$resolved = 'custom_hook' === $action ? $custom : $action;
				if ( isset( $seen[ $resolved ] ) ) {
					continue;
				}
				$seen[ $resolved ] = true;

				$clean[] = array(
					'action' => $action,
					'custom' => $custom,
				);
			}

			return $clean;
		}

Changelog

Changelog
Version Description
4.13.11 Introduced.


User Contributed Notes

You must log in before being able to contribute a note or feedback.