Skip to content
This repository was archived by the owner on Aug 22, 2025. It is now read-only.

Commit 1d3df54

Browse files
Merge pull request #155 from rtMediaWP/vip-compatible
Make plugin VIP compatiable.
2 parents 9e8de97 + 1c47a65 commit 1d3df54

23 files changed

+6760
-3260
lines changed

.eslintrc

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,7 @@
4646
"error",
4747
"1tbs"
4848
],
49-
"camelcase": [
50-
"error",
51-
{
52-
"properties": "never"
53-
}
54-
],
55-
"comma-dangle": [
56-
"error",
57-
"always-multiline"
58-
],
49+
"camelcase": [1],
5950
"comma-spacing": "error",
6051
"comma-style": "error",
6152
"computed-property-spacing": [
@@ -87,7 +78,6 @@
8778
"key-spacing": "error",
8879
"keyword-spacing": "error",
8980
"lines-around-comment": "off",
90-
"no-alert": "error",
9181
"no-bitwise": "error",
9282
"no-caller": "error",
9383
"no-console": "error",
@@ -187,10 +177,6 @@
187177
"error",
188178
"always"
189179
],
190-
"padded-blocks": [
191-
"error",
192-
"never"
193-
],
194180
"prefer-const": "error",
195181
"quote-props": [
196182
"error",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
on: pull_request
2+
name: Inspections
3+
jobs:
4+
runPHPCSInspection:
5+
name: Run PHPCS inspection
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v2
9+
with:
10+
ref: ${{ github.event.pull_request.head.sha }}
11+
- name: Run PHPCS inspection
12+
uses: docker://rtcamp/action-phpcs-code-review:v2.0.0
13+
env:
14+
VAULT_ADDR: ${{ secrets.VAULT_ADDR }}
15+
VAULT_TOKEN: ${{ secrets.VAULT_TOKEN }}
16+
with:
17+
args: WordPress,WordPress-Core,WordPress-Docs

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v13.1.0

admin/js/rt-transcoder-admin.js

Lines changed: 131 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,150 @@
1-
(function( $ ) {
2-
$( document ).ready( function() {
3-
4-
$( document ).on( 'click', '#api-key-submit', function( e ) {
5-
e.preventDefault();
6-
7-
if ( $( this ).next( 'img' ).length === 0 ) {
8-
$( this ).after( $( '<img />' ).attr( 'src', rt_transcoder_script.loader_image ).addClass( 'rtt-loader' ) );
9-
}
10-
11-
var data = {
12-
action: 'rt_enter_api_key',
13-
apikey: $( '#new-api-key' ).val()
14-
};
15-
16-
// Since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
17-
$.getJSON( ajaxurl, data, function( response ) {
18-
if ( response.error === undefined && response.apikey ) {
19-
var tempUrl = window.location.href;
20-
var hash = window.location.hash;
21-
tempUrl = tempUrl.replace( hash, '' );
22-
23-
if ( tempUrl.toString().indexOf( '&apikey=' + response.apikey ) == -1 ) {
24-
tempUrl += '&apikey=' + response.apikey;
25-
}
26-
if ( tempUrl.toString().indexOf( '&update=true' ) == -1 ) {
27-
tempUrl += '&update=true';
1+
/**
2+
* Transcoder admin page.
3+
*
4+
* @package transcoder
5+
*/
6+
7+
/* global ajaxurl, rt_transcoder_script */
8+
9+
( function ( $ ) {
10+
$( document ).ready(
11+
function() {
12+
13+
$( document ).on(
14+
'click',
15+
'#api-key-submit',
16+
function( e ) {
17+
e.preventDefault();
18+
19+
if ( $( this ).next( 'img' ).length === 0 ) {
20+
$( this ).after( $( '<img/>' ).attr( 'src', rt_transcoder_script.loader_image ).addClass( 'rtt-loader' ) );
2821
}
2922

30-
document.location.href = tempUrl + hash;
31-
} else {
32-
$( '#api-key-error' ).remove();
33-
var error_div = $( '<div/>', {
34-
'id' : 'api-key-error',
35-
'class': 'error',
36-
});
37-
$( 'h1:first' ).after( error_div.html( $( '<p />' ).text( response.error ) ) );
38-
}
23+
var data = {
24+
action: 'rt_enter_api_key',
25+
apikey: $( '#new-api-key' ).val()
26+
};
27+
28+
// Since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php.
29+
$.getJSON(
30+
ajaxurl,
31+
data,
32+
function( response ) {
33+
34+
var tempUrl = window.location.href;
35+
var hash = window.location.hash;
36+
37+
if ( response.error === undefined && response.apikey ) {
3938

40-
$( '#api-key-submit' ).next( 'img' ).remove();
41-
} );
42-
} );
39+
tempUrl = tempUrl.replace( hash, '' );
4340

44-
$( document ).on( 'click', '#disable-transcoding', function( e ) {
45-
e.preventDefault();
46-
if ( confirm( rt_transcoder_script.disable_encoding ) ) {
41+
if ( -1 === tempUrl.toString().indexOf( '&apikey=' + response.apikey ) ) {
42+
tempUrl += '&apikey=' + response.apikey;
43+
}
4744

48-
var data = {
49-
action: 'rt_disable_transcoding'
50-
};
45+
if ( -1 === tempUrl.toString().indexOf( '&update=true' ) ) {
46+
tempUrl += '&update=true';
47+
}
5148

52-
if ( $( this ).next( 'img' ).length === 0 ) {
53-
$( this ).after( $( '<img />' ).attr( 'src', rt_transcoder_script.loader_image ).addClass( 'rtt-loader' ) );
49+
document.location.href = tempUrl + hash;
50+
} else {
51+
$( '#api-key-error' ).remove();
52+
53+
var error_div = $(
54+
'<div/>',
55+
{
56+
id: 'api-key-error',
57+
class: 'error'
58+
}
59+
);
60+
61+
$( 'h1:first' ).after( error_div.html( $( '<p/>' ).text( response.error ) ) ); // phpcs:ignoe WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
62+
}
63+
64+
$( '#api-key-submit' ).next( 'img' ).remove();
65+
}
66+
);
5467
}
68+
);
5569

56-
// Since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
57-
$.post( ajaxurl, data, function( response ) {
58-
if ( response ) {
70+
$( document ).on(
71+
'click',
72+
'#disable-transcoding',
73+
function( e ) {
5974

60-
if ( $( '#rtt-settings_updated' ).length > 0 ) {
61-
$( '#rtt-settings_updated p' ).html( response );
62-
$( '#rtt-settings_updated' ).show();
63-
} else {
75+
e.preventDefault();
76+
77+
if ( confirm( rt_transcoder_script.disable_encoding ) ) {
78+
79+
var data = {
80+
action: 'rt_disable_transcoding'
81+
};
82+
83+
if ( $( this ).next( 'img' ).length === 0 ) {
84+
$( this ).after( $( '<img />' ).attr( 'src', rt_transcoder_script.loader_image ).addClass( 'rtt-loader' ) );
6485
}
6586

66-
//$( '#rtmedia-transcoding-usage' ).hide();
67-
$( '#disable-transcoding' ).next( 'img' ).remove();
68-
$( '#disable-transcoding' ).hide();
69-
$( '#enable-transcoding' ).css( 'display', 'inline' );
70-
} else {
87+
// Since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php.
88+
$.post(
89+
ajaxurl,
90+
data,
91+
function( response ) {
92+
if ( response ) {
93+
if ( $( '#rtt-settings_updated' ).length > 0 ) {
94+
$( '#rtt-settings_updated p' ).text( response );
95+
$( '#rtt-settings_updated' ).show();
96+
}
97+
98+
// $( '#rtmedia-transcoding-usage' ).hide();
99+
$( '#disable-transcoding' ).next( 'img' ).remove();
100+
$( '#disable-transcoding' ).hide();
101+
$( '#enable-transcoding' ).css( 'display', 'inline' );
102+
}
103+
}
104+
);
71105
}
72-
} );
73-
}
74-
} );
106+
}
107+
);
75108

76-
$( document ).on( 'click', '#enable-transcoding', function( e ) {
77-
e.preventDefault();
78-
if ( confirm( rt_transcoder_script.enable_encoding ) ) {
109+
$( document ).on(
110+
'click',
111+
'#enable-transcoding',
112+
function( e ) {
79113

80-
var data = {
81-
action: 'rt_enable_transcoding'
82-
};
114+
e.preventDefault();
83115

84-
if ( $( this ).next( 'img' ).length === 0 ) {
85-
$( this ).after( $( '<img />' ).attr( 'src', rt_transcoder_script.loader_image ).addClass( 'rtt-loader' ) );
86-
}
116+
if ( confirm( rt_transcoder_script.enable_encoding ) ) {
87117

88-
$.post( ajaxurl, data, function( response ) {
89-
if ( response ) {
90-
if ( $( '#rtt-settings_updated' ).length > 0 ) {
91-
$( '#rtt-settings_updated p' ).html( response );
92-
$( '#rtt-settings_updated' ).show();
93-
}
118+
var data = {
119+
action: 'rt_enable_transcoding'
120+
};
94121

95-
$( '#enable-transcoding' ).next( 'img' ).remove();
96-
$( '#enable-transcoding' ).hide();
97-
$( '#disable-transcoding' ).css( 'display', 'inline' );
98-
} else {
99-
$( '#settings-error-transcoding-disabled' ).remove();
122+
if ( $( this ).next( 'img' ).length === 0 ) {
123+
$( this ).after( $( '<img />' ).attr( 'src', rt_transcoder_script.loader_image ).addClass( 'rtt-loader' ) );
124+
}
100125

126+
$.post(
127+
ajaxurl,
128+
data,
129+
function( response ) {
130+
if ( response ) {
131+
if ( $( '#rtt-settings_updated' ).length > 0 ) {
132+
$( '#rtt-settings_updated p' ).text( response );
133+
$( '#rtt-settings_updated' ).show();
134+
}
135+
136+
$( '#enable-transcoding' ).next( 'img' ).remove();
137+
$( '#enable-transcoding' ).hide();
138+
$( '#disable-transcoding' ).css( 'display', 'inline' );
139+
} else {
140+
$( '#settings-error-transcoding-disabled' ).remove();
141+
}
142+
}
143+
);
101144
}
102-
} );
103-
}
104-
} );
105-
} );
106-
})( jQuery );
145+
}
146+
);
147+
}
148+
);
149+
150+
} )( jQuery );

admin/js/rt-transcoder-block-editor-support.js

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* Gutenberg support for transcoder.
3+
*
4+
* @package transcoder
5+
*/
6+
17
import apiFetch from '@wordpress/api-fetch';
28

39
const { rtTranscoderBlockEditorSupport } = window;
@@ -19,25 +25,33 @@ const updateAMPStoryMedia = ( BlockEdit ) => {
1925
}
2026
} else if ( mediaAttributes.poster.endsWith( '-fallback-poster.png' ) ) {
2127
const restBase = '/wp-json/transcoder/v1/amp-media';
22-
apiFetch( {
23-
path: `${ restBase }/${ mediaId }`,
24-
} ).then( data => {
25-
if ( false !== data && null !== data ) {
26-
if ( data.poster.length && data.transcodedMedia.length ) {
27-
if ( isAMPStory && typeof mediaAttributes.mediaType !== 'undefined' && 'video' === mediaAttributes.mediaType ) {
28-
props.setAttributes( {
29-
poster: data.poster,
30-
mediaUrl: data.transcodedMedia,
31-
} );
32-
} else if ( isVideoBlock ) {
33-
props.setAttributes( {
34-
poster: data.poster,
35-
src: data.transcodedMedia,
36-
} );
28+
apiFetch(
29+
{
30+
path: `${ restBase } / ${ mediaId }`
31+
}
32+
).then(
33+
data => {
34+
if ( false !== data && null !== data ) {
35+
if ( data.poster.length && data.transcodedMedia.length ) {
36+
if ( isAMPStory && typeof mediaAttributes.mediaType !== 'undefined' && 'video' === mediaAttributes.mediaType ) {
37+
props.setAttributes(
38+
{
39+
poster: data.poster,
40+
mediaUrl: data.transcodedMedia,
41+
}
42+
);
43+
} else if ( isVideoBlock ) {
44+
props.setAttributes(
45+
{
46+
poster: data.poster,
47+
src: data.transcodedMedia,
48+
}
49+
);
50+
}
3751
}
3852
}
3953
}
40-
} );
54+
);
4155
}
4256
}
4357

0 commit comments

Comments
 (0)