add_shortcode('strategic_planner', function () { ob_start(); if ( isset($_POST['save_plan']) && isset($_POST['plan_nonce']) && wp_verify_nonce($_POST['plan_nonce'], 'save_or_update_plan') ) { $post_id = wp_insert_post([ 'post_type' => 'strategic_plan', 'post_status' => 'publish', 'post_title' => sanitize_text_field($_POST['ambition_title']), 'post_author' => get_current_user_id(), ]); if ($post_id) { $description = sanitize_textarea_field($_POST['plan_description']); $area = sanitize_text_field($_POST['ambition_area']); $date = sanitize_text_field($_POST['target_date']); $outcomes = array_map('sanitize_text_field', $_POST['outcomes'] ?? []); $group_url = isset($_POST['group_url']) ? esc_url_raw($_POST['group_url']) : ''; update_post_meta($post_id, 'plan_description', $description); update_post_meta($post_id, 'ambition_area', $area); update_post_meta($post_id, 'target_date', $date); update_post_meta($post_id, 'desired_outcomes', $outcomes); update_post_meta($post_id, 'group_url', $group_url); // Save to custom DB table global $wpdb; $wpdb->insert( $wpdb->prefix . 'planner_plans', [ 'post_id' => $post_id, 'user_id' => get_current_user_id(), 'group_url' => $group_url, 'title' => sanitize_text_field($_POST['ambition_title']), 'description' => $description, 'area' => $area, 'target_date' => $date ?: null, 'outcomes' => json_encode($outcomes), 'created_at' => current_time('mysql'), 'updated_at' => current_time('mysql'), ] ); include plugin_dir_path(__DIR__) . '/includes/priority-matrix.php'; $recommended = []; $optional = []; foreach ($priority_matrix as $activity => $matrix) { foreach ($outcomes as $outcome) { if (!empty($matrix[$outcome])) { if ($matrix[$outcome] === 'Should Do') { $recommended[] = $activity; break; } elseif ($matrix[$outcome] === 'Could Do') { $optional[] = $activity; } } } } update_post_meta($post_id, 'recommended_activities', json_encode(array_unique($recommended))); update_post_meta($post_id, 'optional_activities', json_encode(array_diff(array_unique($optional), $recommended))); // Redirect if ($group_url) { wp_redirect($group_url . 'ambition-planner'); } else { wp_redirect(home_url('/my-planning-sheets')); } exit; } } include plugin_dir_path(__DIR__) . '/includes/create-plan-form.php'; return ob_get_clean(); }); add_action('init', function () { if ( !isset($_POST['update_plan']) || !is_user_logged_in() || !isset($_POST['plan_nonce']) || !wp_verify_nonce($_POST['plan_nonce'], 'save_or_update_plan') ) { return; } $plan_id = intval($_POST['plan_id']); if (!$plan_id || get_post_type($plan_id) !== 'strategic_plan') return; if ((int) get_post_field('post_author', $plan_id) !== get_current_user_id()) return; $title = sanitize_text_field($_POST['ambition_title']); $description = sanitize_textarea_field($_POST['plan_description']); $area = sanitize_text_field($_POST['ambition_area']); $date = sanitize_text_field($_POST['target_date']); $outcomes = array_map('sanitize_text_field', $_POST['outcomes'] ?? []); $group_url = isset($_POST['group_url']) ? esc_url_raw($_POST['group_url']) : ''; // Update the post wp_update_post([ 'ID' => $plan_id, 'post_title' => $title, ]); update_post_meta($plan_id, 'plan_description', $description); update_post_meta($plan_id, 'ambition_area', $area); update_post_meta($plan_id, 'target_date', $date); update_post_meta($plan_id, 'desired_outcomes', $outcomes); update_post_meta($plan_id, 'group_url', $group_url); // Update custom planner_plans table global $wpdb; $wpdb->update( $wpdb->prefix . 'planner_plans', [ 'group_url' => $group_url, 'title' => $title, 'description' => $description, 'area' => $area, 'target_date' => $date ?: null, 'outcomes' => json_encode($outcomes), 'updated_at' => current_time('mysql') ], ['post_id' => $plan_id] ); include plugin_dir_path(__DIR__) . '/priority-matrix.php'; $recommended = []; $optional = []; foreach ($priority_matrix as $activity => $matrix) { foreach ($outcomes as $outcome) { if (!empty($matrix[$outcome])) { if ($matrix[$outcome] === 'Should Do') { $recommended[] = $activity; break; } elseif ($matrix[$outcome] === 'Could Do') { $optional[] = $activity; } } } } update_post_meta($plan_id, 'recommended_activities', json_encode(array_unique($recommended))); update_post_meta($plan_id, 'optional_activities', json_encode(array_diff(array_unique($optional), $recommended))); if ($group_url) { wp_redirect($group_url . 'ambition-planner?action=header_updated'); } else { wp_redirect(home_url('/my-planning-sheets/?header_updated=1')); } exit; }); add_action('init', function () { if ( !isset($_POST['action']) || $_POST['action'] !== 'delete_plan' || !is_user_logged_in() || !isset($_POST['plan_id']) || !wp_verify_nonce($_POST['_wpnonce'], 'delete_plan_' . $_POST['plan_id']) ) { return; } $plan_id = (int) $_POST['plan_id']; if (get_post_type($plan_id) !== 'strategic_plan') return; if ((int) get_post_field('post_author', $plan_id) !== get_current_user_id()) return; wp_delete_post($plan_id, true); global $wpdb; $wpdb->delete($wpdb->prefix . 'planner_activities', ['plan_id' => $plan_id]); $wpdb->delete($wpdb->prefix . 'planner_plans', ['post_id' => $plan_id]); wp_redirect(home_url('/my-planning-sheets?deleted=1')); exit; });
Please confirm you want to block this member.
You will no longer be able to:
Please note: This action will also remove this member from your connections and send a report to the site admin. Please allow a few minutes for this process to complete.