settings = $settings; // Add shortcode add_shortcode( $this->settings[ 'shortcode' ], array( $this, 'shortcode_content' ) ); // Add shortcode aliases foreach ( $settings[ 'shortcode_aliases' ] as $shortcode) { add_shortcode( $shortcode, array( $this, 'shortcode_content' ) ); } // Add shortcode generator button if ( FCA_EOI_EDITION != 'email_popup' && in_array( $pagenow, array( 'post.php', 'page.php', 'post-new.php', 'post-edit.php' ) ) && $typenow != 'download' ) { add_action( 'admin_head', array( $this, 'button_head' ) ); add_action( 'media_buttons', array( $this, 'button' ), 1000 ); add_action( 'admin_footer', array( $this, 'button_footer' ) ); } if ( ! is_admin() ) { add_action( 'wp', array( $this, 'parse_shortcodes' ), 11 ); } } public function wp_head() { foreach ( $this->prerequisites as $form_id => $head ) { echo $head; $this->prerequisites[ $form_id ] = ''; } } public function parse_shortcodes() { global $post; if ( empty( $post ) ) { return; } if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $post->post_content, $matches ) && array_key_exists( 2, $matches ) && array_key_exists( 3, $matches ) && in_array( $this->settings['shortcode'], $matches[2] ) ) { foreach ( $matches[3] as $params ) { $params = shortcode_parse_atts( $params ); if ( ! empty( $params['id'] ) ) { $this->add_prerequisites_for_form( (int) $params['id'] ); } } } if ( ! empty( $this->prerequisites ) ) { $this->enqueue_assets(); add_action( 'wp_head', array( $this, 'wp_head' ) ); } } /** * @param int $form_id * * @return string */ private function add_prerequisites_for_form( $form_id ) { $head = get_post_meta( $form_id, 'fca_eoi_head', true ); if ( !empty ( $head ) ) { return $head; } else { if ( array_key_exists( $form_id, $this->prerequisites ) ) { return $this->prerequisites[ $form_id ]; } $head = ''; $fca_eoi_meta = get_post_meta( $form_id, 'fca_eoi', true ); if ( ! $fca_eoi_meta ) { return $head; } $layout_id = $fca_eoi_meta['layout']; $layout = new EasyOptInsLayout( $layout_id ); $scss_path = $layout->path_to_resource( 'layout', 'scss' ); if ( file_exists( $scss_path ) ) { $css_path = str_replace ( '.scss' , '_min.css', $scss_path ); $css = file_get_contents( $css_path ); $head .= ''; } // Add per form CSS $head .= ''; $css = ''; if ( ! empty( $fca_eoi_meta[ $layout_id ] ) ) { $head .= "'; } if ( $layout->layout_type != 'lightbox' ) { $head .= ''; } $this->prerequisites[ $form_id ] = $head; delete_post_meta( $form_id, 'fca_eoi_head' ); add_post_meta( $form_id, 'fca_eoi_head', $head ); return $head; } } /** * @param int $form_id * * @return string */ private function get_prerequisites_for_form( $form_id ) { $prerequisites = $this->add_prerequisites_for_form( $form_id ); $this->prerequisites[ $form_id ] = ''; if ( ! empty( $prerequisites ) ) { $this->enqueue_assets(); return $prerequisites; } return ''; } public function button_head() { ?> ' . $button_title . ''; } else { $img = ''; echo '' . $img . $button_title . ''; } } } public function button_footer() { $options = array(); foreach ( get_posts( array( 'post_type' => 'easy-opt-ins', 'post_status' => 'publish', 'posts_per_page' => -1 ) ) as $post ) { $form_id = $post->ID; $layout = get_post_meta( $form_id, 'fca_eoi_layout', true ); if ( ! empty( $layout ) && strpos( $layout, 'postbox_' ) === 0 ) { $options[ $form_id ] = empty( $post->post_title ) ? '(no title)' : $post->post_title; } } ?>
assets_enqueued ) { return; } $this->assets_enqueued = true; $protocol = is_ssl() ? 'https' : 'http'; // Get lightboxes $lightboxes = get_posts( array( 'post_type' => 'easy-opt-ins', 'posts_per_page' => -1, 'orderby' => 'ID', 'meta_key' => 'fca_eoi_layout', 'meta_value' => 'lightbox_', 'meta_compare' => 'like', ) ); // Get postboxes $postboxes = get_posts( array( 'post_type' => 'easy-opt-ins', 'posts_per_page' => -1, 'orderby' => 'ID', 'meta_key' => 'fca_eoi_layout', 'meta_value' => 'postbox_', 'meta_compare' => 'like', ) ); // Get postboxes $widgets = get_posts( array( 'post_type' => 'easy-opt-ins', 'posts_per_page' => -1, 'orderby' => 'ID', 'meta_key' => 'fca_eoi_layout', 'meta_value' => 'layout_', 'meta_compare' => 'like', ) ); // Exit function if not optin form exist if ( ! $lightboxes && ! $postboxes && ! $widgets ) { return; } wp_enqueue_script( 'jquery' ); wp_enqueue_style( 'fca_eoi', FCA_EOI_PLUGIN_URL . '/assets/style-new.css' ); wp_enqueue_script( 'fca_eoi_script_js', FCA_EOI_PLUGIN_URL . '/assets/script.js' ); wp_enqueue_style( 'fontawesome', $protocol . '://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css' ); wp_enqueue_script( 'tooltipster', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/jquery.tooltipster.min.js' ); wp_enqueue_style( 'tooltipster', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster.min.css' ); wp_enqueue_script( 'featherlight', FCA_EOI_PLUGIN_URL . '/assets/vendor/featherlight/release/featherlight.min.js' ); wp_enqueue_style( 'featherlight', FCA_EOI_PLUGIN_URL . '/assets/vendor/featherlight/release/featherlight.min.css' ); //PASS VARIABLES TO JAVASCRIPT wp_localize_script( 'fca_eoi_script_js', 'fca_eoi', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) ); } public function shortcode_content( $atts ) { $form_id = $atts['id']; /** * Check that we have a valid post ID */ if( empty ( $form_id ) ) { return 'Missing form ID'; } if( ! $post = get_post( $form_id ) ) { return 'Wrong form ID'; } $fca_eoi_meta = get_post_meta( $form_id, 'fca_eoi', true ); if( ! $fca_eoi_meta ) { return 'Form doesn\'t exist'; } // Get template $layout_id = $fca_eoi_meta[ 'layout' ]; $layout = new EasyOptInsLayout( $layout_id ); $layout_type = $layout->layout_type; $html_path = $layout->path_to_resource( 'layout', 'html' ); $html_wrap_path = $layout->path_to_html_wrapper(); if ( ! file_exists( $html_path ) ) { return ''; } $template = str_replace( '{{{layout}}}', file_get_contents( $html_path ), file_get_contents( $html_wrap_path ) ); $form_wrapper = ''; $form_wrapper_end = ''; if ( $layout->layout_type != 'lightbox' ) { $form_wrapper = '