/** * ============================================================ * MPWL PUBLIC FOLLOW-UP FORM PATCH * ============================================================ * * Paste this at the VERY BOTTOM of: * MP Clinic Patient Dashboard plugin file * * This does NOT make the patient chart dashboard public. * This does NOT replace the website layout. * This does NOT create an MU plugin. * This keeps the regular Gravity Forms shortcode working: * * [gravityform id="23" title="true" description="false" ajax="false"] * * Purpose: * - Force Gravity Form 23 to stay public for logged-out patients. * - Stop Save & Continue from interfering with logged-out patients. * - Force AJAX off. * - Prevent cache/session issues on the follow-up page. * - Block login redirects only on the public follow-up form page. */ if (!defined('ABSPATH')) { exit; } if (!defined('MPCPD_PUBLIC_FOLLOWUP_PATCH_LOADED')) { define('MPCPD_PUBLIC_FOLLOWUP_PATCH_LOADED', true); if (!defined('MPCPD_PUBLIC_FOLLOWUP_FORM_ID')) { define('MPCPD_PUBLIC_FOLLOWUP_FORM_ID', 23); } /* * Your screenshot shows the follow-up page editor URL as post=273. * Keep this page ID here. */ if (!defined('MPCPD_PUBLIC_FOLLOWUP_PAGE_ID')) { define('MPCPD_PUBLIC_FOLLOWUP_PAGE_ID', 273); } /** * Detect the public follow-up form page. */ function mpcpd_public_followup_is_page() { if (is_admin()) { return false; } if (function_exists('is_page') && is_page(MPCPD_PUBLIC_FOLLOWUP_PAGE_ID)) { return true; } if (function_exists('is_page') && is_page(array( 'follow-up', 'followup', 'follow-up-appointment', 'follow-up-appointment-form', 'patient-follow-up', 'glp-1-follow-up', 'glp1-follow-up', 'follow-up-form' ))) { return true; } $request_uri = isset($_SERVER['REQUEST_URI']) ? strtolower((string) $_SERVER['REQUEST_URI']) : ''; if ( strpos($request_uri, 'follow-up') !== false || strpos($request_uri, 'followup') !== false || strpos($request_uri, 'follow-up-appointment') !== false || strpos($request_uri, 'patient-follow-up') !== false || strpos($request_uri, 'glp-1-follow-up') !== false || strpos($request_uri, 'glp1-follow-up') !== false ) { return true; } global $post; if ($post && !empty($post->post_content)) { $content = (string) $post->post_content; if ( strpos($content, '[gravityform') !== false && ( strpos($content, 'id="23"') !== false || strpos($content, "id='23'") !== false || strpos($content, 'id=23') !== false ) ) { return true; } } return false; } /** * Force Gravity Form 23 to be public. */ function mpcpd_public_followup_force_form_public($form) { if (!is_array($form)) { return $form; } $form_id = isset($form['id']) ? absint($form['id']) : 0; if ($form_id !== MPCPD_PUBLIC_FOLLOWUP_FORM_ID) { return $form; } /* * Make sure Gravity Forms itself does not require login. */ $form['requireLogin'] = false; $form['require_login'] = false; /* * Save & Continue can cause logged-out/public session problems. */ if (!isset($form['save']) || !is_array($form['save'])) { $form['save'] = array(); } $form['save']['enabled'] = false; return $form; } add_filter('gform_pre_render_' . MPCPD_PUBLIC_FOLLOWUP_FORM_ID, 'mpcpd_public_followup_force_form_public', 1); add_filter('gform_pre_validation_' . MPCPD_PUBLIC_FOLLOWUP_FORM_ID, 'mpcpd_public_followup_force_form_public', 1); add_filter('gform_pre_submission_filter_' . MPCPD_PUBLIC_FOLLOWUP_FORM_ID, 'mpcpd_public_followup_force_form_public', 1); add_filter('gform_admin_pre_render_' . MPCPD_PUBLIC_FOLLOWUP_FORM_ID, 'mpcpd_public_followup_force_form_public', 1); add_filter('gform_form_post_get_meta_' . MPCPD_PUBLIC_FOLLOWUP_FORM_ID, 'mpcpd_public_followup_force_form_public', 1); /* * Extra Gravity Forms login bypass protection. */ add_filter('gform_require_login_' . MPCPD_PUBLIC_FOLLOWUP_FORM_ID, '__return_false', 1); add_filter('gform_requires_login_' . MPCPD_PUBLIC_FOLLOWUP_FORM_ID, '__return_false', 1); /** * Force AJAX off for Form 23. */ add_filter('gform_form_args', function ($args) { if (!is_array($args)) { return $args; } $form_id = 0; if (isset($args['form_id'])) { $form_id = absint($args['form_id']); } elseif (isset($args['id'])) { $form_id = absint($args['id']); } if ($form_id === MPCPD_PUBLIC_FOLLOWUP_FORM_ID) { $args['ajax'] = false; } return $args; }, 20); /** * No-cache headers for the public follow-up form page. */ add_action('template_redirect', function () { if (!mpcpd_public_followup_is_page()) { return; } if (!defined('DONOTCACHEPAGE')) { define('DONOTCACHEPAGE', true); } if (!defined('DONOTCACHEDB')) { define('DONOTCACHEDB', true); } if (!defined('DONOTCACHEOBJECT')) { define('DONOTCACHEOBJECT', true); } nocache_headers(); if (!headers_sent()) { header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0'); header('Pragma: no-cache'); header('Expires: Wed, 11 Jan 1984 05:00:00 GMT'); } }, 0); /** * If anything tries to redirect the public follow-up page to login, * stop that redirect and keep the patient on the follow-up page. * * This only applies to the follow-up page / Form 23. */ add_filter('wp_redirect', function ($location, $status) { if (!mpcpd_public_followup_is_page()) { return $location; } $location_string = is_string($location) ? strtolower($location) : ''; $looks_like_login_redirect = ( strpos($location_string, 'wp-login.php') !== false || strpos($location_string, '/login') !== false || strpos($location_string, 'redirect_to=') !== false || strpos($location_string, 'my-account') !== false || strpos($location_string, 'account') !== false ); if ($looks_like_login_redirect) { $followup_url = get_permalink(MPCPD_PUBLIC_FOLLOWUP_PAGE_ID); if (!$followup_url) { $followup_url = home_url('/follow-up-appointment-form/'); } return $followup_url; } return $location; }, 9999, 2); /** * Keep the Patient Charts dashboard protected. * * If [mp_clinic_patients] accidentally appears on the public follow-up page, * do not show patient charts to public users. */ add_action('wp', function () { if (is_admin()) { return; } if (!mpcpd_public_followup_is_page()) { return; } if (!current_user_can('manage_options')) { add_shortcode('mp_clinic_patients', function () { return '

This dashboard is for clinic staff only.

'; }); } }, 20); } Page not found – MP Weight Loss Clinic
404

Oops! That page can’t be found.

It looks like nothing was found at this location. Maybe try one of the links below or a search?