| 1 |
<?php |
| 2 |
|
| 3 |
class EasyOptInsPostTypes { |
| 4 |
|
| 5 |
public $settings; |
| 6 |
|
| 7 |
private $activity_day_interval = array( |
| 8 |
'form_list' => null, |
| 9 |
'dashboard_widget' => 30 |
| 10 |
); |
| 11 |
|
| 12 |
private $two_step_ids_on_page = array(); |
| 13 |
|
| 14 |
public function __construct( $settings ) { |
| 15 |
|
| 16 |
$this->settings = $settings; |
| 17 |
|
| 18 |
$providers_available = array_keys( $this->settings[ 'providers' ] ); |
| 19 |
|
| 20 |
// Register custom post type |
| 21 |
add_action( 'init', array( $this, 'register_custom_post_type' ) ); |
| 22 |
add_filter( 'manage_easy-opt-ins_posts_columns', array( $this, 'add_new_columns' ) ); |
| 23 |
add_action( 'manage_easy-opt-ins_posts_custom_column', array( $this, 'set_column_data' ), 10, 2 ); |
| 24 |
add_filter( 'post_row_actions', array( $this, 'post_row_actions' ), 10, 2 ); |
| 25 |
|
| 26 |
// Reset action |
| 27 |
add_action( 'admin_post_fca_eoi_reset_stats', array( $this, 'reset_stats' ) ); |
| 28 |
|
| 29 |
// Dashboard widget |
| 30 |
add_action( 'wp_dashboard_setup', array( $this, 'dashboard_setup' ) ); |
| 31 |
|
| 32 |
// Save |
| 33 |
add_action( 'save_post', array( $this, 'save_meta_box_content' ), 1, 2 ); |
| 34 |
|
| 35 |
// Live preview |
| 36 |
add_filter( 'the_content', array( $this, 'live_preview' ) ); |
| 37 |
|
| 38 |
// Scripts and styles |
| 39 |
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue' ) ); |
| 40 |
|
| 41 |
add_action( 'admin_head', array( $this, 'hide_minor_publishing' ) ); |
| 42 |
|
| 43 |
add_action( 'admin_notices', array( $this, 'onboard_help' ), 1 ); |
| 44 |
|
| 45 |
if ( $this->settings['distribution'] === 'free' ) { |
| 46 |
add_action( 'admin_notices', array( $this, 'review_notice' ) ); |
| 47 |
} |
| 48 |
|
| 49 |
//V 2.0 BLOG POST NOTICE |
| 50 |
add_action( 'admin_notices', array( $this, 'google_changes_notice' ) ); |
| 51 |
|
| 52 |
add_filter( 'admin_body_class', array( $this, 'add_body_class' ) ); |
| 53 |
|
| 54 |
add_filter( 'wp_insert_post_data', array( $this, 'force_published' ) ); |
| 55 |
|
| 56 |
add_action( 'wp_ajax_fca_eoi_subscribe', array( $this, 'ajax_subscribe' ) ); |
| 57 |
add_action( 'wp_ajax_nopriv_fca_eoi_subscribe', array( $this, 'ajax_subscribe' ) ); |
| 58 |
|
| 59 |
add_action( 'wp_ajax_fca_eoi_dismiss', array( $this, 'ajax_dismiss_notice' ) ); |
| 60 |
|
| 61 |
add_filter( 'get_user_option_screen_layout_easy-opt-ins', array( $this, 'force_one_column' ) ); |
| 62 |
|
| 63 |
add_filter( 'get_user_option_meta-box-order_easy-opt-ins', array( $this, 'order_columns' ) ); |
| 64 |
|
| 65 |
add_filter( 'post_updated_messages', array( $this, 'override_text' ) ); |
| 66 |
|
| 67 |
add_filter( 'bulk_actions-edit-easy-opt-ins', array( $this, 'disable_bulk_edit' ) ); |
| 68 |
|
| 69 |
add_filter( 'post_row_actions', array( $this, 'remove_quick_edit' ) ); |
| 70 |
|
| 71 |
add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
| 72 |
|
| 73 |
add_filter( 'enter_title_here', array( $this, 'change_default_title' ) ); |
| 74 |
|
| 75 |
add_filter( 'init', array( $this, 'bind_content_filter' ), 10 ); |
| 76 |
|
| 77 |
add_filter( 'plugin_action_links_' . FCA_EOI_PLUGIN_BASENAME, array( $this, 'add_plugin_action_links' ) ); |
| 78 |
|
| 79 |
//ADD ACTIONS TO GET THE ENTIRE PAGE OUTPUT IN BUFFER |
| 80 |
|
| 81 |
if ( wp_get_theme() == 'Customizr' ) { |
| 82 |
add_filter( 'the_content', array( $this, 'scan_for_shortcodes' ) ); |
| 83 |
} else { |
| 84 |
add_action('wp_head', array( $this, 'fca_eoi_buffer_start' )); |
| 85 |
add_action('wp_footer', array( $this, 'fca_eoi_buffer_end' )); |
| 86 |
} |
| 87 |
|
| 88 |
add_filter( 'wp_footer', array( $this, 'maybe_show_lightbox' ) ); |
| 89 |
|
| 90 |
foreach ( $providers_available as $provider ) { |
| 91 |
add_action( 'wp_ajax_fca_eoi_' . $provider . '_get_lists', $provider . '_ajax_get_lists' ); |
| 92 |
} |
| 93 |
|
| 94 |
// Hook provder callback functions |
| 95 |
foreach ( $providers_available as $provider ) { |
| 96 |
add_filter( 'fca_eoi_alter_admin_notices', $provider . '_admin_notices', 10, 1 ); |
| 97 |
} |
| 98 |
|
| 99 |
// Handle licensing |
| 100 |
if( count( $providers_available ) > 1 ) { |
| 101 |
require_once FCA_EOI_PLUGIN_DIR . 'includes/licensing.php'; |
| 102 |
new EasyOptInsLicense( $this->settings ); |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
public function add_plugin_action_links( $links ) { |
| 107 |
$url = admin_url('post-new.php?post_type=easy-opt-ins'); |
| 108 |
|
| 109 |
$new_links = array( |
| 110 |
'addnew' => "<a href='$url' >" . __('Add New Optin Form', 'easy-opt-ins' ) . '</a>' |
| 111 |
); |
| 112 |
|
| 113 |
$links = array_merge( $new_links, $links ); |
| 114 |
|
| 115 |
return $links; |
| 116 |
|
| 117 |
} |
| 118 |
|
| 119 |
function fca_eoi_buffer_start() { ob_start(array( $this, 'scan_for_shortcodes' )); } |
| 120 |
function fca_eoi_buffer_end() { ob_end_flush(); } |
| 121 |
|
| 122 |
public function register_custom_post_type() { |
| 123 |
|
| 124 |
$labels = array( |
| 125 |
'name' => __('Optin Forms') , |
| 126 |
'singular_name' => __('Optin Form') , |
| 127 |
'add_new' => __('Add New') , |
| 128 |
'add_new_item' => __('Add New Optin Form') , |
| 129 |
'edit_item' => __('Edit Optin Form') , |
| 130 |
'new_item' => __('New Optin Form') , |
| 131 |
'all_items' => __('All Optin Forms') , |
| 132 |
'view_item' => __('View Optin Form') , |
| 133 |
'search_items' => __('Search Optin Form') , |
| 134 |
'not_found' => __('No Optin Form Found') , |
| 135 |
'not_found_in_trash' => __('No Optin Form Found in Trash') , |
| 136 |
'parent_item_colon' => '', |
| 137 |
'menu_name' => __('Optin Forms') |
| 138 |
); |
| 139 |
$args = array( |
| 140 |
'menu_icon' => FCA_EOI_PLUGIN_URL . '/icon.png', |
| 141 |
'labels' => $labels, |
| 142 |
'public' => false, |
| 143 |
'exclude_from_search' => true, |
| 144 |
'publicly_queryable' => false, |
| 145 |
'show_ui' => true, |
| 146 |
'show_in_menu' => true, |
| 147 |
'query_var' => true, |
| 148 |
'rewrite' => array( |
| 149 |
'slug' => 'easy-opt-ins', |
| 150 |
) , |
| 151 |
'capability_type' => 'page', |
| 152 |
'has_archive' => false, |
| 153 |
'hierarchical' => false, |
| 154 |
'menu_position' => 105, |
| 155 |
'supports' => array( |
| 156 |
'title', |
| 157 |
) , |
| 158 |
'register_meta_box_cb' => array( |
| 159 |
$this, |
| 160 |
'add_meta_boxes' |
| 161 |
) |
| 162 |
); |
| 163 |
register_post_type('easy-opt-ins', $args); |
| 164 |
} |
| 165 |
|
| 166 |
private function enqueue_activity_style() { |
| 167 |
wp_enqueue_style( 'admin-cpt-easy-opt-ins-activity', FCA_EOI_PLUGIN_URL . '/assets/admin/cpt-easy-opt-ins-activity.min.css', array(), FCA_EOI_VER ); |
| 168 |
} |
| 169 |
|
| 170 |
public function add_new_columns( $columns ) { |
| 171 |
$new_columns = array(); |
| 172 |
|
| 173 |
if ( ! empty( $columns['cb'] ) ) { |
| 174 |
$new_columns['cb'] = $columns['cb']; |
| 175 |
} |
| 176 |
|
| 177 |
if ( ! empty( $columns['title'] ) ) { |
| 178 |
$new_columns['title'] = $columns['title']; |
| 179 |
} |
| 180 |
|
| 181 |
$this->enqueue_activity_style(); |
| 182 |
$activity = EasyOptInsActivity::get_instance(); |
| 183 |
|
| 184 |
$period = |
| 185 |
'<span class="fca_eoi_activity_period">(' . |
| 186 |
$activity->get_text( 'period', null, array( $this->activity_day_interval['form_list'] ) ) . |
| 187 |
')</span>'; |
| 188 |
|
| 189 |
foreach ( array( 'impressions', 'conversions', 'conversion_rate' ) as $activity_type ) { |
| 190 |
$new_columns[ $activity_type ] = esc_html( $activity->get_text( $activity_type, 'form' ) ) . '<br>' . $period; |
| 191 |
} |
| 192 |
|
| 193 |
return $new_columns; |
| 194 |
} |
| 195 |
|
| 196 |
public function set_column_data( $column_name, $form_id ) { |
| 197 |
$activity = EasyOptInsActivity::get_instance(); |
| 198 |
|
| 199 |
$stats = $activity->get_form_stats( $this->activity_day_interval['form_list'] ); |
| 200 |
$value = 0; |
| 201 |
|
| 202 |
if ( ! empty( $stats[ $column_name ][ $form_id ] ) ) { |
| 203 |
$value = $stats[ $column_name ][ $form_id ]; |
| 204 |
} |
| 205 |
|
| 206 |
echo $activity->format_column_text( $column_name, $value ); |
| 207 |
} |
| 208 |
|
| 209 |
public function post_row_actions( $actions, $post ) { |
| 210 |
if ( $post->post_type == 'easy-opt-ins' ) { |
| 211 |
$action = 'fca_eoi_reset_stats'; |
| 212 |
$title = __( 'Reset stats for this item' ); |
| 213 |
$label = __( 'Reset Stats' ); |
| 214 |
|
| 215 |
$url = add_query_arg( 'action', $action, admin_url( 'admin-post.php?post=' . $post->ID ) ); |
| 216 |
$url = wp_nonce_url( $url ); |
| 217 |
|
| 218 |
$actions[$action] = $this->confirm_tag( |
| 219 |
'<a href="' . $url . '" title="' . $title . '">' . $label . '</a>', |
| 220 |
__( 'Are you sure?' ), |
| 221 |
__( 'Do you really want to reset this Optin Form\'s stats? This action cannot be undone.' ) |
| 222 |
); |
| 223 |
} |
| 224 |
return $actions; |
| 225 |
} |
| 226 |
|
| 227 |
public function reset_stats() { |
| 228 |
if ( wp_verify_nonce( $_REQUEST['_wpnonce'] ) ) { |
| 229 |
EasyOptInsActivity::get_instance()->reset_stats( (int) $_REQUEST['post'] ); |
| 230 |
wp_redirect( wp_get_referer() ); |
| 231 |
} |
| 232 |
} |
| 233 |
|
| 234 |
private function confirm_tag( $tag, $title, $message ) { |
| 235 |
return preg_replace( |
| 236 |
'/>/', |
| 237 |
' onclick="return confirm(' . |
| 238 |
esc_html( '"' . $title . '\n\n' . $message . '"' ) . |
| 239 |
')">', |
| 240 |
$tag, 1 ); |
| 241 |
} |
| 242 |
|
| 243 |
public function dashboard_setup() { |
| 244 |
|
| 245 |
if ( defined ( 'FCA_EOI_DISABLE_STATS_TRACKING' )) { |
| 246 |
$title = 'Optin Cat Summary (TRACKING DISABLED)'; |
| 247 |
} else { |
| 248 |
$title = 'Optin Cat Summary'; |
| 249 |
} |
| 250 |
add_meta_box( |
| 251 |
'fca_eoi_dashboard_widget', |
| 252 |
$title, |
| 253 |
array( $this, 'add_dashboard_widget' ), |
| 254 |
'dashboard', |
| 255 |
'normal', |
| 256 |
'high' |
| 257 |
); |
| 258 |
} |
| 259 |
|
| 260 |
public function add_dashboard_widget() { |
| 261 |
wp_enqueue_script( 'd3_js', FCA_EOI_PLUGIN_URL . '/assets/vendor/nvd3/d3.min.js', array(), FCA_EOI_VER, true ); |
| 262 |
wp_enqueue_script( 'nvd3_js', FCA_EOI_PLUGIN_URL . '/assets/vendor/nvd3/nv.d3.min.js', array(), FCA_EOI_VER, true ); |
| 263 |
wp_enqueue_style( 'nvd3_css', FCA_EOI_PLUGIN_URL . '/assets/vendor/nvd3/nv.d3.min.css', array(), FCA_EOI_VER ); |
| 264 |
$this->enqueue_activity_style(); |
| 265 |
|
| 266 |
$day_interval = $this->activity_day_interval['dashboard_widget']; |
| 267 |
$activity = EasyOptInsActivity::get_instance(); |
| 268 |
$stats = $activity->get_daily_stats( $day_interval ); |
| 269 |
|
| 270 |
$date_labels = array(); |
| 271 |
foreach ( array_keys( $stats['impressions'] ) as $date ) { |
| 272 |
$date_labels[] = strftime( '%e %b', strtotime( $date ) ); |
| 273 |
} |
| 274 |
|
| 275 |
$colors = array( |
| 276 |
'impressions' => '#5b90bf', |
| 277 |
'conversions' => '#bf616a' |
| 278 |
); |
| 279 |
|
| 280 |
?> |
| 281 |
<div class="fca_eoi_activity_chart_title_container"> |
| 282 |
<div class="fca_eoi_activity_chart_legend"> |
| 283 |
<?php foreach ( array( 'impressions', 'conversions' ) as $activity_type ): ?> |
| 284 |
<div class="fca_eoi_activity_chart_legend_item"> |
| 285 |
<div class="fca_eoi_activity_chart_legend_sample" style="background-color: <?php echo $colors[ $activity_type ] ?>;"></div> |
| 286 |
<div class="fca_eoi_activity_chart_legend_text"> |
| 287 |
<?php echo esc_html( $activity->get_text( $activity_type, 'total' ) ) ?> |
| 288 |
</div> |
| 289 |
</div> |
| 290 |
<?php endforeach ?> |
| 291 |
</div> |
| 292 |
<div class="fca_eoi_activity_chart_period"> |
| 293 |
<?php echo esc_html( $activity->get_text( 'period', null, array( $day_interval ) ) ) ?> |
| 294 |
- |
| 295 |
<a href="<?php echo admin_url( 'edit.php?post_type=easy-opt-ins' ) ?>"><?php echo __( 'View All Data' ) ?></a> |
| 296 |
</div> |
| 297 |
</div> |
| 298 |
<div class="fca_eoi_activity_chart" id="fca_eoi_activity_chart"></div> |
| 299 |
<div class="fca_eoi_activity_chart_stat"> |
| 300 |
<?php foreach ( array( 'impressions', 'conversions', 'conversion_rate' ) as $activity_type ): ?> |
| 301 |
<div class="fca_eoi_activity_chart_stat_item"> |
| 302 |
<div class="fca_eoi_activity_chart_stat_value"> |
| 303 |
<?php echo $activity->format_column_text( $activity_type, $stats['totals'][ $activity_type ] ) ?> |
| 304 |
</div> |
| 305 |
<div class="fca_eoi_activity_chart_stat_title"> |
| 306 |
<?php echo esc_html( $activity->get_text( $activity_type, 'total' ) ) ?> |
| 307 |
</div> |
| 308 |
</div> |
| 309 |
<?php endforeach ?> |
| 310 |
</div> |
| 311 |
<script> |
| 312 |
jQuery( function() { |
| 313 |
var impressions = <?php echo json_encode( array_values( $stats['impressions'] ) ) ?>; |
| 314 |
var conversions = <?php echo json_encode( array_values( $stats['conversions'] ) ) ?>; |
| 315 |
var dates = <?php echo json_encode( $date_labels ) ?>; |
| 316 |
|
| 317 |
var chart = nv.models.lineChart().options({ |
| 318 |
duration: 0, |
| 319 |
transitionDuration: 0, |
| 320 |
useInteractiveGuideline: true, |
| 321 |
isArea: true, |
| 322 |
showLegend: false, |
| 323 |
margin: { top: 10, right: 20, bottom: 30, left: 40 } |
| 324 |
} ); |
| 325 |
|
| 326 |
chart.xAxis.tickFormat( function( index ) { return dates[ index ]; } ); |
| 327 |
chart.yAxis.tickFormat( d3.format( 'd' ) ); |
| 328 |
chart.forceY( [ 0, d3.max(impressions) || 1 ] ); |
| 329 |
|
| 330 |
var valuesToPoint = function( value, index ) { |
| 331 |
return { x: index, y: value }; |
| 332 |
}; |
| 333 |
|
| 334 |
d3.select( '#fca_eoi_activity_chart' ).append( 'svg' ).datum( [ |
| 335 |
{ color: '<?php echo $colors['impressions'] ?>', key: 'Impressions', values: impressions.map(valuesToPoint) }, |
| 336 |
{ color: '<?php echo $colors['conversions'] ?>', key: 'Conversions', values: conversions.map(valuesToPoint) } |
| 337 |
] ).call( chart ); |
| 338 |
|
| 339 |
nv.utils.windowResize( chart.update ); |
| 340 |
} ); |
| 341 |
</script> |
| 342 |
<?php |
| 343 |
} |
| 344 |
|
| 345 |
public function add_meta_boxes() { |
| 346 |
|
| 347 |
add_meta_box( |
| 348 |
'fca_eoi_meta_box_setup', |
| 349 |
__( 'Setup' ), |
| 350 |
array( &$this, 'meta_box_content_setup' ), |
| 351 |
'easy-opt-ins', |
| 352 |
'side', |
| 353 |
'high' |
| 354 |
); |
| 355 |
add_meta_box( |
| 356 |
'fca_eoi_meta_box_build', |
| 357 |
__( 'Form Builder' ), |
| 358 |
array( &$this, 'meta_box_content_build' ), |
| 359 |
'easy-opt-ins', |
| 360 |
'side', |
| 361 |
'high' |
| 362 |
); |
| 363 |
|
| 364 |
add_meta_box( |
| 365 |
'fca_eoi_meta_box_provider', |
| 366 |
__( 'Email Marketing Provider Integration' ), |
| 367 |
array( &$this, 'meta_box_content_provider' ), |
| 368 |
'easy-opt-ins', |
| 369 |
'side', |
| 370 |
'high' |
| 371 |
); |
| 372 |
add_meta_box( |
| 373 |
'fca_eoi_meta_box_publish', |
| 374 |
__( 'Publication' ), |
| 375 |
array( &$this, 'meta_box_content_publish' ), |
| 376 |
'easy-opt-ins', |
| 377 |
'side', |
| 378 |
'high' |
| 379 |
); |
| 380 |
add_meta_box( |
| 381 |
'fca_eoi_meta_box_thanks', |
| 382 |
__( 'Messages' ), |
| 383 |
array( &$this, 'meta_box_content_messages' ), |
| 384 |
'easy-opt-ins', |
| 385 |
'side', |
| 386 |
'high' |
| 387 |
); |
| 388 |
if ( has_action( 'fca_eoi_powerups' ) ) { |
| 389 |
add_meta_box( |
| 390 |
'fca_eoi_meta_box_powerups', |
| 391 |
__( 'Power Ups' ), |
| 392 |
array( &$this, 'meta_box_content_powerups' ), |
| 393 |
'easy-opt-ins', |
| 394 |
'side', |
| 395 |
'high' |
| 396 |
); |
| 397 |
} |
| 398 |
} |
| 399 |
|
| 400 |
public function meta_box_content_setup() { |
| 401 |
|
| 402 |
$layouts_types_labels = array( |
| 403 |
'lightbox' => 'Popups', |
| 404 |
'postbox' => 'Post Boxes', |
| 405 |
'widget' => 'Sidebar Widgets', |
| 406 |
'banner' => 'Optin Bars', |
| 407 |
'overlay' => 'Slide Ins', |
| 408 |
); |
| 409 |
|
| 410 |
$layout_names = array( |
| 411 |
'banner_10' => __( 'Optin Bar 1', 'easy-opt-ins'), |
| 412 |
'banner_11' => __( 'Optin Bar 2', 'easy-opt-ins'), |
| 413 |
'banner_12' => __( 'Optin Bar 3', 'easy-opt-ins'), |
| 414 |
'overlay_13' => __( 'Slide In Light', 'easy-opt-ins'), |
| 415 |
'overlay_14' => __( 'Slide In Dark', 'easy-opt-ins'), |
| 416 |
); |
| 417 |
|
| 418 |
// Build the layouts array |
| 419 |
$layouts = $layouts_types = $layouts_types_found = array(); |
| 420 |
foreach ( glob( FCA_EOI_PLUGIN_DIR . 'layouts/*', GLOB_ONLYDIR ) as $v) { |
| 421 |
$layouts_types_found[] = basename( $v ); |
| 422 |
} |
| 423 |
|
| 424 |
$layouts_types_accepted = array_keys( $layouts_types_labels ); |
| 425 |
foreach ( $layouts_types_accepted as $layout_type ) { |
| 426 |
if ( in_array( $layout_type, $layouts_types_found ) ) { |
| 427 |
$layouts_types[] = $layout_type; |
| 428 |
} |
| 429 |
} |
| 430 |
|
| 431 |
// Layouts types mini-tabs |
| 432 |
echo '<ul class="category-tabs" id="layouts_types_tabs">'; |
| 433 |
foreach ( $layouts_types as $layout_type ) { |
| 434 |
K::wrap( |
| 435 |
$layouts_types_labels[ $layout_type ] |
| 436 |
, array( |
| 437 |
'href' => '#'. 'layouts_type_' . $layout_type, |
| 438 |
) |
| 439 |
, array( |
| 440 |
'html_before' => '<li' . ( 'widget' === $layout_type ? ' class="tabs"' : '' ) . ' >', |
| 441 |
'html_after' => '</li> ', |
| 442 |
'in' => 'a', |
| 443 |
) |
| 444 |
); |
| 445 |
} |
| 446 |
echo '<button type="button" class="button button-primary" id="fca_eoi_layout_revert_button" style="display: none">' . __('Back', 'easy-opt-in') . '</button>'; |
| 447 |
|
| 448 |
echo '</ul>'; |
| 449 |
|
| 450 |
//GENERATE SCREENSHOTS / OPTIN THEME PICKER |
| 451 |
//RN NOTE: MAYBE CACHE THIS |
| 452 |
$output = ''; |
| 453 |
foreach ( $layouts_types as $layout_type ) { |
| 454 |
|
| 455 |
$output .= "<div class='fca_eoi_accordion_tab' id='layouts_type_$layout_type'>"; |
| 456 |
$layout_counter = 1; |
| 457 |
foreach ( glob( FCA_EOI_PLUGIN_DIR . "layouts/$layout_type/*", GLOB_ONLYDIR ) as $layout_path ) { |
| 458 |
$layout_id = basename( $layout_path ); |
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
$layout_helper = new EasyOptInsLayout( $layout_id ); |
| 463 |
$layout_type = ucfirst ( $layout_helper->layout_type ); |
| 464 |
|
| 465 |
$screenshot_path = $layout_helper->path_to_resource( 'screenshot', 'png' ); |
| 466 |
$screenshot_url = $layout_helper->url_to_resource( 'screenshot', 'png' ); |
| 467 |
$screenshot = file_exists( $screenshot_path ) ? $screenshot_url : FCA_EOI_PLUGIN_URL . '/layouts/no-image.jpg'; |
| 468 |
|
| 469 |
if ( array_key_exists ( $layout_id, $layout_names ) ) { |
| 470 |
$layout_name = $layout_names[$layout_id]; |
| 471 |
} else { |
| 472 |
$layout_name = ucfirst ( str_replace( 'layout', 'widget', str_replace('_', ' ', $layout_id) ) ); |
| 473 |
$layout_name = str_replace( array('Postbox 0', 'Widget 0'), 'No CSS', $layout_name ); |
| 474 |
} |
| 475 |
|
| 476 |
$output .= "<div class='fca_eoi_layout has-tip fca_eoi_layout_preview' data-layout-id='$layout_id' data-layout-type='$layout_type'>"; |
| 477 |
$output .= "<img src='$screenshot'>"; |
| 478 |
$output .= "<div class='fca_eoi_layout_info'>"; |
| 479 |
$output .= "<h3>$layout_name</h3>"; |
| 480 |
$output .= "</div>"; |
| 481 |
$output .= "</div>"; |
| 482 |
|
| 483 |
$layout_counter = $layout_counter + 1; |
| 484 |
} |
| 485 |
$output .= "</div>"; |
| 486 |
|
| 487 |
} |
| 488 |
$output .= '<br clear="all">'; |
| 489 |
echo $output; |
| 490 |
} |
| 491 |
|
| 492 |
public function meta_box_content_provider() { |
| 493 |
|
| 494 |
global $post; |
| 495 |
$fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true ); |
| 496 |
|
| 497 |
//DISABLE CUSTOM FORM |
| 498 |
$allow_customform = get_option ( 'fca_eoi_allow_customform', 'false' ); |
| 499 |
if ( $allow_customform == 'false' ) { |
| 500 |
$providers = $this->settings[ 'providers' ]; |
| 501 |
unset ( $providers['customform'] ); |
| 502 |
$providers_available = array_keys( $providers ); |
| 503 |
} else { |
| 504 |
$providers_available = array_keys( $this->settings[ 'providers' ] ); |
| 505 |
} |
| 506 |
|
| 507 |
$providers_options = array(); |
| 508 |
|
| 509 |
// Prepare providers options |
| 510 |
foreach ( $this->settings[ 'providers' ] as $provider_id => $provider ) { |
| 511 |
$providers_options[ $provider_id ] = $provider[ 'info' ][ 'name' ]; |
| 512 |
} |
| 513 |
|
| 514 |
if ( $allow_customform == 'false') { |
| 515 |
unset ( $providers_options['customform'] ); |
| 516 |
} |
| 517 |
|
| 518 |
// Provider choice if there are many providers |
| 519 |
if ( 1 < count( $providers_available) ) { |
| 520 |
|
| 521 |
$provider = get_option( 'fca_eoi_last_provider', '' ); |
| 522 |
$provider = empty($provider) ? 'mailchimp' : $provider; // use mailchimp by default |
| 523 |
|
| 524 |
K::select( 'fca_eoi[provider]' |
| 525 |
, array( |
| 526 |
'class' => 'select2', |
| 527 |
'style' => 'width: 27em;', |
| 528 |
) |
| 529 |
, array( |
| 530 |
'format' => '<p><label>:select</label></p>', |
| 531 |
'options' => array( '' => 'Not set' ) + $providers_options, |
| 532 |
'selected' => K::get_var( 'provider', $fca_eoi, $provider ), |
| 533 |
) |
| 534 |
); |
| 535 |
} |
| 536 |
|
| 537 |
foreach ( $providers_available as $provider ) { |
| 538 |
call_user_func( $provider . '_integration', $this->settings ); |
| 539 |
} |
| 540 |
} |
| 541 |
|
| 542 |
//SEND JS TEMPLATE DATA FOR RULE CREATION |
| 543 |
public function prepare_publish_rules_html( $rules = array() ) { |
| 544 |
|
| 545 |
switch ( $this->settings['distribution'] ) { |
| 546 |
case 'free': |
| 547 |
$conditions_options = array( |
| 548 |
'' => __( 'Choose a rule...' ), |
| 549 |
'time_on_page' => __( 'Time on page' ), |
| 550 |
); |
| 551 |
ob_start(); |
| 552 |
?> |
| 553 |
<tr> |
| 554 |
<th><select class="fca_eoi_condition_select"> |
| 555 |
<option selected="selected"> |
| 556 |
Choose a rule... |
| 557 |
</option> |
| 558 |
|
| 559 |
<option value="scrolled_percent"> |
| 560 |
Scrolled down |
| 561 |
</option> |
| 562 |
<optgroup label="Premium Only"> |
| 563 |
|
| 564 |
<option value="pageviews" disabled> |
| 565 |
Number of Pageviews |
| 566 |
</option> |
| 567 |
|
| 568 |
<option value="time_on_page" disabled> |
| 569 |
Time on page |
| 570 |
</option> |
| 571 |
|
| 572 |
<option value="include" disabled> |
| 573 |
Only display on these pages |
| 574 |
</option> |
| 575 |
|
| 576 |
<option value="exclude" disabled> |
| 577 |
Never display on these pages |
| 578 |
</option> |
| 579 |
|
| 580 |
<option value="exit_intervention" disabled> |
| 581 |
Exit Intervention |
| 582 |
</option> |
| 583 |
</optgroup> |
| 584 |
</select><span class='fca_eoi_at_least' style= |
| 585 |
'display:none'>at least</span></th> |
| 586 |
|
| 587 |
<td></td> |
| 588 |
|
| 589 |
<td class='fca_eoi_delete_condition' title='Click to remove'><span class='fca_eoi_close_icon dashicons dashicons-no'></span></td> |
| 590 |
</tr> |
| 591 |
|
| 592 |
<?php |
| 593 |
|
| 594 |
$rowNew = ob_get_clean(); |
| 595 |
break; |
| 596 |
|
| 597 |
case 'premium': |
| 598 |
|
| 599 |
$conditions_options = array( |
| 600 |
'' => __( 'Choose a rule...' ), |
| 601 |
'scrolled_percent' => __( 'Scrolled down' ), |
| 602 |
'pageviews' => __( 'Number of Pageviews' ), |
| 603 |
'time_on_page' => __( 'Time on page' ), |
| 604 |
'include' => __( 'Only display on these pages' ), |
| 605 |
'exclude' => __( 'Never display on these pages' ), |
| 606 |
'exit_intervention' => __( 'Exit Intervention' ), |
| 607 |
); |
| 608 |
|
| 609 |
$rowNew = "<tr><th>" . |
| 610 |
K::select( |
| 611 |
'', |
| 612 |
array( |
| 613 |
'class' => 'fca_eoi_condition_select', |
| 614 |
), |
| 615 |
array( |
| 616 |
'options' => $conditions_options, |
| 617 |
'return' => true, |
| 618 |
) |
| 619 |
) . "<span class='fca_eoi_at_least' style='display:none' >at least</span></th><td></td><td class='fca_eoi_delete_condition' title='Click to remove'><span class='fca_eoi_close_icon dashicons dashicons-no'></span></td></tr>"; |
| 620 |
|
| 621 |
break; |
| 622 |
} |
| 623 |
|
| 624 |
$ruleTableHtml = array ( |
| 625 |
'rowNew' => $rowNew, |
| 626 |
|
| 627 |
'dataScroll' => K::input( |
| 628 |
'fca_eoi[publish_lightbox][conditions][scrolled_percent]', |
| 629 |
array( |
| 630 |
'type' => 'number', |
| 631 |
'min' => '0', |
| 632 |
'max' => '100', |
| 633 |
'value' => '30', |
| 634 |
'class' => '', |
| 635 |
), |
| 636 |
array( |
| 637 |
'return' => true, |
| 638 |
) |
| 639 |
) . ' %', |
| 640 |
|
| 641 |
'dataPageviews' => K::input( |
| 642 |
'fca_eoi[publish_lightbox][conditions][pageviews]', |
| 643 |
array( |
| 644 |
'type' => 'number', |
| 645 |
'min' => '0', |
| 646 |
'value' => '2', |
| 647 |
'class' => '', |
| 648 |
), |
| 649 |
array( |
| 650 |
'return' => true, |
| 651 |
) |
| 652 |
) . ' pageviews', |
| 653 |
|
| 654 |
'dataTime' => K::input( |
| 655 |
'fca_eoi[publish_lightbox][conditions][time_on_page]', |
| 656 |
array( |
| 657 |
'type' => 'number', |
| 658 |
'min' => '0', |
| 659 |
'value' => '30', |
| 660 |
'class' => '', |
| 661 |
), |
| 662 |
array( |
| 663 |
'return' => true, |
| 664 |
) |
| 665 |
) . ' seconds', |
| 666 |
|
| 667 |
'dataExit' => K::input( 'fca_eoi[publish_lightbox][conditions][exit_intervention]', |
| 668 |
array( |
| 669 |
'type' => 'checkbox', |
| 670 |
'class' => 'switch-input' |
| 671 |
), |
| 672 |
array( |
| 673 |
'format' => '<label class="switch">:input<span class="switch-label" data-on="On" data-off="Off"></span><span class="switch-handle"></span></label>', |
| 674 |
'return' => true, |
| 675 |
) |
| 676 |
), |
| 677 |
|
| 678 |
'dataInclude' => k_selector( 'fca_eoi[publish_lightbox][conditions][include]', array(), true ), |
| 679 |
'dataExclude' => k_selector( 'fca_eoi[publish_lightbox][conditions][exclude]', array(), true ), |
| 680 |
); |
| 681 |
|
| 682 |
wp_localize_script( 'fca-eoi-rules', 'fcaEoiRuleTableHtml', $ruleTableHtml ); |
| 683 |
wp_localize_script( 'fca-eoi-rules', 'fcaEoiRules', $rules ); |
| 684 |
wp_localize_script( 'fca-eoi-rules', 'fcaEoiDistro', $this->settings['distribution'] ); |
| 685 |
} |
| 686 |
|
| 687 |
public function meta_box_content_publish( $post ) { |
| 688 |
|
| 689 |
$fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true ); |
| 690 |
|
| 691 |
$conditions = empty( $fca_eoi['publish_lightbox']['conditions'] ) ? array() : $fca_eoi['publish_lightbox']['conditions']; |
| 692 |
$this->prepare_publish_rules_html( $conditions ); |
| 693 |
|
| 694 |
K::wrap( |
| 695 |
sprintf( |
| 696 |
__( 'You can publish this optin box by going to <a href="%s" target="_blank">Appearance › Widgets</a>'), |
| 697 |
admin_url( 'widgets.php') |
| 698 |
), |
| 699 |
array( 'id' => 'fca_eoi_publish_widget' ), |
| 700 |
array( 'in' => 'p' ) |
| 701 |
); |
| 702 |
|
| 703 |
// Post boxes |
| 704 |
echo '<div id ="fca_eoi_publish_postbox">'; |
| 705 |
K::wrap( __( 'Shortcode'), |
| 706 |
array( 'style' => 'padding-left: 0px; padding-right: 0px; ' ), |
| 707 |
array( 'in' => 'h3' ) |
| 708 |
); |
| 709 |
K::wrap( __( "Copy and paste beneath shortcode anywhere on your site where you'd like this opt-in form to appear." ), |
| 710 |
null, |
| 711 |
array( 'in' => 'p' ) |
| 712 |
); |
| 713 |
K::input( '', |
| 714 |
array( |
| 715 |
'class' => 'regular-text autoselect', |
| 716 |
'readonly' => 'readonly', |
| 717 |
'value' => sprintf( '[%s id=%d]', $this->settings[ 'shortcode' ], $post->ID ), |
| 718 |
), |
| 719 |
array( 'format' => '<p>:input</p>', ) |
| 720 |
); |
| 721 |
K::wrap( __( 'Append to post or page'), |
| 722 |
array( 'style' => 'padding-left: 0px; padding-right: 0px; ' ), |
| 723 |
array( 'in' => 'h3' ) |
| 724 |
); |
| 725 |
K::wrap( __( 'Automatically append this optin to the following posts, categories and/or pages.' ), |
| 726 |
null, |
| 727 |
array( 'in' => 'p' ) |
| 728 |
); |
| 729 |
k_selector( 'fca_eoi[publish_postbox]', K::get_var( 'publish_postbox', $fca_eoi, array() ) ); |
| 730 |
echo '</div>'; |
| 731 |
|
| 732 |
// Lightboxes |
| 733 |
|
| 734 |
|
| 735 |
$fca_eoi[ 'publish_lightbox' ] = K::get_var( 'publish_lightbox', $fca_eoi, array() ); |
| 736 |
|
| 737 |
|
| 738 |
echo "<div id='fca_eoi_publish_lightbox'>"; |
| 739 |
|
| 740 |
echo '<div id="publish_lightbox_mode_selector_div">'; |
| 741 |
if ( 'premium' === $this->settings[ 'distribution' ] ) { |
| 742 |
|
| 743 |
K::input( 'fca_eoi[publish_lightbox_mode]', |
| 744 |
array( |
| 745 |
'type' => 'radio', |
| 746 |
'value' => 'two_step_optin', |
| 747 |
'checked' => 'two_step_optin' === K::get_var( 'publish_lightbox_mode', $fca_eoi ), |
| 748 |
), |
| 749 |
array( |
| 750 |
'format' => '<p><label>:input Two-Step Optin (Trigger popup only when the visitor clicks on a call to action link)</label></p>', |
| 751 |
) |
| 752 |
); |
| 753 |
} |
| 754 |
|
| 755 |
K::input( 'fca_eoi[publish_lightbox_mode]', |
| 756 |
array( |
| 757 |
'type' => 'radio', |
| 758 |
'value' => 'traditional_popup', |
| 759 |
'checked' => 'traditional_popup' === K::get_var( 'publish_lightbox_mode', $fca_eoi ), |
| 760 |
), |
| 761 |
array( |
| 762 |
'format' => '<p><label>:input Traditional Popup (Trigger popup when the visitor is browsing your site)</label></p>', |
| 763 |
) |
| 764 |
); |
| 765 |
echo '</div>'; |
| 766 |
|
| 767 |
echo '<div id="fca_eoi_publish_lightbox_mode_traditional_popup">'; |
| 768 |
echo "<h3>Rules</h3>"; |
| 769 |
|
| 770 |
echo "<table class='fca_eoi_display_rules_table'>"; |
| 771 |
echo "<tr><th>Display Frequency" . fca_eoi_tooltip ( __('Set the minimum time between visits your optin will display to each user', 'easy-opt-ins') ) . "</th><td>"; |
| 772 |
K::select( |
| 773 |
'fca_eoi[publish_lightbox][show_every]', |
| 774 |
array(), |
| 775 |
array( |
| 776 |
'options' => array( |
| 777 |
'always' => __( 'On every pageview' ), |
| 778 |
'session' => __( 'Once per visit' ), |
| 779 |
'day' => __( 'Once per day' ), |
| 780 |
'month' => __( 'Once per month' ), |
| 781 |
'once' => __( 'Only once' ), |
| 782 |
), |
| 783 |
'selected' => K::get_var( 'show_every', $fca_eoi[ 'publish_lightbox' ], 'month' ), |
| 784 |
) |
| 785 |
); |
| 786 |
echo "</td></tr>"; |
| 787 |
|
| 788 |
echo "<tr><th>Devices to Display on</th><td>"; |
| 789 |
K::select( |
| 790 |
'fca_eoi[publish_lightbox][devices]', |
| 791 |
array(), |
| 792 |
array( |
| 793 |
'options' => array( |
| 794 |
'desktop' => __( 'Desktop Only' ), |
| 795 |
'mobile' => __( 'Mobile Only' ), |
| 796 |
'all' => __( 'Desktop & Mobile' ), |
| 797 |
), |
| 798 |
'selected' => K::get_var( 'devices', $fca_eoi[ 'publish_lightbox' ], 'all' ), |
| 799 |
) |
| 800 |
); |
| 801 |
echo "</td></tr>"; |
| 802 |
|
| 803 |
echo "<tr><th>Success Cookie Duration" . fca_eoi_tooltip ( __('The number of days before the optin will display again once the user successfully opts in to your campaign.', 'easy-opt-ins') ) . "</th><td>"; |
| 804 |
K::input( 'fca_eoi[publish_lightbox][success_duration]', |
| 805 |
array( |
| 806 |
'type' => 'number', |
| 807 |
'class' => 'regular-text', |
| 808 |
'min' => 0, |
| 809 |
'value' => K::get_var( 'success_duration', $fca_eoi[ 'publish_lightbox' ], 365 ), |
| 810 |
) |
| 811 |
); |
| 812 |
|
| 813 |
echo " days</td></tr>"; |
| 814 |
|
| 815 |
|
| 816 |
echo "</table>"; |
| 817 |
|
| 818 |
echo "<table class='fca_eoi_display_rules_table' id='fca_eoi_primary_rules_table' >"; |
| 819 |
//to be filled dynamically? |
| 820 |
echo "</table>"; |
| 821 |
|
| 822 |
echo "<a href='#' id='fca_eoi_add_rule'>+ Add a rule</a>"; |
| 823 |
|
| 824 |
echo "<h3>Go Live</h3>"; |
| 825 |
echo "<table class='fca_eoi_display_rules_table' >"; |
| 826 |
echo "<tr><th>Deployed (makes this optin go live)</th><td>"; |
| 827 |
K::input( 'fca_eoi[publish_lightbox][live]', |
| 828 |
array( |
| 829 |
'type' => 'checkbox', |
| 830 |
'checked' => K::get_var( 'live', $fca_eoi[ 'publish_lightbox' ], '' ), |
| 831 |
'class' => 'switch-input' |
| 832 |
), |
| 833 |
array( |
| 834 |
'format' => '<label class="switch">:input<span class="switch-label" data-on="On" data-off="Off"></span><span class="switch-handle"></span></label>' |
| 835 |
) |
| 836 |
); |
| 837 |
echo "</td></tr>"; |
| 838 |
echo "</table>"; |
| 839 |
echo "</div>"; |
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
if ( 'premium' === $this->settings[ 'distribution' ] ) { |
| 844 |
|
| 845 |
echo '<div id="fca_eoi_publish_lightbox_mode_two_step_optin">'; |
| 846 |
echo "<h3>Two-Step</h3>"; |
| 847 |
K::input( 'fca_eoi[lightbox_cta_text]', |
| 848 |
array( |
| 849 |
'value' => K::get_var( 'lightbox_cta_text', $fca_eoi ) ? K::get_var( 'lightbox_cta_text', $fca_eoi ) : __( 'Free Download' ), |
| 850 |
'class' => 'regular-text', |
| 851 |
), |
| 852 |
array( |
| 853 |
'format' => '<p><label>Call to action text :input</label></p>', |
| 854 |
) |
| 855 |
); |
| 856 |
K::input( 'fca_eoi[lightbox_cta_link]', |
| 857 |
array( |
| 858 |
'readonly' => 'readonly', |
| 859 |
'value' => htmlspecialchars( sprintf( '<button data-optin-cat="%d">%s</button>', |
| 860 |
$post->ID, |
| 861 |
__( 'Free Download' ) ) ), |
| 862 |
'class' => 'regular-text autoselect', |
| 863 |
), |
| 864 |
array( |
| 865 |
'format' => '<p><label>Call to action link :input</label></p>', |
| 866 |
) |
| 867 |
); |
| 868 |
|
| 869 |
K::wrap( __( 'Post above link into the text editor window of your post/page/widget.' ), |
| 870 |
array( 'class' => 'description' ), |
| 871 |
array( 'in' => 'p' ) |
| 872 |
); |
| 873 |
echo "</div>"; |
| 874 |
} |
| 875 |
echo "</div>"; |
| 876 |
} |
| 877 |
|
| 878 |
private function meta_box_field( $id, $title, $controls = array() ) { |
| 879 |
$content = ''; |
| 880 |
|
| 881 |
foreach ( $controls as $control ) { |
| 882 |
$control[2] = empty( $control[2] ) ? array() : $control[2]; |
| 883 |
$control[3] = empty( $control[3] ) ? array() : $control[3]; |
| 884 |
|
| 885 |
$control[3][ 'return' ] = true; |
| 886 |
|
| 887 |
$content .= call_user_func_array( 'K::' . $control[0], array_slice( $control, 1 ) ); |
| 888 |
} |
| 889 |
|
| 890 |
$content = trim( $content ); |
| 891 |
$class_name = 'accordion-section-primary-' . ( empty( $content ) ? 'empty' : 'full' ); |
| 892 |
$content = '<div class="' . $class_name . '">' . $content . '</div>'; |
| 893 |
|
| 894 |
$title_id = str_replace ( ' ', '_', $title ); |
| 895 |
$title_id = strtolower ( $title_id ); |
| 896 |
$title_id = preg_replace('/[^a-zA-Z0-9_.]/', '', $title_id); |
| 897 |
|
| 898 |
K::wrap( |
| 899 |
K::wrap( |
| 900 |
$title . "<span class='accordion-info' id='accordion-info-$title_id'></span>", |
| 901 |
array( 'class' => 'accordion-section-title' ), |
| 902 |
array( 'return' => true ) |
| 903 |
) . |
| 904 |
K::wrap( |
| 905 |
$content, |
| 906 |
array( 'class' => 'accordion-section-content' ), |
| 907 |
array( 'return' => true ) |
| 908 |
), |
| 909 |
array( |
| 910 |
'class' => 'accordion-section', |
| 911 |
'id' => $id |
| 912 |
) |
| 913 |
); |
| 914 |
} |
| 915 |
|
| 916 |
public function meta_box_content_build() { |
| 917 |
|
| 918 |
global $post; |
| 919 |
$post_meta = get_post_meta( $post->ID, 'fca_eoi', true ); |
| 920 |
$layout = get_post_meta( $post->ID, 'fca_eoi_layout', true ); |
| 921 |
|
| 922 |
$selected_layout = empty( $layout ) ? 'lightbox_not_set' : $layout; |
| 923 |
$class = empty( $layout ) ? 'fca-new-layout' : ''; |
| 924 |
echo "<input id='fca_eoi_layout_select' name='fca_eoi[layout]' value='$selected_layout' hidden readonly class='$class'>"; |
| 925 |
|
| 926 |
//OUTPUT SELECTED OR DEFAULT TEMPLATE |
| 927 |
|
| 928 |
echo "<div id='fca_eoi_form_preview'>"; |
| 929 |
|
| 930 |
$output = '<div id="fca_eoi_preview">'; |
| 931 |
//JS WILL LOAD THE TEMPLATE |
| 932 |
//$output .= fca_eoi_get_layout_html( $selected_layout ); |
| 933 |
|
| 934 |
$output .= '</div>'; |
| 935 |
echo $output; |
| 936 |
/* END FORM HTML GENERATION */ |
| 937 |
|
| 938 |
$providers_available = array_keys( $this->settings[ 'providers' ] ); |
| 939 |
$providers_options = array(); |
| 940 |
$screen = get_current_screen(); |
| 941 |
|
| 942 |
// Prepare providers options |
| 943 |
foreach ($this->settings[ 'providers' ] as $provider_id => $provider ) { |
| 944 |
$providers_options[ $provider_id ] = $provider[ 'info' ][ 'name' ]; |
| 945 |
} |
| 946 |
|
| 947 |
echo '<div id="fca_eoi_settings" class="accordion-container">'; |
| 948 |
|
| 949 |
echo '<div id="fca_eoi_fieldset_layout">'; |
| 950 |
echo '<span id="accordion-info-layout">Layout</span><button title="Change Layout" type="button" id="fca_eoi_layout_select_button" class="button button-secondary"><span style="margin-top: 3px; margin-right: 3px;" class="dashicons dashicons-admin-appearance"></span>Change Layout</button>'; |
| 951 |
echo '</div>'; |
| 952 |
|
| 953 |
$this->meta_box_field( 'fca_eoi_fieldset_form', 'Form', array( |
| 954 |
|
| 955 |
array( 'input', 'fca_eoi[toggle_overlay_position]', |
| 956 |
array( |
| 957 |
'type' => 'checkbox', |
| 958 |
'checked' => K::get_var( 'toggle_overlay_position', $post_meta, 'off' ) === 'off' ? '' : 'on', |
| 959 |
'class' => 'switch-input' |
| 960 |
), |
| 961 |
array( |
| 962 |
'format' => '<p id="fca_eoi_overlay_position_p"><span class="control-title">Placement</span><br><label class="switch">:input<span class="switch-label" data-on="" data-off=""></span><span class="switch-handle"></span></label></p>' |
| 963 |
), |
| 964 |
), |
| 965 |
array( 'input', 'fca_eoi[show_close]', |
| 966 |
array( |
| 967 |
'type' => 'checkbox', |
| 968 |
'checked' => K::get_var( 'show_close', $post_meta, 'on' ) === 'on' ? 'on' : '', |
| 969 |
'class' => 'switch-input' |
| 970 |
), |
| 971 |
array( |
| 972 |
'format' => '<p id="fca_eoi_close_button_p"><span class="control-title">Close Button</span><br><label class="switch">:input<span class="switch-label" data-on="Show" data-off="Hide"></span><span class="switch-handle"></span></label></p>' |
| 973 |
), |
| 974 |
), |
| 975 |
|
| 976 |
array( 'input', 'fca_eoi[push_page]', |
| 977 |
array( |
| 978 |
'type' => 'checkbox', |
| 979 |
'checked' => K::get_var( 'push_page', $post_meta, 'on' ) === 'on' ? 'on' : '', |
| 980 |
'class' => 'switch-input' |
| 981 |
), |
| 982 |
array( |
| 983 |
'format' => '<p id="fca_eoi_push_page_p"><span class="control-title">Push Page Down</span><br><label class="switch">:input<span class="switch-label" data-on="On" data-off="Off"></span><span class="switch-handle"></span></label></p>' |
| 984 |
), |
| 985 |
), |
| 986 |
|
| 987 |
array( 'input', "fca_eoi[offset]", |
| 988 |
array( |
| 989 |
'type' => 'number', |
| 990 |
'min' => '0', |
| 991 |
'value' => K::get_var( 'offset', $post_meta, 0 ), |
| 992 |
'class' => 'fca_eoi_number_input', |
| 993 |
), |
| 994 |
array( |
| 995 |
'format' => "<p id='fca_eoi_offset_p'><label><span class='control-title'>Offset</span></label><br />:inputpx</p>", |
| 996 |
) |
| 997 |
), |
| 998 |
|
| 999 |
$this->generate_hidden_css_select_input('form_background_color_selector'), |
| 1000 |
$this->generate_color_picker('form_background_color','Form Background Color'), |
| 1001 |
$this->generate_hidden_css_select_input('form_border_color_selector'), |
| 1002 |
$this->generate_color_picker('form_border_color','Border Color'), |
| 1003 |
$this->generate_hidden_css_select_input('form_width_selector'), |
| 1004 |
$this->generate_width_select_input('form_width','Width', 100), |
| 1005 |
//$this->generate_hidden_css_select_input('form_alignment_selector'), |
| 1006 |
//$this->generate_alignment_select_input('form_alignment','Alignment', 'center'), |
| 1007 |
|
| 1008 |
) ); |
| 1009 |
|
| 1010 |
$this->meta_box_field( 'fca_eoi_fieldset_headline', 'Headline', array( |
| 1011 |
array( 'input', 'fca_eoi[show_headline_field]', |
| 1012 |
array( |
| 1013 |
'type' => 'checkbox', |
| 1014 |
'checked' => K::get_var( 'show_headline_field', $post_meta, 'on' ) == 'off' ? '' : 'on', |
| 1015 |
'class' => 'switch-input' |
| 1016 |
), |
| 1017 |
array( |
| 1018 |
'format' => '<p><span class="control-title">Headline Field</span><br><label class="switch">:input<span class="switch-label" data-on="Show" data-off="Hide"></span><span class="switch-handle"></span></label></p>' |
| 1019 |
), |
| 1020 |
), |
| 1021 |
array( 'input', 'fca_eoi[headline_copy]', |
| 1022 |
array( 'class' => 'fca_eoi_text_input', 'value' => K::get_var( 'headline_copy', $post_meta ) ), |
| 1023 |
array( 'format' => '<p><label><span class="control-title">Headline Copy</span><br />:input</label></p>' ) |
| 1024 |
), |
| 1025 |
$this->generate_hidden_css_select_input('headline_font_size_selector'), |
| 1026 |
$this->generate_font_size_picker ('headline_font_size', 'Font Size'), |
| 1027 |
$this->generate_hidden_css_select_input('headline_font_color_selector'), |
| 1028 |
$this->generate_color_picker('headline_font_color','Font Color'), |
| 1029 |
$this->generate_hidden_css_select_input('headline_background_color_selector'), |
| 1030 |
$this->generate_color_picker('headline_background_color','Background Color'), |
| 1031 |
|
| 1032 |
) ); |
| 1033 |
|
| 1034 |
$this->meta_box_field( 'fca_eoi_fieldset_description', 'Description', array( |
| 1035 |
array( 'input', 'fca_eoi[show_description_field]', |
| 1036 |
array( |
| 1037 |
'type' => 'checkbox', |
| 1038 |
'checked' => K::get_var( 'show_description_field', $post_meta, 'on' ) == 'off' ? '' : 'on', |
| 1039 |
'class' => 'switch-input' |
| 1040 |
), |
| 1041 |
array( |
| 1042 |
'format' => '<p><span class="control-title">Description Field</span><br><label class="switch">:input<span class="switch-label" data-on="Show" data-off="Hide"></span><span class="switch-handle"></span></label></p>' |
| 1043 |
), |
| 1044 |
), |
| 1045 |
array( 'textarea', 'fca_eoi[description_copy]', array(), array( |
| 1046 |
'format' => ':textarea', |
| 1047 |
'editor' => true, |
| 1048 |
'value' => K::get_var( 'description_copy', $post_meta ), |
| 1049 |
) ), |
| 1050 |
$this->generate_hidden_css_select_input('description_font_size_selector'), |
| 1051 |
$this->generate_font_size_picker ('description_font_size', 'Font Size'), |
| 1052 |
$this->generate_hidden_css_select_input('description_font_color_selector'), |
| 1053 |
$this->generate_color_picker('description_font_color','Font Color'), |
| 1054 |
) ); |
| 1055 |
|
| 1056 |
$this->meta_box_field( 'fca_eoi_fieldset_name_field', 'Name Field', array( |
| 1057 |
array( 'input', 'fca_eoi[show_name_field]', |
| 1058 |
array( |
| 1059 |
'type' => 'checkbox', |
| 1060 |
'checked' => K::get_var( 'show_name_field', $post_meta, 'off' ) == 'off' ? '' : 'on', |
| 1061 |
'class' => 'switch-input' |
| 1062 |
), |
| 1063 |
array( |
| 1064 |
'format' => '<p><span class="control-title">Name Field</span><br><label class="switch">:input<span class="switch-label" data-on="Show" data-off="Hide"></span><span class="switch-handle"></span></label></p>' |
| 1065 |
), |
| 1066 |
), |
| 1067 |
array( 'input', 'fca_eoi[name_placeholder]', |
| 1068 |
array( 'class' => 'fca_eoi_text_input', 'value' => K::get_var( 'name_placeholder', $post_meta, 'First Name' ) ), |
| 1069 |
array( 'format' => '<p><label><span class="control-title">Placeholder Text</span><br />:input</label></p>' ) |
| 1070 |
), |
| 1071 |
$this->generate_hidden_css_select_input('name_font_size_selector'), |
| 1072 |
$this->generate_font_size_picker ('name_font_size', 'Font Size'), |
| 1073 |
$this->generate_hidden_css_select_input('name_font_color_selector'), |
| 1074 |
$this->generate_color_picker('name_font_color','Font Color'), |
| 1075 |
$this->generate_hidden_css_select_input('name_background_color_selector'), |
| 1076 |
$this->generate_color_picker('name_background_color','Background Color'), |
| 1077 |
$this->generate_hidden_css_select_input('name_border_color_selector'), |
| 1078 |
$this->generate_color_picker('name_border_color','Border Color'), |
| 1079 |
$this->generate_hidden_css_select_input('name_width_selector'), |
| 1080 |
$this->generate_width_select_input('name_width','Width', 100), |
| 1081 |
//$this->generate_hidden_css_select_input('name_alignment_selector'), |
| 1082 |
//$this->generate_alignment_select_input('name_alignment','Alignment', 'left'), |
| 1083 |
) ); |
| 1084 |
|
| 1085 |
$this->meta_box_field( 'fca_eoi_fieldset_email_field', 'Email Field', array( |
| 1086 |
array( 'input', 'fca_eoi[email_placeholder]', |
| 1087 |
array( 'class' => 'fca_eoi_text_input', 'value' => K::get_var( 'email_placeholder', $post_meta, 'Your Email' ) ), |
| 1088 |
array( 'format' => '<p><label><span class="control-title">Placeholder Text</span><br />:input</label></p>' ) |
| 1089 |
), |
| 1090 |
$this->generate_hidden_css_select_input('email_font_size_selector'), |
| 1091 |
$this->generate_font_size_picker ('email_font_size', 'Font Size'), |
| 1092 |
$this->generate_hidden_css_select_input('email_font_color_selector'), |
| 1093 |
$this->generate_color_picker('email_font_color','Font Color'), |
| 1094 |
$this->generate_hidden_css_select_input('email_background_color_selector'), |
| 1095 |
$this->generate_color_picker('email_background_color','Background Color'), |
| 1096 |
$this->generate_hidden_css_select_input('email_border_color_selector'), |
| 1097 |
$this->generate_color_picker('email_border_color','Border Color'), |
| 1098 |
$this->generate_hidden_css_select_input('email_width_selector'), |
| 1099 |
$this->generate_width_select_input('email_width','Width', 100), |
| 1100 |
//$this->generate_hidden_css_select_input('email_alignment_selector'), |
| 1101 |
//$this->generate_alignment_select_input('email_alignment','Alignment', 'left'), |
| 1102 |
) ); |
| 1103 |
|
| 1104 |
$this->meta_box_field( 'fca_eoi_fieldset_button', 'Button', array( |
| 1105 |
array( 'input', 'fca_eoi[button_copy]', |
| 1106 |
array( 'class' => 'fca_eoi_text_input', 'value' => K::get_var( 'button_copy', $post_meta, 'Subscribe Now' ) ), |
| 1107 |
array( 'format' => '<p><label><span class="control-title">Button Copy</span><br />:input</label></p>' ) |
| 1108 |
), |
| 1109 |
$this->generate_hidden_css_select_input('button_font_size_selector'), |
| 1110 |
$this->generate_font_size_picker ('button_font_size', 'Font Size'), |
| 1111 |
$this->generate_hidden_css_select_input('button_font_color_selector'), |
| 1112 |
$this->generate_color_picker('button_font_color','Font Color'), |
| 1113 |
|
| 1114 |
$this->generate_hidden_css_select_input('button_background_color_selector'), |
| 1115 |
$this->generate_color_picker('button_background_color','Background Color'), |
| 1116 |
$this->generate_hidden_css_select_input('button_wrapper_background_color_selector'), |
| 1117 |
$this->generate_color_picker('button_wrapper_background_color','Bottom Border Color'), |
| 1118 |
$this->generate_hidden_css_select_input('button_border_color_selector'), |
| 1119 |
$this->generate_color_picker('button_border_color','Border Color'), |
| 1120 |
|
| 1121 |
$this->generate_hidden_css_select_input('button_hover_color_selector'), |
| 1122 |
$this->generate_color_picker('button_hover_color','Hover Color'), |
| 1123 |
|
| 1124 |
$this->generate_hidden_css_select_input('button_width_selector'), |
| 1125 |
$this->generate_width_select_input('button_width','Width', 100), |
| 1126 |
//$this->generate_hidden_css_select_input('button_alignment_selector'), |
| 1127 |
//$this->generate_alignment_select_input('button_alignment','Alignment', 'center'), |
| 1128 |
|
| 1129 |
) ); |
| 1130 |
|
| 1131 |
$this->meta_box_field( 'fca_eoi_fieldset_privacy', 'After Button Area', array( |
| 1132 |
array( 'input', 'fca_eoi[show_privacy_field]', |
| 1133 |
array( |
| 1134 |
'type' => 'checkbox', |
| 1135 |
'checked' => K::get_var( 'show_privacy_field', $post_meta, 'on' ) == 'off' ? '' : 'on', |
| 1136 |
'class' => 'switch-input' |
| 1137 |
), |
| 1138 |
array( |
| 1139 |
'format' => '<p><span class="control-title">After Button Area</span><br><label class="switch">:input<span class="switch-label" data-on="Show" data-off="Hide"></span><span class="switch-handle"></span></label></p>' |
| 1140 |
), |
| 1141 |
), |
| 1142 |
array( 'textarea', 'fca_eoi[privacy_copy]', |
| 1143 |
array( |
| 1144 |
'class' => 'large-text fca_eoi_text_input', |
| 1145 |
), |
| 1146 |
array( |
| 1147 |
'format' => '<p><label><span class="control-title">After Button Area Copy</span><br />:textarea</label></p>', |
| 1148 |
'value' => K::get_var( 'privacy_copy', $post_meta ), |
| 1149 |
) |
| 1150 |
), |
| 1151 |
$this->generate_hidden_css_select_input('privacy_font_size_selector'), |
| 1152 |
$this->generate_font_size_picker ('privacy_font_size', 'Font Size'), |
| 1153 |
$this->generate_hidden_css_select_input('privacy_font_color_selector'), |
| 1154 |
$this->generate_color_picker('privacy_font_color','Font Color'), |
| 1155 |
) ); |
| 1156 |
if ( $this->settings['distribution'] === 'free' ) { |
| 1157 |
$this->meta_box_field( 'fca_eoi_fieldset_fatcatapps', 'Branding', array( |
| 1158 |
array( 'input', 'fca_eoi[show_fatcatapps_link]', |
| 1159 |
array( |
| 1160 |
'type' => 'checkbox', |
| 1161 |
'checked' => K::get_var( 'show_fatcatapps_link', $post_meta ), |
| 1162 |
'class' => 'switch-input' |
| 1163 |
), |
| 1164 |
array( |
| 1165 |
'format' => '<p><span class="control-title"><a href="http://fatcatapps.com/" target="_blank">Optin Cat</a> Branding</span><br><label class="switch">:input<span class="switch-label" data-on="Show" data-off="Hide"></span><span class="switch-handle"></span></label></p>' |
| 1166 |
), |
| 1167 |
), |
| 1168 |
|
| 1169 |
$this->generate_hidden_css_select_input('branding_font_color_selector'), |
| 1170 |
$this->generate_color_picker ('branding_font_color', 'Font Color'), |
| 1171 |
) ); |
| 1172 |
} |
| 1173 |
|
| 1174 |
echo '</div>'; |
| 1175 |
echo '</div>'; |
| 1176 |
echo '<br clear="all"/>'; |
| 1177 |
|
| 1178 |
|
| 1179 |
} |
| 1180 |
public function generate_width_select_input( $id, $name, $default = 100 ) { |
| 1181 |
global $post; |
| 1182 |
$post_meta = get_post_meta( $post->ID, 'fca_eoi', true ); |
| 1183 |
$value = K::get_var( "$id", $post_meta, $default ); |
| 1184 |
$units = K::get_var( "$id" . "-units", $post_meta, '%' ); |
| 1185 |
|
| 1186 |
$px_selected = $units == 'px' ? 'selected' : ''; |
| 1187 |
$pct_selected = $units == '%' ? 'selected' : ''; |
| 1188 |
|
| 1189 |
return array( 'input', "fca_eoi[$id]", |
| 1190 |
array( |
| 1191 |
'type' => 'number', |
| 1192 |
'min' => '0', |
| 1193 |
'value' => $value, |
| 1194 |
'class' => 'fca_eoi_width_input', |
| 1195 |
), |
| 1196 |
array( |
| 1197 |
'format' => "<p><label><span class='control-title'>$name</span></label><br />:input <select class='fca_eoi_width_units_select' name='fca_eoi[$id-units]'><option value='%' $pct_selected>%</option><option value='px' $px_selected>px</option></select></p>", |
| 1198 |
|
| 1199 |
) |
| 1200 |
); |
| 1201 |
} |
| 1202 |
|
| 1203 |
public function generate_alignment_select_input( $id, $name, $default ) { |
| 1204 |
global $post; |
| 1205 |
$post_meta = get_post_meta( $post->ID, 'fca_eoi', true ); |
| 1206 |
$value = K::get_var( "$id", $post_meta, $default ); |
| 1207 |
|
| 1208 |
return array( 'input', "fca_eoi[$id]", |
| 1209 |
array( |
| 1210 |
'type' => 'hidden', |
| 1211 |
'value' => $value, |
| 1212 |
'class' => 'fca_eoi_alignment_input', |
| 1213 |
), |
| 1214 |
array( |
| 1215 |
'format' => "<p><label><span class='control-title'>$name</span></label><br><span data-value='left' class='dashicons dashicons-editor-alignleft fca-eoi-align-button fca-eoi-align-left-btn'></span><span data-value='center' class='dashicons dashicons-editor-aligncenter fca-eoi-align-button fca-eoi-align-center-btn'></span><span data-value='right' class='dashicons dashicons-editor-alignright fca-eoi-align-button fca-eoi-align-right-btn'></span>:input</p>", |
| 1216 |
), |
| 1217 |
); |
| 1218 |
} |
| 1219 |
|
| 1220 |
public function generate_hidden_css_select_input ($id) { |
| 1221 |
return array( 'input', "fca_eoi[$id]", |
| 1222 |
array ( 'class' => 'fca-hidden-input hidden', |
| 1223 |
'value' => '' |
| 1224 |
) |
| 1225 |
); |
| 1226 |
} |
| 1227 |
|
| 1228 |
public function generate_color_picker ($id, $name) { |
| 1229 |
global $post; |
| 1230 |
$post_meta = get_post_meta( $post->ID, 'fca_eoi', true ); |
| 1231 |
return array( 'input', "fca_eoi[$id]", |
| 1232 |
array ( 'class' => 'fca-color-picker', |
| 1233 |
'value' => K::get_var( "$id", $post_meta ) |
| 1234 |
), |
| 1235 |
array( |
| 1236 |
'format' => '<p><label><span class="control-title">'. $name . '</span><br />:input</label></p>', |
| 1237 |
), |
| 1238 |
); |
| 1239 |
} |
| 1240 |
|
| 1241 |
public function generate_font_size_picker ($id, $name) { |
| 1242 |
global $post; |
| 1243 |
$post_meta = get_post_meta( $post->ID, 'fca_eoi', true ); |
| 1244 |
return array( 'select', "fca_eoi[$id]", |
| 1245 |
|
| 1246 |
array ( |
| 1247 |
'data-selected' => K::get_var( "$id", $post_meta ), |
| 1248 |
'class' => 'fca-font-size-picker ', |
| 1249 |
), |
| 1250 |
array( |
| 1251 |
'format' => '<p class="clear"><label><span class="control-title">'. $name . '</span><br />:select</label></p>', |
| 1252 |
'options' => array( |
| 1253 |
'none' => '', |
| 1254 |
'7px' => '7px', |
| 1255 |
'8px' => '8px', |
| 1256 |
'9px' => '9px', |
| 1257 |
'10px' => '10px', |
| 1258 |
'11px' => '11px', |
| 1259 |
'12px' => '12px', |
| 1260 |
'13px' => '13px', |
| 1261 |
'14px' => '14px', |
| 1262 |
'15px' => '15px', |
| 1263 |
'16px' => '16px', |
| 1264 |
'17px' => '17px', |
| 1265 |
'18px' => '18px', |
| 1266 |
'19px' => '19px', |
| 1267 |
'20px' => '20px', |
| 1268 |
'21px' => '21px', |
| 1269 |
'22px' => '22px', |
| 1270 |
'23px' => '23px', |
| 1271 |
'24px' => '24px', |
| 1272 |
'25px' => '25px', |
| 1273 |
'26px' => '26px', |
| 1274 |
'27px' => '27px', |
| 1275 |
'28px' => '28px', |
| 1276 |
'29px' => '29px', |
| 1277 |
'30px' => '30px', |
| 1278 |
'31px' => '31px', |
| 1279 |
'32px' => '32px', |
| 1280 |
'33px' => '33px', |
| 1281 |
'34px' => '34px', |
| 1282 |
'35px' => '35px', |
| 1283 |
'36px' => '36px', |
| 1284 |
), |
| 1285 |
'selected' => K::get_var( "$id", $post_meta ), |
| 1286 |
'return' => true, |
| 1287 |
), |
| 1288 |
); |
| 1289 |
} |
| 1290 |
|
| 1291 |
public function meta_box_content_messages( $post ) { |
| 1292 |
|
| 1293 |
$fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true ); |
| 1294 |
$screen = get_current_screen(); |
| 1295 |
|
| 1296 |
// Get the previous thank you page if this is a new post |
| 1297 |
$last_form_meta = get_option( 'fca_eoi_last_form_meta', '' ); |
| 1298 |
$thank_you_page_suggestion = empty ($last_form_meta['thank_you_page']) ? '~' : $last_form_meta['thank_you_page']; |
| 1299 |
$thank_you_mode_suggestion = empty ($last_form_meta['thankyou_page_mode']) ? 'ajax' : $last_form_meta['thankyou_page_mode']; |
| 1300 |
$thank_you_text_suggestion = empty ($last_form_meta['thankyou_ajax']) ? __('Thank you! Please check your inbox for your confirmation email.', 'easy-opt-ins') : stripslashes( $last_form_meta['thankyou_ajax'] ); |
| 1301 |
$subscribing_suggestion = empty ($last_form_meta['subscribing_message']) ? __('Subscribing...', 'easy-opt-ins') : stripslashes( $last_form_meta['subscribing_message'] ); |
| 1302 |
$text_error_suggestion = empty ($last_form_meta['error_text_field_required']) ? __('Please fill out this field to continue', 'easy-opt-ins') : stripslashes( $last_form_meta['error_text_field_required'] ); |
| 1303 |
$email_error_suggestion = empty ($last_form_meta['error_text_invalid_email']) ? __('Please enter a valid email address. For example "hi@fatcatapps.com".', 'easy-opt-ins') : stripslashes( $last_form_meta['error_text_invalid_email'] ); |
| 1304 |
|
| 1305 |
echo '<h3>' . __('Subscribing Message', 'easy-opt-ins') . fca_eoi_tooltip ( __('This message will be displayed after your visitors submit your form.', 'easy-opt-ins') ) . '</h3>'; |
| 1306 |
echo '<table class="fca_eoi_text_messages_table">'; |
| 1307 |
echo '<tr><th>Message</th><td>'; |
| 1308 |
K::input( 'fca_eoi[subscribing_message]', |
| 1309 |
array( |
| 1310 |
'class' => 'regular-text', |
| 1311 |
'value' => K::get_var( 'subscribing_message', $fca_eoi, $subscribing_suggestion ), |
| 1312 |
), |
| 1313 |
array() |
| 1314 |
); |
| 1315 |
|
| 1316 |
echo '</td></tr></table>'; |
| 1317 |
|
| 1318 |
echo '<h3>' . __('Thank You Message', 'easy-opt-ins') . fca_eoi_tooltip( __('This message will be displayed after someone has successfully subscribed.', 'easy-opt-ins') ) . '</h3>'; |
| 1319 |
echo '<table class="fca_eoi_text_messages_table">'; |
| 1320 |
echo '<tr><th>Behavior</th><td>'; |
| 1321 |
_e('Display immediately', 'easy-opt-ins'); |
| 1322 |
$checked = K::get_var( 'thankyou_page_mode', $fca_eoi, $thank_you_mode_suggestion ); |
| 1323 |
|
| 1324 |
K::input( 'fca_eoi[thankyou_page_mode]', |
| 1325 |
array( |
| 1326 |
'type' => 'checkbox', |
| 1327 |
'value' => 'redirect', |
| 1328 |
'checked' => 'redirect' === $checked, |
| 1329 |
'class' => 'switch-input fca-eoi-redirect-mode-toggle' |
| 1330 |
), |
| 1331 |
array( |
| 1332 |
'format' => '<label class="switch" id="fca-eoi-redirect-mode-toggle-label" >:input<span class="switch-label" data-on="" data-off=""></span><span class="switch-handle"></span></label>' |
| 1333 |
) |
| 1334 |
); |
| 1335 |
_e('Redirect', 'easy-opt-ins'); |
| 1336 |
|
| 1337 |
echo '</td></tr>'; |
| 1338 |
|
| 1339 |
echo '<tr id="fca_eoi_thankyou_ajax_msg"><th>Thank You Message</th><td>'; |
| 1340 |
|
| 1341 |
K::textarea( 'fca_eoi[thankyou_ajax]', array( |
| 1342 |
'class' => 'large-text fca_eoi_text_input', |
| 1343 |
), |
| 1344 |
array( |
| 1345 |
'value' => K::get_var( 'thankyou_ajax', $fca_eoi, $thank_you_text_suggestion ), |
| 1346 |
) |
| 1347 |
); |
| 1348 |
|
| 1349 |
echo '</td></tr>'; |
| 1350 |
|
| 1351 |
|
| 1352 |
echo '<tr id="fca_eoi_thankyou_redirect"><th>Redirect to'; |
| 1353 |
|
| 1354 |
K::select( |
| 1355 |
'fca_eoi[redirect_page_mode]', |
| 1356 |
array( |
| 1357 |
'class' => 'fca-eoi-redirect-page-toggle', |
| 1358 |
), |
| 1359 |
array( |
| 1360 |
'options' => array( |
| 1361 |
'page' => __( 'Page' ), |
| 1362 |
'url' => __( 'URL' ), |
| 1363 |
|
| 1364 |
), |
| 1365 |
'selected' => K::get_var( 'redirect_page_mode', $fca_eoi, 'page' ), |
| 1366 |
) |
| 1367 |
); |
| 1368 |
|
| 1369 |
|
| 1370 |
echo '</th><td>'; |
| 1371 |
|
| 1372 |
echo '<span id="fca_eoi_redirect_page_span">'; |
| 1373 |
$pages = array( '~' => __( 'Front page' ) ); |
| 1374 |
$pages_objects = get_pages(); |
| 1375 |
foreach ( $pages_objects as $page_obj ) { |
| 1376 |
$pages[ $page_obj->ID ] = $page_obj->post_title; |
| 1377 |
} |
| 1378 |
K::select( 'fca_eoi[thank_you_page]', |
| 1379 |
array( |
| 1380 |
'class' => 'select2', |
| 1381 |
'style' => 'width: 27em;', |
| 1382 |
), |
| 1383 |
array( |
| 1384 |
'format' => '<p><label>:select</label></p>', |
| 1385 |
'options' => $pages, |
| 1386 |
'selected' => 'add' === $screen->action |
| 1387 |
? $thank_you_page_suggestion |
| 1388 |
: K::get_var( 'thank_you_page', $fca_eoi, '~' ), |
| 1389 |
) |
| 1390 |
); |
| 1391 |
echo '</span>'; |
| 1392 |
echo '<span id="fca_eoi_redirect_url_span">'; |
| 1393 |
K::input( 'fca_eoi[thank_you_url]', |
| 1394 |
array( |
| 1395 |
'class' => 'regular-text', |
| 1396 |
'value' => K::get_var( 'thank_you_url', $fca_eoi ), |
| 1397 |
'placeholder' => 'enter URL here', |
| 1398 |
), |
| 1399 |
array() |
| 1400 |
); |
| 1401 |
echo '</span>'; |
| 1402 |
echo '</td></tr>'; |
| 1403 |
|
| 1404 |
|
| 1405 |
echo '</table>'; |
| 1406 |
|
| 1407 |
echo '<h3>' . __('Error Messages', 'easy-opt-ins') . fca_eoi_tooltip( __("These messages will be dispalyed if someone fills out the form incorrectly.", 'easy-opt-ins') ) . '</h3>'; |
| 1408 |
echo '<table class="fca_eoi_text_messages_table">'; |
| 1409 |
echo '<tr><th>Field Required</th><td>'; |
| 1410 |
|
| 1411 |
K::textarea( 'fca_eoi[error_text_field_required]', |
| 1412 |
array( |
| 1413 |
'class' => 'large-text fca_eoi_text_input', |
| 1414 |
), |
| 1415 |
array( |
| 1416 |
'value' => K::get_var( 'error_text_field_required', $fca_eoi, $text_error_suggestion ), |
| 1417 |
) |
| 1418 |
); |
| 1419 |
|
| 1420 |
echo '</td></tr>'; |
| 1421 |
|
| 1422 |
echo '<tr><th>Invalid Email</th><td>'; |
| 1423 |
|
| 1424 |
K::textarea( 'fca_eoi[error_text_invalid_email]', |
| 1425 |
array( |
| 1426 |
'class' => 'large-text fca_eoi_text_input', |
| 1427 |
), |
| 1428 |
array( |
| 1429 |
'value' => K::get_var( 'error_text_invalid_email', $fca_eoi, $email_error_suggestion ) |
| 1430 |
) |
| 1431 |
); |
| 1432 |
|
| 1433 |
echo '</td></tr>'; |
| 1434 |
|
| 1435 |
|
| 1436 |
echo '</table>'; |
| 1437 |
} |
| 1438 |
|
| 1439 |
public function meta_box_content_powerups() { |
| 1440 |
|
| 1441 |
global $post; |
| 1442 |
$fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true ); |
| 1443 |
do_action('fca_eoi_powerups', $fca_eoi ); |
| 1444 |
} |
| 1445 |
|
| 1446 |
/** |
| 1447 |
* Save the Metabox Data |
| 1448 |
*/ |
| 1449 |
public function save_meta_box_content( $post_id, $post ) { |
| 1450 |
|
| 1451 |
if ( isset ($_POST['fca_eoi'])) { |
| 1452 |
$form_id = $post_id; |
| 1453 |
$meta = $_POST['fca_eoi']; |
| 1454 |
|
| 1455 |
//SET SHOW/HIDE SETTINGS |
| 1456 |
$toggles = array ( |
| 1457 |
'show_headline_field', |
| 1458 |
'show_description_field', |
| 1459 |
'show_name_field', |
| 1460 |
'show_close', |
| 1461 |
'show_privacy_field', |
| 1462 |
'push_page', |
| 1463 |
); |
| 1464 |
|
| 1465 |
forEach ( $toggles as $field ) { |
| 1466 |
$meta[$field] = empty ( $meta[$field] ) ? 'off' : 'on'; |
| 1467 |
} |
| 1468 |
|
| 1469 |
$settings = array ( |
| 1470 |
'form_background_color_selector' => 'background-color', |
| 1471 |
'form_border_color_selector' => 'border-color', |
| 1472 |
'headline_font_size_selector' => 'font-size', |
| 1473 |
'headline_font_color_selector' => 'color', |
| 1474 |
'headline_background_color_selector' => 'background-color', |
| 1475 |
'description_font_size_selector' => 'font-size', |
| 1476 |
'description_font_color_selector' => 'color', |
| 1477 |
'name_font_size_selector' => 'font-size', |
| 1478 |
'name_font_color_selector' => 'color', |
| 1479 |
'name_background_color_selector' => 'background-color', |
| 1480 |
'name_border_color_selector' => 'border-color', |
| 1481 |
'email_font_size_selector' => 'font-size', |
| 1482 |
'email_font_color_selector' => 'color', |
| 1483 |
'email_background_color_selector' => 'background-color', |
| 1484 |
'email_border_color_selector' => 'border-color', |
| 1485 |
'button_font_size_selector' => 'font-size', |
| 1486 |
'button_font_color_selector' => 'color', |
| 1487 |
'button_background_color_selector' => 'background-color', |
| 1488 |
'button_border_color_selector' => 'border-color', |
| 1489 |
// 'button_hover_color_selector' => 'background-color', special case |
| 1490 |
'button_wrapper_background_color_selector' => 'background-color', |
| 1491 |
'privacy_font_size_selector' => 'font-size', |
| 1492 |
'privacy_font_color_selector' => 'color', |
| 1493 |
'branding_font_color_selector' => 'color', |
| 1494 |
); |
| 1495 |
|
| 1496 |
// Add provider if missing (happens on free distros where there is only one provider) |
| 1497 |
if( ! K::get_var( 'provider', $meta ) ) { |
| 1498 |
$meta[ 'provider' ] = $this->settings[ 'provider' ]; |
| 1499 |
} |
| 1500 |
|
| 1501 |
// Keep only the current providers settings, Remove all [provider]_[setting] not belonging to the current provider |
| 1502 |
$provider = K::get_var( 'provider', $meta ); |
| 1503 |
if( $provider ) { |
| 1504 |
$providers = array_keys( $this->settings[ 'providers' ] ); |
| 1505 |
$other_providers = array_values( array_diff( $providers, array( $provider ) ) ); |
| 1506 |
foreach ( $meta as $k => $v ) { |
| 1507 |
$p = explode( '_', $k ); |
| 1508 |
$k_1 = array_shift( $p ); |
| 1509 |
if( in_array( $k_1, $other_providers ) ) { |
| 1510 |
unset( $meta[ $k ] ); |
| 1511 |
} |
| 1512 |
} |
| 1513 |
|
| 1514 |
foreach ( $_POST as $k => $v ) { |
| 1515 |
if ( strpos( $k, 'fca_eoi_' . $provider . '_' ) === 0 ) { |
| 1516 |
delete_post_meta( $post->ID, $k ); |
| 1517 |
add_post_meta( $post->ID, $k, $v ); |
| 1518 |
$meta[ substr($k, 8) ] = $v; |
| 1519 |
} |
| 1520 |
} |
| 1521 |
} |
| 1522 |
|
| 1523 |
// Make sure empty value for publish_postbox or publish_lightbox are saved as array(-1) |
| 1524 |
if( ! K::get_var( 'publish_postbox' , $meta, array() ) ) { |
| 1525 |
$meta[ 'publish_postbox' ] = array(-1); |
| 1526 |
} |
| 1527 |
if( ! K::get_var( 'publish_lightbox' , $meta, array() ) ) { |
| 1528 |
$meta[ 'publish_lightbox' ] = array(-1); |
| 1529 |
} |
| 1530 |
|
| 1531 |
//sanitize thank you ajax message |
| 1532 |
if ( !empty ( $meta[ 'thankyou_ajax' ] ) ) { |
| 1533 |
$meta[ 'thankyou_ajax' ] = htmlentities($meta[ 'thankyou_ajax' ], ENT_QUOTES, "UTF-8"); |
| 1534 |
} |
| 1535 |
|
| 1536 |
//RN NOTE: THIS DO ANYTHING? -> ONLY FOR CUSTOM HTML FORMS SEEMS LIKE |
| 1537 |
$on_save_function = $provider . '_on_save'; |
| 1538 |
if ( function_exists( $on_save_function ) ) { |
| 1539 |
$meta = $on_save_function( $meta ); |
| 1540 |
} |
| 1541 |
|
| 1542 |
//COMPILE CSS AND SAVE INTO 'HEAD' META |
| 1543 |
$layout_id = $meta[ 'layout' ]; |
| 1544 |
|
| 1545 |
// General CSS for all forms |
| 1546 |
$css = "<style type='text/css' class='fca-eoi-style'>.fca_eoi_form{ margin: auto; } .fca_eoi_form p { width: auto; } #fca_eoi_form_$form_id input{ max-width: 9999px; }"; |
| 1547 |
|
| 1548 |
if ( !empty( $layout_id ) ) { |
| 1549 |
|
| 1550 |
// CACHE (ALMOST) ALL THE OUTPUT HERE |
| 1551 |
$layout = new EasyOptInsLayout( $layout_id ); |
| 1552 |
$scss_path = $layout->path_to_resource( 'layout', 'scss' ); |
| 1553 |
|
| 1554 |
if ( file_exists( $scss_path ) ) { |
| 1555 |
$css_path = str_replace ( '.scss' , '_min.css', $scss_path ); |
| 1556 |
$css_file = file_get_contents( $css_path ); |
| 1557 |
} |
| 1558 |
|
| 1559 |
$show_name = K::get_var( 'show_name_field', $meta, 'off' ); |
| 1560 |
if ( $show_name === 'off' ) { |
| 1561 |
$css .= "#fca_eoi_form_$form_id .fca_eoi_layout_name_field_wrapper {display: none !important;}"; |
| 1562 |
$selector = K::get_var( 'email_width_selector', $meta, '' ); |
| 1563 |
$css .= "#fca_eoi_form_$form_id $selector {float:none;margin-left:auto;margin-right:auto;}"; |
| 1564 |
|
| 1565 |
} |
| 1566 |
$show_headline_field = K::get_var( 'show_headline_field', $meta, 'on' ); |
| 1567 |
if ( $show_headline_field === 'off' ) { |
| 1568 |
$css .= "#fca_eoi_form_$form_id .fca_eoi_layout_headline_copy_wrapper {display: none !important;}"; |
| 1569 |
} |
| 1570 |
|
| 1571 |
$show_description_field = K::get_var( 'show_description_field', $meta, 'on' ); |
| 1572 |
if ( $show_description_field === 'off' ) { |
| 1573 |
$css .= "#fca_eoi_form_$form_id .fca_eoi_layout_description_copy_wrapper {display: none !important;}"; |
| 1574 |
} |
| 1575 |
|
| 1576 |
$show_close = K::get_var( 'show_close', $meta, 'on' ); |
| 1577 |
if ( $show_close === 'off' ) { |
| 1578 |
$css .= "#fca_eoi_form_$form_id .fca_eoi_banner_close_btn {display: none !important;}"; |
| 1579 |
} |
| 1580 |
|
| 1581 |
$toggle_position = K::get_var( 'toggle_overlay_position', $meta, 'off' ); |
| 1582 |
$offset = K::get_var( 'offset', $meta, 0 ) . 'px'; |
| 1583 |
|
| 1584 |
if ( $toggle_position === 'on' && strrpos( $layout_id, 'overlay' ) !== false ) { |
| 1585 |
$css .= "#fca_eoi_form_$form_id .fca_eoi_layout_overlay { left: $offset !important; right: initial !important; }"; |
| 1586 |
} else if ( strrpos( $layout_id, 'overlay' ) !== false ) { |
| 1587 |
$css .= "#fca_eoi_form_$form_id .fca_eoi_layout_overlay { right: $offset !important; }"; |
| 1588 |
} |
| 1589 |
if ( $toggle_position === 'on' && strrpos( $layout_id, 'banner' ) !== false ) { |
| 1590 |
$css .= "#fca_eoi_form_$form_id .fca_eoi_layout_banner { bottom: $offset !important; top: initial !important; }"; |
| 1591 |
} else if ( strrpos( $layout_id, 'banner' ) !== false ) { |
| 1592 |
$css .= "#fca_eoi_form_$form_id .fca_eoi_layout_banner { top: $offset !important; }"; |
| 1593 |
} |
| 1594 |
|
| 1595 |
//VENDOR PREFIXED PLACEHOLDER COLORS |
| 1596 |
$placeholder_color = K::get_var( 'email_font_color', $meta, '#000000' ); |
| 1597 |
$css .= "#fca_eoi_form_$form_id .fca_eoi_form_input_element::-webkit-input-placeholder {opacity:0.6;color:$placeholder_color;}"; |
| 1598 |
$css .= "#fca_eoi_form_$form_id .fca_eoi_form_input_element::-moz-placeholder {opacity:0.6;color:$placeholder_color;}"; |
| 1599 |
$css .= "#fca_eoi_form_$form_id .fca_eoi_form_input_element:-ms-input-placeholder {opacity:0.6;color:$placeholder_color;}"; |
| 1600 |
$css .= "#fca_eoi_form_$form_id .fca_eoi_form_input_element:-moz-placeholder {opacity:0.6;color:$placeholder_color;}"; |
| 1601 |
|
| 1602 |
//HOVER |
| 1603 |
$hover_color = K::get_var( 'button_hover_color', $meta, 'initial' ); |
| 1604 |
$selector = K::get_var( 'button_hover_color_selector', $meta, '' ); |
| 1605 |
|
| 1606 |
$s1 = str_replace ( ' input', ':hover', $selector ); |
| 1607 |
$s2 = str_replace ( ' input', ' input:hover', $selector ); |
| 1608 |
|
| 1609 |
$css .= "#fca_eoi_form_$form_id $s1, #fca_eoi_form_$form_id $s2 {background-color:$hover_color !important;}"; |
| 1610 |
|
| 1611 |
//WIDTHS |
| 1612 |
$width_selects = array( |
| 1613 |
'form_width', |
| 1614 |
'name_width', |
| 1615 |
'email_width', |
| 1616 |
'button_width', |
| 1617 |
); |
| 1618 |
|
| 1619 |
forEach ( $width_selects as $w ) { |
| 1620 |
$width = K::get_var( $w, $meta, '100' ); |
| 1621 |
$units = K::get_var( "$w-units", $meta, '%' ); |
| 1622 |
$selector = K::get_var( $w . "_selector", $meta, '' ); |
| 1623 |
$css .= "#fca_eoi_form_$form_id $selector {width:$width$units;}"; |
| 1624 |
|
| 1625 |
} |
| 1626 |
|
| 1627 |
//ADD CSS FROM FILE |
| 1628 |
$css .= $css_file; |
| 1629 |
|
| 1630 |
//ADD CUSTOM CSS FROM SAVE |
| 1631 |
|
| 1632 |
$added_widget_3_css_rule = false; |
| 1633 |
|
| 1634 |
foreach ( $settings as $key => $property ) { |
| 1635 |
$selector = empty ( $meta[$key] ) ? '' : $meta[$key]; |
| 1636 |
$input = str_replace ( '_selector', '', $key); |
| 1637 |
|
| 1638 |
if ( !empty ( $selector ) ) { |
| 1639 |
//SPECIAL CASE FOR BUTTON BORDER |
| 1640 |
if ( $key === 'button_wrapper_background_color_selector' ) { |
| 1641 |
$selector = str_replace ( 'input', '', $selector ); |
| 1642 |
} |
| 1643 |
//SPECIAL CASE FOR WIDGET 3 |
| 1644 |
if ( $selector == '.fca_eoi_layout_3.fca_eoi_layout_widget div.fca_eoi_layout_headline_copy_wrapper div' && !$added_widget_3_css_rule && $input == 'headline_background_color' ) { |
| 1645 |
$css .= "#fca_eoi_form_$form_id form.fca_eoi_layout_3.fca_eoi_layout_widget svg.fca_eoi_layout_headline_copy_triangle { fill: $meta[$input] !important; }"; |
| 1646 |
$added_widget_3_css_rule = true; |
| 1647 |
} |
| 1648 |
|
| 1649 |
$css .= "#fca_eoi_form_$form_id $selector { $property: $meta[$input] !important; }"; |
| 1650 |
|
| 1651 |
} |
| 1652 |
} |
| 1653 |
|
| 1654 |
$animation = isset( $_POST['fca_eoi_animations'] ) && isset( $_POST['fca_eoi_show_animation_checkbox'] ) ? $_POST['fca_eoi_animations'] : ''; |
| 1655 |
update_post_meta( $post->ID, 'fca_eoi_animation', $animation ); |
| 1656 |
|
| 1657 |
$head = $css . '</style>'; |
| 1658 |
|
| 1659 |
$html = fca_eoi_get_html ( $form_id, $meta ); |
| 1660 |
|
| 1661 |
$head = $head . $html; |
| 1662 |
$meta[ 'post_id' ] = $post_id; |
| 1663 |
|
| 1664 |
//format conditions |
| 1665 |
$new_conditions = array(); |
| 1666 |
$conditions = empty ( $meta['publish_lightbox']['conditions'] ) ? array() : $meta['publish_lightbox']['conditions']; |
| 1667 |
|
| 1668 |
forEach ( $conditions as $key => $value ) { |
| 1669 |
$new_conditions[] = array ( |
| 1670 |
'parameter' => $key, |
| 1671 |
'value' => $value, |
| 1672 |
); |
| 1673 |
} |
| 1674 |
$meta['publish_lightbox']['conditions'] = $new_conditions; |
| 1675 |
|
| 1676 |
//SET THE LIVE TO 'FALSE' FOR BACKWARD COMPATIBILITY |
| 1677 |
$meta['publish_lightbox']['live'] = empty ( $meta['publish_lightbox']['live'] ) ? false : true; |
| 1678 |
|
| 1679 |
update_option( 'fca_eoi_last_provider', $meta[ 'provider' ] ); |
| 1680 |
update_option( 'fca_eoi_last_form_meta', $meta ); |
| 1681 |
update_post_meta( $post->ID, 'fca_eoi_meta_format', '2.0' ); |
| 1682 |
update_post_meta( $post->ID, 'fca_eoi', $meta ); |
| 1683 |
update_post_meta( $post->ID, 'fca_eoi_layout', $meta[ 'layout' ] ); |
| 1684 |
update_post_meta( $post->ID, 'fca_eoi_provider', $meta[ 'provider' ] ); |
| 1685 |
update_post_meta( $post->ID, 'fca_eoi_head', $head ); |
| 1686 |
|
| 1687 |
} |
| 1688 |
} |
| 1689 |
} |
| 1690 |
|
| 1691 |
public function live_preview( $content ) { |
| 1692 |
global $post; |
| 1693 |
if (get_post_type() == 'easy-opt-ins' && is_main_query()) { |
| 1694 |
$shortcode = sprintf( '[%s id=%d]', $this->settings[ 'shortcode' ], $post->ID ); |
| 1695 |
return do_shortcode($shortcode); |
| 1696 |
} else { |
| 1697 |
return $content; |
| 1698 |
} |
| 1699 |
} |
| 1700 |
|
| 1701 |
public function admin_enqueue() { |
| 1702 |
|
| 1703 |
$provider = $this->settings[ 'provider' ]; |
| 1704 |
$providers_available = array_keys( $this->settings[ 'providers' ] ); |
| 1705 |
|
| 1706 |
/** |
| 1707 |
* Disable autosaving optin forms since it causes data loss |
| 1708 |
*/ |
| 1709 |
if ( 'easy-opt-ins' == get_post_type() ) { |
| 1710 |
wp_dequeue_script( 'autosave' ); |
| 1711 |
} |
| 1712 |
|
| 1713 |
$screen = get_current_screen(); |
| 1714 |
if( 'easy-opt-ins' === $screen->id ){ |
| 1715 |
global $post; |
| 1716 |
$meta = get_post_meta($post->ID, 'fca_eoi', true ); |
| 1717 |
$options = get_option( 'fca_eoi_settings' ); |
| 1718 |
//LOAD DEPENDENCIES |
| 1719 |
wp_enqueue_script( 'fca_eoi_tooltipster', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster.bundle.min.js', array(), FCA_EOI_VER, true ); |
| 1720 |
wp_enqueue_style( 'fca_eoi_tooltipster_css', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster.bundle.min.css', array(), FCA_EOI_VER ); |
| 1721 |
wp_enqueue_style( 'fca_eoi_tooltipster_theme_css', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster-borderless.min.css', array(), FCA_EOI_VER ); |
| 1722 |
|
| 1723 |
wp_enqueue_style( 'wp-color-picker' ); |
| 1724 |
wp_enqueue_script( 'wp-color-picker' ); |
| 1725 |
wp_enqueue_script( 'select2', '//cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.js', array(), FCA_EOI_VER, true ); |
| 1726 |
wp_enqueue_style( 'font-awesome', '//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css', array(), FCA_EOI_VER ); |
| 1727 |
wp_enqueue_style( 'select2', '//cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.min.css', array(), FCA_EOI_VER ); |
| 1728 |
wp_enqueue_script( 'accordion' ); |
| 1729 |
|
| 1730 |
if ( !empty( $options['animation'] ) ) { |
| 1731 |
wp_enqueue_style( 'fca_eoi_powerups_animate', FCA_EOI_PLUGIN_URL . '/assets/vendor/animate/animate.min.css', array(), FCA_EOI_VER ); |
| 1732 |
} |
| 1733 |
|
| 1734 |
//LOAD CUSTOM AJAX SPINNER CODE/CSS |
| 1735 |
wp_enqueue_script( 'fca-eoi-ajax-spinner', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-ajax-spinner.min.js', array(), FCA_EOI_VER, true ); |
| 1736 |
wp_enqueue_style( 'fca-eoi-ajax-spinner', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-ajax-spinner.min.css', array(), FCA_EOI_VER ); |
| 1737 |
|
| 1738 |
//LOAD COMMON CSS |
| 1739 |
wp_enqueue_style( 'fca-eoi-common-css', FCA_EOI_PLUGIN_URL .'/assets/style-new.min.css', array(), FCA_EOI_VER ); |
| 1740 |
|
| 1741 |
//LOAD EDITOR JS |
| 1742 |
wp_enqueue_script( 'fca-eoi-editor', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-editor.min.js', array('jquery', 'fca_eoi_tooltipster', 'wp-color-picker', 'select2', 'accordion' ), FCA_EOI_VER, true ); |
| 1743 |
wp_enqueue_script( 'fca-eoi-rules', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-rules.min.js', array('jquery' ), FCA_EOI_VER, true ); |
| 1744 |
|
| 1745 |
//LOAD PROVIDER JS AND CSS |
| 1746 |
foreach ( $providers_available as $provider ) { |
| 1747 |
wp_enqueue_script( 'admin-cpt-easy-opt-ins-' . $provider, FCA_EOI_PLUGIN_URL . '/providers/' . $provider . '/cpt-easy-opt-ins.min.js', array(), FCA_EOI_VER, true ); |
| 1748 |
|
| 1749 |
$css_path = '/providers/' . $provider . '/cpt-easy-opt-ins.min.css'; |
| 1750 |
if ( is_readable( FCA_EOI_PLUGIN_DIR . $css_path ) ) { |
| 1751 |
wp_enqueue_style( 'admin-cpt-easy-opt-ins-' . $provider, FCA_EOI_PLUGIN_URL . $css_path, array(), FCA_EOI_VER ); |
| 1752 |
} |
| 1753 |
} |
| 1754 |
//SEND VARIABLES TO JS |
| 1755 |
$useGroups = empty ( $options['mailchimp_groups'] ) ? array('off') : array('on') ; |
| 1756 |
wp_localize_script( 'admin-cpt-easy-opt-ins-mailchimp', 'fcaEoiUseGroups', $useGroups ); |
| 1757 |
|
| 1758 |
$tags = empty($meta['aweber_tags']) ? '' : $meta['aweber_tags']; |
| 1759 |
$aweberSettings = array( |
| 1760 |
'tags' => $tags, |
| 1761 |
); |
| 1762 |
wp_localize_script( 'admin-cpt-easy-opt-ins-aweber', 'fcaEoiAweberSettings', $aweberSettings ); |
| 1763 |
|
| 1764 |
$file = plugin_dir_path( __FILE__ ) . "layout-cache"; |
| 1765 |
$layout_data = unserialize (file_get_contents($file)); |
| 1766 |
|
| 1767 |
wp_localize_script( 'fca-eoi-editor', 'fcaEoiLayouts', $layout_data ); |
| 1768 |
|
| 1769 |
//EDITOR CSS |
| 1770 |
wp_enqueue_style( 'fca-eoi-editor-css', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-editor.min.css', array(), FCA_EOI_VER ); |
| 1771 |
|
| 1772 |
if ( has_action( 'fca_eoi_powerups' ) ) { |
| 1773 |
wp_enqueue_script('fca_eoi_powerups', FCA_EOI_PLUGIN_URL . '/assets/powerups/fca_eoi_powerups.min.js', array(), FCA_EOI_VER, true); |
| 1774 |
} |
| 1775 |
} |
| 1776 |
if( 'widgets' === $screen->id ){ |
| 1777 |
wp_enqueue_script( 'select2', '//cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.js', array(), FCA_EOI_VER, true ); |
| 1778 |
wp_enqueue_style( 'select2', '//cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.min.css', array(), FCA_EOI_VER ); |
| 1779 |
} |
| 1780 |
} |
| 1781 |
|
| 1782 |
/** |
| 1783 |
* Hides minor publising form items (status, visibility and publication date) |
| 1784 |
* |
| 1785 |
* This function shoud be used along with force_published to prevent |
| 1786 |
* saving posts as drafts |
| 1787 |
*/ |
| 1788 |
public function hide_minor_publishing() { |
| 1789 |
$screen = get_current_screen(); |
| 1790 |
if( in_array( $screen->id, array( 'easy-opt-ins' ) ) ) { |
| 1791 |
echo '<style>#minor-publishing { display: none; }</style>'; |
| 1792 |
} |
| 1793 |
} |
| 1794 |
|
| 1795 |
public function onboard_help() { |
| 1796 |
|
| 1797 |
$current_screen = get_current_screen(); |
| 1798 |
|
| 1799 |
// Exit function if we are not on the opt-in list |
| 1800 |
if ( $current_screen->id === 'edit-easy-opt-ins' ) { |
| 1801 |
$posts = get_posts( 'posts_per_page=-1&post_type=easy-opt-ins' ); |
| 1802 |
|
| 1803 |
if ( empty ( $posts ) ) { |
| 1804 |
|
| 1805 |
wp_enqueue_style( 'fca_eoi_onboard_stylesheet', FCA_EOI_PLUGIN_URL . '/assets/admin/onboard.min.css', array(), FCA_EOI_VER ); |
| 1806 |
|
| 1807 |
echo '<div class="error fca_eoi_onboard_div">'; |
| 1808 |
|
| 1809 |
echo '<img id="fca_eoi_onboard_text" src="' . FCA_EOI_PLUGIN_URL . '/assets/admin/onboarding-text.png' . '">'; |
| 1810 |
echo '<img id="fca_eoi_onboard_arrow" src="' . FCA_EOI_PLUGIN_URL . '/assets/admin/onboarding-arrow.png' . '">'; |
| 1811 |
echo '</div>'; |
| 1812 |
} |
| 1813 |
} |
| 1814 |
} |
| 1815 |
|
| 1816 |
public function google_changes_notice() { |
| 1817 |
|
| 1818 |
$dismissed = get_option ( 'fca_eoi_dismiss_google_changes' ); |
| 1819 |
|
| 1820 |
if ( $dismissed !== 'true' ) { |
| 1821 |
|
| 1822 |
wp_enqueue_script( 'fca_eoi_dismiss_review_js', FCA_EOI_PLUGIN_URL . '/assets/admin/dismiss.min.js', array(), FCA_EOI_VER ); |
| 1823 |
wp_localize_script( 'fca_eoi_dismiss_review_js', 'fcaEoiDismiss', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'fca_eoi_dismiss' ) ) ); |
| 1824 |
$blog_link = 'https://fatcatapps.com/interstitials-update/'; |
| 1825 |
|
| 1826 |
echo '<div class="notice notice-info fca_eoi_review_div" style="padding-bottom: 8px;">'; |
| 1827 |
echo '<img style="float:left" width="120" height="120" src="' . FCA_EOI_PLUGIN_URL . '/assets/admin/optincat.png' . '">'; |
| 1828 |
echo '<p><strong>' . __( "Optin Cat: New Google algorithm update may affect your rankings", 'easy-opt-ins' ) . '</strong></p>'; |
| 1829 |
|
| 1830 |
echo '<p>' . __( "Google has recently made changes to its mobile search results. These changes may negatively impact sites that use popups on mobile devices if no action is taken.", 'easy-opt-ins') . '</p>'; |
| 1831 |
echo '<br>'; |
| 1832 |
|
| 1833 |
echo "<a target='_blank' href='$blog_link' class='button button-primary'>" . __( 'Learn More & Fix This', 'easy-opt-ins') . "</a> "; |
| 1834 |
echo "<button type='button' class='button button-secondary' data-option='fca_eoi_dismiss_google_changes' id='fca-eoi-dismiss-review-btn'>" . __( 'Dismiss', 'easy-opt-ins') . "</button>"; |
| 1835 |
echo '<br style="clear:both">'; |
| 1836 |
echo '</div>'; |
| 1837 |
} |
| 1838 |
} |
| 1839 |
|
| 1840 |
public function review_notice() { |
| 1841 |
|
| 1842 |
$dismissed = get_option ( 'fca_eoi_dismiss_review' ); |
| 1843 |
|
| 1844 |
if ( $dismissed !== 'true' ) { |
| 1845 |
$activity = EasyOptInsActivity::get_instance(); |
| 1846 |
$stats = $activity->get_form_stats( $this->activity_day_interval['form_list'] ); |
| 1847 |
$conversions = empty ( $stats['conversions'] ) ? array() : $stats['conversions']; |
| 1848 |
$conversions = array_sum ( $conversions ); |
| 1849 |
|
| 1850 |
if ( $conversions >= 25 ) { |
| 1851 |
$review_link = 'https://wordpress.org/support/plugin/' . FCA_EOI_PLUGIN_SLUG . '/reviews/?rate=5#new-post'; |
| 1852 |
|
| 1853 |
wp_enqueue_script( 'fca_eoi_dismiss_review_js', FCA_EOI_PLUGIN_URL . '/assets/admin/dismiss.min.js', array(), FCA_EOI_VER ); |
| 1854 |
wp_localize_script( 'fca_eoi_dismiss_review_js', 'fcaEoiDismiss', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'fca_eoi_dismiss' ) ) ); |
| 1855 |
|
| 1856 |
echo '<div class="notice notice-success fca_eoi_review_div">'; |
| 1857 |
echo '<img style="float:left" width="120" height="120" src="' . FCA_EOI_PLUGIN_URL . '/assets/admin/optincat.png' . '">'; |
| 1858 |
echo '<p><strong>' . __( "Great work! You've gotten more than 25 email subscribers using Optin Cat.", 'easy-opt-ins' ) . '</strong></p>'; |
| 1859 |
|
| 1860 |
echo '<p>' . sprintf( __( "If you love Optin Cat, why not leave us a nice review on %sWordPress.org%s? Reviews keeps us motivated - we'd really appreciate it.", 'easy-opt-ins' ), "<a target='_blank' href='$review_link'>", '</a>') . '</p>'; |
| 1861 |
echo '<br>'; |
| 1862 |
|
| 1863 |
echo "<a target='_blank' href='$review_link' class='button button-primary'>" . __( 'Leave a Review', 'easy-opt-ins') . "</a> "; |
| 1864 |
echo "<button type='button' class='button button-secondary' data-option='fca_eoi_dismiss_review' id='fca-eoi-dismiss-review-btn'>" . __( 'Dismiss', 'easy-opt-ins') . "</button>"; |
| 1865 |
echo '<br style="clear:both">'; |
| 1866 |
echo '</div>'; |
| 1867 |
|
| 1868 |
} |
| 1869 |
} |
| 1870 |
} |
| 1871 |
|
| 1872 |
public function ajax_dismiss_notice() { |
| 1873 |
|
| 1874 |
$nonce = empty ( $_REQUEST['nonce'] ) ? '' : $_REQUEST['nonce']; |
| 1875 |
$option = empty ( $_REQUEST['option'] ) ? 'fca_eoi_dismiss_review' : $_REQUEST['option']; |
| 1876 |
|
| 1877 |
if ( wp_verify_nonce ( $nonce, 'fca_eoi_dismiss') == 1 ) { |
| 1878 |
if ( update_option( $option, 'true' ) ) { |
| 1879 |
wp_send_json_success( $option ); |
| 1880 |
} |
| 1881 |
} |
| 1882 |
wp_send_json_error(); |
| 1883 |
} |
| 1884 |
|
| 1885 |
/** |
| 1886 |
* Forces one column |
| 1887 |
*/ |
| 1888 |
public function force_one_column() { |
| 1889 |
|
| 1890 |
return 1; |
| 1891 |
} |
| 1892 |
|
| 1893 |
/** |
| 1894 |
* Sort metaboxes |
| 1895 |
*/ |
| 1896 |
public function order_columns( $order ) { |
| 1897 |
return array( |
| 1898 |
'normal' => join( ",", array( |
| 1899 |
'submitdiv', |
| 1900 |
'fca_eoi_meta_box_nav', |
| 1901 |
'fca_eoi_meta_box_setup', |
| 1902 |
'fca_eoi_meta_box_build', |
| 1903 |
'fca_eoi_meta_box_provider', |
| 1904 |
'fca_eoi_meta_box_thanks', |
| 1905 |
'fca_eoi_meta_box_publish', |
| 1906 |
'fca_eoi_meta_box_powerups', |
| 1907 |
'fca_eoi_meta_box_debug', |
| 1908 |
) ), |
| 1909 |
'side' => '', |
| 1910 |
'advanced' => '', |
| 1911 |
); |
| 1912 |
} |
| 1913 |
|
| 1914 |
/** |
| 1915 |
* replacing the default "Enter title here" placeholder text in the title input box to |
| 1916 |
* |
| 1917 |
*/ |
| 1918 |
public function change_default_title($title) { |
| 1919 |
|
| 1920 |
$screen = get_current_screen(); |
| 1921 |
|
| 1922 |
if ( 'easy-opt-ins' == $screen->post_type ) { |
| 1923 |
$title = 'Enter name here'; |
| 1924 |
} |
| 1925 |
|
| 1926 |
return $title; |
| 1927 |
} |
| 1928 |
|
| 1929 |
/** |
| 1930 |
* Override some strings to match our likings |
| 1931 |
*/ |
| 1932 |
public function override_text( $messages ) { |
| 1933 |
|
| 1934 |
global $post; |
| 1935 |
|
| 1936 |
$post_ID = $post->ID; |
| 1937 |
$post_type = get_post_type( $post_ID ); |
| 1938 |
|
| 1939 |
$obj = get_post_type_object( $post_type ); |
| 1940 |
$singular = $obj->labels->singular_name; |
| 1941 |
|
| 1942 |
if ( 'easy-opt-ins' === $post->post_type ) { |
| 1943 |
|
| 1944 |
$messages[$post_type] = array( |
| 1945 |
0 => '', // Unused. Messages start at index 1. |
| 1946 |
1 => __( 'Opt-In Form updated.' ), |
| 1947 |
2 => __( 'Opt-In Form updated.' ), |
| 1948 |
3 => __( 'Opt-In Form deleted.' ), |
| 1949 |
4 => __( 'Opt-In Form updated.' ), |
| 1950 |
5 => isset( $_GET['revision']) ? sprintf( __('%2$s restored to revision from %1$s' ), wp_post_revision_title( (int) $_GET['revision'], false ), esc_attr( $singular ) ) : false, |
| 1951 |
6 => __( 'Opt-In Form saved.' ), |
| 1952 |
7 => sprintf( __( '%s saved.' ), esc_attr( $singular ) ), |
| 1953 |
8 => sprintf( __( '%s submitted. <a href="%s" target="_blank">Preview %s</a>'), $singular, esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ), strtolower( $singular ) ), |
| 1954 |
9 => sprintf( __( '%s scheduled for: <strong>%s</strong>. <a href="%s" target="_blank">Preview %s</a>' ), $singular, date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post_ID ) ), strtolower( $singular ) ), |
| 1955 |
10 => sprintf( __( '%s draft updated. <a href="%s" target="_blank">Preview %s</a>'), $singular, esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ), strtolower( $singular ) ) |
| 1956 |
); |
| 1957 |
|
| 1958 |
} |
| 1959 |
|
| 1960 |
return $messages; |
| 1961 |
|
| 1962 |
} |
| 1963 |
|
| 1964 |
public function force_published( $post ) { |
| 1965 |
|
| 1966 |
if( ! in_array( $post[ 'post_status' ], array( 'auto-draft', 'trash') ) ) { |
| 1967 |
if( in_array( $post[ 'post_type' ], array( 'easy-opt-ins' ) ) ) { |
| 1968 |
$post['post_status'] = 'publish'; |
| 1969 |
} |
| 1970 |
} |
| 1971 |
return $post; |
| 1972 |
} |
| 1973 |
|
| 1974 |
/** |
| 1975 |
* Disables bulk editing |
| 1976 |
*/ |
| 1977 |
public function disable_bulk_edit( $actions ){ |
| 1978 |
unset( $actions[ 'edit' ] ); |
| 1979 |
return $actions; |
| 1980 |
} |
| 1981 |
|
| 1982 |
/** |
| 1983 |
* Removes quick edit |
| 1984 |
*/ |
| 1985 |
public function remove_quick_edit( $actions ) { |
| 1986 |
global $post; |
| 1987 |
if( 'easy-opt-ins' === $post->post_type ) { |
| 1988 |
unset($actions['inline hide-if-no-js']); |
| 1989 |
} |
| 1990 |
return $actions; |
| 1991 |
} |
| 1992 |
|
| 1993 |
/** |
| 1994 |
* Add the desired body classes (backend) |
| 1995 |
*/ |
| 1996 |
public function add_body_class( $classes ) { |
| 1997 |
return "$classes fca_eoi"; |
| 1998 |
} |
| 1999 |
|
| 2000 |
|
| 2001 |
/** |
| 2002 |
* Handle Adding a subscriber with Ajax |
| 2003 |
*/ |
| 2004 |
public function ajax_subscribe() { |
| 2005 |
|
| 2006 |
$error = ''; |
| 2007 |
// Get meta |
| 2008 |
$id = $_REQUEST['form_id']; |
| 2009 |
|
| 2010 |
if (empty ($id)){ |
| 2011 |
$error .= "Couldn't find form ID"; |
| 2012 |
} |
| 2013 |
|
| 2014 |
$fca_eoi = get_post_meta( $id, 'fca_eoi', true ); |
| 2015 |
|
| 2016 |
if (empty ($fca_eoi)){ |
| 2017 |
$error .= "Couldn't find post meta"; |
| 2018 |
} |
| 2019 |
|
| 2020 |
$provider = K::get_var( 'provider' , $fca_eoi ); |
| 2021 |
|
| 2022 |
// Check a list_id is provided |
| 2023 |
$list_id = K::get_var( $provider . '_list_id' , $fca_eoi ); |
| 2024 |
if ( empty( $list_id ) ) { |
| 2025 |
$error .= "List not set"; |
| 2026 |
} |
| 2027 |
|
| 2028 |
$nonce = $_REQUEST['nonce']; |
| 2029 |
$nonceVerified = wp_verify_nonce( $nonce, 'fca_eoi_submit_form' ); |
| 2030 |
if ($nonceVerified === FALSE) { |
| 2031 |
$error .= "Couldn't verify form submission"; |
| 2032 |
} |
| 2033 |
|
| 2034 |
// Subscribe user |
| 2035 |
$status = false; |
| 2036 |
|
| 2037 |
if( $list_id && $nonceVerified !== FALSE ) { |
| 2038 |
$str = $provider . '_add_user'; |
| 2039 |
|
| 2040 |
$status = call_user_func( $provider . '_add_user' , $this->settings , $_POST , $list_id ); |
| 2041 |
|
| 2042 |
do_action('fca_eoi_after_submission', $fca_eoi, $_POST ); |
| 2043 |
|
| 2044 |
if ($status !== TRUE) { |
| 2045 |
$error .= " Can't add user"; |
| 2046 |
} |
| 2047 |
} |
| 2048 |
|
| 2049 |
if ( $status !== FALSE && $error === '' ) { |
| 2050 |
echo '✓'; |
| 2051 |
EasyOptInsActivity::get_instance()->add_conversion( $id ); |
| 2052 |
} else { |
| 2053 |
echo '✗' . " Error: " . $error; |
| 2054 |
} |
| 2055 |
|
| 2056 |
exit; |
| 2057 |
} |
| 2058 |
|
| 2059 |
public function admin_notices() { |
| 2060 |
|
| 2061 |
//RN NOTE: MAYBE REWRITE |
| 2062 |
$current_screen = get_current_screen(); |
| 2063 |
|
| 2064 |
// Exit function if we are not on the opt-in editing page |
| 2065 |
if ( ! ( |
| 2066 |
'easy-opt-ins' === $current_screen->id |
| 2067 |
&& 'post' === $current_screen->base |
| 2068 |
&& 'edit' === $current_screen->parent_base |
| 2069 |
&& '' === $current_screen->action |
| 2070 |
) ) { |
| 2071 |
return; |
| 2072 |
} |
| 2073 |
|
| 2074 |
global $post; |
| 2075 |
$fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true ); |
| 2076 |
$provider = K::get_var( 'provider', $fca_eoi); |
| 2077 |
$errors = array(); |
| 2078 |
|
| 2079 |
// Add error for missing thank you page |
| 2080 |
$confirmation_page_set = ( bool ) K::get_var( 'thank_you_page', $fca_eoi); |
| 2081 |
if( ! $confirmation_page_set ) { |
| 2082 |
$errors[] = __( 'No "Thank you" page selected. You will not be able to use this form.' ); |
| 2083 |
} |
| 2084 |
|
| 2085 |
// Add error for missing list setting for the current provider |
| 2086 |
$list_set = ( bool ) K::get_var( $provider . '_list_id', $fca_eoi); |
| 2087 |
|
| 2088 |
// @todo: remove |
| 2089 |
// Hack for mailchimp upgrade |
| 2090 |
if( empty( $fca_eoi[ 'provider' ] ) ) { |
| 2091 |
$fca_eoi[ 'mailchimp_list_id' ] = K::get_var( |
| 2092 |
'mailchimp_list_id' |
| 2093 |
, $fca_eoi |
| 2094 |
, K::get_var( 'list_id' , $fca_eoi ) |
| 2095 |
); |
| 2096 |
$list_set = ( bool ) K::get_var( 'mailchimp_list_id', $fca_eoi); |
| 2097 |
} |
| 2098 |
// End of Hack |
| 2099 |
|
| 2100 |
|
| 2101 |
if( ! $list_set ) { |
| 2102 |
$errors[] = __( 'No List selected. You will not be able to use this form.' ); |
| 2103 |
} |
| 2104 |
|
| 2105 |
$errors = apply_filters( 'fca_eoi_alter_admin_notices', $errors ); |
| 2106 |
|
| 2107 |
foreach ( $errors as $error ) { |
| 2108 |
echo '<div class="error"><p>' . $error . '</p></div>'; |
| 2109 |
} |
| 2110 |
} |
| 2111 |
|
| 2112 |
public function bind_content_filter() { |
| 2113 |
|
| 2114 |
// Do nothing in backend |
| 2115 |
if ( is_admin() ) { |
| 2116 |
return; |
| 2117 |
} |
| 2118 |
|
| 2119 |
add_action( 'wp', array( $this, 'content' ), 10 ); |
| 2120 |
} |
| 2121 |
|
| 2122 |
//SEARCH THE CONTENT AND APPEND ANY RELEVANT POST BOXES |
| 2123 |
public function content() { |
| 2124 |
|
| 2125 |
global $post; |
| 2126 |
|
| 2127 |
// Work only when viewing a post of any type & not viewing an opt-in editor |
| 2128 |
if ( empty( $post ) OR $post->post_type === 'easy-opt-ins' ) { |
| 2129 |
return; |
| 2130 |
} |
| 2131 |
|
| 2132 |
//ADD SESSION COOKIE TRACKING SCRIPT |
| 2133 |
wp_enqueue_script( 'fca_eoi_pagecount_js', FCA_EOI_PLUGIN_URL.'/assets/pagecount.min.js', array(), FCA_EOI_VER, true ); |
| 2134 |
|
| 2135 |
$priorities = array(); |
| 2136 |
|
| 2137 |
// Post details |
| 2138 |
$post_ID = $post->ID; |
| 2139 |
$post_type = get_post_type( $post_ID ); |
| 2140 |
|
| 2141 |
// Build the array for testing |
| 2142 |
$post_cond = array( |
| 2143 |
'*', |
| 2144 |
$post_type, |
| 2145 |
'#' . $post_ID, |
| 2146 |
); |
| 2147 |
if ( is_front_page() ) { |
| 2148 |
$post_cond[] = '~'; |
| 2149 |
} |
| 2150 |
|
| 2151 |
$priorities[] = '#' . $post_ID; |
| 2152 |
|
| 2153 |
$taxonomies = get_taxonomies('', 'names'); |
| 2154 |
$post_taxonomies = wp_get_object_terms( $post->ID, $taxonomies); |
| 2155 |
foreach ( $post_taxonomies as $t ) { |
| 2156 |
$condition = $post_type . ':' . $t->term_id; |
| 2157 |
|
| 2158 |
$post_cond[] = $condition; |
| 2159 |
$priorities[] = $condition; |
| 2160 |
} |
| 2161 |
|
| 2162 |
$priorities[] = $post_type; |
| 2163 |
$priorities[] = '*'; |
| 2164 |
|
| 2165 |
$optins = get_posts( 'posts_per_page=99&post_type=easy-opt-ins' ); |
| 2166 |
|
| 2167 |
$fca_eoi_postboxes = array(); |
| 2168 |
|
| 2169 |
foreach ( $optins as $i => $p ) { |
| 2170 |
$fca_eoi_postboxes[ $i ][ 'post' ] = $p; |
| 2171 |
$fca_eoi_postboxes[ $i ][ 'fca_eoi' ] = get_post_meta( $p->ID, 'fca_eoi', true ); |
| 2172 |
} |
| 2173 |
|
| 2174 |
$postboxes = array(); |
| 2175 |
|
| 2176 |
// Append postcode shortcode when the conditions match |
| 2177 |
foreach( $fca_eoi_postboxes as $f ) { |
| 2178 |
|
| 2179 |
// Get conditions |
| 2180 |
$eoi_form_cond = K::get_var( 'publish_postbox', $f[ 'fca_eoi' ], array() ); |
| 2181 |
|
| 2182 |
// Append |
| 2183 |
if ( array_intersect( $eoi_form_cond, $post_cond ) ) { |
| 2184 |
foreach ( $eoi_form_cond as $cond ) { |
| 2185 |
if ( empty( $postboxes[ $cond ] ) ) { |
| 2186 |
$postboxes[ $cond ] = sprintf( '[%s id=%d]', $this->settings['shortcode'], $f['post']->ID ); |
| 2187 |
} |
| 2188 |
} |
| 2189 |
} |
| 2190 |
} |
| 2191 |
|
| 2192 |
if ( ! empty( $postboxes ) ) { |
| 2193 |
foreach ( $priorities as $cond ) { |
| 2194 |
if ( !empty( $postboxes[ $cond ] ) ) { |
| 2195 |
$post->post_content .= $postboxes[ $cond ]; |
| 2196 |
return; |
| 2197 |
} |
| 2198 |
} |
| 2199 |
|
| 2200 |
$post->post_content .= reset( $postboxes ); |
| 2201 |
return; |
| 2202 |
} |
| 2203 |
} |
| 2204 |
|
| 2205 |
public function scan_for_shortcodes( $content ) { |
| 2206 |
if ( preg_match_all( '/data-optin-cat\s*=\s*["\']?\s*(\d+)/', $content, $matches ) ) { |
| 2207 |
$this->two_step_ids_on_page = array_map( 'intval', $matches[1] ); |
| 2208 |
} |
| 2209 |
|
| 2210 |
return $content; |
| 2211 |
} |
| 2212 |
|
| 2213 |
public function maybe_show_lightbox() { |
| 2214 |
|
| 2215 |
// Get lightboxes |
| 2216 |
$lightboxes = get_posts( array( |
| 2217 |
'post_type' => 'easy-opt-ins', |
| 2218 |
'posts_per_page' => -1, |
| 2219 |
'orderby' => 'ID', |
| 2220 |
'meta_key' => 'fca_eoi_layout', |
| 2221 |
'meta_value' => 'lightbox_', |
| 2222 |
'meta_compare' => 'like', |
| 2223 |
) ); |
| 2224 |
|
| 2225 |
// BANNERS |
| 2226 |
$banners = get_posts( array( |
| 2227 |
'post_type' => 'easy-opt-ins', |
| 2228 |
'posts_per_page' => -1, |
| 2229 |
'orderby' => 'ID', |
| 2230 |
'meta_key' => 'fca_eoi_layout', |
| 2231 |
'meta_value' => 'banner_', |
| 2232 |
'meta_compare' => 'like', |
| 2233 |
) ); |
| 2234 |
|
| 2235 |
//OVERLAY AND BANNERS WORK FUNCTIONALLY THE SAME |
| 2236 |
$banners = array_merge ( $banners, get_posts( array( |
| 2237 |
'post_type' => 'easy-opt-ins', |
| 2238 |
'posts_per_page' => -1, |
| 2239 |
'orderby' => 'ID', |
| 2240 |
'meta_key' => 'fca_eoi_layout', |
| 2241 |
'meta_value' => 'overlay_', |
| 2242 |
'meta_compare' => 'like', |
| 2243 |
) ) ); |
| 2244 |
|
| 2245 |
if( empty( $lightboxes ) && empty ( $banners ) ) { |
| 2246 |
return false; |
| 2247 |
} |
| 2248 |
|
| 2249 |
$two_step_popups = array(); |
| 2250 |
$traditional_popups = array(); |
| 2251 |
$banners_to_show = array(); |
| 2252 |
|
| 2253 |
foreach ( $banners as $banner ) { |
| 2254 |
$m = get_post_meta( $banner->ID , 'fca_eoi', true ); |
| 2255 |
$conditions = K::get_var( 'publish_lightbox', $m, array() ); |
| 2256 |
|
| 2257 |
if ( $this->test_server_conditions( $conditions ) ) { |
| 2258 |
$banners_to_show[] = array( |
| 2259 |
'id' => $banner->ID, |
| 2260 |
'meta' => $m, |
| 2261 |
'conditions' => $conditions, |
| 2262 |
); |
| 2263 |
} |
| 2264 |
} |
| 2265 |
|
| 2266 |
foreach ( $lightboxes as $lightbox ) { |
| 2267 |
|
| 2268 |
// Get conditions |
| 2269 |
$lightbox->fca_eoi = get_post_meta( $lightbox->ID , 'fca_eoi', true ); |
| 2270 |
$publish_lightbox_mode = K::get_var( 'publish_lightbox_mode', $lightbox->fca_eoi, array() ); |
| 2271 |
|
| 2272 |
$lightbox_conditions = K::get_var( 'publish_lightbox', $lightbox->fca_eoi, array() ); |
| 2273 |
|
| 2274 |
// If on a free distribution, force traditional popup mode |
| 2275 |
if ( $this->settings['distribution'] === 'free' ) { |
| 2276 |
$publish_lightbox_mode = 'traditional_popup'; |
| 2277 |
} |
| 2278 |
|
| 2279 |
if ( 'two_step_optin' === $publish_lightbox_mode ) { |
| 2280 |
$two_step_popups[] = $lightbox->ID; |
| 2281 |
} else if ( $this->test_server_conditions( $lightbox_conditions ) ) { |
| 2282 |
$traditional_popups[] = array( |
| 2283 |
'id' => $lightbox->ID, |
| 2284 |
'meta' => $lightbox->fca_eoi, |
| 2285 |
'conditions' => $lightbox_conditions, |
| 2286 |
); |
| 2287 |
} |
| 2288 |
} |
| 2289 |
|
| 2290 |
$two_step_popups = array_intersect( $two_step_popups, $this->two_step_ids_on_page ); |
| 2291 |
|
| 2292 |
if ( !empty( $traditional_popups ) OR !empty( $two_step_popups ) OR !empty( $banners_to_show ) ) { |
| 2293 |
wp_enqueue_script ( 'jquery' ); |
| 2294 |
wp_enqueue_style( 'fca_eoi_tooltipster_css', FCA_EOI_PLUGIN_URL.'/assets/vendor/tooltipster/tooltipster.bundle.min.css', array(), FCA_EOI_VER ); |
| 2295 |
wp_enqueue_style( 'fca_eoi_tooltipster_borderless', FCA_EOI_PLUGIN_URL.'/assets/vendor/tooltipster/tooltipster-borderless.min.css', array(), FCA_EOI_VER ); |
| 2296 |
wp_enqueue_script( 'fca_eoi_tooltipster_js', FCA_EOI_PLUGIN_URL.'/assets/vendor/tooltipster/tooltipster.bundle.min.js', array(), FCA_EOI_VER, true ); |
| 2297 |
|
| 2298 |
wp_enqueue_script( 'fca_eoi_featherlight_js', FCA_EOI_PLUGIN_URL.'/assets/vendor/featherlight/release/featherlight.min.js', array(), FCA_EOI_VER, true ); |
| 2299 |
wp_enqueue_style( 'fca_eoi_featherlight_css', FCA_EOI_PLUGIN_URL.'/assets/vendor/featherlight/release/featherlight.min.css', array(), FCA_EOI_VER ); |
| 2300 |
|
| 2301 |
wp_enqueue_script( 'fca_eoi_script_js', FCA_EOI_PLUGIN_URL.'/assets/script.min.js', array( 'jquery', 'fca_eoi_tooltipster_js', 'fca_eoi_featherlight_js' ), FCA_EOI_VER, true ); |
| 2302 |
|
| 2303 |
$data = array ( |
| 2304 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 2305 |
'nonce' => wp_create_nonce( 'fca_eoi_submit_form' ), |
| 2306 |
); |
| 2307 |
wp_localize_script( 'fca_eoi_script_js', 'fcaEoiScriptData', $data ); |
| 2308 |
|
| 2309 |
empty ( $traditional_popups ) ? '' : $this->display_traditional_popups( $traditional_popups ); |
| 2310 |
empty ( $two_step_popups ) ? '' : $this->display_two_step_popups( $two_step_popups ); |
| 2311 |
empty ( $banners_to_show ) ? '' : $this->display_banners( $banners_to_show ); |
| 2312 |
} |
| 2313 |
|
| 2314 |
} |
| 2315 |
|
| 2316 |
public function test_server_conditions( $conditions ) { |
| 2317 |
|
| 2318 |
//CHECK FOR LIVE |
| 2319 |
if ( ! K::get_var( 'live', $conditions, true ) ) { |
| 2320 |
return false; |
| 2321 |
} |
| 2322 |
|
| 2323 |
//CHECK MOBILE |
| 2324 |
$mobile_detect = new Mobile_Detect; |
| 2325 |
$is_mobile = $mobile_detect->isMobile(); |
| 2326 |
|
| 2327 |
$mobile_mode = K::get_var( 'devices', $conditions, 'all' ); |
| 2328 |
$fail_mobile = $mobile_mode === 'mobile' && !$is_mobile; |
| 2329 |
$fail_desktop = $mobile_mode === 'desktop' && $is_mobile; |
| 2330 |
$pass_mobile = !$fail_mobile && !$fail_desktop; |
| 2331 |
|
| 2332 |
if ( empty( $conditions['conditions'] ) ) { |
| 2333 |
return $pass_mobile; |
| 2334 |
} |
| 2335 |
|
| 2336 |
//CHECK INCLUDED AND EXCLUDED PAGES & TAXONOMIES |
| 2337 |
global $post; |
| 2338 |
$post_id = $post->ID; |
| 2339 |
|
| 2340 |
$includes = array(); |
| 2341 |
$excludes = array(); |
| 2342 |
|
| 2343 |
forEach ( $conditions['conditions'] as $condition ) { |
| 2344 |
if ( $condition['parameter'] === 'exclude' ) { |
| 2345 |
$excludes = $condition['value']; |
| 2346 |
} else if ( $condition['parameter'] === 'include' ) { |
| 2347 |
$includes = $condition['value']; |
| 2348 |
} |
| 2349 |
} |
| 2350 |
|
| 2351 |
$post_cond = array( '*' ); |
| 2352 |
|
| 2353 |
if ( is_front_page() ) { |
| 2354 |
$post_cond[] = '~'; |
| 2355 |
} |
| 2356 |
|
| 2357 |
if ( $post_id ) { |
| 2358 |
$post_type = get_post_type( $post_id ); |
| 2359 |
$post_cond[] = $post_type; |
| 2360 |
$post_cond[] = '#' . $post_id; |
| 2361 |
$taxonomies = get_taxonomies( '', 'names' ); |
| 2362 |
$post_taxonomies = wp_get_object_terms( $post_id, $taxonomies ); |
| 2363 |
foreach ( $post_taxonomies as $t ) { |
| 2364 |
$post_cond[] = $post_type . ':' . $t->term_id; |
| 2365 |
} |
| 2366 |
} else { |
| 2367 |
//FIX FOR NOT DISPLAYING ON BLOG PAGE |
| 2368 |
if ( is_home() ) { |
| 2369 |
$post_cond[] = '#' . get_option('page_for_posts'); |
| 2370 |
} |
| 2371 |
|
| 2372 |
} |
| 2373 |
|
| 2374 |
$pass_includes = empty( $includes ) ? true : count ( array_intersect( $includes, $post_cond ) ) > 0; |
| 2375 |
$pass_excludes = empty( $excludes ) ? true : count ( array_intersect( $excludes, $post_cond ) ) == 0; |
| 2376 |
|
| 2377 |
return $pass_includes && $pass_excludes && $pass_mobile; |
| 2378 |
|
| 2379 |
} |
| 2380 |
|
| 2381 |
private function display_two_step_popups( $lightbox_ids ) { |
| 2382 |
wp_enqueue_script( 'fca_eoi_twostep_js', FCA_EOI_PLUGIN_URL.'/assets/twostep.min.js', array( 'jquery', 'fca_eoi_tooltipster_js', 'fca_eoi_featherlight_js', 'fca_eoi_script_js' ), FCA_EOI_VER, true ); |
| 2383 |
|
| 2384 |
foreach ( $lightbox_ids as $id ) { |
| 2385 |
$this->prepare_lightbox_html( $id ); |
| 2386 |
} |
| 2387 |
} |
| 2388 |
|
| 2389 |
private function display_banners( $banners ) { |
| 2390 |
|
| 2391 |
$target_data = array(); |
| 2392 |
|
| 2393 |
forEach ( $banners as $p ) { |
| 2394 |
$id = $p['id']; |
| 2395 |
$target_data[$id] = empty( $p['conditions'] ) ? array() : $p['conditions']; |
| 2396 |
|
| 2397 |
echo "<div id='fca_eoi_banner_$id' style='display:none;'>"; |
| 2398 |
echo do_shortcode( "[easy-opt-in id=$id]" ); |
| 2399 |
echo '</div>'; |
| 2400 |
} |
| 2401 |
|
| 2402 |
wp_enqueue_script( 'fca_eoi_targeting_js', FCA_EOI_PLUGIN_URL.'/assets/targeting.min.js', array( 'jquery' ), FCA_EOI_VER, true ); |
| 2403 |
|
| 2404 |
$targetData = array ( |
| 2405 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 2406 |
'nonce' => wp_create_nonce( 'fca_eoi_activity' ), |
| 2407 |
'banners' => $target_data, |
| 2408 |
); |
| 2409 |
|
| 2410 |
wp_localize_script( 'fca_eoi_targeting_js', 'fcaEoiBannerTargetingData', $targetData ); |
| 2411 |
|
| 2412 |
return true; |
| 2413 |
} |
| 2414 |
|
| 2415 |
private function display_traditional_popups( $popups ) { |
| 2416 |
|
| 2417 |
$target_data = array(); |
| 2418 |
|
| 2419 |
forEach ( $popups as $p ) { |
| 2420 |
$this->prepare_lightbox_html( $p['id'] ); |
| 2421 |
$target_data[$p['id']] = empty( $p['conditions'] ) ? array() : $p['conditions']; |
| 2422 |
} |
| 2423 |
|
| 2424 |
wp_enqueue_script( 'fca_eoi_targeting_js', FCA_EOI_PLUGIN_URL.'/assets/targeting.min.js', array( 'jquery' ), FCA_EOI_VER, true ); |
| 2425 |
|
| 2426 |
$targetData = array ( |
| 2427 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 2428 |
'nonce' => wp_create_nonce( 'fca_eoi_activity' ), |
| 2429 |
'popups' => $target_data, |
| 2430 |
); |
| 2431 |
|
| 2432 |
wp_localize_script( 'fca_eoi_targeting_js', 'fcaEoiTargetingData', $targetData ); |
| 2433 |
|
| 2434 |
return true; |
| 2435 |
} |
| 2436 |
|
| 2437 |
public function prepare_lightbox_html( $id ) { |
| 2438 |
$id = (int) $id; |
| 2439 |
|
| 2440 |
$content = do_shortcode( "[easy-opt-in id=$id]" ); |
| 2441 |
|
| 2442 |
?> |
| 2443 |
<div style="display:none"> |
| 2444 |
<div id="fca_eoi_lightbox_<?php echo $id ?>"><?php echo $content ?></div> |
| 2445 |
</div> |
| 2446 |
<?php |
| 2447 |
} |
| 2448 |
|
| 2449 |
} |
| 2450 |
|