Skip to content

Instantly share code, notes, and snippets.

View hsleonis's full-sized avatar
🏝️
Travellers unite.

Hasan Shahriar hsleonis

🏝️
Travellers unite.
View GitHub Profile
@hsleonis
hsleonis / .htaccess
Created March 29, 2016 04:08
HTAccess file with ETag, Cache, GZip and custom routing
<ifModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/css text/javascript application/javascript application/x-javascript application/json
</ifModule>
Header unset ETag
FileETag None
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
@hsleonis
hsleonis / wp-plugin-page-link.php
Created March 30, 2016 04:43
WP add plugin settings page link to plugins.php
@hsleonis
hsleonis / wp-register-textdomain.php
Created March 30, 2016 04:45
WP register text domain
<?php
/**
* Register text domain
*
* @since 0.1
*/
function tmx_textdomain() {
load_plugin_textdomain( 'themeaxe', false, dirname(plugin_basename(__FILE__)). '/languages/' );
}
add_action( 'init', 'tmx_textdomain' );
@hsleonis
hsleonis / wp-plugin-constants.php
Created March 30, 2016 04:48
WP plugin constant definition
<?php
/**
* Prevent Direct Access
*
* @since 0.1
*/
defined('ABSPATH') or die("No script kiddies please!");
/**
* Plugin constants
@hsleonis
hsleonis / js-inline-xml-parser-validation.html
Created March 30, 2016 04:50
Validate inline script '<' and '&' in XML parsers
<script type='text/javascript'>
/* <![CDATA[ */
var scriptParams = {"theme":"light"};
/* ]]> */
</script>
@hsleonis
hsleonis / wp-admin-dashboard-widget.php
Created March 30, 2016 04:53
WP add a widget to the dashboard
<?php
/**
* Add a widget to the dashboard.
*
* This function is hooked into the 'wp_dashboard_setup' action below.
* Reference: https://codex.wordpress.org/Dashboard_Widgets_API
*/
function example_add_dashboard_widgets() {
wp_add_dashboard_widget(
@hsleonis
hsleonis / wp-basic-widget.php
Last active March 30, 2016 05:37
Wordpress widget
<?php
/**
* Extend WP_Widget class,
*
* Reference:
* https://codex.wordpress.org/Widgets_API
* https://codex.wordpress.org/Function_Reference/the_widget
*/
// Creating the widget
<?php
/**
* The Transients API is very similar to the Options API but with the added feature of an expiration time,
* which simplifies the process of using the wp_options database table to temporarily store cached information.
* Reference: https://codex.wordpress.org/Transients_API
*/
// Get any existing copy of our transient data
if ( false === ( $special_query_results = get_transient( 'special_query_results' ) ) ) {
// It wasn't there, so regenerate the data and save the transient
@hsleonis
hsleonis / wp-theme-customizr.php
Created March 30, 2016 08:43
WP theme customizer section
<?php
/**
* Adds the individual sections, settings, and controls to the theme customizer
* Reference: https://codex.wordpress.org/Theme_Customization_API
*/
function tmx_theme_customizer( $wp_customize ) {
$wp_customize->add_section(
'social_section',
array(
'title' => 'Social Links',
@hsleonis
hsleonis / wp-theme-modification.php
Last active March 30, 2016 09:43
WP Theme Modification API
<?php
/**
* Retrieves a modification setting for the current theme
* Get, set or remove values of theme customizer
*
* Functions
* get_theme_mod()
* get_theme_mods()
* set_theme_mod()
* remove_theme_mod()