This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('wp_ajax_dn-query', 'dn_query'); | |
function dn_query(){ | |
$entries = array(); | |
$entries = dn_messages_query(); | |
if( count( $entries ) == 0 ) | |
$entries = dn_notifications_query(); | |
if( count( $entries ) == 0 ) | |
$entries = dn_activities_query(); | |
echo json_encode( apply_filters( 'dn_entries', $entries ) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* register the API route | |
* | |
* @since 0.9 | |
**/ | |
add_action( 'rest_api_init', 'dn_rest_routes' ); | |
function dn_rest_routes() { | |
register_rest_route( | |
'buddypress-desktop-notification/v1', '/notifications/', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery.ajax({ | |
url: dnStrings.ajax_url, | |
data: { | |
'since':wpNotifyCurrentDate | |
}, | |
method: 'GET', | |
beforeSend: function ( xhr ) { | |
xhr.setRequestHeader( 'X-WP-Nonce', dnStrings.nonce ); | |
}, | |
success: function( response ){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
register_meta( 'post', 'mein_metakey', 'mein_metakey_sanitize_callback' ); | |
function mein_metakey_sanitize_callback( $value, $key, $type ){ | |
if ( 'post' === $type && 'mein_metakey' === $key ) | |
return (int) $value; | |
return $value; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Schöner Sterben mit wp_die() | |
* Plugin Author: David Remer/Websupporter | |
**/ | |
add_filter( 'wp_die_handler', 'die_in_beauty_filter' ); | |
function die_in_beauty_filter( $die_handler ) { | |
if ( is_admin() ) { | |
return $die_handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'rest_api_init', 'my_own_restroute' ); | |
function my_own_restroute() { | |
register_rest_route( | |
'my-namespace/v1', | |
'/route/', | |
array( | |
'methods' => 'GET', | |
'callback' => 'my_restroute_callback', | |
'args' => array( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function register_cpt() { | |
$args = array( | |
'labels' => array( | |
'name' => 'Name', | |
'singular_name' => 'Single', | |
), | |
'menu_position' => 5, | |
'public' => true, | |
'show_in_rest' => true, // Mache diesen Post Type über die API zugänglich. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$args = array( | |
'type' => 'string', | |
'description' => 'The International Standard Book Number', | |
'single' => true, | |
'sanitize_callback' => 'sanitize_isbn', | |
'auth_callback' => 'is_allowed_to_change_isbn', | |
'show_in_rest' => true, | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'rest_api_init', 'slug_register_something_random' ); | |
function slug_register_something_random() { | |
register_rest_field( 'post', | |
'something', | |
array( | |
'get_callback' => 'slug_get_something', | |
'update_callback' => 'slug_update_something', | |
'schema' => null, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function slug_enqueue_scripts() { | |
wp_enqueue_script( 'api-script', plugins_url( __FILE__ ) . 'script.js', array( 'jquery' ) ); | |
wp_localize_script( | |
'wp-script', | |
'wpApiSettings', | |
array( | |
'root' => esc_url_raw( rest_url() ), | |
'nonce' => wp_create_nonce( 'wp_rest' ) |