Skip to content

Hooks and filters

Admin Options Pages stores normal WordPress options, so all hooks of WordPress itself work too: pre_option_{$option}, option_{$option}, pre_update_option_{$option} and so on. The hooks below are added by the plugin.

Changing a saved value

When an options page is saved (or an import runs), every value is first sanitized by its field type. After that, two filters let you change it before it is stored.

Filter Arguments Runs for
aop_sanitized_option $value, array $field, $raw every field
aop_sanitized_option_{$option_name} $value, array $field, $raw one field, after the filter above

$value is already sanitized, so you do not have to sanitize it again. $raw is the value as it was posted: use it for reference only, never store it as it is. $field is the stored field, with keys such as type, field_name and field_label.

// Store every email address in lowercase.
add_filter( 'aop_sanitized_option', function ( $value, $field, $raw ) {
    if ( $field['type'] === 'email' ) {
        return strtolower( $value );
    }

    return $value;
}, 10, 3 );

// Remove spaces from one field.
add_filter( 'aop_sanitized_option_phone', function ( $value ) {
    return str_replace( ' ', '', $value );
} );

Replacing the sanitizing

Filter Arguments
aop_sanitize_option_{$option_name} $value

This filter replaces the sanitizing of the field type: whatever it returns is stored. Use it only when the sanitizing of the type is wrong for your field, and sanitize the value yourself.

add_filter( 'aop_sanitize_option_tracking_code', function ( $value ) {
    return preg_replace( '/[^A-Z0-9-]/', '', strtoupper( $value ) );
} );

The wysiwyg editor

Filter Arguments
aop_editor_settings_{$option_name} array $settings

Change the arguments that are passed to wp_editor() for one wysiwyg field.

add_filter( 'aop_editor_settings_intro_text', function ( $settings ) {
    $settings['textarea_rows'] = 5;

    return $settings;
} );

Output on the website

Filter Arguments
aop_display_value string $html, $value, array $field, array $args

Change the HTML that the shortcode and bound blocks show. $args are the attributes of the shortcode. The result is printed as it is, so escape what you add.

add_filter( 'aop_display_value', function ( $html, $value, $field, $args ) {
    if ( $field['field_name'] === 'phone' ) {
        return sprintf( '<a href="tel:%s">%s</a>', esc_attr( $value ), $html );
    }

    return $html;
}, 10, 4 );

Import

Filter Arguments
aop_import_max_bytes int $bytes

The largest file that can be imported, 5 MB by default.

Upgrading

Filter Arguments
aop_backup_days int $days

How many days the copy of your pages from before 1.0 is kept, 90 by default. See Upgrading from 0.9.

Field types

Hook Kind Purpose
aop_register_field_types action Register your own field types.
aop_field_types filter Remove or replace a field type.
aop_enqueue_editor_assets action Load the editor script of your field types.

See Custom field types.