Plugin Directory

Changeset 2964519


Ignore:
Timestamp:
09/08/2023 01:49:24 PM (3 years ago)
Author:
cleuenberg
Message:

v1.2 - Added admin option for overlays, updated German language file, small bugfixes

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

Legend:

Unmodified
Added
Removed
  • image-rights/trunk/image-rights.php

    r2833883 r2964519  
    1313Author: WSM – Walter Solbach Metallbau GmbH
    1414Author URI: https://www.wsm.eu/
    15 Version: 1.1
     15Version: 1.2
    1616Text Domain: photocredits
    1717Domain Path: /languages/
     
    6060
    6161/**
     62 * Register admin setting
     63 *
     64 */
     65function pcr_settings_section() { 
     66    add_settings_section( 
     67        'pcr_settings_section', // Section ID
     68        __( 'Image Rights Options', 'photocredits' ), // Section Title
     69        'pcr_section_options_callback', // Callback
     70        'media' // What Page?  This makes the section show up on the General Settings Page
     71    );
     72   
     73    add_settings_field(
     74        'pcr_option_1',
     75        __( 'Copyright overlay on images', 'photocredits' ),
     76        'pcr_imageoverlay_field_cb',
     77        'media',
     78        'pcr_settings_section',
     79        array(
     80            'type'         => 'checkbox',
     81            'option_group' => 'pcr_options',
     82            'name'         => 'pcr_option_1',
     83            'label_for'    => 'pcr_option_1',
     84            'value'        => get_option('pcr_option_1', '0'),
     85            'description'  => __( 'activate', 'photocredits' ),
     86            'checked'      => get_option('pcr_option_1', '0'),
     87            )
     88    );
     89     
     90    register_setting('media', 'pcr_option_1', 'esc_attr');
     91 }
     92 add_action('admin_init', 'pcr_settings_section'); 
     93 
     94 function pcr_section_options_callback() { // Section Callback
     95    echo ''; 
     96 }
     97 
     98function pcr_imageoverlay_field_cb($args) {
     99     $checked = $args['checked'];
     100     $value = $args['value'];
     101
     102     if($checked) { $checked = ' checked="checked" '; }
     103         // Could use ob_start.
     104         $html  = '';
     105         $html .= '<input id="' . esc_attr( $args['name'] ) . '"
     106         name="' . esc_attr( $args['name'] ) .'" value="1"
     107         type="checkbox" ' . $checked . '/>';
     108         $html .= '<span class="wndspan">' . esc_html( $args['description'] ) .'</span>';
     109 
     110         echo $html;
     111 }
     112 
     113
     114/**
    62115 * Load Front styles and scripts
    63116 *
     
    76129    wp_enqueue_style( 'pcr_front_styles', $pcr_styles_css, array(), filemtime( $pcr_styles_path_css ), 'all' );
    77130
    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    
    82131    $post_thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true );
    83132    $pcr_photographer_name = get_post_meta( $post_thumbnail_id, 'pcr_photographer_name', true );
     
    243292 */
    244293function 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
     294   
     295    // check if overlay was activted in admin settings
     296    if ( get_option('pcr_option_1') == "1" ) {
     297
     298        // check if not a single post or front page
     299        if ( !is_singular() || is_front_page() ) {
     300   
     301            // Return default if NOT single post / page / front
     302            return $html;
     303   
     304        } else {
     305   
     306            //get meta information
     307            $meta_photographer = get_post_meta( $post_image_id, 'pcr_photographer_name', true );
     308            $meta_platform     = get_post_meta( $post_image_id, 'pcr_photographer_platform', true );
     309            $featured_image    = get_the_post_thumbnail_url( $post_id, 'medium' );
     310           
     311            // init string
     312            $meta = $meta_photographer . ' | ' . $meta_platform;
     313   
     314            // remove pipe sign if only one meta field present
     315            if ( str_starts_with( $meta, ' | ' ) || str_ends_with( $meta, ' | ' ) ) :
     316                $meta = str_replace( ' | ', '', $meta );
     317            endif;
     318   
     319            // add layer if meta present
     320            if ( !empty( $meta ) ) :       
     321                if ( str_contains( $html, 'figcaption' ) ) {
     322                    $html = str_replace( '</figcaption>', '</figcaption><span>' . $meta . '</span>', $html );
     323                    $html = '<div class="pcr_featured_wrap">' . $html . '</div>';
     324                } else {
     325                    $html = '<div class="pcr_featured_wrap">' . $html . '<span>' . $meta . '</span></div>';
     326                }
     327            endif;
     328   
     329            return $html;
     330        }
     331       
     332    } else {
     333       
     334        // not activated, return standard markup
    250335        return $html;
    251 
    252     } else {
     336       
     337    }
     338}
     339add_filter( 'post_thumbnail_html', 'pcr_post_thumb_meta_data', 10, 3 );
     340
     341
     342/**
     343 * Add meta layer over content images
     344 *
     345 */
     346function pcr_img_add_meta_data( $filtered_image, $context, $attachment_id ) {
     347   
     348    // check if overlay was activted in admin settings
     349    if ( get_option('pcr_option_1') == "1" ) {
    253350
    254351        //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' );
     352        $meta_photographer = get_post_meta( $attachment_id, 'pcr_photographer_name', true );
     353        $meta_platform     = get_post_meta( $attachment_id, 'pcr_photographer_platform', true );
     354        $featured_image = get_the_post_thumbnail_url( get_the_ID(), 'medium' );
    258355       
    259356        // init string
    260357        $meta = $meta_photographer . ' | ' . $meta_platform;
    261 
     358   
    262359        // remove pipe sign if only one meta field present
    263360        if ( str_starts_with( $meta, ' | ' ) || str_ends_with( $meta, ' | ' ) ) :
    264361            $meta = str_replace( ' | ', '', $meta );
    265362        endif;
    266 
     363   
    267364        // add layer if meta present
    268365        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>';
     366            if ( str_contains( $filtered_image, 'figcaption' ) ) {
     367                $filtered_image = str_replace( '</figcaption>', '</figcaption><span>' . $meta . '</span>', $filtered_image );
     368                $filtered_image = '<div class="pcr_content_wrap">' . $filtered_image . '</div>';
    272369            } else {
    273                 $html = '<div class="pcr_featured_wrap">' . $html . '<span>' . $meta . '</span></div>';
     370                $filtered_image = '<div class="pcr_content_wrap">' . $filtered_image . '<span>' . $meta . '</span></div>';
    274371            }
    275372        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;
     373        // return the block content
     374        return $filtered_image;
     375       
     376    } else {
     377       
     378        // not activated, return standard image
     379        return $filtered_image;
     380       
     381    }
    313382}
    314383add_filter( 'wp_content_img_tag', 'pcr_img_add_meta_data', 15, 3 );
  • image-rights/trunk/languages/photocredits-de_DE.po

    r2466964 r2964519  
    11msgid ""
    22msgstr ""
    3 "Plural-Forms: nplurals=2; plural=(n != 1);\n"
    4 "Project-Id-Version: Photo Credits\n"
    5 "POT-Creation-Date: 2021-02-01 19:56+0100\n"
    6 "PO-Revision-Date: 2021-02-01 19:58+0100\n"
    7 "Language-Team: Christian Leuenberg\n"
     3"Project-Id-Version: Image Rights\n"
     4"POT-Creation-Date: 2023-09-08 14:57+0200\n"
     5"PO-Revision-Date: 2023-09-08 14:58+0200\n"
     6"Last-Translator: \n"
     7"Language-Team: \n"
     8"Language: de\n"
    89"MIME-Version: 1.0\n"
    910"Content-Type: text/plain; charset=UTF-8\n"
     
    1112"X-Generator: Poedit 1.8.12\n"
    1213"X-Poedit-Basepath: ..\n"
    13 "X-Poedit-WPHeader: photo-credits.php\n"
     14"X-Poedit-WPHeader: image-rights.php\n"
     15"Plural-Forms: nplurals=2; plural=(n != 1);\n"
    1416"X-Poedit-SourceCharset: UTF-8\n"
    15 "X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;_nx_noop:3c,1,2;__ngettext_noop:1,2\n"
    16 "Last-Translator: Christian Leuenberg\n"
    17 "Language: de_DE\n"
     17"X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;"
     18"esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;"
     19"_n_noop:1,2;_nx_noop:3c,1,2;__ngettext_noop:1,2\n"
    1820"X-Poedit-SearchPath-0: .\n"
    1921"X-Poedit-SearchPathExcluded-0: *.js\n"
    2022
    21 #: photo-credits.php:63
     23#: image-rights.php:68
     24msgid "Image Rights Options"
     25msgstr "Image Rights Einstellungen"
     26
     27#: image-rights.php:75
     28msgid "Copyright overlay on images"
     29msgstr "Bildrechte-Overlay auf Bildern"
     30
     31#: image-rights.php:85
     32msgid "activate"
     33msgstr "aktivieren"
     34
     35#: image-rights.php:155
    2236msgid "Photographer Name"
    23 msgstr "Name Fotograf"
     37msgstr "Name des Fotografen"
    2438
    25 #: photo-credits.php:66
     39#: image-rights.php:158
    2640msgid "Provide name of photographer"
    27 msgstr "Gib den Namen des Fotografen an"
     41msgstr "Geben Sie den Namen des Fotografen an"
    2842
    29 #: photo-credits.php:70 photo-credits.php:176 photo-credits.php:178
     43#: image-rights.php:162 image-rights.php:271 image-rights.php:273
    3044msgid "Platform"
    3145msgstr "Plattform"
    3246
    33 #: photo-credits.php:73
     47#: image-rights.php:165
    3448msgid "Provide name of platform (e.g. Adobe Stock)"
    35 msgstr "Gib den Namen der Plattform an (z. B. Adobe Stock)"
     49msgstr "Geben Sie den Namen der Plattform an (z. B. Adobe Stock)"
    3650
    37 #: photo-credits.php:154
     51#: image-rights.php:249
    3852msgid "Image"
    3953msgstr "Bild"
    4054
    41 #: photo-credits.php:154
     55#: image-rights.php:249
    4256msgid "Image rights"
    4357msgstr "Bildrechte"
    4458
    45 #: photo-credits.php:171
     59#: image-rights.php:266
    4660msgid "Photographer"
    4761msgstr "Fotograf"
    4862
    4963#. Plugin Name of the plugin/theme
    50 msgid "Photo Credits"
    51 msgstr "Bildquellennachweise"
     64msgid "Image Rights"
     65msgstr ""
    5266
    5367#. Description of the plugin/theme
    54 msgid "Adds additional fields for photo credits into Media Library items."
     68msgid "Adds additional fields for setting image credits in the media library."
    5569msgstr ""
    5670
    5771#. Author of the plugin/theme
    58 msgid "Christian Leuenberg, L.net Web Solutions"
     72msgid "WSM – Walter Solbach Metallbau GmbH"
    5973msgstr ""
    6074
    6175#. Author URI of the plugin/theme
    62 msgid "https://www.l-net.biz/"
     76msgid "https://www.wsm.eu/"
    6377msgstr ""
  • image-rights/trunk/readme.txt

    r2833891 r2964519  
    44Tags: image rights, photo credits, copyrights, media library, custom fields, meta fields, images, photos, copyright, dsgvo
    55Requires at least:
    6 Tested up to: 6.1.1
    7 Stable tag: 1.1
     6Tested up to: 6.3.1
     7Stable tag: 1.2
    88License: GPLv3
    99License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    2121* set an optional stock photo platform
    2222* shortcode `[photo_credits]` displays all images with credits set
     23* optional image overlay with copyright information
    2324
    2425== Installation ==
     
    29303. Use the shortcode `[photo_credits]` in order to display a simple table with all your copyrighted images.
    30314. Optionally change table layout by addressing CSS class `table.photo-credits-table` in your theme's stylesheet.
     325. Activate an optional copyright overlay for images under Settings > Media > Image Rights Options
    3133
    3234== Screenshots ==
     
    3739== Changelog ==
    3840
     41= 1.2 =
     42* Added admin option to make overlays in frontend optional
     43* Updated German language file
     44* Small bugfixes
     45
    3946= 1.1 =
    4047* Added layers on images with credits in frontend.
Note: See TracChangeset for help on using the changeset viewer.