Skip to content

Instantly share code, notes, and snippets.

View Jany-M's full-sized avatar
🎯
Focusing

Jany Martelli Jany-M

🎯
Focusing
View GitHub Profile
@Jany-M
Jany-M / WP_order_hierarchical_list_by_date.php
Created April 8, 2016 15:04
[WordPress] Order Page and Hierarchical Custom Post Types list by date
<?php
// Change all pages and hierarchical custom post types to date order
function custom_page_order( $wp_query ) {
global $pagenow;
if (is_admin() && 'edit.php' == $pagenow && !isset($_GET['orderby'])) {
$wp_query->set( 'orderby', 'date' );
$wp_query->set( 'order', 'DSC' );
}
}
@Jany-M
Jany-M / post-expirator.php
Created June 30, 2016 15:15
[WP] Added "Pending Review" as post status option, for plugin "Post Expirator"
<?php
/*
Plugin Name: Post Expirator
Plugin URI: http://wordpress.org/extend/plugins/post-expirator/
Description: Allows you to add an expiration date (minute) to posts which you can configure to either delete the post, change it to a draft, or update the post categories at expiration time.
Author: Aaron Axelsen
Version: 2.1.4
Author URI: http://postexpirator.tuxdocs.net/
Translation: Thierry (http://palijn.info)
Text Domain: post-expirator
@Jany-M
Jany-M / wp_ics.php
Last active September 19, 2023 03:15 — forked from jakebellacera/ICS.php
[WP] Generate a downloadable .ics file from any WordPress post or custom post type
<?php
/*
For a better understanding of ics requirements and time formats
please check https://gist.github.com/jakebellacera/635416
*/
// UTILS
// Check if string is a timestamp
@Jany-M
Jany-M / check_h3_tags.php
Created August 1, 2016 15:56
[WP] Check content for h3 tags
<?php
// Check content for h3
$doc = new DOMDocument;
$doc->loadHTML(get_the_content(get_the_ID()));
$titles = $doc->getElementsByTagName('h3');
//var_dump($titles); // int
// Prints the content
if( !is_null($titles->item(0)) ) {
@Jany-M
Jany-M / wp_posts.reset.sql
Created August 5, 2016 20:07 — forked from abrudtkuhl/wp_posts.reset.sql
Reset Auto_Increment in WordPress Posts table
/*DELETE FROM wp_posts;
DELETE FROM wp_postmeta;*/
TRUNCATE TABLE wp_posts;
TRUNCATE TABLE wp_postmeta;
@Jany-M
Jany-M / wp_weekly_cal.php
Created August 12, 2016 14:45
[WP] Custom WordPress weekly dynamic calendar, with custom post types, custom date fields and caching
<div id="calendar">
<?php
// Dates
$year = date('Y');
$first_month_this_year_ts = mktime(0, 0, 0, date("F", strtotime('first month of this year')) + 1, date('d'), date('Y')); // timestamp
$today = date("j F Y", strtotime('today')); // human date
$today_ts = strtotime('today'); // timestamp
$today_day_of_year = date("z", $today_ts);// int
@Jany-M
Jany-M / php_find_string_between_strings.php
Created August 17, 2016 01:22
[PHP] Parse a string between two strings
<?php
// PHP – parse a string between two strings
// Credits: http://www.justin-cook.com/wp/2006/03/31/php-parse-a-string-between-two-strings/
function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
@Jany-M
Jany-M / wp_gallery_shortcode_url_parser.php
Last active August 19, 2016 18:05
[WP] Shortcode for a custom Swiper gallery, extract & convert plain text image urls from WordPress post content
@Jany-M
Jany-M / fixed_width_columns_table.html
Created September 1, 2016 14:34
[HTML] Fixed column width table
<table style="table-layout: fixed;">
<colgroup>
<col span="1" style="width: 10%;">
<col span="1" style="width: 10%;">
<col span="1" style="width: 40%;">
<col span="1" style="width: 40%;">
</colgroup>
<tbody>
@Jany-M
Jany-M / php_regex.php
Last active June 6, 2021 16:23
[PHP] Common RegEx
<?php
// Let's be honest, RegEx is not fun, so these may come in handy
// I'll update this in case I write/find more
$text = '[video mp4="http://somevideo.com/abc"]';
preg_match_all("\bmp4="(.+)\b", $text, $matches);
var_dump($matches[0]);
// http://somevideo.com/abc