TRADITIONAL | HEADLESS |
---|---|
WP_DEBUG_DISPLAY |
|
die() / wp_die() / var_dump() |
wp_send_json() or Enable GraphQL Debug Mode and use graphql_debug() |
Postman/REST client | |
WP_DEBUG_LOG |
|
Xdebug on page load | |
Query Monitor | |
NewRelic/Profiling tools |
View debugging-methods.md
View lazilyLoadedComponent.js
import React, { Suspense } from "react" | |
import hasMounted from "../hooks/useHasMounted" | |
const SomeNpmPackage = React.lazy(() => import("some-npm-package")) | |
function LazyLoadedComponent() { | |
if (!hasMounted) return null | |
return ( | |
<Suspense fallback={<p>Loading...</p>}> |
View pwaInstallPrompt.js
import React, { Suspense } from "react" | |
import hasMounted from "../hooks/useHasMounted" | |
const PWAPrompt = React.lazy(() => import("react-ios-pwa-prompt")) | |
function PWAInstallPrompt() { | |
if (!hasMounted) return null | |
const isMobileChrome = navigator.userAgent.includes("CriOS") |
View useSounds.js
import React, { createContext, useContext } from "react" | |
import useSound from "use-sound" | |
import popDownSound from "../sounds/pop-down.mp3" | |
import marioCoinSound from "../sounds/mario-coin.mp3" | |
import applauseSound from "../sounds/applause.mp3" | |
import fanfareSound from "../sounds/fanfare.mp3" | |
const SoundsContext = createContext() |
View greeting.js
function Greeting() { | |
const hasMounted = useHasMounted(); | |
const username = hasMounted ? localStorage.getItem("username") : null; | |
return <p>Welcome back {username}!</p>; | |
} |
View useHasMounted.js
import React, { useState, useEffect } from "react" | |
/** | |
* @return {boolean} Whether the component has mounted. | |
*/ | |
function useHasMounted() { | |
const [hasMounted, setHasMounted] = useState(false) | |
useEffect(() => { | |
setHasMounted(true) |
View remove-cpt-slug-from-permalinks.php
<?php | |
/** | |
* Plugin Name: Remove CPT Slug from Permalinks | |
* Description: Remove Custom Post Type Slug from Permalinks | |
* Version: 0.1.0 | |
* Author: Kellen Mace | |
* Author URI: https://kellenmace.com/ | |
* License: GPLv2 or later | |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html | |
*/ |
View check-if-user-exists-wordpress.php
<?php | |
/** | |
* @param int $user_id User ID. | |
* | |
* @return bool Whether the user exists. | |
*/ | |
function does_user_exist( int $user_id ) : bool { | |
return (bool) get_users( [ 'include' => $user_id, 'fields' => 'ID' ] ); | |
} |
View PasswordChangeEmailHandler.php
<?php | |
class PasswordChangeEmailHandler { | |
/** | |
* User ID of the registered user. | |
* | |
* @var int | |
*/ | |
private $registered_user_id = 0; |
View exclude-super-admins-from-wpgraphql-users-query.php
<?php | |
function filter_super_admin($result, $source, $args, $context, $info, $type_name, $field_key, $field, $field_resolver) { | |
if ( $type_name === 'RootQuery' && $field_key === 'users') { | |
$result['edges'] = array_filter($result['edges'], function($edge) { | |
return !is_super_admin((int)$edge["node"]); | |
}); | |
} | |
return $result; |
NewerOlder