Page_API::save_page( string $nonce )
Save a Facebook Page using ajax.
Contents
Parameters
- $nonce
-
(string) (Required) The save action nonce to check.
Return
(string) An html message for success or failure when saving.
Source
File: src/Tribe/Meetings/Facebook/Page_API.php
public function save_page( $nonce ) {
if ( ! $this->check_ajax_nonce( Settings::$save_action, $nonce ) ) {
return false;
}
$local_id = tribe_get_request_var( 'local_id' );
// If there is no local id fail the request.
if ( empty( $local_id ) ) {
$error_message = _x(
'The local id to save the Facebook Page is missing.',
'The local id for the facebook page is missing error message.',
'events-virtual'
);
tribe( Template_Modifications::class )->get_settings_message_template( $error_message, 'error' );
wp_die();
}
$page_name = tribe_get_request_var( 'page_name' );
$page_id = tribe_get_request_var( 'page_id' );
// If there is no page name or page id fail the request.
if ( empty( $page_name ) || empty( $page_id ) ) {
$error_message = _x(
'The Facebook Page Name or ID is missing.',
'Facebook Page Name or ID is missing error message.',
'events-virtual'
);
tribe( Template_Modifications::class )->get_settings_message_template( $error_message, 'error' );
wp_die();
}
// If no page, setup initial fields
$page_data = $this->get_page_by_id( $local_id );
if ( empty( $page_data['local_id'] ) ) {
$page_data = [
'local_id' => esc_attr( $local_id ),
'name' => esc_attr( $page_name ),
'page_id' => esc_attr( $page_id ),
'access_token' => '',
'expiration' => '',
];
} else {
// Otherwise update an existing page.
$page_data['name'] = esc_attr( $page_name );
$page_data['page_id'] = esc_attr( $page_id );
}
$this->set_page_by_id( $page_data );
$message = _x(
'Facebook Page Saved.',
'Facebook Page is saved to the options.',
'events-virtual'
);
tribe( Template_Modifications::class )->get_settings_message_template( $message );
$page = $this->get_page_by_id( $local_id );
tribe( Template_Modifications::class )->get_page_fields( $local_id, $page );
wp_die();
}
Changelog
| Version | Description |
|---|---|
| 1.7.0 | Introduced. |