function mytheme_handle_current_year_shortcode()
{
$year = date('Y');
return $year;
}
add_shortcode('mytheme_current_year', 'mytheme_handle_current_year_shortcode');
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
add_filter('auto_core_update_send_email', '__return_false');
add_filter('auto_theme_update_send_email', '__return_false');
add_filter('auto_plugin_update_send_email', '__return_false');
//Increase the login session expiration time (by default, it's 2 days, or 14 days if you checked "Remember me")
function extend_wordpress_login_sessions($seconds, $user_id, $remember)
{
if ($remember)
{
$expiration = 90 * 24 * 60 * 60; //Extend remembered sessions to 90 days
}
else
{
$expiration = 15 * 24 * 60 * 60; //Extend non-remembered sessions to 15 days
}
return $expiration;
}
add_filter('auth_cookie_expiration', 'extend_wordpress_login_sessions', 99, 3);
function mysite_get_foobar_ajax()
{
$response = [
'status' => 'success',
'text_message' => 'The foobar was successful.',
'html_message' => '<p class="success-message">The foobar was successful.</p>',
];
echo json_encode($response);
wp_die();
}
add_action('wp_ajax_mysite_get_foobar_ajax', 'mysite_get_foobar_ajax');
?>
<script>
let form_data = new FormData();
form_data.append('action', 'mysite_get_foobar_ajax');
fetch('/wp-admin/admin-ajax.php', {method: 'POST', headers: {}, body: form_data})
.then
(
response => response.json()
)
.then
(
data =>
{
console.log(data);
if (data.status === 'success')
{
alert(data.text_message);
}
else if (data.status === 'error')
{
alert(data.text_message);
}
else
{
throw 'Unexpected response status';
}
}
)
.catch(error =>
{
console.log(error);
alert('An unknown error occured.');
});
</script>
/*
* Plugin Name: Custom Foobar Plugin
* Description: Our custom foobar plugin
* Version: 1.0
* Author: Author
* Author URI: https://www.example.com
*/
function handle_foobar_shortcode($original_shortcode_attributes)
{
$attributes = shortcode_atts([
'lorem' => null,
],
$original_shortcode_attributes);
$lorem = $attributes['lorem'] ?? null;
if ($attributes['lorem'] !== 'ipsum')
{
return '<p>Error: Unexpected value for "lorem" attribute (expected "ipsum").</p>';
}
$output_html = '<p>The shortcode works!</p>';
return $output_html;
}
add_shortcode('foobar', 'handle_foobar_shortcode');
$debug_tags = array();
add_action('all', function ($tag)
{
global $debug_tags;
if (in_array($tag, $debug_tags))
{
return;
}
echo "<pre>" . $tag . "</pre>";
$debug_tags[] = $tag;
});