Skip to content

Instantly share code, notes, and snippets.

@ray1980
ray1980 / mb-block.js
Created June 1, 2021 02:30 — forked from pupunzi/mb-block.js
A simple Wordpress Gutenberg plug-in
/**
* mb Gutemberg block
* Copyright (c) 2001-2018. Matteo Bicocchi (Pupunzi)
*/
var el = wp.element.createElement,
registerBlockType = wp.blocks.registerBlockType,
ServerSideRender = wp.components.ServerSideRender,
TextControl = wp.components.TextControl,
TextareaControl = wp.components.TextareaControl,
InspectorControls = wp.editor.InspectorControls;
// Get helper functions from global scope
const { registerBlockType } = window.wp.blocks;
const { __ } = window.wp.i18n;
// Use registerBlockType to create a custom block
registerBlockType(
'example-plugin/example-custom-block',
{
// Localize title using wp.i18n.__()
title: __( 'Block Title' ),
@ray1980
ray1980 / custom_walker.php
Created April 27, 2021 13:51 — forked from cleverinx/custom_walker.php
Custom Wordpress Sub-Menu Walker
class custom_sub_walker extends Walker_Nav_Menu {
public function start_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat( "\t", $depth );
$output .= "\n$indent<ul role=\"menu\" class=\" dropdown-menu\">\n";
}
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
@ray1980
ray1980 / bootstrap-4-menu-wordpress-filters.md
Created April 27, 2021 06:11 — forked from jakebellacera/bootstrap-4-menu-wordpress-filters.md
Bootstrap 4 menus in WordPress via filters. No walker needed!

Bootstrap 4 menus in WordPress with filters

No walker needed!

This snippet allows you to create Bootstrap 4 menus without the use of a Walker. Instead, we're using filters to leverage WordPress core functionality as much as possible. Basically, all you need to do is this and you're done:

<nav class="navbar navbar-expand-lg fixed-top">
  <div class="container">
    <a class="navbar-brand" href="<?php echo home_url(); ?>">
@ray1980
ray1980 / block.php
Created April 16, 2021 08:38 — forked from nextend/block.php
Gutenberg block.php Smart Slider 3
<?php
defined('ABSPATH') || exit;
class NextendSmartSlider3Gutenberg {
public function __construct() {
add_action('enqueue_block_editor_assets', array(
$this,
'enqueue_block_editor_assets'
@ray1980
ray1980 / block.js
Created April 16, 2021 08:38 — forked from nextend/block.js
Gutenberg block.js Smart Slider 3
(function (blocks, editor, i18n, element, components, _) {
var el = element.createElement;
blocks.registerBlockType('nextend/smartslider3', {
title: 'Smart Slider 3',
icon: 'welcome-learn-more',
category: 'common',
attributes: {
slider: {
type: 'string'
@ray1980
ray1980 / ajax-file-upload.js
Created March 29, 2021 12:30 — forked from greenyleaf/ajax-file-upload.js
Upload files using ajax. Using FormData only if there are file fields in the form, to reduce the upload size when not needed.
$.ajax('http://custom.sdrkyj.top/form-action-url', {
contentType: hasFiles ? false : undefined,
data: hasFiles ? new FormData(formDom) : $(formDom).serialize(),
method: 'post',// 'patch'
dataType: 'json',
processData: !hasFiles,
xhr: function () {
let xhr = $.ajaxSettings.xhr();
hasFiles && xhr.upload.addEventListener('progress', function (e) {
if (e.lengthComputable && e.total > 1 << 17) {
@ray1980
ray1980 / china-national-radio.m3u8
Created March 29, 2021 12:23 — forked from greenyleaf/china-national-radio.m3u8
China National Radio streams
#EXTM3U
#EXTINF:60,中国之声
#EXTVLCOPT:network-caching=1000
http://ngcdn001.cnr.cn/live/zgzs/index.m3u8
#EXTINF:60,中国之声 low resolution
#EXTVLCOPT:network-caching=1000
http://ngcdn001.cnr.cn/live/zgzs48/index.m3u8
#EXTINF:60,经济之声
#EXTVLCOPT:network-caching=1000
http://ngcdn002.cnr.cn/live/jjzs/index.m3u8
@ray1980
ray1980 / comments-ajax-8Lxhzl32Y243.php
Created September 9, 2020 01:51 — forked from loveyu/comments-ajax-8Lxhzl32Y243.php
wordpress 自定义评论提交
<?php
header("Content-Type: text/html; charset=utf-8");
function err($error){
header('HTTP/1.1 405 Method Not Allowed');
echo $error;
comment_error_record($error);
exit;
}
function is_black_author($author){
<style>
body.grayDay {
filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);
-webkit-filter: grayscale(100%); }
</style>
<script>
window.onload = function() {
var grayDay = [108, 207, 219, 404, 420, 512, 815, 909, 918, 1213];
var today = new Date();
var d = (today.getMonth() + 1) * 100 + today.getDate();