Skip to content

Commit 382e747

Browse files
committed
Add a setting to enqueue the PDK external controller
1 parent 56f725d commit 382e747

2 files changed

Lines changed: 39 additions & 24 deletions

File tree

thePlatform-constants.php

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,24 @@ function TP_ACCOUNT_OPTIONS_DEFAULTS() {
5858

5959
function TP_PREFERENCES_OPTIONS_DEFAULTS() {
6060
return array(
61-
'plugin_version' => TP_PLUGIN_VERSION,
62-
'embed_tag_type' => 'iframe',
63-
'default_player_name' => '',
64-
'default_player_pid' => '',
65-
'mpx_server_id' => 'DEFAULT_SERVER',
66-
'default_publish_id' => 'tp_wp_none',
67-
'thumbnail_profile_id' => 'tp_wp_none',
68-
'user_id_customfield' => '(None)',
69-
'transform_user_id_to' => 'nickname',
70-
'filter_by_user_id' => 'false',
71-
'autoplay' => 'true',
72-
'rss_embed_type' => 'article',
73-
'default_width' => intval( $GLOBALS['content_width'] ),
74-
'default_height' => intval( ( $GLOBALS['content_width'] / 16 ) * 9 ),
75-
'player_embed_type' => 'true',
76-
'embed_hook' => 'tinymce',
77-
'media_embed_type' => 'pid'
61+
'plugin_version' => TP_PLUGIN_VERSION,
62+
'embed_tag_type' => 'iframe',
63+
'default_player_name' => '',
64+
'default_player_pid' => '',
65+
'mpx_server_id' => 'DEFAULT_SERVER',
66+
'default_publish_id' => 'tp_wp_none',
67+
'thumbnail_profile_id' => 'tp_wp_none',
68+
'user_id_customfield' => '(None)',
69+
'transform_user_id_to' => 'nickname',
70+
'filter_by_user_id' => 'false',
71+
'autoplay' => 'true',
72+
'rss_embed_type' => 'article',
73+
'default_width' => intval( $GLOBALS['content_width'] ),
74+
'default_height' => intval( ( $GLOBALS['content_width'] / 16 ) * 9 ),
75+
'player_embed_type' => 'true',
76+
'embed_hook' => 'tinymce',
77+
'media_embed_type' => 'pid',
78+
'enqueue_external_controller' => 'false'
7879
);
7980
}
8081

@@ -130,6 +131,11 @@ function TP_PREFERENCES_OPTIONS_FIELDS() {
130131
'type' => 'select',
131132
'values' => array( 'IFrame' => 'iframe', 'Script' => 'script' ),
132133
),
134+
array(
135+
'id' => 'enqueue_external_controller',
136+
'title' => 'Enqueue PDK External Controller',
137+
'type' => 'boolean'
138+
),
133139
array(
134140
'id' => 'media_embed_type',
135141
'title' => 'Media Embed Type',

thePlatform.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function __construct() {
6262
add_action( 'admin_init', array( $this, 'register_scripts' ) );
6363
add_action( 'admin_init', array( $this, 'theplatform_register_plugin_settings' ) );
6464
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
65+
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_external_controller' ) );
6566

6667
if ( current_user_can( $this->tp_editor_cap ) ) {
6768
add_filter( 'media_upload_tabs', array( $this, 'tp_upload_tab' ) );
@@ -133,6 +134,18 @@ function admin_enqueue_scripts( $hook ) {
133134
}
134135
}
135136

137+
function enqueue_external_controller( $hook ) {
138+
$preferences = get_option( TP_PREFERENCES_OPTIONS_KEY );
139+
140+
if ( $preferences === false ) {
141+
return;
142+
}
143+
144+
if ( $preferences['enqueue_external_controller'] == 'true' ) {
145+
wp_enqueue_script( 'tp_pdk_external_controller_js', '//pdk.theplatform.com/pdk/tpPdkController.js' );
146+
}
147+
}
148+
136149
/**
137150
* Registers javascripts and css used throughout the plugin
138151
*/
@@ -348,17 +361,15 @@ function check_plugin_update() {
348361
update_option( TP_BASIC_METADATA_OPTIONS_KEY, array_merge( TP_BASIC_METADATA_OPTIONS_DEFAULTS(), get_option( TP_BASIC_METADATA_OPTIONS_KEY, array() ) ) );
349362

350363
// We had a messy update with 1.2.2/1.3.0, let's clean up
351-
if ( ( $oldVersion['major'] == '1' && $oldVersion['minor'] == '2' && $oldVersion['patch'] == '2' ) ||
352-
( $oldVersion['major'] == '1' && $oldVersion['minor'] == '3' && $oldVersion['patch'] == '0' )
364+
if ( ( $oldVersion['major'] == '1' && $oldVersion['minor'] == '2' && $oldVersion['patch'] == '2' ) || ( $oldVersion['major'] == '1' && $oldVersion['minor'] == '3' && $oldVersion['patch'] == '0' )
353365
) {
354366
$basicMetadataFields = get_option( TP_BASIC_METADATA_OPTIONS_KEY, array() );
355367
$customMetadataFields = get_option( TP_CUSTOM_METADATA_OPTIONS_KEY, array() );
356368
update_option( TP_BASIC_METADATA_OPTIONS_KEY, array_diff_assoc( $basicMetadataFields, $customMetadataFields ) );
357369
}
358370

359371
// Move account settings from preferences (1.2.0)
360-
if ( ( $oldVersion['major'] == '1' && $oldVersion['minor'] < '2' ) &&
361-
( $newVersion['major'] > '1' || ( $newVersion['major'] >= '1' && $newVersion['minor'] >= '2' ) )
372+
if ( ( $oldVersion['major'] == '1' && $oldVersion['minor'] < '2' ) && ( $newVersion['major'] > '1' || ( $newVersion['major'] >= '1' && $newVersion['minor'] >= '2' ) )
362373
) {
363374
$preferences = get_option( TP_PREFERENCES_OPTIONS_KEY, array() );
364375
if ( array_key_exists( 'mpx_account_id', $preferences ) ) {
@@ -661,9 +672,7 @@ function shortcode( $atts ) {
661672
'params' => '',
662673
'playall' => '',
663674
'instance' => '',
664-
), $atts
665-
)
666-
);
675+
), $atts ) );
667676

668677
if ( empty( $width ) ) {
669678
$width = (int) $this->preferences['default_width'];

0 commit comments

Comments
 (0)