Changeset 2833883
- Timestamp:
- 12/14/2022 03:53:13 PM (3 years ago)
- Location:
- image-rights
- Files:
-
- 13 added
- 1 deleted
- 4 edited
-
tags/1.1 (added)
-
tags/1.1/css (added)
-
tags/1.1/css/admin-styles.css (added)
-
tags/1.1/css/styles.css (added)
-
tags/1.1/image-rights.php (added)
-
tags/1.1/js (added)
-
tags/1.1/js/admin-scripts.js (added)
-
tags/1.1/js/scripts.js (added)
-
tags/1.1/languages (added)
-
tags/1.1/languages/photocredits-de_DE.mo (added)
-
tags/1.1/languages/photocredits-de_DE.po (added)
-
tags/1.1/languages/photocredits.pot (added)
-
tags/1.1/readme.txt (added)
-
trunk/css/styles.css (modified) (1 diff)
-
trunk/image-rights.php (modified) (14 diffs)
-
trunk/js/scripts.js (modified) (1 diff)
-
trunk/js/scripts.min.js (deleted)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
image-rights/trunk/css/styles.css
r2466964 r2833883 1 /* 2 table.photo-credits-table {} 3 */ 1 .pcr_featured_wrap, 2 .pcr_content_wrap { 3 display: inline-block; 4 position: relative; 5 } 6 7 .pcr_featured_wrap span, 8 .pcr_content_wrap span { 9 position: absolute; 10 bottom: 0px; 11 right: 0px; 12 padding: 0 10px; 13 line-height: 26px; 14 background: rgba(255, 255, 255, 0.5); 15 16 } 17 18 .pcr_content_wrap figcaption + span { 19 bottom: 39px; 20 } 21 22 .pcr_content_wrap img { 23 vertical-align: top; 24 } -
image-rights/trunk/image-rights.php
r2466964 r2833883 1 1 <?php 2 2 3 /** 3 4 * @package Image Rights 4 * @author Christian Leuenberg <[email protected]>5 * @author WSM – Walter Solbach Metallbau GmbH <[email protected]> 5 6 * @license GPLv3 6 * @copyright 202 1 by Christian Leuenberg7 * @copyright 2022 by WSM – Walter Solbach Metallbau GmbH 7 8 */ 8 9 /* … … 10 11 Plugin URI: 11 12 Description: Adds additional fields for setting image credits in the media library. 12 Author: Christian Leuenberg, L.net Web Solutions13 Author URI: https://www. l-net.biz/14 Version: 1. 013 Author: WSM – Walter Solbach Metallbau GmbH 14 Author URI: https://www.wsm.eu/ 15 Version: 1.1 15 16 Text Domain: photocredits 16 17 Domain Path: /languages/ … … 18 19 19 20 Image Rights 20 Copyright (C) 202 1 Christian Leuenberg21 Copyright (C) 2022 WSM – Walter Solbach Metallbau GmbH 21 22 22 23 This program is free software: you can redistribute it and/or modify … … 34 35 */ 35 36 37 36 38 /** 37 39 * Load plugin textdomain … … 39 41 */ 40 42 function pcr_load_textdomain() { 41 load_plugin_textdomain( 'photocredits', false, basename( dirname( __FILE__ ) ) . '/languages' );43 load_plugin_textdomain( 'photocredits', false, basename( dirname(__FILE__) ) . '/languages' ); 42 44 } 43 45 add_action( 'plugins_loaded', 'pcr_load_textdomain' ); 44 46 47 45 48 /** 46 49 * Load admin styles and scripts … … 48 51 */ 49 52 function pcr_load_scripts() { 50 $plugin_url = plugin_dir_url( __FILE__);51 wp_enqueue_style( 'pcr_styles', $plugin_url . 'css/ styles.css' );52 wp_register_script( 'pcr_scripts', $plugin_url . 'js/ scripts.min.js', array('jquery'));53 $plugin_url = plugin_dir_url(__FILE__); 54 wp_enqueue_style( 'pcr_styles', $plugin_url . 'css/admin-styles.css' ); 55 wp_register_script( 'pcr_scripts', $plugin_url . 'js/admin-scripts.js', array('jquery') ); 53 56 wp_enqueue_script( 'pcr_scripts' ); 54 57 } 55 58 add_action( 'admin_enqueue_scripts', 'pcr_load_scripts' ); 59 60 61 /** 62 * Load Front styles and scripts 63 * 64 */ 65 function pcr_load_front_scripts() { 66 global $post; 67 68 if ( is_singular() ) { 69 $single_status = '1'; 70 } else { 71 $single_status = '0'; 72 } 73 74 $pcr_styles_css = plugin_dir_url(__FILE__) . 'css/styles.css'; 75 $pcr_styles_path_css = plugin_dir_path(__FILE__) . 'css/styles.css'; 76 wp_enqueue_style( 'pcr_front_styles', $pcr_styles_css, array(), filemtime( $pcr_styles_path_css ), 'all' ); 77 78 //$pcr_scripts_js = plugin_dir_url(__FILE__) . 'js/scripts.js'; 79 //$pcr_scripts_path_js = plugin_dir_path(__FILE__) . 'js/scripts.js'; 80 //wp_enqueue_script( 'pcr-custom-js', $pcr_scripts_js, array( 'jquery' ), filemtime( $pcr_scripts_path_js ), true ); 81 82 $post_thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true ); 83 $pcr_photographer_name = get_post_meta( $post_thumbnail_id, 'pcr_photographer_name', true ); 84 $pcr_photographer_platform = get_post_meta( $post_thumbnail_id, 'pcr_photographer_platform', true ); 85 86 wp_localize_script( 87 'pcr-custom-js', 88 'pcr_frontend_ajax_object', 89 array( 90 'ajaxurl' => admin_url( 'admin-ajax.php' ), 91 'pcr_photographer_name' => $pcr_photographer_name, 92 'pcr_photographer_platform' => $pcr_photographer_platform, 93 'single_status' => $single_status 94 ) 95 ); 96 } 97 add_action( 'wp_enqueue_scripts', 'pcr_load_front_scripts' ); 98 56 99 57 100 /** … … 61 104 function pcr_attachment_field_credit( $form_fields, $post ) { 62 105 $form_fields['pcr-photographer-name'] = array( 63 'label' => __( 'Photographer Name', 'photocredits'),106 'label' => __( 'Photographer Name', 'photocredits' ), 64 107 'input' => 'text', 65 108 'value' => get_post_meta( $post->ID, 'pcr_photographer_name', true ), 66 'helps' => __( 'Provide name of photographer', 'photocredits'),109 'helps' => __( 'Provide name of photographer', 'photocredits' ), 67 110 ); 68 111 69 112 $form_fields['pcr-photographer-platform'] = array( 70 'label' => __( 'Platform', 'photocredits'),113 'label' => __( 'Platform', 'photocredits' ), 71 114 'input' => 'text', 72 115 'value' => get_post_meta( $post->ID, 'pcr_photographer_platform', true ), 73 'helps' => __( 'Provide name of platform (e.g. Adobe Stock)', 'photocredits'),116 'helps' => __( 'Provide name of platform (e.g. Adobe Stock)', 'photocredits' ), 74 117 ); 75 118 76 119 return $form_fields; 77 120 } 78 121 add_filter( 'attachment_fields_to_edit', 'pcr_attachment_field_credit', 10, 2 ); 79 122 123 80 124 /** 81 125 * Save values of Photographer Name and URL in media uploader … … 83 127 */ 84 128 function pcr_attachment_field_credit_save( $post, $attachment ) { 85 if ( isset( $attachment['pcr-photographer-name'] ) ) :129 if ( isset( $attachment['pcr-photographer-name'] ) ) : 86 130 update_post_meta( $post['ID'], 'pcr_photographer_name', $attachment['pcr-photographer-name'] ); 87 131 endif; 88 89 if ( isset( $attachment['pcr-photographer-platform'] ) ) :132 133 if ( isset( $attachment['pcr-photographer-platform'] ) ) : 90 134 update_post_meta( $post['ID'], 'pcr_photographer_platform', $attachment['pcr-photographer-platform'] ); 91 135 endif; 92 136 93 137 return $post; 94 138 } 95 139 add_filter( 'attachment_fields_to_save', 'pcr_attachment_field_credit_save', 10, 2 ); 140 96 141 97 142 /** … … 124 169 // Query 125 170 $query_images = new WP_Query( $args ); 126 171 127 172 // Put desired information into output 128 173 $images = array(); 129 foreach ( $query_images->posts as $image ) {130 $images[] = $image;174 foreach ( $query_images->posts as $image ) { 175 $images[] = $image; 131 176 } 132 177 … … 134 179 } 135 180 181 136 182 /** 137 183 * Shortcode for displaying photo credits 138 184 * 139 185 */ 140 function pcr_shortcode_photo_credits( $atts) {186 function pcr_shortcode_photo_credits( $atts ) { 141 187 // Attributes 142 extract(shortcode_atts( array(188 extract(shortcode_atts(array( 143 189 'fields' => '', 144 ), $atts ));190 ), $atts)); 145 191 146 192 // init some vars … … 149 195 150 196 // images found? 151 if ( $the_images) {152 197 if ( $the_images ) { 198 153 199 $html .= '<table class="table photo-credits-table">'; 154 200 $html .= '<thead><tr><th style="width:25%;">' . __('Image', 'photocredits') . '</th><th>' . __('Image rights', 'photocredits') . '</th></tr></thead>'; … … 156 202 157 203 // loop over images with our meta fields 158 foreach ( $the_images as $image) {204 foreach ( $the_images as $image ) { 159 205 160 206 // get meta information … … 164 210 // puzzle the markup 165 211 $html .= '<tr><td>'; 166 $html .= '<img src="' .wp_get_attachment_thumb_url( $image->ID ).'" alt="'.$image->post_title.'" title="'.$image->post_title.'" class="image wp-image-'.$image->ID.' attachment-thumbnail size-thumbnail img-thumbnail">';212 $html .= '<img src="' . wp_get_attachment_thumb_url( $image->ID ) . '" alt="' . $image->post_title . '" title="' . $image->post_title . '" class="image wp-image-' . $image->ID . ' attachment-thumbnail size-thumbnail img-thumbnail">'; 167 213 $html .= '</td><td>'; 168 214 $html .= '<p>'; 169 215 170 if ( !empty($meta_photographer)) :171 $html .= __( 'Photographer', 'photocredits') . ': ' . $meta_photographer;216 if ( !empty( $meta_photographer ) ) : 217 $html .= __( 'Photographer', 'photocredits' ) . ': ' . $meta_photographer; 172 218 $html .= '<br>'; 173 219 endif; 174 220 175 if ( !empty($meta_platform_defaults)) :176 $html .= __( 'Platform', 'photocredits') . ': ' . $meta_platform_defaults;177 elseif (!empty($meta_platform)) : 178 $html .= __( 'Platform', 'photocredits') . ': ' . $meta_platform;221 if ( !empty( $meta_platform_defaults ) ) : 222 $html .= __( 'Platform', 'photocredits' ) . ': ' . $meta_platform_defaults; 223 elseif (!empty($meta_platform)) : 224 $html .= __( 'Platform', 'photocredits' ) . ': ' . $meta_platform; 179 225 endif; 180 226 … … 190 236 } 191 237 add_shortcode( 'photo_credits', 'pcr_shortcode_photo_credits' ); 238 239 240 /** 241 * Add meta layer over featured images 242 * 243 */ 244 function pcr_post_thumb_meta_data( $html, $post_id, $post_image_id ) { 245 246 // check if not a single post 247 if ( !is_singular() ) { 248 249 // Return default if NOT single post / page 250 return $html; 251 252 } else { 253 254 //get meta information 255 $meta_photographer = get_post_meta( $post_image_id, 'pcr_photographer_name', true ); 256 $meta_platform = get_post_meta( $post_image_id, 'pcr_photographer_platform', true ); 257 $featured_image = get_the_post_thumbnail_url( $post_id, 'medium' ); 258 259 // init string 260 $meta = $meta_photographer . ' | ' . $meta_platform; 261 262 // remove pipe sign if only one meta field present 263 if ( str_starts_with( $meta, ' | ' ) || str_ends_with( $meta, ' | ' ) ) : 264 $meta = str_replace( ' | ', '', $meta ); 265 endif; 266 267 // add layer if meta present 268 if ( !empty( $meta ) ) : 269 if ( str_contains( $html, 'figcaption' ) ) { 270 $html = str_replace( '</figcaption>', '</figcaption><span>' . $meta . '</span>', $html ); 271 $html = '<div class="pcr_featured_wrap">' . $html . '</div>'; 272 } else { 273 $html = '<div class="pcr_featured_wrap">' . $html . '<span>' . $meta . '</span></div>'; 274 } 275 endif; 276 277 return $html; 278 } 279 } 280 add_filter( 'post_thumbnail_html', 'pcr_post_thumb_meta_data', 10, 3 ); 281 282 283 /** 284 * Add meta layer over content images 285 * 286 */ 287 function pcr_img_add_meta_data( $filtered_image, $context, $attachment_id ) { 288 289 //get meta information 290 $meta_photographer = get_post_meta( $attachment_id, 'pcr_photographer_name', true ); 291 $meta_platform = get_post_meta( $attachment_id, 'pcr_photographer_platform', true ); 292 $featured_image = get_the_post_thumbnail_url( get_the_ID(), 'medium' ); 293 294 // init string 295 $meta = $meta_photographer . ' | ' . $meta_platform; 296 297 // remove pipe sign if only one meta field present 298 if ( str_starts_with( $meta, ' | ' ) || str_ends_with( $meta, ' | ' ) ) : 299 $meta = str_replace( ' | ', '', $meta ); 300 endif; 301 302 // add layer if meta present 303 if ( !empty( $meta ) ) : 304 if ( str_contains( $filtered_image, 'figcaption' ) ) { 305 $filtered_image = str_replace( '</figcaption>', '</figcaption><span>' . $meta . '</span>', $filtered_image ); 306 $filtered_image = '<div class="pcr_content_wrap">' . $filtered_image . '</div>'; 307 } else { 308 $filtered_image = '<div class="pcr_content_wrap">' . $filtered_image . '<span>' . $meta . '</span></div>'; 309 } 310 endif; 311 // return the block content 312 return $filtered_image; 313 } 314 add_filter( 'wp_content_img_tag', 'pcr_img_add_meta_data', 15, 3 ); 315 192 316 ?> -
image-rights/trunk/js/scripts.js
r2466964 r2833883 1 (function($) { 2 $(function() { 3 /* additional scripts */ 4 }); 5 })(jQuery); 1 jQuery('document').ready(function($) { 2 /* additional scripts */ 3 }); -
image-rights/trunk/readme.txt
r2764432 r2833883 1 1 === Image Rights === 2 Contributors: cleuenberg3 Donate link: https://paypal.me/Lnet4 Tags: image rights, photo credits, copyrights, media library, custom fields, meta fields, images, photos, copyright 2 Contributors: wsmeu, cleuenberg 3 Donate link: 4 Tags: image rights, photo credits, copyrights, media library, custom fields, meta fields, images, photos, copyright, dsgvo 5 5 Requires at least: 6 6 Tested up to: 6.0.1 7 Stable tag: 1. 07 Stable tag: 1.1 8 8 License: GPLv3 9 9 License URI: https://www.gnu.org/licenses/gpl-3.0.html … … 37 37 == Changelog == 38 38 39 = 1.1 = 40 * Added layers on images with credits in frontend. 41 39 42 = 1.0 = 40 43 * Initial release for WordPress plugin directory.
Note: See TracChangeset
for help on using the changeset viewer.