Skip to content

Instantly share code, notes, and snippets.

View Roshanb54's full-sized avatar
🏠
Working From Home

Roshan Banstola Roshanb54

🏠
Working From Home
View GitHub Profile
@Roshanb54
Roshanb54 / .gitignore
Created May 16, 2017 04:23 — forked from vishalbasnet23/.gitignore
git ignore for wordpress
*.log
.htaccess
sitemap.xml
sitemap.xml.gz
wp-config.php
wp-content/advanced-cache.php
wp-content/backup-db/
wp-content/backups/
wp-content/blogs.dir/
wp-content/cache/
@Roshanb54
Roshanb54 / functions.php
Created May 16, 2017 04:24 — forked from vishalbasnet23/functions.php
Append async to wp_enqueue_script
<?php
function advanced_asyc_scripts($url) {
if ( strpos( $url, '#asyncload') === false ) {
return $url;
} else if ( is_admin() ) {
return str_replace( '#asyncload', '', $url );
} else {
return str_replace( '#asyncload', '', $url )."' async='async' defer='defer";
}
}
@Roshanb54
Roshanb54 / detectMobile
Created May 19, 2017 11:01 — forked from anyulled/detectMobile
Detect mobile browser
<?php
$mobile = false;
$useragent=$_SERVER['HTTP_USER_AGENT'];
if(preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipa
@Roshanb54
Roshanb54 / wordpress-base-custom-data.php
Created June 27, 2017 07:40 — forked from paulund/wordpress-base-custom-data.php
A PHP class to handle CRUD functionality in WordPress default tables.
<?php
/**
* Abstract class which has helper functions to get data from the database
*/
abstract class Base_Custom_Data
{
/**
* The current table name
*
* @var boolean
@Roshanb54
Roshanb54 / file.php
Created June 27, 2017 08:30 — forked from qutek/file.php
[Wordpress] Display data with native wordpress table
<?php
/*
Plugin Name: Custom table example
Description: example plugin to demonstrate wordpress capatabilities
Plugin URI: http://mac-blog.org.ua/
Author URI: http://mac-blog.org.ua/
Author: Marchenko Alexandr
License: Public Domain
Version: 1.1
*/
<?php
add_shortcode( 'front_end_post_form', 'front_end_post_form' );
function front_end_post_form( $atts ) {
ob_start();?>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('#succes').hide();
});
<?php
$upload_dir = wp_upload_dir();
$image_data = file_get_contents($image_url);
$filename = basename($image_url);
if(wp_mkdir_p($upload_dir['path'])) $file = $upload_dir['path'] . '/' . $filename;
else $file = $upload_dir['basedir'] . '/' . $filename;
file_put_contents($file, $image_data);
$wp_filetype = wp_check_filetype($filename, null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
@Roshanb54
Roshanb54 / WP Customizer - Dropdown-pages
Created November 17, 2017 11:14 — forked from ajskelton/WP Customizer - Dropdown-pages
Add a Dropdown-pages field to the WordPress Customizer.
$wp_customize->add_setting( 'themeslug_dropdownpages_setting_id', array(
'capability' => 'edit_theme_options',
'sanitize_callback' => 'themeslug_sanitize_dropdown_pages',
) );
$wp_customize->add_control( 'themeslug_dropdownpages_setting_id', array(
'type' => 'dropdown-pages',
'section' => 'custom_section', // Add a default or your own section
'label' => __( 'Custom Dropdown Pages' ),
'description' => __( 'This is a custom dropdown pages option.' ),
add_filter( 'rest_prepare_(post_type)', 'function_name', 10, 3 );
function function_name( $data, $post, $request ) {
$_data = $data->data;
$thumbnail_id = get_post_thumbnail_id( $post->ID );
$thumbnail_full = wp_get_attachment_image_src( $thumbnail_id, 'full' );
$thumbnail_thumb = wp_get_attachment_image_src( $thumbnail_id, 'thumbnail' );
$thumbnail_medium = wp_get_attachment_image_src( $thumbnail_id, 'medium' );
$thumbnail_large = wp_get_attachment_image_src( $thumbnail_id, 'large' );
if( ! empty($thumbnail_id) ) {
<?php
/*
* Paginate Advanced Custom Field repeater
*/
if( get_query_var('page') ) {
$page = get_query_var( 'page' );
} else {
$page = 1;
}
// Variables