ID, 'landing_page_id', true );
$landing_page_name = get_post_meta( $post->ID, 'landing_page_name', true );
$landing_page_folder = get_post_meta( $post->ID, 'landing_page_folder', true );
$landing_page_type = get_post_meta( $post->ID, 'landing_page_type', true );
$account_id = get_post_meta( $post->ID, 'account_id', true );
// New if account id not yet set
$is_new = empty( $account_id );
$homepage_enabled = !$homepage || $homepage->ID == $post->ID;
if ($landing_page_type !== 'homepage' || !$homepage_enabled) {
$landing_page_type = 'normal';
}
// Add a nonce field to hook submit
wp_nonce_field( 'landing_page_meta_box', 'landing_page_meta_box_nonce' );
print('';
// Start table output
echo '
';
echo '';
echo '';
// Hidden fields for landing page folder and name
echo '';
}
function allclients_landing_pages_meta_box_save( $post_id) {
// Check if our nonce is set.
if ( !isset( $_POST['landing_page_meta_box_nonce'] ) ) {
return;
}
// Verify that the nonce is valid.
if ( ! wp_verify_nonce( $_POST['landing_page_meta_box_nonce'], 'landing_page_meta_box' ) ) {
return;
}
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
// Check the user's permissions.
if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return;
}
} else {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
}
// Get landing page id
if ( !isset( $_POST['landing_page_id'] ) ) {
return;
}
$landing_page_id = sanitize_text_field( $_POST['landing_page_id'] );
$landing_page_name = sanitize_text_field( $_POST['landing_page_name'] );
$landing_page_type = sanitize_text_field( $_POST['landing_page_type'] );
// Get landing page folder
if ( !isset( $_POST['landing_page_folder'] ) ) {
$landing_page_folder = '';
} else {
$landing_page_folder = sanitize_text_field( $_POST['landing_page_folder'] );
}
// Account id from API configuration
$account_id = get_allclients()->get_api()->get_account_id();
update_post_meta( $post_id, 'landing_page_id', $landing_page_id );
update_post_meta( $post_id, 'landing_page_folder', $landing_page_folder );
update_post_meta( $post_id, 'landing_page_name', $landing_page_name );
update_post_meta( $post_id, 'landing_page_type', $landing_page_type );
update_post_meta( $post_id, 'account_id', $account_id );
}