Skip to content

Commit

Permalink
fix!: fix user role capability
Browse files Browse the repository at this point in the history
BREAKING CHANGE: change field type reference ($this->name)
  • Loading branch information
frugan-dev committed Nov 26, 2024
1 parent 7ca7898 commit d88e4e5
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ If you use Composer to manage WordPress plugins, you can install it from this re
"type": "package",
"package": {
"name": "frugan-dev/upload-field-to-youtube-for-acf",
"version": "0.1.0",
"version": "0.2.0",
"type": "wordpress-plugin",
"dist": {
"url": "https://github.com/frugan-dev/upload-field-to-youtube-for-acf/releases/download/v0.1.0/upload-field-to-youtube-for-acf.zip",
"url": "https://github.com/frugan-dev/upload-field-to-youtube-for-acf/releases/download/v0.2.0/upload-field-to-youtube-for-acf.zip",
"type": "zip"
}
}
Expand Down
4 changes: 2 additions & 2 deletions upload-field-to-youtube-for-acf/asset/css/main.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.youtube_uploader__wrapper .youtube_uploader__spinner {
.upload_field_to_youtube_for_acf__wrapper .upload_field_to_youtube_for_acf__spinner {
display: none;
}
.youtube_uploader__wrapper .youtube_uploader__spinner .spinner {
.upload_field_to_youtube_for_acf__wrapper .upload_field_to_youtube_for_acf__spinner .spinner {
float: none;
margin: 0;
}
14 changes: 8 additions & 6 deletions upload-field-to-youtube-for-acf/asset/js/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/**
* Included when youtube_uploader fields are rendered for editing by publishers.
* Included when fields are rendered for editing by publishers.
*/
( function( $ ) {
class YTUploader {
window.FRUGAN_UFTYFACF = window.FRUGAN_UFTYFACF || {};

FRUGAN_UFTYFACF.Field = class {
/**
* $field is a jQuery object wrapping field elements in the editor.
*/
Expand Down Expand Up @@ -378,11 +380,11 @@
* Run initialize_field when existing fields of this type load,
* or when new fields are appended via repeaters or similar.
*/
acf.add_action( 'ready_field/type=youtube_uploader', function($field) {
new YTUploader($field);
acf.add_action( 'ready_field/type=upload_field_to_youtube_for_acf', function($field) {
new FRUGAN_UFTYFACF.Field($field);
});
acf.add_action( 'append_field/type=youtube_uploader', function($field) {
new YTUploader($field);
acf.add_action( 'append_field/type=upload_field_to_youtube_for_acf', function($field) {
new FRUGAN_UFTYFACF.Field($field);
});
}
} )( jQuery );
2 changes: 1 addition & 1 deletion upload-field-to-youtube-for-acf/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: Frugan
Tags: acf, fields, repeater, upload, youtube
Requires at least: 5.6.0
Tested up to: 6.6.1
Stable tag: 0.1.1
Stable tag: 0.2.0
Requires PHP: 8.0
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html
Expand Down
10 changes: 6 additions & 4 deletions upload-field-to-youtube-for-acf/src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __construct()
*
* No spaces. Underscores allowed.
*/
$this->name = 'youtube_uploader';
$this->name = FRUGAN_UFTYFACF_NAME_UNDERSCORE;

$this->title = __('Upload Field to YouTube for ACF', 'upload-field-to-youtube-for-acf');

Expand Down Expand Up @@ -110,7 +110,7 @@ public function __construct()
* Allows JS strings to be translated in PHP and loaded in JS via:
*
* ```js
* const errorMessage = acf._e("youtube_uploader", "error");
* const errorMessage = acf._e(this.field.data('type'), "error");
* ```
*/
$this->l10n = [
Expand Down Expand Up @@ -138,6 +138,8 @@ public function __construct()
'version' => FRUGAN_UFTYFACF_VERSION,
'url' => FRUGAN_UFTYFACF_URL,
'path' => FRUGAN_UFTYFACF_PATH,
'debug' => WP_DEBUG,
'locale' => get_locale(),
'cache_busting' => \defined('FRUGAN_UFTYFACF_CACHE_BUSTING_ENABLED') && !empty(FRUGAN_UFTYFACF_CACHE_BUSTING_ENABLED) && !is_numeric(FRUGAN_UFTYFACF_CACHE_BUSTING_ENABLED) && filter_var(FRUGAN_UFTYFACF_CACHE_BUSTING_ENABLED, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ? true : false,
];

Expand Down Expand Up @@ -804,7 +806,7 @@ public function handle_oauth(): array
$this->check_oauth_token();

if (!$this->get_access_token()) {
if (!current_user_can('manage_options') || !current_user_can('manage_'.$this->name)) {
if (!current_user_can('manage_options') && !current_user_can('manage_'.$this->name)) {
$data = [
'status' => 'error',
'message' => __('App not authorized, contact your system administrator.', 'upload-field-to-youtube-for-acf'),
Expand Down Expand Up @@ -947,7 +949,7 @@ public function wp_ajax_get_youtube_upload_url(): void
// To lift this restriction, each API project must undergo an audit to verify compliance
// with the Terms of Service. Please see the API Revision History for more details.
$googleServiceYouTubeVideoStatus->setPrivacyStatus($field['privacy_status']);
$googleServiceYouTubeVideoStatus->setSelfDeclaredMadeForKids($field['made_for_kids']); // or setMadeForKids()
$googleServiceYouTubeVideoStatus->setSelfDeclaredMadeForKids((bool) $field['made_for_kids']); // or setMadeForKids()

$googleServiceYouTubeVideo = new \Google_Service_YouTube_Video();
$googleServiceYouTubeVideo->setSnippet($googleServiceYouTubeVideoSnippet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"label": "Video",
"name": "youtube_video_id",
"aria-label": "",
"type": "youtube_uploader",
"type": "upload_field_to_youtube_for_acf",
"instructions": "",
"required": 1,
"conditional_logic": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Plugin Name: Upload Field to YouTube for ACF
* Plugin URI: https://github.com/frugan-dev/upload-field-to-youtube-for-acf
* Description: Upload Field to YouTube for ACF is a WordPress plugin that allows you to upload videos directly to YouTube via API from the WordPress admin area and/or select existing videos on your YouTube channel based on playlists.
* Version: 0.1.1
* Version: 0.2.0
* Requires Plugins: advanced-custom-fields
* Requires PHP: 8.0
* Author: Frugan
Expand All @@ -35,7 +35,7 @@
require __DIR__.'/vendor/autoload.php';
}

define('FRUGAN_UFTYFACF_VERSION', '0.1.1');
define('FRUGAN_UFTYFACF_VERSION', '0.2.0');
define('FRUGAN_UFTYFACF_BASENAME', plugin_basename(__FILE__));
define('FRUGAN_UFTYFACF_NAME', dirname(FRUGAN_UFTYFACF_BASENAME));
define('FRUGAN_UFTYFACF_NAME_UNDERSCORE', str_replace('-', '_', FRUGAN_UFTYFACF_NAME));
Expand Down

0 comments on commit d88e4e5

Please sign in to comment.