Skip to content

Instantly share code, notes, and snippets.

@tanjimahmmed
Last active February 24, 2020 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanjimahmmed/8d7cc559ec19a6a363780cce776767a6 to your computer and use it in GitHub Desktop.
Save tanjimahmmed/8d7cc559ec19a6a363780cce776767a6 to your computer and use it in GitHub Desktop.
attachments plugin method add
<?php
define('ATTACHMENTS_SETTINGS_SCREEN', false);
add_filter('attachments_default_instance', '__return_false');
// field area
function philosophy_attachments($attachments){
// if else
$post_id = null;
if( isset( $_REQUEST['post']) || isset( $_REQUEST['post_ID'] ) ){
$post_id = empty($_REQUEST['post_ID']) ? $_REQUEST['post'] : $_REQUEST['post_ID'];
}
if(!$post_id || get_post_format( $post_id )!="gallery"){
return;
}
$fields = array(
array(
'name' => 'title',
'type' => 'text',
'label' => __('Title', 'philosophy'),
),
);
// add area
$args = array(
'label' => 'Gallery',
'post_type' => array('post'),
'filetype' => array("image"),
'note' => 'Add Gallery Images',
'button_text' => __('Attach Image', 'philosophy'),
'fields' => $fields,
);
// add slider
$attachments->register('gallery', $args);
}
add_action('attachments_register', 'philosophy_attachments');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment