EasyOptInsShortcodes

The Mailchimp Forms by Optin Cat EasyOptInsShortcodes class.

Defined (1)

The class is defined in the following location(s).

/includes/eoi-shortcode.php  
  1. class EasyOptInsShortcodes { 
  2.  
  3. var $settings; 
  4. var $prerequisites = array(); 
  5. var $assets_enqueued = false; 
  6.  
  7. public function __construct( $settings = array() ) { 
  8. global $pagenow, $typenow; 
  9.  
  10. $this->settings = $settings; 
  11.  
  12. // Add shortcode 
  13. add_shortcode( $this->settings[ 'shortcode' ], array( $this, 'shortcode_content' ) ); 
  14.  
  15. // Add shortcode aliases 
  16. foreach ( $settings[ 'shortcode_aliases' ] as $shortcode) { 
  17. add_shortcode( $shortcode, array( $this, 'shortcode_content' ) ); 
  18.  
  19. // Add shortcode generator button 
  20. if ( FCA_EOI_EDITION != 'email_popup' && in_array( $pagenow, array( 'post.php', 'page.php', 'post-new.php', 'post-edit.php' ) ) && $typenow != 'download' ) { 
  21. add_action( 'admin_head', array( $this, 'button_head' ) ); 
  22. add_action( 'media_buttons', array( $this, 'button' ), 1000 ); 
  23. add_action( 'admin_footer', array( $this, 'button_footer' ) ); 
  24.  
  25.  
  26. public function button_head() { 
  27. ?> 
  28.  
  29. <style> 
  30. #fca-eoi-media-button { 
  31. background: url(<?php echo FCA_EOI_PLUGIN_URL . '/icon.png' ?>) 0 -1px no-repeat; 
  32. background-size: 16px 16px; 
  33. </style> 
  34.  
  35. <?php 
  36.  
  37. public function button() { 
  38. global $post; 
  39. if (current_user_can( 'delete_pages' ) && $post->post_type != 'easy-opt-ins') { 
  40.  
  41. $button_title = __( 'Add Optin Form' ); 
  42.  
  43. if ( version_compare( $GLOBALS['wp_version'], '3.5', '<' ) ) { 
  44. echo '<a href="#TB_inline?width=640&inlineId=fca-eoi-shortcode-thickbox" class="thickbox" title="' . $button_title . '">' . $button_title . '</a>'; 
  45. } else { 
  46. $img = '<span class="wp-media-buttons-icon" id="fca-eoi-media-button"></span>'; 
  47. echo '<a href="#TB_inline?width=640&inlineId=fca-eoi-shortcode-thickbox" class="thickbox button" title="' . $button_title . '" style="padding-left: .4em;">' . $img . $button_title . '</a>'; 
  48.  
  49. public function button_footer() { 
  50. $options = array(); 
  51.  
  52. foreach ( get_posts( array( 'post_type' => 'easy-opt-ins', 'post_status' => 'publish', 'posts_per_page' => -1 ) ) as $post ) { 
  53. $form_id = $post->ID; 
  54. $layout = get_post_meta( $form_id, 'fca_eoi_layout', true ); 
  55.  
  56. if ( ! empty( $layout ) && strpos( $layout, 'postbox_' ) === 0 ) { 
  57. $options[ $form_id ] = empty( $post->post_title ) ? '(no title)' : $post->post_title; 
  58.  
  59. ?> 
  60.  
  61. <script type="text/javascript"> 
  62. jQuery( function( $ ) { 
  63. $( '#fca-eoi-shortcode-insert' ).on( 'click', function() { 
  64. var id = $( '#fca-eoi-shortcode' ).val(); 
  65.  
  66. if ( '' === id ) { 
  67. alert( <?php echo json_encode( __( 'You must choose a form' ) ) ?> ); 
  68. return; 
  69.  
  70. window.send_to_editor( '[<?php echo $this->settings[ 'shortcode' ] ?> id="' + id + '"]' ); 
  71. } ); 
  72. } ); 
  73. </script> 
  74. <div id="fca-eoi-shortcode-thickbox" style="display: none;"> 
  75. <div class="wrap" style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"> 
  76. <p><?php _e('Use the form below to insert an Optin Cat shortcode .' ) ?></p> 
  77. <div> 
  78. <select id="fca-eoi-shortcode"> 
  79. <option value=""><?php _e( 'Please select...' ) ?></option> 
  80. <?php foreach ( $options as $form_id => $title ) { ?> 
  81. <option value="<?php echo (int) $form_id ?>"><?php echo esc_html( $title ) ?></option> 
  82. <?php } ?> 
  83. </select> 
  84. </div> 
  85. <p class="submit"> 
  86. <input type="button" id="fca-eoi-shortcode-insert" class="button-primary" value="<?php _e( 'Insert' ) ?>"> 
  87. <a id="fca-eoi-shortcode-cancel" class="button-secondary" onclick="tb_remove();" title="<?php _e( 'Cancel' ) ?>"><?php _e( 'Cancel' ) ?></a> 
  88. </p> 
  89. </div> 
  90. </div> 
  91.  
  92. <?php 
  93.  
  94. public function enqueue_assets() { 
  95. $protocol = is_ssl() ? 'https' : 'http'; 
  96.  
  97. wp_enqueue_script( 'jquery' ); 
  98. wp_enqueue_style( 'fontawesome', $protocol . '://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css', array(), FCA_EOI_VER ); 
  99.  
  100. wp_enqueue_script( 'fca_eoi_tooltipster_js', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster.bundle.min.js', array(), FCA_EOI_VER, true ); 
  101. wp_enqueue_style( 'fca_eoi_tooltipster_css', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster.bundle.min.css', array(), FCA_EOI_VER ); 
  102. wp_enqueue_style( 'fca_eoi_tooltipster_theme_css', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster-borderless.min.css', array(), FCA_EOI_VER ); 
  103.  
  104. wp_enqueue_script( 'fca_eoi_featherlight_js', FCA_EOI_PLUGIN_URL . '/assets/vendor/featherlight/release/featherlight.min.js', array(), FCA_EOI_VER, true ); 
  105. wp_enqueue_style( 'fca_eoi_featherlight_css', FCA_EOI_PLUGIN_URL . '/assets/vendor/featherlight/release/featherlight.min.css', array(), FCA_EOI_VER ); 
  106.  
  107. wp_enqueue_script( 'fca_eoi_jstz', FCA_EOI_PLUGIN_URL . '/assets/vendor/jstz/jstz.min.js', array(), FCA_EOI_VER, true ); 
  108.  
  109. wp_enqueue_style( 'fca_eoi', FCA_EOI_PLUGIN_URL . '/assets/style-new.min.css', array(), FCA_EOI_VER ); 
  110. wp_enqueue_script( 'fca_eoi_script_js', FCA_EOI_PLUGIN_URL . '/assets/script.min.js', array( 'fca_eoi_jstz', 'jquery', 'fca_eoi_tooltipster_js', 'fca_eoi_featherlight_js'), FCA_EOI_VER, true ); 
  111.  
  112. //PASS VARIABLES TO JAVASCRIPT 
  113. $data = array ( 
  114. 'ajax_url' => admin_url( 'admin-ajax.php' ),  
  115. 'nonce' => wp_create_nonce( 'fca_eoi_submit_form' ),  
  116. ); 
  117.  
  118. wp_localize_script( 'fca_eoi_script_js', 'fcaEoiScriptData', $data );  
  119.  
  120. public function shortcode_content( $atts ) { 
  121. if ( empty ( $atts['id'] ) ) { 
  122. return 'Optin Cat: Invalid Form ID'; 
  123. } else { 
  124. $form_id = $atts['id']; 
  125. $post = get_post( $form_id ); 
  126.  
  127. if( !is_object( $post ) OR $post->post_status == 'trash' ) { 
  128. return 'Optin Cat: Missing Form Data. Is it in the trash?'; 
  129.  
  130. $animation = get_post_meta( $form_id, 'fca_eoi_animation', true); 
  131. if (!empty( $animation ) ) { 
  132. wp_enqueue_style( 'fca_eoi_powerups_animate', FCA_EOI_PLUGIN_URL . '/assets/vendor/animate/animate.min.css', array(), FCA_EOI_VER ); 
  133.  
  134. $this->enqueue_assets(); 
  135. $head = get_post_meta( $form_id, 'fca_eoi_head', true ); 
  136.  
  137. $layout_id = get_post_meta ( $form_id, 'fca_eoi_layout', true ); 
  138. $layout = new EasyOptInsLayout( $layout_id ); 
  139.  
  140. if ( $layout->layout_type !== 'lightbox' && $layout->layout_type !== 'banner' && $layout->layout_type !== 'overlay' ) { 
  141.  
  142. require_once FCA_EOI_PLUGIN_DIR . 'includes/classes/RobotDetector/RobotDetector.php'; 
  143. $robot_detector = new RobotDetector(); 
  144.  
  145. if ( get_post( $form_id ) && !is_user_logged_in() && !$robot_detector->is_robot() ) { 
  146. EasyOptInsActivity::get_instance()->add_impression( $form_id ); 
  147.  
  148. }  
  149.  
  150. return $head;