Skip to content

Commit

Permalink
Clone of "Image and Media Byline Credits" v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mirtoto committed Dec 13, 2020
0 parents commit d045fd7
Show file tree
Hide file tree
Showing 27 changed files with 1,902 additions and 0 deletions.
339 changes: 339 additions & 0 deletions LICENSE.txt

Large diffs are not rendered by default.

74 changes: 74 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
=== Image and Media Byline Credits ===
Contributors: devbackroom
Tags: image byline, image credit, byline, credit, image, featured, thumbnail, attachment, media, Gutenberg block, image block, gallery
Donate link: https://www.devbackroom.com/donate
Requires at least: 4.6.0
Tested up to: 5.4.1
Requires PHP: 7.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.txt

A simple way to add a byline credit to your images, media and other content.

== Description ==
We are blessed with free resources like plugins, apps, images, audio and video. Content creators give their time, skills and love to provide us with their creations. Show your appreciation by giving due credit and a link back to the provider, this could be to their donate page, website or hosted page.

This simple and flexible plugin makes it easy for you to add a byline credit to your images and other media. You can do the following:

* Add a byline credit field when uploading media.
* Automatically display the byline credit under featured images
* Automatically display the byline credit under images added with the Gutenberg image block.
* Include an optional link to the web page of the content owner or creator.
* Add freeform byline credit via a shortcode e.g. `[byline]Picture by Green Ant Media[/byline]` for more complex attribution or for a variety of media types.
* Use a list of users with a specified role or a simple list to autocomplete the names on the Byline field.
* Easily apply your own styles to the byline credit.

== Installation ==
1. Upload `image-byline.php` to the `/wp-content/plugins/` directory
2. Activate the plugin through the \"Plugins\" menu in WordPress

== Frequently Asked Questions ==
= Can I add a byline credit to audio or video? =

Yes. The byline shortcode can be used anywhere a shortcode can be used in a page or post. The shortcode takes the format `[byline]Picture by Green Ant Media[/byline]`. We plan to support more blocks in future, including audio, video and gallery blocks.

= Does the byline credit work with the classic editor? =

Yes. The byline shortcode can be used anywhere a shortcode can be used in a page or post. The shortcode takes the format `[byline]Picture by Green Ant Media[/byline]`.

= Does the byline credit work with Gutenberg image block? =

Yes. The byline credit is automatically added to the caption for the Gutenberg core image block.

= Are other Gutenberg blocks supported? =

As of this release, the credit is only added to the image block however you can use the shortcode to place a byline credit under the media. The shortcode takes the format `[byline]Picture by Green Ant Media[/byline]`. We plan to support more blocks in future, including audio, video and gallery blocks.

= Why is the byline credit not showing under the featured images? =

The byline credit gets added to the caption so if your theme is not outputting the caption for the featured image you will not see the credit. You can output the caption in your template or theme functions by using something like `the_post_thumbnail_caption(get_the_ID());`.

= Can I change how the byline credit looks? =

You can change how the byline credit looks by adding some custom css to your theme.

= Can I hide the byline credit on some images? =

If you have added a byline credit to your image in the media library, it will be output under the image. The simplest way would be to remove the byline. However, if you want to leave the creator data with your image, you can hide the byline credit adding a class `no-credit` to your image block in Additional CSS class(es). This hides the credit but still displays the caption if there is one. To hide both add `no-credit no-caption`.

= Can I show the byline credit but not the caption? =

You can show the byline credit without the caption by adding a class `no-caption` to your image block in Additional CSS class(es).

= Can I use the byline credit with my custom blocks or page builder? =

The byline shortcode can be used anywhere a shortcode can be used in a page or post. We are considering adding a support plan in future which will allow us to support more options. If your budget allows, you can contact us for developing a custom add-on for you for a cost. And you can always donate so that we can provide more options and support to you.

== Screenshots ==
1. Byline/credit on a post featured image.
2. Byline and Byline Link fields in the Media Library attachment editor page.
3. Image Byline Options page in dashboard.

== Changelog ==
= 1.0.0 =
* Initial version
311 changes: 311 additions & 0 deletions admin/class-image-byline-admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,311 @@
<?php

/**
* The admin-specific functionality of the plugin.
*
* @link https://www.devbackroom.com/
* @since 1.0.0
*
* @package Image_Byline
* @subpackage Image_Byline/admin
*/

/**
* The admin-specific functionality of the plugin.
*
* Defines the plugin name, version, enqueues the admin-specific stylesheets
* and JavaScript.
*
* @package Image_Byline
* @subpackage Image_Byline/admin
* @author Michelle Earl <michelle@devbackroom.com>
*/
class Image_Byline_Admin {

/**
* The ID of this plugin.
*
* @since 1.0.0
* @access private
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;

/**
* The version of this plugin.
*
* @since 1.0.0
* @access private
* @var string $version The current version of this plugin.
*/
private $version;

/**
* Initialize the class and set its properties.
*
* @since 1.0.0
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
*/
public function __construct( $plugin_name, $version ) {

$this->plugin_name = $plugin_name;
$this->version = $version;

}

/**
* Register the stylesheets for the admin area.
*
* @since 1.0.0
*/
public function enqueue_styles() {

wp_enqueue_style( 'auto_complete', plugin_dir_url( __FILE__ ) . 'css/jquery.auto-complete.css', array(), $this->version, 'all' );
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/image-byline-admin.css', array(), $this->version, 'all' );

}

/**
* Register the JavaScript for the admin area.
*
* @since 1.0.0
*/
public function enqueue_scripts() {

wp_enqueue_script( 'auto_complete_js', plugin_dir_url( __FILE__ ) . 'js/jquery.auto-complete.min.js', array( 'jquery' ), $this->version, false );
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/image-byline-admin.js', array( 'jquery' ), $this->version, false );

}

/**
* Output a json list of names for the autocomplete search.
*
* @since 1.0.0
*/
public function ajax_search_list() {

$options = get_option( 'imageByline_options' );
$search_list = array();

if ( !empty($options['search_suggestions_role']) ) {
$users = get_users( 'orderby=nicename&role='.$options['search_suggestions_role'] );

foreach ( $users as $value ) {
$search_list[] = addslashes($value->display_name);
}
}

if ( !empty($options['search_suggestions']) ) {
$names = explode("\n", str_replace(array("\n", "\r\n"), "\n", $options['search_suggestions']));
foreach ($names as $value) {
$value = trim($value);
if (!in_array($value, $search_list)) {
$search_list[] = $value;
}
}
}

echo json_encode($search_list);
die(); //stop "0" from being output
}

/**
* Add byline_attachment_field to the $form_fields array
*
* @param array $form_fields
* @param object $post
* @return array
* @since 1.0.0
*/
function byline_attachment_fields( $form_fields, $post ) {

$form_fields['byline'] = array(
'label' => __('Byline Credit', 'image-byline'),
'input' => 'text',
'value' => get_post_meta( $post->ID, '_byline', true )
);

$form_fields['byline_link'] = array(
'label' => __('Byline Credit Link', 'image-byline'),
'input' => 'text',
'value' => get_post_meta( $post->ID, '_byline_link', true )
);

return $form_fields;
}

/**
* Add byline_attachment_field to the $form_fields array
*
* @param object $post
* @param array $attachment
* @return object
* @since 1.0.0
*/
function byline_attachment_fields_save( $post, $attachment ) {

if ( isset( $attachment['byline'] ) ) {
update_post_meta( $post['ID'], '_byline', $attachment['byline'] );
}

if ( isset( $attachment['byline_link'] ) ) {
update_post_meta( $post['ID'], '_byline_link', $attachment['byline_link'] );
}

return $post;
}

/**
* Add the dashboard settings menu item.
*
* @since 1.0.0
*/
public function add_admin_menu( ) {

add_submenu_page(
'tools.php',
__( 'Image Byline', 'image-byline' ),
__( 'Image Byline', 'image-byline' ),
'manage_options',
'image_byline',
array( $this, 'options_page' )
);

}

/**
* Initialize the dashboard settings page.
*
* @since 1.0.0
*/
public function settings_init() {

register_setting(
'imageByline_group',
'imageByline_options',
array('type' => 'array')
);

add_settings_section(
'imageByline_group_section',
__( 'General Options', 'image-byline' ),
array( $this, 'settings_section_callback' ),
'imageByline_group'
);

add_settings_field(
'before_byline',
__( 'Prefix byline credit', 'image-byline' ),
array( $this, 'before_byline_render' ),
'imageByline_group',
'imageByline_group_section'
);

add_settings_field(
'search_suggestions_role',
__( 'Search suggestions role', 'image-byline' ),
array( $this, 'search_suggestions_role_render' ),
'imageByline_group',
'imageByline_group_section'
);

add_settings_field(
'search_suggestions',
__( 'Search suggestions', 'image-byline' ),
array( $this, 'search_suggestions_render' ),
'imageByline_group',
'imageByline_group_section'
);
}

/**
* Render the before_byline text field on the settings/options page.
*
* @since 1.0.0
*/
function before_byline_render() {

$options = get_option( 'imageByline_options' );
if ( !empty($options['before_byline']) ) {
$value = $options['before_byline'];
} else {
$value = '';
}
?>
<input type="text" name="imageByline_options[before_byline]" value="<?php echo $value; ?>">
<td class="align-top"><em><?php esc_html_e( 'A short label to show before the byline credit e.g. Source:.', 'image-byline' ); ?></em></td>
<?php

}

/**
* Render the search_suggestions_role select on the settings/options page.
*
* @since 1.0.0
*/
function search_suggestions_role_render() {

$options = get_option( 'imageByline_options' );

global $wp_roles;
$select_options = '<option value="">Select user role</option>';
foreach ($wp_roles->get_names() as $key => $value) {
if ( !empty($options['search_suggestions_role'] ) && $options['search_suggestions_role'] === $key ) {
$selected = ' selected="selected"';
} else {
$selected = '';
}
$select_options .= '<option value="'.$key.'"'.$selected.'>'.$value.'</option>';
}

?>
<select name="imageByline_options[search_suggestions_role]"><?php echo $select_options; ?></select>
<td class="align-top"><em><?php esc_html_e( 'You can use a user role to automatically get a list of sources to show in the Media Library Byline Credit field suggestions. Leave this field blank if you just want to use the simple list.', 'image-byline' ); ?></em></td>
<?php

}

/**
* Render the search_suggestions field on the settings/options page.
*
* @since 1.0.0
*/
function search_suggestions_render() {
$options = get_option( 'imageByline_options' );
if ( !empty($options['search_suggestions']) ) {
$value = $options['search_suggestions'];
} else {
$value = '';
}

?>
<textarea cols='40' rows='30' name='imageByline_options[search_suggestions]'><?php echo $value; ?></textarea>
<td class="align-top"><em><?php esc_html_e( 'A list of sources to show in the Media Library Byline Credit field suggestions. Put each value on a new line. Leave this field blank if you just want to use a user role for your suggestions.', 'image-byline' ); ?></em></td>
<?php

}

/**
* Callback for the settings/options page.
*
* @since 1.0.0
*/
function settings_section_callback() {

esc_html_e( 'Here you can configure your options for the Image and Media Byline Credits plugin. All the settings are optional.', 'image-byline' );

}

/**
* Render the settings/options page.
*
* @since 1.0.0
*/
function options_page() {

include_once('partials/image-byline-admin-display.php');

}

}
Loading

0 comments on commit d045fd7

Please sign in to comment.