Skip to content

Instantly share code, notes, and snippets.

carlodaniele

Block or report user

Report or block carlodaniele

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View save-post-food.php
<?php
/**
* Store custom field meta box data
*
* @param int $post_id The post ID.
*/
function food_save_meta_boxes_data( $post_id ){
// code here
}
add_action( 'save_post_food', 'food_save_meta_boxes_data', 10, 2 );
View verify-nonce.php
<?php
// verify meta box nonce
if ( !isset( $_POST['food_meta_box_nonce'] ) || !wp_verify_nonce( $_POST['food_meta_box_nonce'], basename( __FILE__ ) ) ){
return;
}
View autosave.php
<?php
// return if autosave
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ){
return;
}
View user-can-edit.php
<?php
// Check the user's permissions.
if ( ! current_user_can( 'edit_post', $post_id ) ){
return;
}
View save-delete-custom-fields.php
<?php
// store custom fields values
// cholesterol string
if ( isset( $_REQUEST['cholesterol'] ) ) {
update_post_meta( $post_id, '_food_cholesterol', sanitize_text_field( $_POST['cholesterol'] ) );
}
// store custom fields values
// carbohydrates string
if ( isset( $_REQUEST['carbohydrates'] ) ) {
View food-save-meta-box-data.php
<?php
/**
* Store custom field meta box data
*
* @param int $post_id The post ID.
* @link https://codex.wordpress.org/Plugin_API/Action_Reference/save_post
*/
function food_save_meta_box_data( $post_id ){
// verify taxonomies meta box nonce
if ( !isset( $_POST['food_meta_box_nonce'] ) || !wp_verify_nonce( $_POST['food_meta_box_nonce'], basename( __FILE__ ) ) ){
@carlodaniele
carlodaniele / food-example-plugin.php
Last active Mar 29, 2019
An example plugin for WPMU DEV readers
View food-example-plugin.php
<?php
/**
* @package Food_example_plugin
* @version 1.0
*/
/*
Plugin Name: Food example plugin
Plugin URI: http://wordpress.org/extend/plugins/#
Description: This is an example plugin for WPMU DEV readers
Author: Carlo Daniele
@carlodaniele
carlodaniele / remove-toolbar.php
Last active Feb 27, 2016
Remove WordPress Toolbar for non-admin users
View remove-toolbar.php
<?php
/**
* Remove WordPress Toolbar for subscribers
*/
function myplugin_remove_admin_bar() {
if ( ! current_user_can( 'publish_posts' ) ) {
show_admin_bar( false );
}
}
add_action( 'plugins_loaded', 'myplugin_remove_admin_bar' );
@carlodaniele
carlodaniele / remove-toolbar-2.php
Created Feb 18, 2016
Remove Toolbar for all users
View remove-toolbar-2.php
<?php show_admin_bar( false ); ?>
@carlodaniele
carlodaniele / remove-toolbar-3.php
Last active Feb 18, 2016
Remove WordPress Toolbar for non-admin users
View remove-toolbar-3.php
<?php
/**
* Remove WordPress Toolbar for all users except admins and editors
*
*/
function mytheme_remove_admin_bar() {
if ( ! current_user_can( 'publish_posts' ) ) {
show_admin_bar( false );
}
}
You can’t perform that action at this time.