Skip to content

Commit

Permalink
[IN-1850] Added sailthru-wrap outer scope for JQuery selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
rzsouza-st committed Mar 12, 2021
1 parent 629815f commit 3538df1
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 57 deletions.
80 changes: 40 additions & 40 deletions classes/class-sailthru-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Sailthru_Content_Settings {

public function __construct() {

// make sure the priority is above the default of 10, the meta boxes are saved first.
// make sure the priority is above the default of 10, the meta boxes are saved first.
add_action( 'admin_menu', array( $this, 'add_admin_menu' ), 11 );
add_action( 'admin_init', array( $this, 'init_settings' ), 11 );
add_action( 'save_post', array( $this, 'sailthru_save_post' ), 11, 3 );
Expand Down Expand Up @@ -51,7 +51,7 @@ public function init_settings() {

// 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' ),
Expand Down Expand Up @@ -116,7 +116,7 @@ public function page_layout() {
}

// Admin Page Layout
echo '<div class="wrap">' . "\n";
echo '<div class="wrap sailthru-wrap">' . "\n";
echo ' <h1>Sailthru for WordPress</h1>' . "\n";
echo ' <form action="options.php" method="post">' . "\n";

Expand Down Expand Up @@ -182,11 +182,11 @@ function render_sailthru_content_post_types_field() {
$value = isset( $options['sailthru_content_post_types'] ) ? $options['sailthru_content_post_types'] : '';

if ( false != $options ) {

$post_type_args = ['public' => true];
$post_types = get_post_types( $post_type_args, 'names');
// Always remove the attachment post type, we never need this.

// Always remove the attachment post type, we never need this.
unset ($post_types['attachment']);

echo '<p class="description">' . esc_attr__( 'Choose which type of post types should be synced to Sailthru', 'text_domain' ) . '</p>';
Expand All @@ -197,7 +197,7 @@ function render_sailthru_content_post_types_field() {
echo '<input type="checkbox" name="sailthru_content_settings[sailthru_content_post_types][]" class="sailthru_content_post_types_field" value="' . esc_attr( $type ) . '" ' . esc_attr( $selected ) . '> ' . esc_attr__( ucwords ( $type ) , 'text_domain' ) . '<br>';
}

}
}

}

Expand Down Expand Up @@ -252,10 +252,10 @@ function render_sailthru_taxonomy_tag_options_field() {
$value = isset( $options['sailthru_taxonomy_tag_options'] ) ? $options['sailthru_taxonomy_tag_options'] : array();

foreach ($taxonomies as $tag) {

echo '<input type="checkbox" name="sailthru_content_settings[sailthru_taxonomy_tag_options][]" class="sailthru_taxonomy_tag_options_field" value="' . esc_attr( $tag ) . '" ' . ( in_array( $tag, $value, true ) ? 'checked="checked"' : '' ) . '" /> ' . esc_attr__( $tag, 'text_domain' ) . '<br>';
}

}


Expand Down Expand Up @@ -317,17 +317,17 @@ function generate_payload( $post, $post_id ) {
$data['images']['thumb']['url'] = $post_thumbnail;
}

// Add any galleries from the post to the images.
// Add any galleries from the post to the images.
$data['images']['galleries'] = get_post_galleries_images( $post );

$data['tags'] = $this->generate_tags( $post->ID);

// Apply any filters to the tags.
$data['tags'] = apply_filters( 'sailthru_horizon_meta_tags', ['sailthru.tags' => $data['tags'] ] ) ;
// Apply any filters to the tags.
$data['tags'] = apply_filters( 'sailthru_horizon_meta_tags', ['sailthru.tags' => $data['tags'] ] ) ;

// Check if the filter has returned sailthru.tags and convert to string.
// Check if the filter has returned sailthru.tags and convert to string.
if ( is_array( $data['tags'] ) && isset ( $data['tags']['sailthru.tags'] ) ) {
$data['tags'] = $data['tags']['sailthru.tags'];
$data['tags'] = $data['tags']['sailthru.tags'];
}

$post_expiration = get_post_meta( $post->ID, 'sailthru_post_expiration', true );
Expand All @@ -341,7 +341,7 @@ function generate_payload( $post, $post_id ) {
// Add the vars
$data['vars'] = $this->generate_vars( $post->ID, $post );


return $data;
}

Expand Down Expand Up @@ -387,7 +387,7 @@ function generate_meta_tags() {
$post_title = get_the_title();
$horizon_tags['sailthru.title'] = esc_attr( $post_title );

// Get the tags.
// Get the tags.
$content = new Sailthru_Content_Settings;
$post_tags = $content->generate_tags( $post->ID);

Expand Down Expand Up @@ -450,41 +450,41 @@ function generate_meta_tags() {
}

/**
* Generates the output of the interest tags for both the Content API and the meta tags.
* Generates the output of the interest tags for both the Content API and the meta tags.
*
* @param integer $post_id
*/

function generate_tags( $post_id ) {

$options = get_option( 'sailthru_content_settings' );
$post_tags = get_post_meta( $post_id, 'sailthru_meta_tags', true );

// Add WordPress tags if option set.
// Add WordPress tags if option set.
if ( isset( $options['sailthru_interest_tag_options'] ) && in_array( 'wordpress_tags',$options['sailthru_interest_tag_options'] ) ) {

$wp_tags = get_the_tags();
if ( $wp_tags ) {
$post_tags .= ',' .esc_attr( implode( ',', wp_list_pluck( $wp_tags, 'name' ) ) );
}
}

// Add WordPress categories if option set.
// Add WordPress categories if option set.
if ( isset( $options['sailthru_interest_tag_options'] ) && in_array( 'wordpress_categories', $options['sailthru_interest_tag_options'] ) ) {
$post_categories = get_the_category( $post->ID );
foreach ( $post_categories as $post_category ) {
$post_tags .= ','. $post_category->name;
}
}

// Add WordPress taxonomies if option set.
// Add WordPress taxonomies if option set.
if ( !empty( $options['sailthru_taxonomy_tag_options'] ) ) {
$terms = wp_get_post_terms( $post_id, $options['sailthru_taxonomy_tag_options'] );
$post_tags .= ',' .esc_attr( implode( ',', wp_list_pluck( $terms, 'name' ) ) );
}


// check if there's any global tags needing added.
// check if there's any global tags needing added.
if ( ! empty($options['sailthru_content_interest_tags'] ) ) {
$post_tags .= ',' . $options['sailthru_content_interest_tags'];
}
Expand All @@ -493,13 +493,13 @@ function generate_tags( $post_id ) {
}

/**
* Generates the output of the interest tags for both the Content API and the meta tags.
* Generates the output of the interest tags for both the Content API and the meta tags.
*
* @param integer $post_id
*/

function generate_vars( $post_id, $post ) {

$vars = [
'post_type' => $post->post_type,
'id' => $post->ID,
Expand All @@ -511,16 +511,16 @@ function generate_vars( $post_id, $post ) {
$field_names = array_keys( array_merge( $custom_fields, $vars ) );

// always exclude these vars
$exclude_fields = array( '_edit_lock',
'_edit_last',
'_encloseme',
'_pingme',
'sailthru_meta_tags',
'sailthru_post_expiration',
'sailthru_sailthru_tags_extra_data'
$exclude_fields = array( '_edit_lock',
'_edit_last',
'_encloseme',
'_pingme',
'sailthru_meta_tags',
'sailthru_post_expiration',
'sailthru_sailthru_tags_extra_data'
);

// Set vars from the custom fields.
// Set vars from the custom fields.
foreach ( $custom_fields as $key => $val ) {

if ( ! in_array( $key, $exclude_fields, true ) ) {
Expand All @@ -535,7 +535,7 @@ function generate_vars( $post_id, $post ) {
}

/**
* Generates vars from the whitelisted vars and filters
* Generates vars from the whitelisted vars and filters
*
* @param array $vars
*/
Expand All @@ -544,13 +544,13 @@ function whitelist_vars( $vars ) {
$options = get_option( 'sailthru_content_settings' );

if (! empty($options['sailthru_content_vars'] ) ) {
// Get the Whitelisted vars from the settings screen.

// Get the Whitelisted vars from the settings screen.
$whitelist = explode(', ', $options['sailthru_content_vars']);
$whitelist = apply_filters( 'sailthru_content_whitelist_vars', $whitelist);

foreach ($vars as $key => $val) {

if ( !in_array($key, $whitelist) ) {
unset( $vars[$key] );
}
Expand All @@ -573,15 +573,15 @@ function whitelist_vars( $vars ) {

function sailthru_save_post( $post_id, $post, $update ) {

// Get the content options to see if we want to fire the API.
// Get the content options to see if we want to fire the API.
$options = get_option( 'sailthru_content_settings' );

// Check to see if Content API is disabled in the UI
if( !isset ($options['sailthru_content_api_status'] ) || "false" === $options['sailthru_content_api_status'] ) {
return;
}

// See if a filter has disabled the content API, this may be done to override a specific use case.
// See if a filter has disabled the content API, this may be done to override a specific use case.
if ( false === apply_filters( 'sailthru_content_api_enable', true ) ) {
return;
}
Expand All @@ -597,7 +597,7 @@ function sailthru_save_post( $post_id, $post, $update ) {
$api_secret = $sailthru['sailthru_api_secret'];
$client = new WP_Sailthru_Client( $api_key, $api_secret );
try {

if ( $client ) {
$data = $this->generate_payload($post, $post_id);
// Make the API call to Sailthru
Expand Down
25 changes: 12 additions & 13 deletions js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@
// datepicker for meta box
// but since Datepicker causes a jQuery conflict, wrap it
// and prevent from initializing unless necessary
if ($('.datepicker').length) {
$('.datepicker').datepicker({
if ($('.datepicker', 'sailthru-wrap').length) {
$('.datepicker', 'sailthru-wrap').datepicker({
dateFormat: 'yy-mm-dd'
});
}


// custom form fields

$('.selection').parent().parent().hide();
$('.selection', '.sailthru-wrap').parent().parent().hide();
$('#type').closest('table').find("tr").last().hide();
// hide hidden field
$("#sailthru_customfield_hidden_value").closest('tr').hide();
Expand All @@ -70,14 +70,14 @@

if ($(this).attr('value') == 'select' || $(this).attr('value') == 'radio' || $(this).attr('value') == 'checkbox') {
$(this).closest('table').find("tr").last().show();
$('#add_value').show();
$('#add_value', 'sailthru-wrap').show();
$("input[name*=sailthru_customfield_value1]").show();
$('.selection').parent().parent().show();
$('#add_value').show();
$('.selection', 'sailthru-wrap').parent().parent().show();
$('#add_value', 'sailthru-wrap').show();
$("input[name*=sailthru_customfield_value1]").show();

if ($(this).attr('value') == 'hidden') {
$('#add_value').hide();
$('#add_value', 'sailthru-wrap').hide();
$("input[name*=sailthru_customfield_value1]").hide();
$("input[name*=sailthru_customfield_value1]").parent().parent().find('th').html('Field Value');
}
Expand All @@ -87,11 +87,10 @@
}
}));

$('#add_value').on("click", (function(e) {
$('#add_value', 'sailthru-wrap').on("click", (function(e) {
e.preventDefault();
var new_val = parseInt($('#value_amount').attr('value'), 10);
new_val = new_val + 1;
var second_val = new_val + 1;
$('#sailthru_value_fields_block').append('<div><input class="selection" name="sailthru_forms_options[sailthru_customfield_value][' + new_val + '][value]" type="text" placeholder="display value"/><input class="selection" name="sailthru_forms_options[sailthru_customfield_value][' + new_val + '][label]" type="text" placeholder="value"/></div>');
$('#value_amount').attr('value', parseInt(new_val, 10));
}));
Expand All @@ -118,12 +117,12 @@
$("#sailthru_setup_email_template").parents('tr').addClass('grayBorder');

// datepickerfor meta box
$('.datepicker').datepicker({
$('.datepicker', 'sailthru-wrap').datepicker({
dateFormat: 'yy-mm-dd'
});

$("#sortable").disableSelection();
var sort = $("#sortable").sortable({
$("#sortable", 'sailthru-wrap').disableSelection();
var sort = $("#sortable", 'sailthru-wrap').sortable({
axis: 'y',
stop: function(event, ui) {
var data = sort.sortable("serialize");
Expand All @@ -143,4 +142,4 @@

});

}(jQuery));
}(jQuery));
6 changes: 3 additions & 3 deletions views/admin.functions.subscribe.options.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function sailthru_forms_callback( $args ) {
** Custom and Extra Sections should be in a first column.
** Begin the column here. It ends in delete_field()
*/
echo '<div class="wrap">';
echo '<div class="wrap sailthru-wrap">';

$customfields = get_option( 'sailthru_forms_options' );
$key = get_option( 'sailthru_forms_key' );
Expand Down Expand Up @@ -202,7 +202,7 @@ function sailthru_success_field( $args ) {
echo '<p><textarea name="' . esc_attr( $collection ) . '[sailthru_customfield_success]" placeholder="" rows="5" cols="80">' . esc_textarea( $message ) . '</textarea></p>';
echo '<p>Use the field above to update the message that the user sees after subscribing</p>';

/* ends the wrapper */
/* ends the wrapper */
echo '</div>';
echo '</div>';

Expand Down Expand Up @@ -607,7 +607,7 @@ function sailthru_forms_handler( $input ) {
$values = rtrim( $values, ',' );
$output[ $new_key ]['sailthru_customfield_value'] = $values;
}

if ( 'hidden' === $input['sailthru_customfield_type'] ) {
$output[ $new_key ]['sailthru_customfield_value'] = sanitize_text_field( $input['sailthru_customfield_hidden_value'] );
}
Expand Down
2 changes: 1 addition & 1 deletion views/admin.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- Create a header in the default WordPress 'wrap' container -->
<div class="wrap" id="sailthru-admin">
<div class="wrap sailthru-wrap" id="sailthru-admin">
<div id="icon-sailthru" class="icon32"></div>
<h2><?php esc_html_e( 'Sailthru for WordPress', 'sailthru-for-wordpress' ); ?></h2>
<?php
Expand Down

0 comments on commit 3538df1

Please sign in to comment.