PHP Class Dynamic_Featured_Image, Dynamic-Featured-Image

Author: Ankit Pokhrel ([email protected])
Exibir arquivo Open project: ankitpokhrel/dynamic-featured-image

Protected Properties

Property Type Description
$_metabox_title * Title for dfi metabox
$_textDomain * Plugin text domain
$_userFilter * Users post type filter for dfi metabox

Public Methods

Method Description
__construct ( ) Constructor. Hooks all interactions to initialize the class.
add_metabox_classes ( $classes ) : string Add custom class 'featured-meta-box' to meta box
ajax_callback ( ) : Void Load new featured meta box via ajax
dfi_action_links ( array $links ) : array Add upgrade link
enqueue_admin_scripts ( ) : Void Add required admin scripts
featured_meta_box ( Object $post, Array $featured ) : Void Featured meta box as seen in the admin
get_all_featured_images ( integer $post_id = null ) : Array Retrieve featured images for specific post(s) including the default Featured Image
get_featured_images ( integer $post_id = null ) : Array Retrieve featured images for specific post(s)
get_image_alt ( String $image_url ) : String Get image alternate text
get_image_alt_by_id ( integer $attachment_id ) : String Get image alternate text by attachment id
get_image_caption ( String $image_url ) : String Get image caption
get_image_caption_by_id ( integer $attachment_id ) : String Get image caption by id
get_image_description ( String $image_url ) : String Get image description
get_image_description_by_id ( integer $attachment_id ) : String Get image description by id
get_image_id ( String $image_url ) : integer | Null Gets attachment id from given image url
get_image_thumb ( String $image_url, String $size = 'thumbnail' ) : String Get image thumbnail url of specific size by image url
get_image_title ( String $image_url ) : String Get image title
get_image_title_by_id ( integer $attachment_id ) : String Get image title by id
get_image_url ( integer $attachment_id, String $size = 'full' ) : String Get image url of the image by attachment id
get_link_to_image ( integer $attachment_id ) : string | null Get link to image
get_nth_featured_image ( integer $position, integer $post_id = null ) : Array Fetches featured image data of nth position
get_post_attachment_ids ( integer $post_id ) : Array Get all attachment ids of the post
initialize_featured_box ( ) : Void Add featured meta boxes dynamically
is_attached ( $attachment_id, $post_id ) : boolean Check if the image is attached with the particular post
load_plugin_textdomain ( ) : void Load the plugin's textdomain hooked to 'plugins_loaded'.
media_attachment_custom_fields ( $form_fields, $post ) : Array Add custom fields in media uploader
media_attachment_custom_fields_save ( $post, $attachment ) : Array Save values of media uploader custom fields
save_meta ( integer $post_id ) : Void Update featured images in the database
update_notice ( ) : Void Add update notice. Displayed in plugin update page.

Protected Methods

Method Description
_get_attachment_id ( String $image_url ) : string Get attachment id of the image by image url
_get_number_translation ( integer $number ) : String Translates more than one digit number digit by digit.
_get_real_upload_path ( string $img ) : string Check to see if the upload url is already available in path.
_nonce_field ( string $key ) : string Create a nonce field
_verify_nonces ( ) : boolean Verify metabox nonces

Private Methods

Method Description
__get_protocol ( ) : string Return site protocol
_dfi_add_meta_box ( Array $postTypes, Object $featured = null, integer $i = null ) : Void adds meta boxes
_get_featured_box ( String $featuredImgTrimmed, String $featuredImg, String $featuredId, String $thumbnail, $postId ) : String Returns featured box html content
_separate ( string $urlString, string $state = 'thumb' ) : string | null Separate thumb and full image url from given URL string
execute_query ( $query ) Helper functions

Method Details

__construct() public method

Constructor. Hooks all interactions to initialize the class.
See also: add_action()
Since: 1.0.0
public __construct ( )

_get_attachment_id() protected method

Get attachment id of the image by image url
Since: 3.1.7
protected _get_attachment_id ( String $image_url ) : string
$image_url String url of the image
return string

_get_number_translation() protected method

Translates more than one digit number digit by digit.
protected _get_number_translation ( integer $number ) : String
$number integer Integer to be translated
return String Translated number

_get_real_upload_path() protected method

Check to see if the upload url is already available in path.
Since: 3.1.14
protected _get_real_upload_path ( string $img ) : string
$img string
return string

_nonce_field() protected method

Create a nonce field
See also: wp_nonce_field()
See also: plugin_basename()
Since: 3.5.0
protected _nonce_field ( string $key ) : string
$key string Nonce key
return string

_verify_nonces() protected method

Verify metabox nonces
See also: wp_verify_nonce()
protected _verify_nonces ( ) : boolean
return boolean

add_metabox_classes() public method

Add custom class 'featured-meta-box' to meta box
See also: add_metabox_classes
Since: 1.0.0
public add_metabox_classes ( $classes ) : string
$classes classes to add in the meta box
return string

ajax_callback() public method

Load new featured meta box via ajax
Since: 1.0.0
public ajax_callback ( ) : Void
return Void

enqueue_admin_scripts() public method

Add required admin scripts
See also: wp_enque_style()
See also: wp_register_script()
See also: wp_enqueue_script()
Since: 1.0.0
public enqueue_admin_scripts ( ) : Void
return Void

get_image_alt() public method

Get image alternate text
See also: get_post_meta()
Since: 2.0.0
public get_image_alt ( String $image_url ) : String
$image_url String url of an image
return String

get_image_alt_by_id() public method

Get image alternate text by attachment id
See also: get_post_meta()
Since: 2.0.0
public get_image_alt_by_id ( integer $attachment_id ) : String
$attachment_id integer attachment id of an image
return String

get_image_caption() public method

Get image caption
Since: 2.0.0
public get_image_caption ( String $image_url ) : String
$image_url String url of an image
return String

get_image_caption_by_id() public method

Get image caption by id
Since: 2.0.0
public get_image_caption_by_id ( integer $attachment_id ) : String
$attachment_id integer attachment id of an image
return String

get_image_description() public method

Get image description
Since: 3.0.0
public get_image_description ( String $image_url ) : String
$image_url String url of an image
return String

get_image_description_by_id() public method

Get image description by id
Since: 3.0.0
public get_image_description_by_id ( integer $attachment_id ) : String
$attachment_id integer attachment id of an image
return String

get_image_id() public method

Gets attachment id from given image url
Since: 2.0.0
public get_image_id ( String $image_url ) : integer | Null
$image_url String url of an image
return integer | Null attachment id of an image

get_image_thumb() public method

Get image thumbnail url of specific size by image url
See also: get_image_id()
See also: wp_get_attachment_image_src()
Since: 2.0.0
public get_image_thumb ( String $image_url, String $size = 'thumbnail' ) : String
$image_url String url of an image
$size String size of the image to fetch (thumbnail, medium, full)
return String

get_image_title() public method

Get image title
Since: 2.0.0
public get_image_title ( String $image_url ) : String
$image_url String url of an image
return String

get_image_title_by_id() public method

Get image title by id
Since: 2.0.0
public get_image_title_by_id ( integer $attachment_id ) : String
$attachment_id integer attachment id of an image
return String

get_image_url() public method

Get image url of the image by attachment id
See also: wp_get_attachment_image_src()
Since: 2.0.0
public get_image_url ( integer $attachment_id, String $size = 'full' ) : String
$attachment_id integer attachment id of an image
$size String size of the image to fetch (thumbnail, medium, full)
return String

get_post_attachment_ids() public method

Get all attachment ids of the post
See also: get_post_meta()
Since: 2.0.0
public get_post_attachment_ids ( integer $post_id ) : Array
$post_id integer id of the current post
return Array

is_attached() public method

Check if the image is attached with the particular post
See also: get_post_attachment_ids()
Since: 2.0.0
public is_attached ( $attachment_id, $post_id ) : boolean
$attachment_id attachment id of an image
$post_id id of the current post
return boolean

load_plugin_textdomain() public method

Load the plugin's textdomain hooked to 'plugins_loaded'.
See also: load_plugin_textdomain()
See also: plugin_basename()
Since: 1.0.0
public load_plugin_textdomain ( ) : void
return void

media_attachment_custom_fields() public method

Add custom fields in media uploader
Since: 3.4.0
public media_attachment_custom_fields ( $form_fields, $post ) : Array
$form_fields Array Fields to include in media attachment form
$post Array Post data
return Array

media_attachment_custom_fields_save() public method

Save values of media uploader custom fields
Since: 3.4.0
public media_attachment_custom_fields_save ( $post, $attachment ) : Array
$post Array The post data for database
$attachment Array Attachment fields from $_POST form
return Array

save_meta() public method

Update featured images in the database
See also: plugin_basename()
See also: update_post_meta()
See also: current_user_can()
Since: 1.0.0
public save_meta ( integer $post_id ) : Void
$post_id integer current post id
return Void

update_notice() public method

Add update notice. Displayed in plugin update page.
Since: 2.0.0
public update_notice ( ) : Void
return Void

Property Details

$_metabox_title protected_oe property

* Title for dfi metabox
protected $_metabox_title

$_textDomain protected_oe property

* Plugin text domain
protected $_textDomain

$_userFilter protected_oe property

* Users post type filter for dfi metabox
protected $_userFilter