function perspectives_project_detail_page() { global $wpdb; $project_id = isset($_GET['project_id']) ? intval($_GET['project_id']) : 0; $projects_table = $wpdb->prefix . 'perspectives_projects'; $perspectives_table = $wpdb->prefix . 'perspectives'; // Check if perspectives table exists $perspectives_table_exists = ($wpdb->get_var("SHOW TABLES LIKE '$perspectives_table'") == $perspectives_table); // Handle add perspective form if ( $perspectives_table_exists && isset($_POST['add_perspective']) && !empty($_POST['perspective_name']) && !empty($_POST['perspective_type']) ) { $name = sanitize_text_field($_POST['perspective_name']); $type = sanitize_text_field($_POST['perspective_type']); $states = isset($_POST['perspective_states']) ? sanitize_text_field($_POST['perspective_states']) : null; $is_default = !empty($_POST['perspective_default']) ? 1 : 0; $target_project_id = $is_default ? null : $project_id; // Only allow user to add non-fixed perspectives if ($type === 'fixed') { echo '

Cannot add new fixed perspectives.

'; } else { $result = $wpdb->insert($perspectives_table, [ 'project_id' => $target_project_id, 'name' => $name, 'type' => $type, 'states' => $states, 'default' => $is_default, 'created_at' => current_time('mysql'), ]); if ($result === false) { echo '

Failed to add perspective: ' . esc_html($wpdb->last_error) . '

'; } else { echo '

Perspective added.

'; } } } if (!$project_id) { echo '

Invalid project.

'; return; } $project = $wpdb->get_row($wpdb->prepare("SELECT * FROM $projects_table WHERE id = %d", $project_id)); if (!$project) { echo '

Project not found.

'; return; } $perspectives = []; if ($perspectives_table_exists) { $perspectives = $wpdb->get_results($wpdb->prepare( "SELECT * FROM $perspectives_table WHERE `default` = 1 OR project_id = %d ORDER BY name ASC", $project_id )); } https://juliushuijnk.nl/wp-sitemap-posts-page-1.xml