Plugin Directory

Changeset 3486553


Ignore:
Timestamp:
03/19/2026 02:13:52 PM (2 weeks ago)
Author:
palasthotel
Message:

Release version 1.6.7

Location:
media-license
Files:
62 added
4 edited

Legend:

Unmodified
Added
Removed
  • media-license/trunk/classes/Assets.php

    r3465002 r3486553  
    2626        add_action('init', array($this, 'register'), 1);
    2727        add_action('wp_enqueue_scripts', array($this, 'enqueue_script'));
     28        add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_script'));
    2829    }
    2930
     
    4142        );
    4243        wp_localize_script(Plugin::HANDLE_API_JS, "MediaLicense_API", $obj);
     44
     45        wp_register_script(
     46            Plugin::HANDLE_ADMIN_TEXTAREA_JS,
     47            $this->plugin->getUrl('/js/admin-textarea-toolbar.js'),
     48            [],
     49            filemtime($this->plugin->getPath('/js/admin-textarea-toolbar.js')),
     50            true
     51        );
    4352    }
    4453
     
    5463                [],
    5564                filemtime($this->plugin->getPath('/styles/frontend.css'))
    56             );
    57         }
     65            );
     66        }
     67    }
     68
     69    function enqueue_admin_script($hook_suffix){
     70        if (!in_array($hook_suffix, ['upload.php', 'post.php', 'post-new.php', 'media-upload.php', 'media_page_media-license-settings'], true)) {
     71            return;
     72        }
     73
     74        wp_enqueue_script(Plugin::HANDLE_ADMIN_TEXTAREA_JS);
    5875    }
    5976}
  • media-license/trunk/classes/MetaFields.php

    r3483729 r3486553  
    143143                    }
    144144                    break;
     145                case "textarea":
     146                    if ($this->use_textarea_toolbar($fd)) {
     147                        $fd['input'] = 'html';
     148                        $fd['html'] = $this->get_textarea_editor_markup($post->ID, $meta_key, (empty($value)) ? '' : $value);
     149                    } else {
     150                        $fd['value'] = (empty($value))? '': $value;
     151                    }
     152                    break;
    145153                default:
    146154                    $fd['value'] = (empty($value))? '': $value;
     
    153161
    154162        return $form_fields;
     163    }
     164
     165    private function use_textarea_toolbar($field_definition){
     166        return isset($field_definition['sanitize']) && 'html' === $field_definition['sanitize'];
     167    }
     168
     169    private function get_textarea_editor_markup($post_id, $meta_key, $value){
     170        $field_name = "attachments[{$post_id}][{$meta_key}]";
     171        $field_id = "attachments-{$post_id}-{$meta_key}";
     172        $preview_id = $field_id . '-preview';
     173        $buttons = [
     174            ['tag' => 'strong', 'label' => __('Bold', 'media_license')],
     175            ['tag' => 'em', 'label' => __('Italic', 'media_license')],
     176            ['tag' => 'link', 'label' => __('Link', 'media_license')],
     177        ];
     178
     179        $html = "<div class='media-license-textarea-editor'>";
     180        $html .= "<div class='media-license-textarea-toolbar' data-target='" . esc_attr($field_id) . "'>";
     181        foreach ($buttons as $button) {
     182            $html .= "<button type='button' class='button button-small media-license-textarea-button' data-tag='" . esc_attr($button['tag']) . "'>" . esc_html($button['label']) . "</button> ";
     183        }
     184        $html .= "</div>";
     185        $html .= "<div class='media-license-textarea-link-form' data-target='" . esc_attr($field_id) . "' hidden>";
     186        $html .= "<label>" . esc_html(__('Link URL', 'media_license')) . " <input type='url' class='regular-text media-license-textarea-link-input' value='https://' placeholder='https://' /></label> ";
     187        $html .= "<button type='button' class='button button-small media-license-textarea-link-apply'>" . esc_html(__('Apply', 'media_license')) . "</button> ";
     188        $html .= "<button type='button' class='button button-small media-license-textarea-link-cancel'>" . esc_html(__('Cancel', 'media_license')) . "</button>";
     189        $html .= "</div>";
     190        $html .= "<textarea id='" . esc_attr($field_id) . "' name='" . esc_attr($field_name) . "'>" . esc_textarea($value) . "</textarea>";
     191        $html .= "<p><strong>" . esc_html(__('Preview', 'media_license')) . "</strong></p>";
     192        $html .= "<div id='" . esc_attr($preview_id) . "' class='media-license-textarea-preview' data-source='" . esc_attr($field_id) . "'></div>";
     193        $html .= "</div>";
     194
     195        return $html;
    155196    }
    156197
  • media-license/trunk/media-license.php

    r3483729 r3486553  
    44 * Plugin URI: https://github.com/palasthotel/media-license
    55 * Description: Advanced caption with license for media files
    6  * Version: 1.6.6
     6 * Version: 1.6.7
    77 * Author: Palasthotel <rezeption@palasthotel.de> (in person: Edward Bock, Lucas Regalar)
    88 * Author URI: http://www.palasthotel.de
     
    105105    const HANDLE_API_JS = "media-license-js";
    106106    const HANDLE_GUTENBERG_JS = "media-license-gutenberg";
     107    const HANDLE_ADMIN_TEXTAREA_JS = "media-license-admin-textarea";
    107108
    108109    /**
     
    183184
    184185require_once dirname( __FILE__ ) . "/public-functions.php";
    185 
  • media-license/trunk/readme.txt

    r3483729 r3486553  
    55Requires at least: 5.0
    66Tested up to: 6.8.1
    7 Stable tag: 1.6.6
     7Stable tag: 1.6.7
    88License: GPLv3
    99License URI: http://www.gnu.org/licenses/gpl
     
    3232
    3333== Changelog ==
     34= 1.6.7 =
     35* Feature: Add rich text editor tools to textarea input
     36
    3437= 1.6.6 =
    3538* Feature: Add html-sanitization option to add_fields hook
Note: See TracChangeset for help on using the changeset viewer.