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 / 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_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 / WP_display_children_metabox.php
Created April 8, 2016 14:58
[WordPress] Display Post or Page Children in custom MetaBox
<?php
// This requires that your post type is hierarchical obviously (like Pages)
// Display all children of this post/page in a custom metabox below title
function display_msg_for_parents( $post ) {
$children = get_pages(array('child_of' => $post->ID, 'post_type' => get_post_type($post->ID),));
if(!empty($children)) { ?>
<div class="rp_children postbox">
<button class="handlediv button-link" aria-expanded="true" type="button">
<span class="screen-reader-text">Toggle panel: Children</span>
@Jany-M
Jany-M / WP_all_posts_default.php
Created April 8, 2016 14:54
[WordPress] Go to All Posts by default, not Mine
<?php
// Go to All posts by default, not Mine
function go_to_all() {
global $typenow;
// Use this if you need this only on specific post types
/*if( 'post' !== $typenow )
return;*/
@Jany-M
Jany-M / WP_hide_trash_link_check_role_move_last.php
Created April 8, 2016 14:49
[WordPress] Hide Trash link depending on User Role and place it for last
@Jany-M
Jany-M / WP_view_link_new_tab.php
Created April 8, 2016 14:44
[WordPress] View link opens Post in a new Tab
@Jany-M
Jany-M / WP_extend_duplicate_content_create_clones_and_identical_children.php
Created April 8, 2016 14:38
[WordPress[ Extend Duplicate Content functions to create clones and identical post children
<?php
// Requires the duplicate_content() function
// https://gist.github.com/Jany-M/ba36a0499e4fb505105e
// Add link to create a cloned CHILD of this post, to action list for post_row_actions
function duplicate_content_link( $actions, $post ) {
global $typenow;
$user_id = get_current_user_id();
$user_data = get_userdata($user_id);
@Jany-M
Jany-M / WP_automatically_rename_slug_on_post_save.php
Last active June 6, 2021 16:29
[WordPress] Automatically rename post slug on post save
<?php
// Change & Save New Permalink if post title was changed
function update_slug_on_edit( $data, $postarr ) {
global $post;
$id = $post->ID;
$status = $post->post_status;
$cpt = get_post_type($id);
$parent = $post->post_parent;
@Jany-M
Jany-M / WP_gists_as_wordpress_posts.php
Last active June 6, 2021 16:29
[WordPress] Display Gists as if they were real WordPress Posts (without saving them to database)
<?php
// This will display Gists as if they were real WP posts, so you can display them mixed with real ones too
// This will NOT add the Gists as real posts in your DB, you won't see them in your backend
/* --------------------------------------
|
| Real Posts Loop
|
|---------------------------------------*/
@Jany-M
Jany-M / WP_flush_cache_and_transients.php
Last active January 20, 2025 12:13
[WordPress] Flush Object Cache (Memcached) & Transients - Admin buttons
<?php
// Flush Cache from Admin bar
function flush_memcache_button() {
global $wp_admin_bar;
// If User isnt even logged in or if admin bar is disabled
if ( !is_user_logged_in() || !is_admin_bar_showing() )
return false;