npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mtcmedia/vue-wordpress-media-library

v1.0.0

Published

Vue JS Wordpress media library

Downloads

8

Readme

@mtcmedia/vue-wordpress-media-library

Vue component to allow user to access/upload files using Wordpress' build in media library. Uses draggable to allow user to re-order files when using multiple functionality

Install to production site

npm install @mtcmedia/vue-wordpress-media-library

Usage

import MtcWordpressMediaLibrary from '@mtcmedia/vue-wordpress-media-library'

Vue.component('mtc-wordpress-media-library', MtcWordpressMediaLibrary)

Add this to your theme where you want the button to show. The condition prevents user from seeing the button who don't have permissions to upload files to your site

<?php
if (current_user_can('upload_files')) {
  ?>
  <mtc-wordpress-media-library
    v-model="images"
  >
  </mtc-wordpress-media-library>
  <?php
}
?>

Example with custom item slot and access to slotPropItem (selected file object)

<mtc-wordpress-media-library
  v-model="images"
>
  <template #item="{ slotPropItem }">
    {{ slotPropItem }}
   </template>
</mtc-wordpress-media-library>

images should equal and array of images in the following format as a minimum.

const images = [{
    "alt": "Alt tag of image",
    "id": 0,
    "mime": "image/jpeg",
    "sizes": {
        "thumbnail": {
            "url": "path_to_thumbnail_image" // pass in wordpress document icon managing document files
        }
    },
    "url": "path_to_main_image"
}]

Add the following to your themes function file

<?php
// enqueue js and css for wp media library
if (current_user_can('upload_files')) {
    add_action('wp_enqueue_scripts', 'wp_enqueue_media', 999);
}

// This limits users so that they can only see content that they have uploaded to the media library
function hideMediaFromOtherUsers($query) {
    $user_id = get_current_user_id();
    if ($user_id && !current_user_can('manage_options')) {
        $query['author'] = $user_id;
    }
    return $query;
}
add_filter('ajax_query_attachments_args', 'hideMediaFromOtherUsers');

Props

The component accepts these props:

| Attribute | Type | Default | Description | Required | | :--- | :--- | :--- | :--- | :--- | | multiple | Boolean | false | Set to true to allow user to select more than one image | false | | max | Number | Infinity | Define the maximum number of images that can be selected. Only useful when multiple is true | false | | delete-image | Boolean | true | Allow user to remove images from selection | false | | edit | Boolean | false | Allow user to make a change to selected image | false | | imageSize | String | 'thumbnail' | Image size used when displaying selected image image must contain this images size | false | | resetSelection | Boolean | false | When true users selection will be cleared when they open the media library | false | | showFilename | Boolean | false | Add filename to DOM after displayed image or can be used to display filename when file is a document | false | | hideImage | Boolean | false | Choose to hide the image, useful if you are only managing documents and don't want to show the wordpress default icons | false | | mimeType | String | '' | Define the mime type of valid files | false |

Slots

The component accepts these slots:

| Name | Default | Description | | :--- | :--- | :--- | | item | HTML see here | Markup for images that are selected from the media library. Has access to file object | | remove-button-content | HTML see here | Entire cntent of remove button | | remove-button-icon | '×' | Icon within remove button | | add-button-content | 'Select File' | Content of select file button | | edit-button-content | 'Update File' | Content of update file button - this button shows when max number of files have been selected |

Development Setup

For developing it's best to download the directory from bitbucket and use the full component directly within a wordpress theme.