Skip to content

Instantly share code, notes, and snippets.

@sybarite
Created February 8, 2013 10:53
Show Gist options
  • Save sybarite/4738114 to your computer and use it in GitHub Desktop.
Save sybarite/4738114 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: Vedamore
* Plugin URI: http://vedamore.com/
* Description: Plugin to add a meta box for beads for different products
* Version: 1.6.6
* Author: Webly
* Author URI: http://webly.co
* Requires at least: 3.3
* Tested up to: 3.5
*
* Text Domain: webly
* Domain Path: /languages/
*
* @package Vedamore
* @category Core
* @author Webly
*/
/**
* Check if WooCommerce is active
**/
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
function wr_call_meta_box($post = null)
{
add_meta_box(
'weather_box',
__('Current Weather', 'wr_plugin'),
'wr_display_meta_box',
'product',
'advanced',
'default'
);
}
add_action('add_meta_boxes_product', 'wr_call_meta_box', 10, 1);
add_action('save_post', 'wr_save_meta_box', 10, 2);
function wr_save_meta_box($post_id, $post)
{
if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return;
if('page' == $_POST['post_type'])
{
if(!current_user_can('edit_page', $post_id))
return;
}
else
if(!current_user_can('edit_post', $post_id))
return;
if(isset($_POST['wr_plugin_noncename']) && wp_verify_nonce($_POST['wr_plugin_noncename'], plugins_url(__FILE__)) && check_admin_referer(plugins_url(__FILE__), 'wr_plugin_noncename'))
{
if(is_numeric($_POST['wr-temperature']))
{
update_post_meta($post_id, 'wr-temperature', $_POST['wr-temperature']);
}
}
return;
}
function wr_display_meta_box($post, $args)
{
wp_nonce_field(plugins_url(__FILE__), 'wr_plugin_noncename');
?>
<p>
<label for="wr-temperature"><?php _e('Temperature (&deg;F)', 'wr_plugin'); ?>: </label>
<input type="text" id="wr-temperature" name="wr-temperature" value="<?php echo get_post_meta($post->ID, 'wr-temperature', true); ?>" />
<em><?php _e('Must be a numeric value', 'wr_plugin'); ?></em>
</p>
<?php
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment