Skip to content

Commit

Permalink
init project
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianGroshaupt committed Jun 9, 2021
0 parents commit 0e33298
Show file tree
Hide file tree
Showing 18 changed files with 1,925 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .distignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.git
/.github
/.wordpress-org

.distignore
.gitignore
33 changes: 33 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: release plugin

on:
push:
tags:
- "*.*.*"

jobs:
release:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: create zip
run: |
zip -r privacy-embed.zip ./ -x \*.git\* \*.github\* .wordpress-org\* .distignore\* .gitignore\*
- name: release on github
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
privacy-embed.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: release on wordpress
uses: 10up/action-wordpress-plugin-deploy@stable
env:
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SLUG: privacy-embed
20 changes: 20 additions & 0 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: update assets/readme

on:
push:
branches:
- main

jobs:
update:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: update on wordpress
uses: 10up/action-wordpress-plugin-asset-update@stable
env:
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SLUG: privacy-embed
339 changes: 339 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Privacy Embed (Wordpress Plugin)

This plugin adds some shortcodes to let you embed external content like youtube videos on your wordpress pages. Nothing new so far - why another plugin?

Well, this plugin puts emphasis on data protection. Before the content is loaded from an external area of responsibility (a third-party provider), the user must explicitly agree to the data transfer. In this way, the site operator is supported in designing his website in a data protection-compliant manner (taking into account the GDPR, among other things).

For the WPBakery Page Builder plugin, prefabricated blocks are also provided so that the shortcodes can be used directly.

Currently, embeddings of the following services are supported:

- YouTube videos (Google)
- Spotify
- Artists
- Albums
- Tracks

## installation & usage

1. Make sure that your WordPress installation meets the minimum requirements of this plugin.
2. Upload the plugin to the /wp-content/plugins/ directory or install it directly from the admin pages.
3. Use the shortcodes:
- Spotify\*:
`[privacy-embed_spotify title="Title of embed" spotify_url="spotify:album:1DFixLWuPkv3KT3TnV35m3"]`
- YouTube:
`[privacy-embed_youtube title="Title of embed" youtube_link="https://www.youtube.com/watch?v=kV9sNmujCPk"]`

\* You can get the Spotify URI by clicking \"Share\" on the Spotify page of any artist, album or track and then selecting \"Copy Spotify URI\".

## license

GPL v2 or later, see [LICENSE](https://github.com/JulianGroshaupt/privacy-embed/blob/main/LICENSE)
45 changes: 45 additions & 0 deletions functions/privacy_embed__add_jpg_to_wordpress_media.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* Function adding an image (jpg) to the wordpress media library.
*
* @param $file_data the jpg-file to add to the media library
* @param $filename the name of the file
* @param $title the title of the image
*
* @return int the id of the created media item
*/

// exit if accessed directly
if (!defined('ABSPATH')) {
exit;
}

if (!function_exists('privacy_embed__add_jpg_to_wordpress_media')) {
function privacy_embed__add_jpg_to_wordpress_media($file_data, $filename, $title)
{
// set file in upload directory
$upload_dir = wp_upload_dir();
if (wp_mkdir_p($upload_dir['path'])) {
$file = $upload_dir['path'] . '/' . $filename;
} else {
$file = $upload_dir['basedir'] . '/' . $filename;
}

// upload file
file_put_contents($file, $file_data);
$wp_filetype = wp_check_filetype($filename, null);
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => $title,
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment($attachment, $file);
require_once(ABSPATH . 'wp-admin/includes/image.php');
$attach_data = wp_generate_attachment_metadata($attach_id, $file);
wp_update_attachment_metadata($attach_id, $attach_data);

return $attach_id;
}
}
22 changes: 22 additions & 0 deletions functions/privacy_embed__does_file_exists.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/**
* Function to check wheather a file with a given filename exists in the media library.
*
* @param $filename the name of the file
*
* @return int the id of the media item (0 if the item was not found)
*/

// exit if accessed directly
if (!defined('ABSPATH')) {
exit;
}

if (!function_exists('privacy_embed__does_file_exists')) {
function privacy_embed__does_file_exists($filename)
{
global $wpdb;
return intval($wpdb->get_var("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_value LIKE '%/$filename'"));
}
}
Loading

0 comments on commit 0e33298

Please sign in to comment.