Skip to content

Instantly share code, notes, and snippets.

@pareshsojitra
pareshsojitra / customizer-preview.js
Created March 16, 2021 11:19 — forked from danielck/customizer-preview.js
Some basic Customizer examples
/*
Include this file in your theme and enqueue it like this in PHP:
function my_customize_preview_js() {
wp_enqueue_script( 'customizer-preview', get_template_directory_uri() . '/path/to/customizer.js', array( 'customize-preview' ), '20170422', true );
}
add_action( 'customize_preview_init', 'my_customize_preview_js' );
*/
@pareshsojitra
pareshsojitra / boilerplate.php
Created March 2, 2021 18:25 — forked from krasenslavov/boilerplate.php
Use WP-CLI to quickly generate WordPress child themes. Visit blog post https://bit.ly/2VEkdyf
<?php
$options = [
'parent' => '',
'name' => 'Child Theme',
'description' => 'Enter child theme description...',
'screenshot' => '',
'bootstrap' => false
];
@pareshsojitra
pareshsojitra / FixZipArchive.php
Created February 17, 2021 16:52 — forked from ninadsp/FixZipArchive.php
Code snippets for my blogpost Recursively Zip a directory with PHP (http://ninad.pundaliks.in/blog/2011/05/recursively-zip-a-directory-with-php/)
<?
/**
* FlxZipArchive, Extends ZipArchiv.
* Add Dirs with Files and Subdirs.
*
* <code>
* $archive = new FlxZipArchive;
* // .....
* $archive->addDir( 'test/blub', 'blub' );
* </code>
@pareshsojitra
pareshsojitra / function.php
Created February 13, 2021 15:24 — forked from joviczarko/function.php
Add countries as a custom taxonomy term
<?php
add_action('init', 'add_countries', 100);
function add_countries()
{
$country_array = array (
'AF' => 'Afghanistan',
'AX' => 'Åland Islands',
'AL' => 'Albania',
@pareshsojitra
pareshsojitra / page-subscribe.php
Created February 13, 2021 15:20 — forked from joviczarko/page-subscribe.php
Sending form data to an API URL (Postman app helped to test API)
<?php
/*
Template Name: Subscribe Page
*/
get_header();
if( isset($_POST['subscriber_email']) ){
$api_url = 'http://API_URL';
$subscriber_name = $_POST['subscriber_name'];
@pareshsojitra
pareshsojitra / demo.php
Created February 12, 2021 12:57 — forked from freekrai/demo.php
PHP session-based rate limiter for APIs
<?php
date_default_timezone_set('America/Los_Angeles');
session_start();
include("ratelimiter.php");
// in this sample, we are using the originating IP, but you can modify to use API keys, or tokens or what-have-you.
$rateLimiter = new RateLimiter($_SERVER["REMOTE_ADDR"]);
$limit = 100; // number of connections to limit user to per $minutes
$minutes = 1; // number of $minutes to check for.
@pareshsojitra
pareshsojitra / updater.php
Created February 11, 2021 03:47 — forked from dancameron/updater.php
Theme Updater Example.
<?php
if ( is_admin() ) {
add_filter( 'pre_set_site_transient_update_themes', 'gb_check_for_premium_theme_update' );
}
function gb_check_for_premium_theme_update( $transient ) {
$current_version = 1.2;
$api_key = get_option('theme_api_key'); // your theme options will need to have an option to add the API key.
$theme_slug = 'theme_slug'; // Change to match with API Key Manager
$api_url = 'http://yoursite.com/check-key/'; // change to your site
@pareshsojitra
pareshsojitra / post-related-articles.php
Created February 7, 2021 15:23 — forked from brankoconjic/post-related-articles.php
HighendWP - comments and likes count in post related articles.
<?php
/**
* @package WordPress
* @subpackage Highend
*/
$tags = wp_get_post_tags(get_the_ID());
if ( !$tags ) return;
$related_tags = array();
foreach ($tags as $tag) {
@pareshsojitra
pareshsojitra / hide-admin-bar.php
Created February 7, 2021 15:16 — forked from devinsays/hide-admin-bar.php
Disables the #wpadmin bar for users without "edit_posts" permissions.
<?php
/**
* Disables the #wpadmin bar for users without "edit_posts" permissions.
*/
function prefix_hide_admin_bar() {
if ( ! current_user_can( 'edit_posts' ) ) {
add_filter( 'show_admin_bar', '__return_false' );
}
}
add_action( 'after_setup_theme', 'prefix_hide_admin_bar' );
@pareshsojitra
pareshsojitra / redirect-admin.php
Created February 7, 2021 15:14 — forked from devinsays/redirect-admin.php
Redirects subscribers back to the home page if they attempt to access the dashboard.
<?php
/**
* Redirects subscribers back to the home page if they attempt to access the dashboard.
*/
function prefix_redirect_admin() {
if ( ! current_user_can( 'edit_posts' ) && ! defined( 'DOING_AJAX' ) ) {
wp_safe_redirect( home_url() );
exit;
}
}