plugin_slug = $plugin_slug; $this->namespace = $namespace; } // phpcs:ignore Generic.Commenting.DocComment.MissingShort /** * @ignore */ public function register_routes() { $route_base = 'preference-check'; register_rest_route( $this->namespace, '/' . $route_base, array( array( 'methods' => 'POST', 'callback' => array( $this, 'check_preferences' ), 'permission_callback' => function() { return current_user_can( 'manage_options' ); }, 'args' => array(), ), ) ); } /** * Get conflicts. * * @param WP_REST_Request $request Full data about the request. * @return FontAwesome_REST_Response */ public function check_preferences( $request ) { try { fa()->gather_preferences(); $conflicts = fa()->conflicts_by_option( $request->get_json_params() ); return new FontAwesome_REST_Response( $conflicts, 200 ); } catch ( FontAwesome_ServerException $e ) { return new FontAwesome_REST_Response( wpe_fontawesome_server_exception( $e ), 500 ); } catch ( FontAwesome_Exception $e ) { return new FontAwesome_REST_Response( wpe_fontawesome_client_exception( $e ), 400 ); } catch ( Exception $e ) { return new FontAwesome_REST_Response( wpe_fontawesome_unknown_error( $e ), 500 ); } catch ( Error $e ) { return new FontAwesome_REST_Response( wpe_fontawesome_unknown_error( $e ), 500 ); } } }