Skip to content

Commit

Permalink
Merge pull request #78 from sailthru/IN-1395_Wordpress_Content_Settin…
Browse files Browse the repository at this point in the history
…gs_Update

[IN-1395_WORDPRESS_CONTENT_SETTINGS_UPDATE] Added spider toggle
  • Loading branch information
henrivrod authored Jul 15, 2020
2 parents 4b644a3 + e3b0f3e commit 2b70b32
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: brownac, lcooper, asilverman, nickgundry, sailthru-wp, automattic,
Tags: personalization, email,
Requires at least: 3.6
Tested up to: 5.4
Stable tag: 3.4.4
Stable tag: 3.5.0

This plugin provides fast and easy integration of the core Sailthru features into your Wordpress site.

Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v3.5.0 (2020-07-15)
Added option for users to change Spider value in Content API calls (defaults to enabled)
Renamed Global Vars to Custom Fields and updated helper text on Content Settings page

## v3.4.4 (2020-07-01)
Fixed bug where “Scout from Sailthru” page was created for all sites, rather than just Scout-enabled sites.

Expand Down
68 changes: 49 additions & 19 deletions classes/class-sailthru-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,49 +44,58 @@ public function init_settings() {
add_settings_field(
'sailthru_content_api_status',
__( 'Content API Syncing', 'text_domain' ),
array( $this, 'render_sailthru_content_api_status_field' ),
[$this, 'render_sailthru_content_api_status_field' ],
'sailthru_content_settings',
'sailthru_content_settings_section'
);

// Only show these fields if the status has been enabled
if ( isset ( $options['sailthru_content_api_status'] ) && 'true' === $options['sailthru_content_api_status'] ) {

add_settings_field(
'sailthru_spider_status',
__( 'Spider', 'text_domain' ),
[$this, 'render_sailthru_spider_status_field' ],
'sailthru_content_settings',
'sailthru_content_settings_section'
);

add_settings_field(
'sailthru_content_post_types',
__( 'Included Post Types', 'text_domain' ),
array( $this, 'render_sailthru_content_post_types_field' ),
[$this, 'render_sailthru_content_post_types_field' ],
'sailthru_content_settings',
'sailthru_content_settings_section'
);

add_settings_field(
'sailthru_content_vars',
__( 'Global Content Vars', 'text_domain' ),
array( $this, 'render_sailthru_content_vars_field' ),
__( 'Custom Fields', 'text_domain' ),
[$this, 'render_sailthru_content_vars_field' ],
'sailthru_content_settings',
'sailthru_content_settings_section'
);

add_settings_field(
'sailthru_interest_tag_options',
__( 'Additional Interest Tags', 'text_domain' ),
array( $this, 'render_sailthru_interest_tag_options_field' ),
[$this, 'render_sailthru_interest_tag_options_field' ],
'sailthru_content_settings',
'sailthru_content_settings_section'
);

add_settings_field(
'sailthru_taxonomy_tag_options',
__( 'Include Taxonomies', 'text_domain' ),
array( $this, 'render_sailthru_taxonomy_tag_options_field' ),
[$this, 'render_sailthru_taxonomy_tag_options_field' ],
'sailthru_content_settings',
'sailthru_content_settings_section'
);

add_settings_field(
'sailthru_content_interest_tags',
__( 'Global Interest Tag', 'text_domain' ),
array( $this, 'render_sailthru_content_interest_tags_field' ),
[$this, 'render_sailthru_content_interest_tags_field' ],
'sailthru_content_settings',
'sailthru_content_settings_section'
);
Expand Down Expand Up @@ -146,6 +155,23 @@ function render_sailthru_content_api_status_field() {

}

function render_sailthru_spider_status_field() {

// Retrieve data from the database.
$options = get_option( 'sailthru_content_settings' );

// Set default value.
$value = isset( $options['sailthru_spider_status'] ) ? $options['sailthru_spider_status'] : 'true';

// Field output.
echo '<select name="sailthru_content_settings[sailthru_spider_status]" class="sailthru_spider_status_field">';
echo ' <option value="true" ' . selected( $value, 'true', false ) . '> ' . esc_attr__( 'Enabled', 'text_domain' ) . '</option>';
echo ' <option value="false" ' . selected( $value, 'false', false ) . '> ' . esc_attr__( 'Disabled', 'text_domain' ) . '</option>';
echo '</select>';
echo '<p class="description">' . esc_attr__( 'Triggers the Sailthru spider to add onsite tags when syncing content. In most cases, this can be disabled.', 'text_domain' ) . '</p>';

}

/**
* Renders the post types field.
*/
Expand Down Expand Up @@ -188,7 +214,8 @@ function render_sailthru_content_vars_field() {

// Field output.
echo '<input type="text" name="sailthru_content_settings[sailthru_content_vars]" class="regular-text sailthru_content_vars_field" placeholder="' . esc_attr__( '', 'text_domain' ) . '" value="' . esc_attr( $value ) . '">';
echo '<p class="description">' . __( '<p>Provide a comma separated list of vars to include.</p> <p class="small">When left blank all WordPress content type attributes will be synced with Sailthru.</p>', 'text_domain' ) . '</p>';
echo '<p class="description">' . __( '<p>Please provide a comma-separated list of WordPress custom fields to include in the Sailthru Content Library.</p>', 'text_domain' ) . '</p>';
echo '<p class="description">' . esc_attr__( 'These fields will be usable within Sailthru messages and content feeds. If blank, all fields will be sent to Sailthru.', 'text_domain' ) . '</p>';

}

Expand Down Expand Up @@ -258,22 +285,25 @@ function render_sailthru_content_interest_tags_field() {
*/
function generate_payload( $post, $post_id ) {

$options = get_option( 'sailthru_content_settings' );
$spider_value = isset( $options['sailthru_spider_status'] ) ? $options['sailthru_spider_status'] : false;

$url = get_permalink( $post->ID );
$url_with_correct_protocol = set_url_scheme( $url );

$data = array();
$data['url'] = $url_with_correct_protocol;
$data['title'] = $post->post_title;
$data['author'] = get_the_author_meta( 'display_name', $post->post_author );
$data['date'] = $post->post_date;
$data['vars']['post_type'] = $post->post_type;
$data['spider'] = 1;

if ( ! empty( $post->post_excerpt ) ) {
$data['description'] = $post->post_excerpt;
} else {
$data = [
'url' => $url_with_correct_protocol,
'title' => $post->post_title,
'author' => get_the_author_meta( 'display_name', $post->post_author ),
'date' => $post->post_date,
'vars'['post_type'] => $post->post_type,
'spider' => $spider_value == "false" ? 0 : 1,
'description' => $post->post_excerpt
];
if ( empty( $post->post_excerpt ) ) {
$data['description'] = wp_trim_words( $post->post_content, 250, '' );
}

// image & thumbnail
if ( has_post_thumbnail( $post->ID ) ) {
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
Expand Down
4 changes: 2 additions & 2 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Sailthru for WordPress
Plugin URI: http://sailthru.com/
Description: Add the power of Sailthru to your WordPress set up.
Version: 3.4.4
Version: 3.5.0
Author: Sailthru
Author URI: http://sailthru.com
Author Email: [email protected]
Expand Down Expand Up @@ -35,7 +35,7 @@
* @var const $version The current version of the plugin.
*/
if ( ! defined( 'SAILTHRU_PLUGIN_VERSION' ) ) {
define( 'SAILTHRU_PLUGIN_VERSION', '3.4.4' );
define( 'SAILTHRU_PLUGIN_VERSION', '3.5.0' );
}

if ( ! defined( 'SAILTHRU_PLUGIN_PATH' ) ) {
Expand Down

0 comments on commit 2b70b32

Please sign in to comment.