/** * Outputs the optin view. * * @since 2.0.2.1 */ public function do_preview() { // Filter the data for preview mode. add_filter('optin_monster_data', array(Optin_Monster_Output::get_instance(), 'preview_data'), 9999); $optin = Optin_Monster_Output::get_instance()->get_optin_monster(Optin_Monster_Output::get_instance()->optin_id); remove_filter('optin_monster_data', array(Optin_Monster_Output::get_instance(), 'preview_data'), 9999); // Output the optin. if ($optin) { echo $optin; } }
/** * Outputs the widget within the widgetized area. * * @since 2.0.0 * * @param array $args The default widget arguments. * @param array $instance The input settings for the current widget instance. * * @return void */ public function widget($args, $instance) { $title = apply_filters('widget_title', $instance['title']); $optin_id = $instance['optin_monster_id']; do_action('optin_monster_widget_before_output', $args, $instance); echo $args['before_widget']; do_action('optin_monster_widget_before_title', $args, $instance); // If a title exists, output it. if ($title) { echo $args['before_title'] . $title . $args['after_title']; } do_action('optin_monster_widget_before_optin', $args, $instance); // If a optin has been selected, output it. if ($optin_id) { // If we are in preview mode, don't output the widget. if (Optin_Monster_Output::get_instance()->is_preview()) { return; } // Grab the optin object. If it does not exist, return early. $optin = absint($optin_id) ? Optin_Monster::get_instance()->get_optin($optin_id) : Optin_Monster::get_instance()->get_optin_by_slug($optin_id); if (!$optin) { return; } // Check for split tests. $original = $optin; $split_tests = Optin_Monster::get_instance()->get_split_tests($optin->ID); if ($split_tests) { // Merge the main optin with the split tests, shuffle the array, and set the optin to the first item in the array. $split_tests[] = $optin; shuffle($split_tests); $optin = $split_tests[0]; } // If a clone is selected but it is not enabled, default back to parent optin. $clone = get_post_meta($optin->ID, '_om_is_clone', true); if (!empty($clone)) { $meta = get_post_meta($optin->ID, '_om_meta', true); if (empty($meta['display']['enabled']) || !$meta['display']['enabled']) { $optin = $original; } } // If in test mode but not logged in, skip over the optin. $test = get_post_meta($optin->ID, '_om_test_mode', true); if (!empty($test) && !is_user_logged_in()) { return; } // Load the optin. optin_monster($optin->ID); } do_action('optin_monster_widget_after_optin', $args, $instance); echo $args['after_widget']; do_action('optin_monster_widget_after_output', $args, $instance); }
/** * Returns the optin data. * * @since 2.0.0 * * @return array $data An array of optin data. */ public function get_optin_data($optin) { // Prepare some needed variables. $meta = get_post_meta($optin->ID, '_om_meta', true); $theme = isset($meta['theme']) ? $meta['theme'] : false; // If no theme exists, return false. if (!$theme) { return false; } // Load the optin data and theme and tailor it to the manual click experience. $data = Optin_Monster_Output::get_instance()->get_optin_monster_data($optin->ID); $data['delay'] = 0; $data['exit'] = 0; $data['manual'] = 0; $data['html'] = Optin_Monster_Output::get_instance()->get_optin_monster($optin->ID, true); // Return the data. return $data; }
/** * Outputs the fields controls for the theme. * * @since 2.0.0 * * @param array $fields Array of input fields. * @param object $instance The Edit UI instance. * @return array $fields Amended array of input fields. */ public function input_fields($fields, $instance) { // Build the name field. $fields['name_header'] = $instance->get_field_header(__('Name Field', 'optin-monster-post'), 'name', true); $fields['name_show'] = $instance->get_checkbox_field('name_show', $instance->get_name_setting('show'), __('Show optin name field?', 'optin-monster-post'), __('Displays or hides the name field in the optin.', 'optin-monster-post'), array('target' => '#om-' . $this->type . '-' . $this->theme . '-right', 'input' => esc_attr('<input id="om-' . $this->type . '-' . $this->theme . '-optin-name" type="text" value="" data-om-action="selectable" data-om-target="#optin-monster-field-name_field" placeholder="' . $this->get_name_setting('placeholder', __('Enter your name here...', 'optin-monster-post')) . '" style="' . $this->get_element_style('name', array('font' => 'Helvetica')) . '" />'), 'name' => '#om-' . $this->type . '-' . $this->theme . '-optin-name')); $fields['name_field'] = $instance->get_text_field('name_field', $instance->get_name_setting('placeholder', __('Enter your name here...', 'optin-monster-post')), __('Name Placeholder', 'optin-monster-post'), __('The placeholder text for the email field.', 'optin-monster-post'), false, array('target' => '#om-' . $this->type . '-' . $this->theme . '-optin-name', 'method' => 'attr', 'attr' => 'placeholder'), array('om-live-preview')); $fields['name_color'] = $instance->get_color_field('name_color', $instance->get_name_setting('color', '#858585'), __('Name Color', 'optin-monster-post'), __('The text color for the name field.', 'optin-monster-post'), '', array('target' => '#om-' . $this->type . '-' . $this->theme . '-optin-name', 'props' => 'color')); $fields['name_font'] = $instance->get_font_field('name_font', $instance->get_name_setting('font', 'Helvetica'), Optin_Monster_Output::get_instance()->get_supported_fonts(), __('Name Font', 'optin-monster-post'), __('The font family for the name field.', 'optin-monster-post'), array('target' => '#om-' . $this->type . '-' . $this->theme . '-optin-name', 'attr' => 'font-family', 'method' => 'css'), array('om-live-preview')); // Build the email field. $fields['email_header'] = $instance->get_field_header(__('Email Field', 'optin-monster-post'), 'email'); $fields['email_field'] = $instance->get_text_field('email_field', $instance->get_email_setting('placeholder', __('Enter your email address here...', 'optin-monster-post')), __('Email Placeholder', 'optin-monster-post'), __('The placeholder text for the email field.', 'optin-monster-post'), false, array('target' => '#om-' . $this->type . '-' . $this->theme . '-optin-email', 'method' => 'attr', 'attr' => 'placeholder'), array('om-live-preview')); $fields['email_color'] = $instance->get_color_field('email_color', $instance->get_email_setting('color', '#858585'), __('Email Color', 'optin-monster-post'), __('The text color for the email field.', 'optin-monster-post'), '', array('target' => '#om-' . $this->type . '-' . $this->theme . '-optin-email', 'props' => 'color')); $fields['email_font'] = $instance->get_font_field('email_font', $instance->get_email_setting('font', 'Helvetica'), Optin_Monster_Output::get_instance()->get_supported_fonts(), __('Email Font', 'optin-monster-post'), __('The font family for the email field.', 'optin-monster-post'), array('target' => '#om-' . $this->type . '-' . $this->theme . '-optin-email', 'attr' => 'font-family', 'method' => 'css'), array('om-live-preview')); // Build the submit field. $fields['submit_header'] = $instance->get_field_header(__('Submit Field', 'optin-monster-post'), 'submit'); $fields['submit_field'] = $instance->get_text_field('submit_field', $instance->get_submit_setting('placeholder', __('Sign Up', 'optin-monster-post')), __('Submit Field', 'optin-monster-post'), __('The value of the submit button field.', 'optin-monster-post'), false, array('target' => '#om-' . $this->type . '-' . $this->theme . '-optin-submit', 'method' => 'val'), array('om-live-preview')); $fields['submit_color'] = $instance->get_color_field('submit_color', $instance->get_submit_setting('field_color', '#fff'), __('Submit Button Color', 'optin-monster-post'), __('The text color for the submit button field.', 'optin-monster-post'), '', array('target' => '#om-' . $this->type . '-' . $this->theme . '-optin-submit', 'props' => 'color')); $fields['submit_bg'] = $instance->get_color_field('submit_bg', $instance->get_submit_setting('bg_color', '#50bbe8'), __('Submit Button Background', 'optin-monster-post'), __('The background color of the submit button.', 'optin-monster-post'), '', array('target' => '#om-' . $this->type . '-' . $this->theme . '-optin-submit', 'props' => 'background-color')); $fields['submit_border'] = $instance->get_hidden_field('submit_border', $instance->get_submit_setting('border', '#429bc0'), array('target' => '#om-' . $this->type . '-' . $this->theme . '-optin-submit', 'attr' => 'border-color', 'method' => 'css', 'source' => 'submit_bg'), array('om-live-preview')); $fields['submit_font'] = $instance->get_font_field('submit_font', $instance->get_submit_setting('font', 'Helvetica'), Optin_Monster_Output::get_instance()->get_supported_fonts(), __('Submit Button Font', 'optin-monster-post'), __('The font family for the submit button field.', 'optin-monster-post'), array('target' => '#om-' . $this->type . '-' . $this->theme . '-optin-submit', 'attr' => 'font-family', 'method' => 'css'), array('om-live-preview')); return $fields; }
/** * Retrieves an optin meta setting for the submit field. * * @since 2.0.0 * * @param string $setting The possible subfield for the main field. * @param string $default The default if the value is not found. * @return string The setting value or the default if it does not exist. */ public function get_submit_setting($setting, $default = '') { return Optin_Monster_Output::get_instance()->get_submit_setting($setting, $default); }
/** * Method for saving API account info to an optin. * * @since 2.0.0 * * @param int $optin_id The ID of the optin to target. * @param string $provider The email provider slug. * @param string $account The unique account ID for the optin. */ public function save_account($optin_id, $provider, $account) { $meta = get_post_meta($optin_id, '_om_meta', true); $meta['email']['provider'] = $provider; $meta['email']['account'] = $account; update_post_meta($optin_id, '_om_meta', $meta); // Flush any optin caches. Optin_Monster_Common::get_instance()->flush_optin_caches($optin_id); // Now reset the meta property with our updated meta field. Optin_Monster_Output::get_instance()->meta = get_post_meta($optin_id, '_om_meta', true); }
/** * Register and enqueue settings page specific JS. * * @since 2.0.0 */ public function optin_admin_scripts() { if ('overview' == $this->view) { wp_enqueue_script('jquery-ui-sortable'); wp_register_script($this->base->plugin_slug . '-overview-script', plugins_url('assets/js/overview.js', $this->base->file), array('jquery', 'jquery-ui-sortable'), $this->base->version, true); wp_enqueue_script($this->base->plugin_slug . '-overview-script'); wp_localize_script($this->base->plugin_slug . '-overview-script', 'optin_monster_overview', array('active' => __('Status: Active', 'optin-monster'), 'activate' => __('Activate', 'optin-monster'), 'activate_nonce' => wp_create_nonce('optin-monster-activate'), 'activating' => __('Activating...', 'optin-monster'), 'ajax' => admin_url('admin-ajax.php'), 'confirm' => __('Are you sure you want to perform this action?', 'optin-monster'), 'deactivate' => __('Deactivate', 'optin-monster'), 'deactivate_nonce' => wp_create_nonce('optin-monster-deactivate'), 'deactivating' => __('Deactivating...', 'optin-monster'), 'inactive' => __('Status: Inactive', 'optin-monster'), 'install' => __('Install Addon', 'optin-monster'), 'install_nonce' => wp_create_nonce('optin-monster-install'), 'installing' => __('Installing...', 'optin-monster'), 'int_delete' => __('Are you sure you want to delete this integration?', 'optin-monster'), 'int_error' => __('There was an error deleting the integration.', 'optin-monster'), 'proceed' => __('Proceed', 'optin-monster'), 'redirect' => add_query_arg(array('post_type' => 'optin-monster', 'optin-monster-upgraded' => true), admin_url('edit.php')), 'upgrade_nonce' => wp_create_nonce('optin-monster-upgrade'), 'saving' => __('Saving...', 'optin-monster'))); } if ('edit' == $this->view) { // Continue enqueueing media. wp_enqueue_media(array('post' => isset($_GET['om_optin_id']) ? $_GET['om_optin_id'] : 0)); wp_enqueue_script($this->base->plugin_slug . '-google-fonts', '//ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js'); wp_register_script($this->base->plugin_slug . '-color-script', plugins_url('assets/js/color.js', $this->base->file), array('jquery'), $this->base->version, true); wp_enqueue_script($this->base->plugin_slug . '-color-script'); wp_register_script($this->base->plugin_slug . '-jquery-color-script', plugins_url('assets/js/jquery.color.js', $this->base->file), array('jquery'), $this->base->version, true); wp_enqueue_script($this->base->plugin_slug . '-jquery-color-script'); wp_register_script($this->base->plugin_slug . '-chosen-script', plugins_url('assets/chosen/chosen.jquery.min.js', $this->base->file), array('jquery'), $this->base->version, true); wp_enqueue_script($this->base->plugin_slug . '-chosen-script'); wp_register_script($this->base->plugin_slug . '-postmessage-script', plugins_url('assets/js/postmessage.js', $this->base->file), array('jquery'), $this->base->version, true); wp_enqueue_script($this->base->plugin_slug . '-postmessage-script'); wp_register_script($this->base->plugin_slug . '-edit-script', plugins_url('assets/js/edit.js', $this->base->file), array('jquery', $this->base->plugin_slug . '-color-script', $this->base->plugin_slug . '-postmessage-script'), $this->base->version, true); wp_enqueue_script($this->base->plugin_slug . '-edit-script'); wp_localize_script($this->base->plugin_slug . '-edit-script', 'optin_monster_edit', array('ajax' => admin_url('admin-ajax.php'), 'confirm' => __('Are you sure you want to exit? Changes to your optin will not be saved.', 'optin-monster'), 'id' => isset($_GET['om_optin_id']) ? absint($_GET['om_optin_id']) : 0, 'ie' => sprintf(__('Internet Explorer does not support the protocol required to authenticate with this provider. Please save your changes and use another browser (such as Google Chrome or Mozilla Firefox) to authenticate with this provider. <a href="%s" title="Click here to learn more about this issue." target="_blank">Click here to learn more about this issue.</a>', 'optin-monster'), 'http://optinmonster.com/docs/issues-with-internet-explorer-and-oauth/'), 'iframe' => $this->get_preview_url(), 'insert' => __('Insert Image into Optin', 'optin-monster'), 'fields' => __('Please fill out all email provider fields.', 'optin-monster'), 'fonts' => urlencode(implode('|', Optin_Monster_Output::get_instance()->get_supported_fonts(true))), 'save_nonce' => wp_create_nonce('optin-monster-save'), 'saving' => __('Saving...', 'optin-monster'), 'split' => isset($_GET['om_split']) ? 1 : 0, 'title' => __('Select or Upload an Image', 'optin-monster'), 'theme' => __('Active: ', 'optin-monster'), 'theme_nonce' => wp_create_nonce('optin-monster-theme'))); } if ('new' == $this->view) { wp_register_script($this->base->plugin_slug . '-new-script', plugins_url('assets/js/new.js', $this->base->file), array('jquery'), $this->base->version, true); wp_enqueue_script($this->base->plugin_slug . '-new-script'); wp_localize_script($this->base->plugin_slug . '-new-script', 'optin_monster_new', array('ajax' => admin_url('admin-ajax.php'), 'campaign' => __('Please enter an optin campaign title before selecting your theme.', 'optin-monster'), 'create_nonce' => wp_create_nonce('optin-monster-create'), 'type_nonce' => wp_create_nonce('optin-monster-type'))); } if ('split' == $this->view) { wp_register_script($this->base->plugin_slug . '-split-script', plugins_url('assets/js/split.js', $this->base->file), array('jquery'), $this->base->version, true); wp_enqueue_script($this->base->plugin_slug . '-split-script'); wp_localize_script($this->base->plugin_slug . '-split-script', 'optin_monster_split', array('ajax' => admin_url('admin-ajax.php'), 'confirm' => __('Are you sure you want to perform this action?', 'optin-monster'), 'id' => isset($_GET['om_optin_id']) ? $_GET['om_optin_id'] : 0)); } if ($this->is_admin_preview()) { Optin_Monster_Preview::get_instance()->preview_scripts(); } // Run a hook to load in custom scripts. do_action('optin_monster_admin_scripts', $this->view); }
/** * Retrieves and generates the HTML for image placeholders. * * @since 2.0.0 * * @param int $optin_id The optin ID to target. * @param string $type The type of theme to target. * @param string $theme The theme to target for the thumbnail size. * @return string HTML markup for the image placeholder. */ function optin_monster_ajax_get_image_placeholder($optin_id, $type, $theme) { $api = Optin_Monster_Output::get_instance()->get_optin_monster_theme($theme, $optin_id, true); $output = '<div class="optin-monster-image-placeholder" style="width:' . $api->img_width . 'px;height:' . $api->img_height . 'px;">'; $output .= '<span class="optin-monster-image-placeholder-dims">' . $api->img_width . '×' . $api->img_height . '</span>'; $output .= '<a class="om-media-modal" href="#" data-om-action="selectable" data-om-theme="' . $theme . '" data-om-type="' . $type . '"></a>'; $output .= '</div>'; return $output; }
/** * Creates the shortcode for the plugin. * * @since 2.0.0 * * @global object $post The current post object. * * @param array $atts Array of shortcode attributes. * @return string The optin output. */ public function shortcode($atts) { global $post; $optin_id = false; if (isset($atts['id'])) { $optin_id = (int) $atts['id']; } else { if (isset($atts['slug'])) { $optin = get_page_by_path($atts['slug'], OBJECT, 'optin'); if ($optin) { $optin_id = $optin->ID; } } else { // A custom attribute must have been passed. Allow it to be filtered to grab the optin ID from a custom source. $optin_id = apply_filters('optin_monster_custom_optin_id', false, $atts, $post); } } // Allow the optin ID to be filtered before it is stored and used to create the optin output. $optin_id = apply_filters('optin_monster_pre_optin_id', $optin_id, $atts, $post); // If there is no optin, do nothing. if (!$optin_id) { return false; } // If we are in a preview state, the optin needs to match the one requested, otherwise return false. if (Optin_Monster_Output::get_instance()->is_preview()) { if (Optin_Monster_Output::get_instance()->optin_id && Optin_Monster_Output::get_instance()->optin_id !== $optin_id || !empty(Optin_Monster_Output::get_instance()->data[$optin_id])) { return false; } } // Return the output. return Optin_Monster_Output::get_instance()->get_optin_monster($optin_id); }
/** * Returns the supported theme fonts. * * @since 2.0.0 * * @return array $fonts Array of supported font families. */ public function get_supported_fonts($google_only = false) { return Optin_Monster_Output::get_instance()->get_supported_fonts($google_only); }
/** * Returns the singleton instance of the class. * * @since 2.0.0 * * @return object The Optin_Monster_Output object. */ public static function get_instance() { if (!isset(self::$instance) && !self::$instance instanceof Optin_Monster_Output) { self::$instance = new Optin_Monster_Output(); } return self::$instance; }
/** * Enqueues scripts necessary for live preview and edit functionality. * * @since 2.0.0 */ public function preview_scripts() { wp_enqueue_script($this->base->plugin_slug . '-google-fonts', '//ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js'); wp_enqueue_script($this->base->plugin_slug . '-api', plugins_url('assets/js/api.js', $this->base->file), array('jquery'), $this->base->version); wp_enqueue_script($this->base->plugin_slug . '-postmessage', plugins_url('assets/js/postmessage.js', $this->base->file), array('jquery'), $this->base->version); wp_enqueue_script($this->base->plugin_slug . '-ckeditor', plugins_url('assets/ckeditor/ckeditor.js', $this->base->file), array('jquery', $this->base->plugin_slug . '-postmessage'), $this->base->version); wp_enqueue_script($this->base->plugin_slug . '-color', plugins_url('assets/js/color.js', $this->base->file), array('jquery', $this->base->plugin_slug . '-postmessage', $this->base->plugin_slug . '-ckeditor'), $this->base->version); wp_enqueue_script($this->base->plugin_slug . '-preview', plugins_url('assets/js/preview.js', $this->base->file), array('jquery', $this->base->plugin_slug . '-postmessage', $this->base->plugin_slug . '-ckeditor', $this->base->plugin_slug . '-color'), $this->base->version); wp_localize_script($this->base->plugin_slug . '-preview', 'optin_monster_preview', array('ajax' => admin_url('admin-ajax.php'), 'ckfonts' => implode(';', Optin_Monster_Output::get_instance()->get_supported_fonts()), 'ckpath' => plugins_url('assets/ckeditor/', $this->base->file), 'config' => plugins_url('assets/js/ckeditor.js', $this->base->file), 'fonts' => urlencode(implode('|', Optin_Monster_Output::get_instance()->get_supported_fonts(true))), 'google' => set_url_scheme('//fonts.googleapis.com/css?family='), 'id' => isset($_GET['om_preview_optin']) ? absint($_GET['om_preview_optin']) : 0, 'remove' => __('Are you sure you want to remove this image from the optin?', 'optin-monster'), 'optin' => $this->optin->post_name, 'optinjs' => str_replace('-', '_', $this->optin->post_name))); }