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_custom_column_with_cloning.php
Last active June 6, 2021 16:30
[WordPress] Custom column with clone button to other custom post type
<?php
// Duplicate function
function duplicate_content(){
global $wpdb;
if (! ( isset( $_GET['post']) || isset( $_POST['post']) || ( isset($_REQUEST['action']) && 'duplicate_content' == $_REQUEST['action'] ) ) ) {
wp_die('No post to duplicate has been supplied!');
}
// Get original ID
@Jany-M
Jany-M / WP_get_facebook_page_likes.php
Last active February 29, 2016 23:01
[WordPress] Get Facebook Page Likes and Cache them
<?php
// Get a user Access Token (or Page Token if you're the page admin)
// https://developers.facebook.com/tools/explorer/145634995501895/
function get_fb_likes($what) {
$token = 'your_token_here';
//delete_transient('cached_fb');
if(false === ( $cached_fb_results = get_transient( 'cached_fb' ))) {
$json_url = 'https://graph.facebook.com/v2.5/'.$what.'?fields=likes&access_token='.$token;
$json = file_get_contents($json_url);
@Jany-M
Jany-M / WP_flush_cache_and_transients.php
Last active June 2, 2020 09:31
[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;
@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_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_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_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_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_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_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>