Skip to content

Instantly share code, notes, and snippets.

View laxmariappan's full-sized avatar

Lax Mariappan laxmariappan

View GitHub Profile
@laxmariappan
laxmariappan / wp-context-check.php
Created December 12, 2023 17:29
wp-context package example
<?php
use Inpsyde\WpContext;
// Instantiate the class
$context = WpContext::determine();
// Use the WpContext::is() method to check context
if (!$context->is(WpContext::FRONTOFFICE, WpContext::BACKOFFICE)) {
return false;
}
@laxmariappan
laxmariappan / gist:537b2721d01f8dd4845af283d6357efb
Created September 26, 2023 15:05
common image and video file formats in a comma separated list
.jpg, .jpeg, .png, .gif, .bmp, .svg, .mp4, .avi, .mkv, .mov, .wmv, .flv, .mpeg, .3gp, .webm, .ogv
@laxmariappan
laxmariappan / did-filter.php
Last active November 27, 2022 12:52
Quick demo of how to use did_filter hook in WordPress
<?php
/*
Plugin Name: Did filter Check
Plugin URI: https://gist.github.com/laxmariappan/d49b5930875d1d8f134173742f37774d
Description: Check how did filter works
Version: 1.0
*/
add_filter('lax_plugin','plugin_title_change');
@laxmariappan
laxmariappan / index.jsx
Last active May 23, 2022 20:15
data fetching example - Remix
// import loader hook
import { useLoaderData, Link } from "@remix-run/react";
export let loader = async () => {
const result = await fetch("https://wordpress.org/news/wp-json/wp/v2/posts");
const posts = await result.json();
return posts;
};
@laxmariappan
laxmariappan / root.jsx
Created May 23, 2022 20:00
ErrorBoundary for Remix app
export function ErrorBoundary({ error }) {
console.log(error);
return (
<Document>
<Layout>
<section className="p-6">
<div className="relative items-center w-full px-5 py-12 mx-auto md:px-12 lg:px-24 max-w-7xl">
<h1>There was an Error</h1>
<p>{error.message}</p>
@laxmariappan
laxmariappan / root.jsx
Created May 23, 2022 19:59
Layout for Remix Tailwind app
export function Layout({ children }) {
return (
<>
<Header />
{children}
<Footer />
</>
);
}
@laxmariappan
laxmariappan / root.jsx
Created May 23, 2022 19:57
Document for Remix Tailwind app
function Document({ children }) {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<Meta />
<Links />
</head>
<body className="bg-gray-100">
@laxmariappan
laxmariappan / root.jsx
Last active May 23, 2022 19:54
Remix App component
export default function App() {
return (
<Document>
<Layout>
<Outlet />
</Layout>
</Document>
);
}
@laxmariappan
laxmariappan / root.jsx
Created May 23, 2022 19:46
Remix Tailwind importing styles
import styles from "./tailwind.css";
//Link the stylesheet
export const links = () => [
{ rel: "stylesheet", href: styles },
];
@laxmariappan
laxmariappan / installation.js
Last active May 23, 2022 20:32
Remix + WP demo
npx create-remix@latest
//Hit enter to confirm the installation
? Where would you like to create your app? (./my-remix-app) `remix-wp`
//The default name is my-remix-app, you name your app here. I’ve named it remix-wp
//The next step would be choosing the app server.