Skip to content

Instantly share code, notes, and snippets.

View laxmariappan's full-sized avatar

Lax Mariappan laxmariappan

View GitHub Profile
@laxmariappan
laxmariappan / custom-table-meta.php
Created December 4, 2024 09:55
Example of custom tables for storing post meta data in WordPress
<?php
/**
* Plugin Name: Books Custom Post Type V1.1
* Plugin URI:
* Description: A plugin to create a custom post type for books.
* Version: 1.1
* Text Domain: lwp-books
*/
if ( ! defined( 'ABSPATH' ) ) {
@laxmariappan
laxmariappan / book-cpt.php
Last active December 4, 2024 14:01
WordPress custom post type example plugin: Books CPT, Genre Taxonomy and Subscribers CPT
<?php
/**
* Plugin Name: Books Custom Post Type
* Plugin URI:
* Description: A plugin to create a custom post type for books.
* Version: 1.0
* Text Domain: lwp-books
*/
if ( ! defined( 'ABSPATH' ) ) {
@laxmariappan
laxmariappan / lwp-announcement.php
Created November 20, 2024 13:10
Example of WordPress Hooks and filters
<?php
/**
* Plugin Name: LWP Announcement
* Description: LWP Announcement
* Version: 1.0.1
* Author: Lax Mariappan
*/
add_action('wp_head', 'my_announcement');
/**
@laxmariappan
laxmariappan / test-wp-hooks.php
Created November 19, 2024 11:29
Testing WP hooks
<?php
/**
* Plugin Name: Testing
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Hook into wp_footer to trigger the custom action
@laxmariappan
laxmariappan / wp-hooks-guide.php
Created November 19, 2024 11:28
WP hooks introduction
<?php
/**
* Plugin Name: WP Hooks Guide
* Description: A guide to WordPress hooks.
* Version: 1.0
* Author: Your Name
* Author URI: http://yourwebsite.com
* License: GPL2
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: wp-hooks-guide
@laxmariappan
laxmariappan / acf-fields-list.php
Created November 12, 2024 18:18
Get all ACF fields and their sub fields for a given page id
<?php
function get_all_acf_fields_and_subfields($page_id) {
$all_fields = [];
// Get all field groups associated with the page
$field_groups = acf_get_field_groups(['post_id' => $page_id]);
if ($field_groups) {
foreach ($field_groups as $field_group) {
@laxmariappan
laxmariappan / wp-contact-form.php
Created October 16, 2024 11:29
Learn WP - Contact Form Workshop Code
<?php
/**
* Plugin Name: WP Contact Form
* Description: WordPress Contact Form
* Version: 1.0.0
* Author: Lax, Jon
* Plugin URI: https://github.com/lax-mariappan/wp-contact-form
* Requires at least: 5.8
* Requires PHP: 8.0
* License: MIT
@laxmariappan
laxmariappan / simple-contact-form-demo.php
Created September 5, 2024 13:48
Simple contact form plugin for WordPress. This is a basic demo, not intended for production.
<?php
/**
* Plugin Name: LWP Contact Form
* Description: A simple contact form plugin for WordPress.
* Version: 1.0.0
* Author: Lax Mariappan
* Text Domain: lwp-contact-form
*
* @package lwp-contact-form
*/
@laxmariappan
laxmariappan / download.php
Created July 27, 2024 09:53
Download video from Pixabay using PHP
<?php
/**
* Downloads the publicly accessible videos.
* This is just a basic demo, can be improved with proper file handling.
*
* @param string $video_url Video URL.
* @param string $referer Referer site.
*/
function download_video( $video_url, $referer ) {
@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;
}