Skip to content

Instantly share code, notes, and snippets.

@Cheslab
Cheslab / upload.js
Created October 23, 2019 23:28
WordPress Media Library with pre-selected items
/**
* Utilize WordPress' media library. Easy select/upload files for your plugin/theme admin page.
* It uses build-in jQuery 1.4.1
* Tested with WordPress 5.2.4
*/
$('.my-upload-button').click(function(e) {
e.preventDefault();
// setup our media library frame
// jQuery UI is required
<form action="" class="form-filters">
<label for="from">From</label>
<input type="text" id="from" name="from">
<label for="to">to</label>
<input type="text" id="to" name="to">
<script>
$(function() {
var dateFrom = new Date();
@Cheslab
Cheslab / are_you_sure.js
Last active March 25, 2018 20:45
SweetAlert confirmation window + ajax
// SweetAlert.js is required
$('.trigger').click(function(e) {
e.preventDefault();
swal({
title: "Are you sure?",
text: "If you're sure click YES",
icon: "warning",
buttons: true,
dangerMode: true
@Cheslab
Cheslab / autocomplete.js
Last active January 18, 2018 01:19
Input autocomplete with ajax
// jQuery UI is required
$("#target_input").autocomplete({
minLength: 2,
source: "ajax/autocomplete.php", // expects JSON
select: function(event, ui) {
$("#target_input").val(ui.item.label); // display the selected text
$("#target_input-id").val(ui.item.value); // save selected id to hidden input
event.preventDefault(); // prevent autocomplete from updating the textbox
return false; // prevent from inserting id into the input instead of label
<script src="https://api-maps.yandex.ru/2.1/?lang=ru_RU" type="text/javascript"></script>
<div id="map" style="width: 100%; height: 600px"></div>
<script type="text/javascript">
var elementExists = document.getElementById("map");
if (elementExists != null) {
ymaps.ready(init);
var myMap,
myPlacemark;
@Cheslab
Cheslab / wordpress-plugin-admin-styling.php
Last active June 8, 2017 16:16
wordpress plugin admin page style external file
// In order to use an external css file in the plugin's admin panel:
// 1. Copy following code to the main php file of your plugin (plugins/your_plugin/your_plugin_name.php)
// 2. Create admin.css (or adjust the name below)
function plugin_name_admin_css()
{
$siteurl = get_option('siteurl');
$url = $siteurl . '/wp-content/plugins/' . basename(dirname(__FILE__)) . '/admin.css';
echo "<link rel='stylesheet' type='text/css' href='$url' />\n";
}