Last active
November 26, 2018 11:33
-
-
Save avillegasn/0e14fbe630e1c7763a871ca538860f2a to your computer and use it in GitHub Desktop.
Plugin file to use different image sizes with Nelio Content and Advanced Custom Fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"key": "group_5bf27651e03b6", | |
"title": "Social Images", | |
"fields": [ | |
{ | |
"key": "field_5bf2766a5c07d", | |
"label": "Facebook", | |
"name": "nc-facebook-featured-image", | |
"type": "image", | |
"instructions": "", | |
"required": 0, | |
"conditional_logic": 0, | |
"wrapper": { | |
"width": "", | |
"class": "", | |
"id": "" | |
}, | |
"return_format": "url", | |
"preview_size": "thumbnail", | |
"library": "all", | |
"min_width": "", | |
"min_height": "", | |
"min_size": "", | |
"max_width": "", | |
"max_height": "", | |
"max_size": "", | |
"mime_types": "" | |
}, | |
{ | |
"key": "field_5bf277b54e5cc", | |
"label": "Twitter", | |
"name": "nc-twitter-featured-image", | |
"type": "image", | |
"instructions": "", | |
"required": 0, | |
"conditional_logic": 0, | |
"wrapper": { | |
"width": "", | |
"class": "", | |
"id": "" | |
}, | |
"return_format": "url", | |
"preview_size": "thumbnail", | |
"library": "all", | |
"min_width": "", | |
"min_height": "", | |
"min_size": "", | |
"max_width": "", | |
"max_height": "", | |
"max_size": "", | |
"mime_types": "" | |
}, | |
{ | |
"key": "field_5bfbd906694d9", | |
"label": "Instagram", | |
"name": "nc-instagram-featured-image", | |
"type": "image", | |
"instructions": "", | |
"required": 0, | |
"conditional_logic": 0, | |
"wrapper": { | |
"width": "", | |
"class": "", | |
"id": "" | |
}, | |
"return_format": "url", | |
"preview_size": "thumbnail", | |
"library": "all", | |
"min_width": "", | |
"min_height": "", | |
"min_size": "", | |
"max_width": "", | |
"max_height": "", | |
"max_size": "", | |
"mime_types": "" | |
}, | |
{ | |
"key": "field_5bfbd921694da", | |
"label": "Pinterest", | |
"name": "nc-pinterest-featured-image", | |
"type": "image", | |
"instructions": "", | |
"required": 0, | |
"conditional_logic": 0, | |
"wrapper": { | |
"width": "", | |
"class": "", | |
"id": "" | |
}, | |
"return_format": "url", | |
"preview_size": "thumbnail", | |
"library": "all", | |
"min_width": "", | |
"min_height": "", | |
"min_size": "", | |
"max_width": "", | |
"max_height": "", | |
"max_size": "", | |
"mime_types": "" | |
}, | |
{ | |
"key": "field_5bfbd937694db", | |
"label": "LinkedIn", | |
"name": "nc-linkedin-featured-image", | |
"type": "image", | |
"instructions": "", | |
"required": 0, | |
"conditional_logic": 0, | |
"wrapper": { | |
"width": "", | |
"class": "", | |
"id": "" | |
}, | |
"return_format": "url", | |
"preview_size": "thumbnail", | |
"library": "all", | |
"min_width": "", | |
"min_height": "", | |
"min_size": "", | |
"max_width": "", | |
"max_height": "", | |
"max_size": "", | |
"mime_types": "" | |
} | |
], | |
"location": [ | |
[ | |
{ | |
"param": "post_type", | |
"operator": "==", | |
"value": "post" | |
} | |
] | |
], | |
"menu_order": 0, | |
"position": "side", | |
"style": "default", | |
"label_placement": "top", | |
"instruction_placement": "label", | |
"hide_on_screen": "", | |
"active": 1, | |
"description": "" | |
} | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* The plugin bootstrap file. | |
* | |
* Plugin Name: Nelio Content Social Featured Images | |
* Plugin URI: https://neliosoftware.com/content | |
* Description: Set better featured images depending on network. | |
* Version: 1.0.0 | |
* | |
* Author: Nelio Software | |
* Author URI: https://neliosoftware.com | |
* License: GPL-2.0+ | |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt | |
* | |
* @package Nelio_Content | |
* @subpackage Root | |
* @author David Aguilera <[email protected]> | |
* @since 1.0.0 | |
*/ | |
// If this file is called directly, abort. | |
if ( ! defined( 'WPINC' ) ) { | |
die; | |
}//end if | |
function nc_featured_images() { | |
if ( ! function_exists( 'get_field' ) ) { | |
return; | |
}//end if | |
$networks = array( 'facebook', 'googleplus', 'instagram', 'linkedin', 'pinterest', 'twitter' ); | |
foreach ( $networks as $network ) { | |
add_filter( "nelio_content_${network}_featured_image", | |
"nc_featured_images_set_${network}_featured_image", 10, 2 ); | |
}//end foreach | |
}//end nc_featured_images() | |
add_action( 'init', 'nc_featured_images' ); | |
function nc_featured_images_set_facebook_featured_image( $img, $post_id ) { | |
$image = get_field( 'nc-facebook-featured-image' ); | |
if ( ! empty( $image ) ) { | |
return $image; | |
}//end if | |
$post_thumbnail_id = get_post_meta( $post_id, 'nc-facebook-featured-image', true ); | |
if ( ! empty( $post_thumbnail_id ) ) { | |
return wp_get_attachment_url( $post_thumbnail_id ); | |
}//end if | |
return $img; | |
}//end nc_featured_images_set_facebook_featured_image() | |
function nc_featured_images_set_googleplus_featured_image( $img, $post_id ) { | |
$image = get_field( 'nc-googleplus-featured-image' ); | |
if ( ! empty( $image ) ) { | |
return $image; | |
}//end if | |
$post_thumbnail_id = get_post_meta( $post_id, 'nc-googleplus-featured-image', true ); | |
if ( ! empty( $post_thumbnail_id ) ) { | |
return wp_get_attachment_url( $post_thumbnail_id ); | |
}//end if | |
return $img; | |
}//end nc_featured_images_set_googleplus_featured_image() | |
function nc_featured_images_set_instagram_featured_image( $img, $post_id ) { | |
$image = get_field( 'nc-instagram-featured-image' ); | |
if ( ! empty( $image ) ) { | |
return $image; | |
}//end if | |
$post_thumbnail_id = get_post_meta( $post_id, 'nc-instagram-featured-image', true ); | |
if ( ! empty( $post_thumbnail_id ) ) { | |
return wp_get_attachment_url( $post_thumbnail_id ); | |
}//end if | |
return $img; | |
}//end nc_featured_images_set_instagram_featured_image() | |
function nc_featured_images_set_linkedin_featured_image( $img, $post_id ) { | |
$image = get_field( 'nc-linkedin-featured-image' ); | |
if ( ! empty( $image ) ) { | |
return $image; | |
}//end if | |
$post_thumbnail_id = get_post_meta( $post_id, 'nc-linkedin-featured-image', true ); | |
if ( ! empty( $post_thumbnail_id ) ) { | |
return wp_get_attachment_url( $post_thumbnail_id ); | |
}//end if | |
return $img; | |
}//end nc_featured_images_set_linkedin_featured_image() | |
function nc_featured_images_set_pinterest_featured_image( $img, $post_id ) { | |
$image = get_field( 'nc-pinterest-featured-image' ); | |
if ( ! empty( $image ) ) { | |
return $image; | |
}//end if | |
$post_thumbnail_id = get_post_meta( $post_id, 'nc-pinterest-featured-image', true ); | |
if ( ! empty( $post_thumbnail_id ) ) { | |
return wp_get_attachment_url( $post_thumbnail_id ); | |
}//end if | |
return $img; | |
}//end nc_featured_images_set_pinterest_featured_image() | |
function nc_featured_images_set_twitter_featured_image( $img, $post_id ) { | |
$image = get_field( 'nc-twitter-featured-image' ); | |
if ( ! empty( $image ) ) { | |
return $image; | |
}//end if | |
$post_thumbnail_id = get_post_meta( $post_id, 'nc-twitter-featured-image', true ); | |
if ( ! empty( $post_thumbnail_id ) ) { | |
return wp_get_attachment_url( $post_thumbnail_id ); | |
}//end if | |
return $img; | |
}//end nc_featured_images_set_twitter_featured_image() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment