Skip to content

Instantly share code, notes, and snippets.

View gasatrya's full-sized avatar
🏠
Working from home

Ga Satrya gasatrya

🏠
Working from home
View GitHub Profile
@gasatrya
gasatrya / tab.tsx
Last active November 22, 2023 15:36
Radix UI Tabs URL based in next.js
import React from "react";
import { useRouter } from "next/router";
import * as Tabs from "@radix-ui/react-tabs";
const TabsDemo = () => {
const router = useRouter();
const initialTab = router.query.tab;
const [activeTab, setActiveTab] = React.useState(initialTab || "tab1");
const handleTabChange = (value) => {
@gasatrya
gasatrya / tab.tsx
Created November 22, 2023 06:29
Shadcn UI / Radix Primitives: Programmatically Switch Tabs
export function TabsDemo() {
const [tab, setTab] = useState("tab1");
const onTabChange = (value) => {
setTab(value);
}
return (
<Tabs value={tab} onValueChange={onTabChange} className="w-[400px]">
<TabsList className="grid w-full grid-cols-2">
@gasatrya
gasatrya / fetch_plugin.js
Created October 17, 2022 18:34 — forked from cwhittl/fetch_plugin.js
Using Fetch with Wordpress Plugins Ajax
fetch(ajax_url, {
method: 'POST',
credentials: 'same-origin',
headers: new Headers({'Content-Type': 'application/x-www-form-urlencoded'}),
body: 'action=zget_profile_user'
})
.then((resp) => resp.json())
.then(function(data) {
if(data.status == "success"){
_this.setState({loaded:true,user:data.user});
@gasatrya
gasatrya / wpmudev-forminator-editor-access.php
Created October 12, 2022 13:57 — forked from wpmudev-sls/wpmudev-forminator-editor-access.php
[Forminator] Grants Full Acesses For Editor Role. This plugin allows users with the editor role to have full access (view and save) to the Forminator administrative pages.
<?php
/**
* Plugin Name: [Forminator] Grants Full Access For Editor Role.
* Plugin URI: https://premium.wpmudev.org/
* Description: This plugin allows users with the editor role to have full access (view and save) to the Forminator administrative pages.
* Author: Glauber Silva @ WPMUDEV
* Author URI: https://premium.wpmudev.org/
* Task: 0/11289012348292/1169742392170370
* License: GPLv2 or later
*
@gasatrya
gasatrya / wsl2-ubuntu-lamp.md
Created August 8, 2022 14:13 — forked from abobija/wsl2-ubuntu-lamp.md
LAMP stack on WSL2 (Ubuntu 20.04) - Apache, MySQL, PHP, PhpMyAdmin

LAMP stack on WSL2 (Ubuntu 20.04) - Apache, MySQL, PHP, PhpMyAdmin

Apache

sudo apt-get update && sudo apt-get upgrade 
sudo apt-get install -y apache2

PHP

@gasatrya
gasatrya / forminator-load-cpt-select-field.php
Created July 18, 2022 12:51 — forked from wpmudev-sls/forminator-load-cpt-select-field.php
[Forminator] Load custom posts on Select Field and get IDs on the on-change event.
<?php
/**
* Plugin Name: [Forminator] Load custom posts on Select Field and get IDs on the on-change event.
* Plugin URI: https://wpmudev.com/
* Description: With the ID retrieved on the "on change" event, you can write your custom code to get the post data and fill the correspondent fields on the form, more details about how to do it on the comment of this snippet.
* Author: Glauber Silva @ WPMUDEV
* Author URI: https://wpmudev.com/
* Task: SLS-3568
* License: GPLv2 or later
*
@gasatrya
gasatrya / category.php
Created June 9, 2015 14:55
WordPress: If the post has several categories, display the first one only.
<?php
$category = get_the_category( get_the_ID() );
if ( $category ) :
?>
<span class="entry-category">
<a href="<?php echo esc_url( get_category_link( $category[0]->term_id ) ); ?>"><?php echo esc_attr( $category[0]->name ); ?></a>
</span>
<?php endif; // End if category ?>
@gasatrya
gasatrya / excerpt.php
Created June 9, 2015 14:46
Change the WordPress excerpt more string
<?php
/**
* Change the excerpt more string.
*
* @since 1.0.0
* @param string $more
* @return string
*/
function prefix_excerpt_more( $more ) {
return '&hellip;';
@gasatrya
gasatrya / excerpt.php
Created June 9, 2015 14:43
Control WordPress excerpt length
<?php
/**
* Control excerpt length.
*/
function prefix_excerpt_length( $length ) {
return 20;
}
add_filter( 'excerpt_length', 'prefix_excerpt_length', 999 );
@gasatrya
gasatrya / comments.php
Created February 3, 2015 17:53
WordPress recent comments w/ avatar
<?php
$comments = get_comments( array(
'number' => 5,
'status' => 'approve',
'post_status' => 'publish'
) );
?>
<?php if ( $comments ) : ?>
<ul>
<?php foreach( $comments as $comment ) : ?>