Skip to main content

Read or change a show’s Outlinks affiliate disclosure settings from code

Premium Beginner

GET / PATCH /benecaster-outlinks/v1/shows/{show_id}/disclosure is the route behind the Outlinks tab’s Affiliate disclosure section. It needs manage_options (an X-WP-Nonce for wp_rest) and Outlinks on for {show_id}, else 403 benecaster_outlinks_not_active.

Both methods answer { enabled, text, default_text, max_length }. text is the show’s own wording ('' means the default), default_text is the default in the site’s language, and max_length is 300. A show that has never saved the setting has the disclosure on with the default text.

PATCH { enabled?, text? } changes only the keys sent. enabled must be a JSON boolean. text is cleaned with sanitize_text_field(); '', null or the default’s exact words are stored as ''. Over 300 characters is 400 benecaster_outlinks_disclosure_invalid with data.field, and nothing is saved.

Code

<?php
wp_set_current_user( 1 );
$request = new WP_REST_Request( 'PATCH', '/benecaster-outlinks/v1/shows/12/disclosure' );
$request->set_header( 'X-WP-Nonce', wp_create_nonce( 'wp_rest' ) );
$request->set_body_params( [ 'text' => 'We earn from qualifying purchases.' ] );
$settings = rest_do_request( $request )->get_data(); // [ 'enabled' => true, 'text' => 'We earn from qualifying purchases.', … ]

View on GitHub →

Need this built rather than just documented? See our services →