Skip to content

Instantly share code, notes, and snippets.

@fklein-lu
fklein-lu / gist:99f69de65e74743c14b8
Created June 8, 2015 15:34
Code for A Guide to Writing Secure Themes - Part 4: Securing Post Meta
<?php
function wptrt_add_meta_box() {
add_meta_box( 'wptrt-sample-meta-box', esc_html__( 'WPTRT Sample Meta Box', 'wptrt' ), 'wptrt_print_meta_box', 'post' );
}
add_action( 'add_meta_boxes', 'wptrt_add_meta_box' );
function wptrt_print_meta_box() {
wp_nonce_field( 'wptrt-post-meta-box-save', 'wptrt-post-meta-box-nonce' );
?>
@fklein-lu
fklein-lu / fk_is_front_end_query.php
Last active October 7, 2020 19:17
Gutenberg block development helper function to detect whether a block renders on the frontend or the backend
<?php
/**
* Hackish solution to distinguish between block renders on the front end, and the back end.
*
* In the admin, the global `$wp_query` does not contain a query. We use this to determine whether a rendering is
* happening on the front end or the back end.
*
* @return bool Whether we're in the admin or on the front end.
*/
function fk_is_front_end_query() {