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 ''; // If there are folders output the select box if ( count($folders) > 0 ) { // Folder values $all_folder_value = ""; $all_folder_text = 'All Landing Pages'; $not_in_folder_value = '\\'; $not_in_folder_text = 'Not in a Folder'; $current_folder = $not_in_folder_value; $pages = allclients_api_get_landing_pages( $current_folder ); if ( !$is_new && $landing_page_folder != $current_folder ) { $folder_pages = allclients_api_get_landing_pages( $landing_page_folder ); foreach ($folder_pages as $page) { if ( $page['webformid'] == $landing_page_id) { $current_folder = $landing_page_folder; $pages = $folder_pages; break; } } } echo ''; } else { $current_folder = ''; $pages = allclients_api_get_landing_pages( $current_folder ); } // Page select $no_pages_text = esc_html__( 'No landing pages on file.' ); $select_pages_text = esc_html__( 'Choose a Landing Page:' ); echo ''; // Type echo ''; echo ''; echo '
'; echo '
'; echo ''; echo '
'; echo ''; echo '
'; echo '
'; echo ''; echo '
'; echo ''; echo '
Type:'; echo ''; echo ''; echo '   '; echo ''; echo ''; 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 ); }