dewdw

* Hint App Paywall Toggle + JSON API
*/

// ======================================================
// ADMIN PAGE: HINT APP PAYWALL TOGGLE
// ======================================================

add_action(‘admin_menu’, function () {
add_options_page(
‘Hint App Paywall’,
‘Hint App Paywall’,
‘manage_options’,
‘hint-app-paywall’,
‘hint_app_paywall_settings_page’
);
});

function hint_app_paywall_settings_page() {
if (!current_user_can(‘manage_options’)) {
return;
}

// Save the setting
if (isset($_POST[‘hint_app_paywall_submit’])) {
check_admin_referer(
‘hint_app_paywall_action’,
‘hint_app_paywall_nonce’
);

$enabled = isset($_POST[‘hint_app_paywall_enabled’]) ? 1 : 0;

update_option(‘hint_app_paywall_enabled’, $enabled);

echo ‘

‘;
echo ‘Hint App paywall is now ‘;
echo $enabled ? ‘ENABLED’ : ‘DISABLED’;
echo ‘
.

‘;
echo ‘

‘;
}

// Default: paywall enabled
$current_status = (int) get_option(
‘hint_app_paywall_enabled’,
1
);

$api_url = add_query_arg(
‘hint_app_config’,
‘1’,
home_url(‘/’)
);
?>

Hint App Paywall

Use this setting to remotely show or hide the paywall
inside the Hint App.

Current status:


Require users to see the Hint App paywall

 

Hint App API URLAdd this URL to the Hint App:



‘paywallEnabled’ => $paywall_enabled,
‘updatedAt’ => current_time(‘timestamp’),
‘status’ => $paywall_enabled ? ‘enabled’ : ‘disabled’,
‘message’ => $paywall_enabled
? ‘Hint App paywall is enabled’
: ‘Hint App paywall is disabled’,
];

echo wp_json_encode(
$response,
JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT
);

exit;
});