Skip to content

Commit

Permalink
REST interface for getting hello bar data (#598)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Abraham <[email protected]>
  • Loading branch information
cjyabraham committed Sep 16, 2024
1 parent 3dd0e63 commit 289a6e0
Showing 1 changed file with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ class LF_MU_REST_Controller extends WP_REST_Controller {
public function register_routes() {
$version = '1';
$namespace = 'lf/v' . $version;
$base = 'sync_people';

register_rest_route(
$namespace,
'/' . $base,
'/sync_people',
array(
array(
'methods' => WP_REST_Server::ALLMETHODS,
Expand All @@ -39,6 +39,19 @@ public function register_routes() {
),
)
);

register_rest_route(
$namespace,
'/get_hello',
array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_hello' ),
'permission_callback' => '__return_true',
'args' => array(),
),
)
);
}

/**
Expand Down Expand Up @@ -66,4 +79,22 @@ public function sync_people( $request ) {

return new WP_REST_Response( array( 'Success' ), 200 );
}

/**
* Get hello bar data.
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|WP_REST_Response
*/
public function get_hello( $request ) {
$items = array();

$options = get_option( 'lf-mu' );
$items['show_hello_bar'] = ( isset( $options['show_hello_bar'] ) && ! empty( $options['show_hello_bar'] ) ) ? 1 : 0;
$items['hello_bar_content'] = ( isset( $options['hello_bar_content'] ) && ! empty( $options['hello_bar_content'] ) ) ? $options['hello_bar_content'] : '';
$items['hello_bar_bg'] = ( isset( $options['hello_bar_bg'] ) && ! empty( $options['hello_bar_bg'] ) ) ? esc_attr( $options['hello_bar_bg'] ) : '';
$items['hello_bar_text'] = ( isset( $options['hello_bar_text'] ) && ! empty( $options['hello_bar_text'] ) ) ? esc_attr( $options['hello_bar_text'] ) : '';

return new WP_REST_Response( $items, 200 );
}
}

0 comments on commit 289a6e0

Please sign in to comment.