Skip to content

Instantly share code, notes, and snippets.

Dinesh Kesarwani cyberwani

View GitHub Profile
@cyberwani
cyberwani / Youtube_Regex_Grab_Video-Playlist_ID_With_Time.php Best regex pattern to get youtube video/playlist id with/without time from any youtube link and generate embed code. This regex works with 1) youtube & youtu.be 2) http/https 3) with/without www.
View Youtube_Regex_Grab_Video-Playlist_ID_With_Time.php
<?php
/*
* @gist Regex to get youtube video/playlist id with/without time & generate embed code
* @license UNLICENSE (http://unlicense.org)
*/
$youtube_url = array(
"https://youtu.be/yVpbFMhOAwE",
"https://www.youtube.com/embed/yVpbFMhOAwE",
@cyberwani
cyberwani / .editorconfig
Created Feb 17, 2020 — forked from salcode/.editorconfig
WordPress .editorconfig - modified version of the WordPress coding standards
View .editorconfig
# EditorConfig helps keep your project formatting consistent.
# See https://EditorConfig.org
#
# This is a modified version of the WordPress coding standards.
#
# Author: Sal Ferrarello (@salcode)
# https://salferrarello.com/wordpress-editorconfig/
#
# You can download this file directly
# to your project from the command-line with
@cyberwani
cyberwani / sendmail in wamp
Created Feb 11, 2020 — forked from abdullahbutt/sendmail in wamp
how to send email from wamp using sendmail
View sendmail in wamp
Install Fake Sendmail (http://glob.com.au/sendmail/). Then configure C:\wamp\sendmail\sendmail.ini:
smtp_server=smtp.gmail.com
smtp_port=465
auth_username=user@gmail.com
auth_password=your_password
The above will work against a Gmail account. And then configure php.ini:
sendmail_path = "C:\wamp\sendmail\sendmail.exe -t"
Now, restart Apache, and that is basically all you need to do.
@cyberwani
cyberwani / is_localhost
Created Feb 10, 2020 — forked from troutacular/is_localhost
PHP - Check if localhost
View is_localhost
// Check if we are in a local environment
function is_localhost() {
// set the array for testing the local environment
$whitelist = array( '127.0.0.1', '::1' );
// check if the server is in the array
if ( in_array( $_SERVER['REMOTE_ADDR'], $whitelist ) ) {
@cyberwani
cyberwani / sample-admin-notice.php
Created Jan 8, 2020 — forked from glueckpress/sample-admin-notice.php
[WordPress] Sample Admin Notices
View sample-admin-notice.php
<?php
defined( 'ABSPATH' ) or die( 'Poop.' );
/**
* Plugin Name: _Sample Admin Notice
* Description: Displays a sample admin notice once for admins. (Requires PHP 5.3+.)
* Version: 0.1
* Author: Caspar Hübinger
* Plugin URI: https://gist.github.com/glueckpress/6befeb937da89025d4d8#file-sample-admin-notice-php
* Author URI: https://profiles.wordpress.org/glueckpress
* License: GNU General Public License v3
@cyberwani
cyberwani / gist:13b58596ba7782a7d7aac8b55c534452
Created Dec 10, 2019 — forked from danielbachhuber/gist:7684646
How to integrate WordPress Core updates with your custom Plugin or Theme
View gist:13b58596ba7782a7d7aac8b55c534452
<?php
/**
* How to integrate WordPress Core updates with your custom Plugin or Theme
*
* Filter the `update_plugins` transient to report your plugin as out of date.
* Themes have a similar transient you can filter.
*/
add_filter( 'site_transient_update_plugins', 'wprp_extend_filter_update_plugins' );
add_filter( 'transient_update_plugins', 'wprp_extend_filter_update_plugins' );
function wprp_extend_filter_update_plugins( $update_plugins ) {
@cyberwani
cyberwani / installed-plugin-details.php
Created Dec 10, 2019 — forked from bradyvercher/installed-plugin-details.php
WordPress Plugin: Show a "Details" link for installed plugins to view information from the WordPress.org plugin directory.
View installed-plugin-details.php
<?php
/**
* Plugin Name: Installed Plugin Details
* Description: Show a "Details" link for installed plugins to view information from the WordPress.org plugin directory.
* Version: 1.0.0
* Author: Blazer Six
* Author URI: http://www.blazersix.com/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
*
@cyberwani
cyberwani / upload-a-file.MD
Created Dec 4, 2019 — forked from websupporter/upload-a-file.MD
Upload a file using the WordPress REST API
View upload-a-file.MD

Upload files

Using the REST API to upload a file to WordPress is quite simple. All you need is to send the file in a POST-Request to the wp/v2/media route.

There are two ways of sending a file. The first method simply sends the file in the body of the request. The following PHP script shows the basic principle:

@cyberwani
cyberwani / gist:47005097c9e74100bfab92bb72dc6d12
Created Oct 24, 2019 — forked from mikejolley/gist:1604009
WooCommerce - Add a special field to the checkout, order emails and user/order meta
View gist:47005097c9e74100bfab92bb72dc6d12
/**
* Add the field to the checkout
**/
add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');
function my_custom_checkout_field( $checkout ) {
echo '<div id="my_custom_checkout_field"><h3>'.__('My Field').'</h3>';
/**
View WORDPRESS: Base64 Image to Wordpress Uploads directory
<?php
function tattoo_submit() {
if ( isset( $_POST['addtattoo'] ) ) {
$title = 'tattoo';
// Upload dir.
$upload_dir = wp_upload_dir();
$upload_path = str_replace( '/', DIRECTORY_SEPARATOR, $upload_dir['path'] ) . DIRECTORY_SEPARATOR;
$img_type = 'jpeg';
You can’t perform that action at this time.