|
<?php |
|
// Add a Metabox to the backend |
|
function add_nxt_custom_footer_cta() { |
|
add_meta_box("nxt-custom-footer-cta", "CTA im Footer-Bereich", "nxt_custom_footer_cta_construction", "page", "side", "high", null); |
|
} |
|
add_action("add_meta_boxes", "add_nxt_custom_footer_cta"); |
|
|
|
// Fill Metabox with our custom variable |
|
function nxt_custom_footer_cta_construction() { |
|
wp_nonce_field(basename(__FILE__), "nxt-custom-footer-metabox-nonce"); |
|
if(get_post_meta(get_the_ID(), '_nxt_footer_cta', true) != '') { |
|
$nxt_current_footer_cta = get_post_meta(get_the_ID(),'_nxt_footer_cta',true); |
|
echo '<select name="nxt_footer_cta" id="nxt_footer_cta"><option value="optin">Newsletter-Anmeldung</option><option value="form" selected="true">Kontaktformular</option></select>'; |
|
} else { |
|
echo '<select name="nxt_footer_cta" id="nxt_footer_cta"><option value="optin">Newsletter-Anmeldung</option><option value="form">Kontaktformular</option></select>'; |
|
} |
|
} |
|
|
|
// Save value of Metabox |
|
function save_nxt_custom_footer_cta($post_id) { |
|
// check nonce to avoid hacker shit |
|
if (!isset($_POST["nxt-custom-footer-metabox-nonce"]) || !wp_verify_nonce($_POST["nxt-custom-footer-metabox-nonce"], basename(__FILE__))) return $post_id; // else echo "<!-- debug - did not make it through nonce check! -->"; |
|
|
|
// check permissions of user |
|
if(!current_user_can("edit_post", $post_id)) return $post_id; |
|
|
|
// make sure this isn't an auto-save |
|
if(defined("DOING_AUTOSAVE") && DOING_AUTOSAVE) return $post_id; |
|
|
|
// echo "<!-- debug - this is not an autosave -->"; |
|
// make sure this is only being displayed for pages |
|
$slug = "page"; |
|
if( $slug != get_post_type($post_id)) return $post_id; |
|
if((isset($_POST["nxt_footer_cta"])) && ($_POST["nxt_footer_cta"] <> 'optin' )) { |
|
// echo "<!-- debug - nxt_second_author is set in POST variable - value: " . $_POST['nxt_second_author'] . " -->"; |
|
update_post_meta($post_id, "_nxt_footer_cta", $_POST["nxt_footer_cta"]); |
|
} else { |
|
delete_post_meta($post_id, "_nxt_footer_cta"); |
|
} |
|
} |
|
add_action('save_post', 'save_nxt_custom_footer_cta', 10, 3); |