Skip to content

Commit

Permalink
Merge pull request #11 from alleyinteractive/master
Browse files Browse the repository at this point in the history
Add Support For Static Url and Update Relative Path to Embed.js
  • Loading branch information
wyattjoh authored Feb 21, 2018
2 parents 3f887fd + c4e6d84 commit 07a6c7b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ We recommend something like:
if ( comments_open() ) {
coral_talk_comments_template();
}
```
```

## Version
Talk version <= `v3.9.1` use talk-wp-plugin `v0.0.6`

Talk version >= `4.0.0` use talk-wp-plugin `v0.1.0`
36 changes: 34 additions & 2 deletions inc/class-talk-settings-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,19 @@ function() {
);
register_setting( 'talk-settings', 'coral_talk_base_url', array(
'type' => 'string',
'sanitize_callback' => array( $this, 'sanitize_base_url' ),
'sanitize_callback' => array( $this, 'sanitize_url' ),
) );

add_settings_field(
'coral_talk_static_url',
__( 'Talk Static Asset URL', 'coral-project-talk' ),
array( $this, 'render_static_url_field' ),
'talk-settings',
'about-talk'
);
register_setting( 'talk-settings', 'coral_talk_static_url', array(
'type' => 'string',
'sanitize_callback' => array( $this, 'sanitize_url' ),
) );

add_settings_field(
Expand All @@ -73,7 +85,7 @@ function() {
* @return String Sanitized and untrailingslashed URL.
* @since 0.0.6
*/
public function sanitize_base_url( $url ) {
public function sanitize_url( $url ) {
return esc_url( untrailingslashit( $url ) );
}

Expand All @@ -92,6 +104,26 @@ public function render_base_url_field() {
type="url"
value="<?php echo esc_url( get_option( 'coral_talk_base_url' ) ); ?>"
/>
<p class="description">The root url of the installed Talk application. This is the same value as <a href="<?php echo esc_url( 'https://coralproject.github.io/talk/configuration/#talk_root_url' ); ?>">TALK_ROOT_URL</a> defined in the Talk application configuration.</p>
<?php
}

/**
* Prints input field for static url setting.
*
* @since 0.1.0
*/
public function render_static_url_field() {
?>
<input
style="width: 600px; height: 40px;"
name="coral_talk_static_url"
placeholder="https://cdn.talk-assets.com"
id="coral_talk_static_url"
type="url"
value="<?php echo esc_url( get_option( 'coral_talk_static_url' ) ); ?>"
/>
<p class="description">The root url where static Talk assets should be served from. This is the same value as <a href="<?php echo esc_url( 'https://coralproject.github.io/talk/advanced-configuration/#talk_static_uri' ); ?>">TALK_STATIC_URI</a> defined in the Talk application configuration.</p>
<?php
}

Expand Down
3 changes: 2 additions & 1 deletion inc/comments-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
*/

$talk_url = get_option( 'coral_talk_base_url' );
$static_url = get_option( 'coral_talk_static_url', $talk_url );
$talk_container_classes = get_option( 'coral_talk_container_classes' );
$div_id = 'coral_talk_' . absint( rand() );
if ( ! empty( $talk_url ) ) : ?>
<div class="<?php echo esc_attr( $talk_container_classes ); ?>" id="<?php echo esc_attr( $div_id ); ?>"></div>
<script src="<?php echo esc_url( $talk_url . '/embed.js' ); ?>" async onload="
<script src="<?php echo esc_url( $static_url . '/static/embed.js' ); ?>" async onload="
Coral.talkStream = Coral.Talk.render(document.getElementById('<?php echo esc_js( $div_id ); ?>'), {
talk: '<?php echo esc_url( $talk_url ); ?>'
});
Expand Down
2 changes: 1 addition & 1 deletion talk.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Coral Project Talk
* Plugin URI: https://coralproject.net
* Description: A plugin to replace stock WP commenting with Talk from the Coral Project
* Version: 0.0.6
* Version: 0.1.0
* Author: Alley Interactive, The Coral Project
* Author URI: https://www.alleyinteractive.com
* License: Apache 2.0
Expand Down

0 comments on commit 07a6c7b

Please sign in to comment.