This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
programmieren:wordpress:rest_api_einrichten [2021/07/26 15:26] – jgehrke | programmieren:wordpress:rest_api_einrichten [2022/12/17 12:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 52: | Line 52: | ||
]; | ]; | ||
- | return$return_array; | + | return $return_array; |
} | } | ||
</ | </ | ||
+ | |||
+ | ===== Alternative Schreibweise als Klasse/ | ||
+ | |||
+ | Es ist sinnvoll die Registrierung der REST-API Route in Wordpress in eine eigene Klasse zu packen. Man verhindert Namenskonflikte, | ||
+ | |||
+ | <code php> | ||
+ | /** | ||
+ | * | ||
+ | */ | ||
+ | class CreateTrackingPoint | ||
+ | { | ||
+ | |||
+ | function __construct() | ||
+ | { | ||
+ | add_action( ' | ||
+ | } | ||
+ | |||
+ | public function register_endpoint() | ||
+ | { | ||
+ | // / | ||
+ | $namespace = ' | ||
+ | $route | ||
+ | $args | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ]; | ||
+ | |||
+ | register_rest_route( $namespace, $route, $args ); | ||
+ | } | ||
+ | |||
+ | public function render_endpoint( $request ) { | ||
+ | |||
+ | $user_id | ||
+ | | ||
+ | |||
+ | $return_array = [ | ||
+ | ' | ||
+ | ' | ||
+ | ]; | ||
+ | |||
+ | |||
+ | |||
+ | return $return_array; | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ |