This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
programmieren:wordpress:admin_pages_hinzufuegen [2021/08/19 09:56] – [Settings-Page als PHP-Klasse] jgehrke | programmieren:wordpress:admin_pages_hinzufuegen [2022/12/17 12:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 3: | Line 3: | ||
Mit diesem Code Beispiel werden zwei Options / Settings Pages für Wordpress hinzugefügt. Dieser Code fügt nur die Seiten ins Menü ein. Es müssen noch Render Funktionen geschrieben werden, die eine Ausgabe erzeugen. Der Namespace ist optional, macht die Sache aber sauberer. | Mit diesem Code Beispiel werden zwei Options / Settings Pages für Wordpress hinzugefügt. Dieser Code fügt nur die Seiten ins Menü ein. Es müssen noch Render Funktionen geschrieben werden, die eine Ausgabe erzeugen. Der Namespace ist optional, macht die Sache aber sauberer. | ||
- | ===== Settings-Page Registrieren ===== | + | ===== 1. Settings-Page Registrieren |
<code php> | <code php> | ||
Line 46: | Line 46: | ||
Mehr dazu in der [[https:// | Mehr dazu in der [[https:// | ||
- | ===== HTML Ausgabe und Speichern ===== | ||
- | Page Renderer Function, so etwas wie: | + | ===== 2. Settings-Page als PHP-Klasse ===== |
- | <code php> | + | |
- | function admin_setting_page_theme_links(){ | + | |
- | $menu_slug | + | |
- | $echo | + | |
- | $form_action | + | |
- | + | ||
- | $v = [ | + | |
- | ' | + | |
- | ]; | + | |
- | + | ||
- | require_once ' | + | |
- | } | + | |
- | + | ||
- | /* Rudimentäre Saving & Lade Function */ | + | |
- | function save_and_load_option( $key, $default = null ){ | + | |
- | $value = get_option( $key, $default ); | + | |
- | + | ||
- | if( isset( $_POST[$key] ) ){ | + | |
- | $new_value = $_POST[$key]; | + | |
- | $autoload | + | |
- | update_option( $key, $new_value, $autoload ); | + | |
- | $value | + | |
- | } | + | |
- | + | ||
- | return $new_value; | + | |
- | } | + | |
- | + | ||
- | </ | + | |
- | + | ||
- | HTML-Sub-File für das Template der Settings-Page, | + | |
- | <code php> | + | |
- | <div class=" | + | |
- | < | + | |
- | <form method=" | + | |
- | + | ||
- | <table class=" | + | |
- | < | + | |
- | < | + | |
- | <th scope=" | + | |
- | < | + | |
- | </ | + | |
- | < | + | |
- | < | + | |
- | <p class=" | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | </ | + | |
- | </ | + | |
- | + | ||
- | <?php submit_button(); | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | </ | + | |
- | + | ||
- | ===== Settings-Page als PHP-Klasse ===== | + | |
Es kann nützlich sein Settings als PHP Class oder Objekt zu registrieren, | Es kann nützlich sein Settings als PHP Class oder Objekt zu registrieren, | ||
Line 171: | Line 113: | ||
} | } | ||
} | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== 3. HTML Ausgabe und Speichern (rudimentär) ===== | ||
+ | |||
+ | Page Renderer Function, so etwas wie: | ||
+ | <code php> | ||
+ | function admin_setting_page_theme_links(){ | ||
+ | $menu_slug | ||
+ | $echo | ||
+ | $form_action = menu_page_url( $menu_slug, $echo ); | ||
+ | |||
+ | $v = [ | ||
+ | ' | ||
+ | ]; | ||
+ | |||
+ | require_once ' | ||
+ | } | ||
+ | |||
+ | /* Rudimentäre Saving & Lade Function */ | ||
+ | function save_and_load_option( $key, $default = null ){ | ||
+ | $value = get_option( $key, $default ); | ||
+ | |||
+ | if( isset( $_POST[$key] ) ){ | ||
+ | $new_value = $_POST[$key]; | ||
+ | $autoload | ||
+ | update_option( $key, $new_value, $autoload ); | ||
+ | $value | ||
+ | } | ||
+ | |||
+ | return $new_value; | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | HTML-Sub-File für das Template der Settings-Page, | ||
+ | <code php> | ||
+ | <div class=" | ||
+ | < | ||
+ | <form method=" | ||
+ | |||
+ | <table class=" | ||
+ | < | ||
+ | < | ||
+ | <th scope=" | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | <p class=" | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <?php submit_button(); | ||
+ | </ | ||
+ | </ | ||
</ | </ |