Plugin Directory

Changeset 2833883


Ignore:
Timestamp:
12/14/2022 03:53:13 PM (3 years ago)
Author:
cleuenberg
Message:

v1.1 - code cleaning, added image overlay in front-end, changed author/contributor

Location:
image-rights
Files:
13 added
1 deleted
4 edited

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  
    11<?php
     2
    23/**
    34 * @package Image Rights
    4  * @author Christian Leuenberg <[email protected]>
     5 * @author WSM – Walter Solbach Metallbau GmbH <[email protected]>
    56 * @license GPLv3
    6  * @copyright 2021 by Christian Leuenberg
     7 * @copyright 2022 by WSM – Walter Solbach Metallbau GmbH
    78 */
    89/*
     
    1011Plugin URI:
    1112Description: Adds additional fields for setting image credits in the media library.
    12 Author: Christian Leuenberg, L.net Web Solutions
    13 Author URI: https://www.l-net.biz/
    14 Version: 1.0
     13Author: WSM – Walter Solbach Metallbau GmbH
     14Author URI: https://www.wsm.eu/
     15Version: 1.1
    1516Text Domain: photocredits
    1617Domain Path: /languages/
     
    1819
    1920    Image Rights
    20     Copyright (C) 2021 Christian Leuenberg
     21    Copyright (C) 2022 WSM – Walter Solbach Metallbau GmbH
    2122
    2223    This program is free software: you can redistribute it and/or modify
     
    3435*/
    3536
     37
    3638/**
    3739 * Load plugin textdomain
     
    3941 */
    4042function pcr_load_textdomain() {
    41     load_plugin_textdomain( 'photocredits', false, basename( dirname( __FILE__ ) ) . '/languages' );
     43    load_plugin_textdomain( 'photocredits', false, basename( dirname(__FILE__) ) . '/languages' );
    4244}
    4345add_action( 'plugins_loaded', 'pcr_load_textdomain' );
    4446
     47
    4548/**
    4649 * Load admin styles and scripts
     
    4851 */
    4952function 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') );
    5356    wp_enqueue_script( 'pcr_scripts' );
    5457}
    5558add_action( 'admin_enqueue_scripts', 'pcr_load_scripts' );
     59
     60
     61/**
     62 * Load Front styles and scripts
     63 *
     64 */
     65function 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}
     97add_action( 'wp_enqueue_scripts', 'pcr_load_front_scripts' );
     98
    5699
    57100/**
     
    61104function pcr_attachment_field_credit( $form_fields, $post ) {
    62105    $form_fields['pcr-photographer-name'] = array(
    63         'label' => __('Photographer Name', 'photocredits'),
     106        'label' => __( 'Photographer Name', 'photocredits' ),
    64107        'input' => 'text',
    65108        'value' => get_post_meta( $post->ID, 'pcr_photographer_name', true ),
    66         'helps' => __('Provide name of photographer', 'photocredits'),
     109        'helps' => __( 'Provide name of photographer', 'photocredits' ),
    67110    );
    68111
    69112    $form_fields['pcr-photographer-platform'] = array(
    70         'label' => __('Platform', 'photocredits'),
     113        'label' => __( 'Platform', 'photocredits' ),
    71114        'input' => 'text',
    72115        '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' ),
    74117    );
    75  
     118
    76119    return $form_fields;
    77120}
    78121add_filter( 'attachment_fields_to_edit', 'pcr_attachment_field_credit', 10, 2 );
    79  
     122
     123
    80124/**
    81125 * Save values of Photographer Name and URL in media uploader
     
    83127 */
    84128function pcr_attachment_field_credit_save( $post, $attachment ) {
    85     if( isset( $attachment['pcr-photographer-name'] ) ) :
     129    if ( isset( $attachment['pcr-photographer-name'] ) ) :
    86130        update_post_meta( $post['ID'], 'pcr_photographer_name', $attachment['pcr-photographer-name'] );
    87131    endif;
    88  
    89     if( isset( $attachment['pcr-photographer-platform'] ) ) :
     132
     133    if ( isset( $attachment['pcr-photographer-platform'] ) ) :
    90134        update_post_meta( $post['ID'], 'pcr_photographer_platform', $attachment['pcr-photographer-platform'] );
    91135    endif;
    92  
     136
    93137    return $post;
    94138}
    95139add_filter( 'attachment_fields_to_save', 'pcr_attachment_field_credit_save', 10, 2 );
     140
    96141
    97142/**
     
    124169    // Query
    125170    $query_images = new WP_Query( $args );
    126    
     171
    127172    // Put desired information into output
    128173    $images = array();
    129     foreach ( $query_images->posts as $image) {
    130         $images[]= $image;
     174    foreach ( $query_images->posts as $image ) {
     175        $images[] = $image;
    131176    }
    132177
     
    134179}
    135180
     181
    136182/**
    137183 * Shortcode for displaying photo credits
    138184 *
    139185 */
    140 function pcr_shortcode_photo_credits($atts) {
     186function pcr_shortcode_photo_credits( $atts ) {
    141187    // Attributes
    142     extract(shortcode_atts( array(
     188    extract(shortcode_atts(array(
    143189        'fields' => '',
    144     ), $atts ) );
     190    ), $atts));
    145191
    146192    // init some vars
     
    149195
    150196    // images found?
    151     if ($the_images) {
    152        
     197    if ( $the_images ) {
     198
    153199        $html .= '<table class="table photo-credits-table">';
    154200        $html .= '<thead><tr><th style="width:25%;">' . __('Image', 'photocredits') . '</th><th>' . __('Image rights', 'photocredits') . '</th></tr></thead>';
     
    156202
    157203        // loop over images with our meta fields
    158         foreach ($the_images as $image) {
     204        foreach ( $the_images as $image ) {
    159205
    160206            // get meta information
     
    164210            // puzzle the markup
    165211            $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">';
    167213            $html .= '</td><td>';
    168214            $html .= '<p>';
    169215
    170             if (!empty($meta_photographer)) :
    171                 $html .= __('Photographer', 'photocredits') . ': ' . $meta_photographer;
     216            if ( !empty( $meta_photographer ) ) :
     217                $html .= __( 'Photographer', 'photocredits' ) . ': ' . $meta_photographer;
    172218                $html .= '<br>';
    173219            endif;
    174220
    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;
    179225            endif;
    180226
     
    190236}
    191237add_shortcode( 'photo_credits', 'pcr_shortcode_photo_credits' );
     238
     239
     240/**
     241 * Add meta layer over featured images
     242 *
     243 */
     244function 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}
     280add_filter( 'post_thumbnail_html', 'pcr_post_thumb_meta_data', 10, 3 );
     281
     282
     283/**
     284 * Add meta layer over content images
     285 *
     286 */
     287function 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}
     314add_filter( 'wp_content_img_tag', 'pcr_img_add_meta_data', 15, 3 );
     315
    192316?>
  • image-rights/trunk/js/scripts.js

    r2466964 r2833883  
    1 (function($) {
    2     $(function() {
    3         /* additional scripts */
    4     });
    5 })(jQuery);
     1jQuery('document').ready(function($) {
     2    /* additional scripts */
     3});
  • image-rights/trunk/readme.txt

    r2764432 r2833883  
    11=== Image Rights ===
    2 Contributors: cleuenberg
    3 Donate link: https://paypal.me/Lnet
    4 Tags: image rights, photo credits, copyrights, media library, custom fields, meta fields, images, photos, copyright
     2Contributors: wsmeu, cleuenberg
     3Donate link:
     4Tags: image rights, photo credits, copyrights, media library, custom fields, meta fields, images, photos, copyright, dsgvo
    55Requires at least:
    66Tested up to: 6.0.1
    7 Stable tag: 1.0
     7Stable tag: 1.1
    88License: GPLv3
    99License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    3737== Changelog ==
    3838
     39= 1.1 =
     40* Added layers on images with credits in frontend.
     41
    3942= 1.0 =
    4043* Initial release for WordPress plugin directory.
Note: See TracChangeset for help on using the changeset viewer.