Skip to content

Instantly share code, notes, and snippets.

@cyberwani
cyberwani / sample-admin-notice.php
Created January 8, 2020 12:11 — forked from glueckpress/sample-admin-notice.php
[WordPress] Sample Admin Notices
<?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 December 10, 2019 10:42 — forked from danielbachhuber/gist:7684646
How to integrate WordPress Core updates with your custom Plugin or Theme
<?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 December 10, 2019 07:57 — 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.
<?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 December 4, 2019 08:07 — forked from websupporter/upload-a-file.MD
Upload a file using the WordPress REST API

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 October 24, 2019 12:40 — forked from mikejolley/gist:1604009
WooCommerce - Add a special field to the checkout, order emails and user/order meta
/**
* 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>';
/**
@cyberwani
cyberwani / WORDPRESS: Base64 Image to Wordpress Uploads directory
Last active September 13, 2019 10:50 — forked from tjhole/WORDPRESS: Base64 Image to Wordpress Uploads directory
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';
@cyberwani
cyberwani / wordpress-upload-base64.php
Created September 13, 2019 10:19
Upload a base64 string as image to the WordPress media library
<?php
/**
* Save the image on the server.
*/
function save_image( $base64_img, $title ) {
// Upload dir.
$upload_dir = wp_upload_dir();
$upload_path = str_replace( '/', DIRECTORY_SEPARATOR, $upload_dir['path'] ) . DIRECTORY_SEPARATOR;
@cyberwani
cyberwani / gist:f0987fd98acc65e4193f519344538bf0
Created September 8, 2019 19:16 — forked from rolinger/gist:d6500d65128db95f004041c2b636753a
PHP => FCM Push notification tutorial for Android and iOS
Below is a full tutorial on how to setup and use Googles Firebase push notification API for both Android and iOS. It is based on this
earlier implementation of Googles GCM method: https://gist.github.com/prime31/5675017 - FCM is the new method and GCM will eventually be
retired.
## THE BELOW METHOD IS THE NEWER FCM METHOD:
Register your app in the FCM Console: https://console.firebase.google.com (add project)
1. Click on the newly added project, in the upper left menu is the "Overview" and Gear Settings.
2. Click on the GEAR settings icon, and then on "Project Settings"
3. In the main screen, click on "Cloud Messaging"
@cyberwani
cyberwani / gist:34d769e29f8a4f71f6fa015ce5e32eb4
Created September 8, 2019 19:14 — forked from prime31/gist:5675017
Simple PHP script showing how to send an Android push notification. Be sure to replace the API_ACCESS_KEY with a proper one from the Google API's Console page. To use the script, just call scriptName.php?id=THE_DEVICE_REGISTRATION_ID
<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'YOUR-API-ACCESS-KEY-GOES-HERE' );
$registrationIds = array( $_GET['id'] );
// prep the bundle
$msg = array
@cyberwani
cyberwani / PushNotifications.php
Created September 8, 2019 19:14 — forked from joashp/PushNotifications.php
Simple PHP script to send Android Push Notification, iOS Push Notification and Windows Phone 8 Push Notification
<?php
// Server file
class PushNotifications {
// (Android)API access key from Google API's Console.
private static $API_ACCESS_KEY = 'AIzaSyDG3fYAj1uW7VB-wejaMJyJXiO5JagAsYI';
// (iOS) Private key's passphrase.
private static $passphrase = 'joashp';
// (Windows Phone 8) The name of our push channel.
private static $channelName = "joashp";