Skip to content

Instantly share code, notes, and snippets.

@mark2me
mark2me / 10to2.py
Last active October 12, 2022 06:38
可計算小數點的10進位轉2進位
from decimal import Decimal
def calc(num):
rs = ''
try:
num = int(num)
except ValueError:
try:
num = Decimal(num)
@mark2me
mark2me / wp_duplicate_post.php
Last active December 5, 2021 05:52
WordPress 複製文章
<?php
/*
* Function for post duplication. Dups appear as drafts. User is redirected to the edit screen
*/
function sig_duplicate_post_as_draft(){
global $wpdb;
if (! ( isset( $_GET['post']) || isset( $_POST['post']) || ( isset($_REQUEST['action']) && 'sig_duplicate_post_as_draft' == $_REQUEST['action'] ) ) ) {
@mark2me
mark2me / use-first-image-as-thumbnail.php
Created August 12, 2021 06:57
若沒有設定精選圖片,則抓取內容的第一張圖當成精選圖
add_filter( 'has_post_thumbnail' ,function(){
return true;
});
add_filter( 'post_thumbnail_html' ,function ( $html, $post_id, $post_thumbnail_id ){
if( empty($html) ){
global $post;
if ($img = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches));
if ( isset($matches[1][0]) ){
$id = attachment_url_to_postid($matches[1][0]);
@mark2me
mark2me / wp-install.sh
Last active August 24, 2021 02:21
安裝 WordPress 自動化
#!/usr/bin/env bash
clear
# User Inputs
read -p "Site URL: " url
read -p "Site title: " title
read -p "DB Name: " dbname
read -p "DB User: " dbuser
read -p "DB Pass: " dbpass
read -p "WP version [Enter is default]: " wpver
public function check_gd( $args = array() ) {
if ( ! extension_loaded( 'gd' ) || ! function_exists( 'gd_info' ) ) {
return false;
}
return true;
}
public function check_imagick() {
// check Imagick's extension and classes
if ( ! extension_loaded( 'imagick' ) || ! class_exists( 'Imagick', false ) || ! class_exists( 'ImagickPixel', false ) )
return false;
// check version
if ( version_compare( phpversion( 'imagick' ), '2.2.0', '<' ) )
return false;
// check for deep requirements within Imagick
@mark2me
mark2me / curl-get-post.php
Last active October 19, 2020 02:22
curl-get-post.php
<?php
class Curl {
protected $token = "";
protected $http_status_code = 0;
public function __construct() {
}
<?php
add_action('in_widget_form', 'sig_in_widget_form', 5, 3);
add_filter('widget_update_callback', 'sig_in_widget_form_update', 5, 3);
add_filter('widget_tag_cloud_args', 'sig_tag_cloud_widget_limit', 5, 2);
function sig_in_widget_form($widget, $return, $instance){
$number = isset( $instance['number'] ) ? $instance['number'] : 45 ;
if( $widget->id_base === 'tag_cloud' ){ ?>
<p>
@mark2me
mark2me / jquery-ui-sortable-child.js
Last active August 11, 2020 03:25
Let jquery ui sortable enable child items
$('#menu-items').sortable({
placeholder: "placeholder",
sort: function( event, ui ) {
if( ui.item.index() > 0 && ui.position.left > 80){
$('.placeholder').css('margin-left','30px');
}
},
stop: function( event, ui ) {
if( ui.item.index() > 0 && ui.position.left > 80){
ui.item.css('margin-left','30px');
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">