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 | |
/** | |
* 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 ); |
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 | |
// verify meta box nonce | |
if ( !isset( $_POST['food_meta_box_nonce'] ) || !wp_verify_nonce( $_POST['food_meta_box_nonce'], basename( __FILE__ ) ) ){ | |
return; | |
} |
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 | |
// return if autosave | |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ){ | |
return; | |
} |
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 | |
// Check the user's permissions. | |
if ( ! current_user_can( 'edit_post', $post_id ) ){ | |
return; | |
} |
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 | |
// 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'] ) ) { |
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 | |
/** | |
* 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__ ) ) ){ |
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 | |
/** | |
* @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 |
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 | |
/** | |
* 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' ); |
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 show_admin_bar( false ); ?> |
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 | |
/** | |
* 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 ); | |
} | |
} |