st_id ) || ! current_user_can( 'edit_post', $post_id ) || empty( $variation_key ) ) { return $invalid_request; } if ( ob_get_contents() ) { ob_clean(); } $variation = tve_leads_get_form_variation( $post_id, $variation_key ); if ( empty( $variation ) ) { return $invalid_request; } $variation[ TVE_LEADS_FIELD_SAVED_CONTENT ] = wp_unslash( $_POST['tve_content'] ); $variation[ TVE_LEADS_FIELD_INLINE_CSS ] = trim( $_POST['inline_rules'] ); $variation[ TVE_LEADS_FIELD_USER_CSS ] = $_POST['tve_custom_css']; $variation[ TVE_LEADS_FIELD_GLOBALS ] = ! empty( $_POST['tve_globals'] ) ? $_POST['tve_globals'] : array( 'e' => 1 ); $variation[ TVE_LEADS_FIELD_CUSTOM_FONTS ] = tve_leads_get_custom_font_links( empty( $_POST['custom_font_classes'] ) ? array() : $_POST['custom_font_classes'] ); $variation[ TVE_LEADS_FIELD_ICON_PACK ] = empty( $_POST['has_icons'] ) ? 0 : 1; $variation[ TVE_LEADS_FIELD_HAS_MASONRY ] = empty( $_POST['tve_has_masonry'] ) ? 0 : 1; $variation[ TVE_LEADS_FIELD_HAS_TYPEFOCUS ] = empty( $_POST['tve_has_typefocus'] ) ? 0 : 1; /** * UPDATE 19.11.2015 - the custom CSS will be saved in the parent form */ if ( ! empty( $variation['parent_id'] ) && ( $parent_state = tve_leads_get_form_variation( null, $variation['parent_id'] ) ) ) { $parent_state[ TVE_LEADS_FIELD_USER_CSS ] = $_POST['tve_custom_css']; $variation[ TVE_LEADS_FIELD_USER_CSS ] = ''; tve_leads_save_form_variation( $parent_state ); } /** * always re-generate CSS IDs for elements inside the variation - conflicts can occur on pages where multiple Lead Forms are shown */ Thrive_Leads_State_Manager::instance( $variation )->regenerate_css_ids( $variation ); tve_leads_save_form_variation( $variation ); return array( 'success' => true, ); } /** * get the default variation content from a pre-defined template * * @param array $variation the form design object * @param string $template_key formatted like {main_key}|{template_name} * * @return string the content */ function tve_leads_get_editor_template_content( & $variation, $template_key = null ) { if ( $template_key === null && ! empty( $variation ) && ! empty( $variation[ TVE_LEADS_FIELD_TEMPLATE ] ) ) { $template_key = $variation[ TVE_LEADS_FIELD_TEMPLATE ]; } list( $type, $template ) = explode( '|', $template_key ); $type = Thrive_Leads_Template_Manager::tpl_type_map( $type ); $base = plugin_dir_path( dirname( __FILE__ ) ) . 'editor-templates/'; /** @var array $templates all templates for a form type */ $templates = Thrive_Leads_Template_Manager::for_variation( $variation ); /** if the template does not exists */ if ( strpos( $template, 'tcb2_' ) !== 0 && ! isset( $templates[ $template ] ) ) { return ''; } /** * also read in any other configuration values that might be required for this form */ $tpl_config_data = tve_leads_get_editor_template_config( $template_key ); /** if the template is from cloud */ if ( isset( $templates[ $template ]['API_VERSION'] ) ) { $content = file_get_contents( $templates[ $template ]['base_dir'] . '/' . $template . '.tpl' ); /** replace the placeholder url */ $content = str_replace( '{tve_leads_base_url}', $tpl_config_data['base_url'], $content ); } /** @var string $template_path disk template file */ $template_path = $base . $type . '/' . $template . '.php'; /** if no cloud and no file on disk return empty content */ if ( ! isset( $content ) && ! is_file( $template_path ) ) { return ''; } /** if no cloud content then read it from disk */ if ( ! isset( $content ) ) { ob_start(); include $template_path; $content = ob_get_contents(); ob_end_clean(); } $meta = array(); if ( isset( $tpl_config_data['meta'] ) ) { $meta = $tpl_config_data['meta']; } /** * we need to make sure we don't have any left-over data from the previous template */ $variation[ TVE_LEADS_FIELD_INLINE_CSS ] = tve_leads_get_default_template_css( $template_key, $tpl_config_data ); $variation[ TVE_LEADS_FIELD_USER_CSS ] = isset( $meta[ TVE_LEADS_FIELD_USER_CSS ] ) ? $meta[ TVE_LEADS_FIELD_USER_CSS ] : ''; $variation[ TVE_LEADS_FIELD_CUSTOM_FONTS ] = array(); $variation[ TVE_LEADS_FIELD_ICON_PACK ] = ''; $variation[ TVE_LEADS_FIELD_HAS_MASONRY ] = ''; $variation[ TVE_LEADS_FIELD_HAS_TYPEFOCUS ] = isset( $meta[ TVE_LEADS_FIELD_HAS_TYPEFOCUS ] ) ? $meta[ TVE_LEADS_FIELD_HAS_TYPEFOCUS ] : ''; if ( ! empty( $tpl_config_data[ TVE_LEADS_FIELD_GLOBALS ] ) ) { $variation[ TVE_LEADS_FIELD_GLOBALS ] = $tpl_config_data[ TVE_LEADS_FIELD_GLOBALS ]; } elseif ( ! empty( $meta[ TVE_LEADS_FIELD_GLOBALS ] ) ) { $variation[ TVE_LEADS_FIELD_GLOBALS ] = $meta[ TVE_LEADS_FIELD_GLOBALS ]; } else { $variation[ TVE_LEADS_FIELD_GLOBALS ] = array( 'e' => 1 ); } return $content; } /** * handles template-related actions: * choose new template * reset current form design to the default content * perhaps at some point: save / load template versions */ function tve_leads_template_action() { add_filter( 'tcb_is_editor_page_ajax', '__return_true' ); add_filter( 'tcb_is_editor_page_raw_ajax', '__return_true' ); $result = array( 'success' => false, 'message' => __( 'Something went wrong, try again later', 'thrive-leads' ), ); if ( empty( $_POST['post_id'] ) || ! current_user_can( 'edit_post', $_POST['post_id'] ) || empty( $_POST['_key'] ) || empty( $_POST['custom'] ) ) { return $result; } /** * if in development then delete cache */ if ( defined( 'TL_CLOUD_DEBUG' ) && TL_CLOUD_DEBUG && ! empty( $_REQUEST['tpl'] ) ) { delete_transient( $_REQUEST['tpl'] ); } /** * if template is from cloud then download and set it in cache */ if ( ! empty( $_REQUEST['cloud'] ) && false === ( $downloaded = get_transient( $_REQUEST['tpl'] ) ) ) { $template = explode( '|', $_REQUEST['tpl'] ); $template = end( $template ); $tpl = array( 'form_type' => $_REQUEST['form_type'], 'multi_step' => $_REQUEST['multi_step'], ); try { /** * Download the template */ Thrive_Leads_Cloud_Templates_APi::getInstance()->init( $tpl )->download( $template ); /** * Mark it as cached */ set_transient( $_REQUEST['tpl'], true, 8 * HOUR_IN_SECONDS ); } catch ( Exception $e ) { $result['message'] = $e->getMessage(); return $result; } } $form_type = tve_leads_get_form_type( $_POST['post_id'] ); $variation = tve_leads_get_form_variation( $_POST['post_id'], $_POST['_key'] ); if ( empty( $variation ) || empty( $form_type ) ) { return $result; } require_once dirname( dirname( __FILE__ ) ) . '/inc/classes/Thrive_Leads_Template_Manager.php'; require_once dirname( dirname( __FILE__ ) ) . '/inc/classes/Thrive_Leads_State_Manager.php'; Thrive_Leads_Template_Manager::instance( $variation )->api( $_POST['route'] ); } /** * enqueue and return custom fonts for a specific variation * * @param array $variation the form variation * * @return array */ function tve_leads_enqueue_custom_fonts( $variation ) { if ( empty( $variation[ TVE_LEADS_FIELD_CUSTOM_FONTS ] ) ) { return array(); } return tve_enqueue_fonts( $variation[ TVE_LEADS_FIELD_CUSTOM_FONTS ] ); } /** * transform an array of font classes into links to the actual google font * * @param array $custom_font_classes the classes used for custom fonts * * @return array */ function tve_leads_get_custom_font_links( $custom_font_classes = array() ) { $all_fonts = tve_get_all_custom_fonts(); $post_fonts = array(); foreach ( array_unique( $custom_font_classes ) as $cls ) { foreach ( $all_fonts as $font ) { if ( Tve_Dash_Font_Import_Manager::isImportedFont( $font->font_name ) ) { $post_fonts[] = Tve_Dash_Font_Import_Manager::getCssFile(); } else if ( $font->font_class == $cls && ! tve_is_safe_font( $font ) ) { $post_fonts[] = tve_custom_font_get_link( $font ); break; } } } return array_unique( $post_fonts ); } /** * Checks if a form is being edited and, if yes include the Thrive Themes Page Section element in the control panel menu * * @param bool $show_menu * * @return bool */ function tve_leads_show_page_section_menu( $show_menu ) { if ( empty( $_GET['_key'] ) ) { return $show_menu; } $variation_key = $_GET['_key']; // this should always be present $variation = tve_leads_get_form_variation( null, $variation_key ); if ( empty( $variation ) ) { return $show_menu; } return true; } /** * transform the tve_globals meta field into css / html properties and rules * * @param array $variation * * @return array */ function tve_leads_lightbox_globals( $variation ) { $config = ! empty( $variation[ TVE_LEADS_FIELD_GLOBALS ] ) ? $variation[ TVE_LEADS_FIELD_GLOBALS ] : array(); $html = array( 'overlay' => array( 'css' => empty( $config['l_oo'] ) ? '' : ( 'opacity:' . $config['l_oo'] ), 'custom_color' => empty( $config['l_ob'] ) ? '' : ( ' data-tve-custom-colour="' . $config['l_ob'] . '"' ), ), 'content' => array( 'custom_color' => empty( $config['l_cb'] ) ? '' : ( ' data-tve-custom-colour="' . $config['l_cb'] . '"' ), 'class' => empty( $config['l_ccls'] ) ? '' : ' ' . $config['l_ccls'], 'css' => '', ), 'inner' => array( 'css' => '', ), 'close' => array( 'class' => '', 'css' => '', ), ); $html['content']['custom_color'] .= empty( $config['content_css'] ) ? '' : ( ' data-css="' . $config['content_css'] . '"' ); if ( ! empty( $config['l_cimg'] ) ) { // background image $html['content']['css'] .= "background-image:url('{$config['l_cimg']}');background-repeat:no-repeat;background-size:cover;"; } elseif ( ! empty( $config['l_cpat'] ) ) { $html['content']['css'] .= "background-image:url('{$config['l_cpat']}');background-repeat:repeat;"; } if ( ! empty( $config['l_cbs'] ) ) { // content border style $html['content']['class'] .= ' ' . $config['l_cbs']; $html['close']['class'] .= ' ' . $config['l_cbs']; } if ( ! empty( $config['l_cbw'] ) ) { // content border width $html['content']['css'] .= "border-width:{$config['l_cbw']};"; $html['close']['css'] .= "border-width:{$config['l_cbw']};"; } if ( ! empty( $config['l_cmw'] ) ) { // content max width $html['content']['css'] .= "max-width:{$config['l_cmw']}"; } // Close Custom Color settings $html['close']['custom_color'] = empty( $config['l_ccc'] ) ? '' : ' data-tve-custom-colour="' . $config['l_ccc'] . '"'; /** * @deprecated */ if ( ! empty( $config['l_cmh'] ) ) { // content max height if ( ! is_editor_page() ) { $_height = intval( $config['l_cmh'] ); /* we need to substract 30px, the padding of the lightbox - when not in editing mode */ $config['l_cmh'] = ( $_height - 30 ) . 'px'; } $html['inner']['css'] .= "max-height:{$config['l_cmh']}"; } return $html; } /** * check if a post type from Thrive Leads is editable with tcb. Currently supported: form types and shortcodes * * @param mixed $post_id_or_type if is_numeric -> consider it as ID * * @return bool */ function tve_leads_post_type_editable( $post_id_or_type ) { $post_type = is_numeric( $post_id_or_type ) ? get_post_type( $post_id_or_type ) : $post_id_or_type; return in_array( $post_type, array( TVE_LEADS_POST_FORM_TYPE, TVE_LEADS_POST_SHORTCODE_TYPE, TVE_LEADS_POST_TWO_STEP_LIGHTBOX, ) ); } /** * check if the current post / variation is not included in a test. * If there's a test running, the form should not be editable * * @param bool $is_editable * * @return bool */ function tve_leads_check_editable_post( $is_editable ) { if ( ! $is_editable || ! isset( $_GET['_key'] ) ) { return $is_editable; } $post_id = get_the_ID(); if ( ! $post_id ) { return $is_editable; } $key = $_GET['_key']; /* we cannot edit a variation that's archived or deleted */ $variation = tve_leads_get_form_variation( $post_id, $key ); if ( $variation['post_status'] != TVE_LEADS_STATUS_PUBLISH ) { return false; } global $tvedb; $running_test = $tvedb->check_if_test_exists( $post_id, $key ); return ! empty( $running_test ) ? false : true; } /** * called when there is no active license for TCB, but it is installed and enabled * the function returns true only for pieces of content that "belong" to Thrive Leads, so only the following: * * TVE_LEADS_POST_FORM_TYPE * TVE_LEADS_POST_SHORTCODE_TYPE * tcb_lightbox (this is to be used in two-step optins) * * @param bool $value * * @return bool whether or not the current piece of content can be edited with TCB core functions */ function tve_leads_tcb_license_override( $value ) { /** * if already valid, return it */ if ( $value ) { return true; } $post_type = get_post_type(); return $post_type == 'tcb_lightbox' || tve_leads_post_type_editable( $post_type ); } /** * TODO: add function documentation * * @param $existing_icons * * @return array */ function tve_leads_get_form_icons( $existing_icons ) { if ( empty( $_POST['_key'] ) ) { return $existing_icons; } $variation_key = $_POST['_key']; $variation = tve_leads_get_form_variation( null, $variation_key ); if ( empty( $config[ TVE_LEADS_FIELD_TEMPLATE ] ) ) { return $existing_icons; } $config = tve_leads_get_editor_template_config( $variation[ TVE_LEADS_FIELD_TEMPLATE ] ); if ( empty( $config['icons'] ) ) { return $existing_icons; } return array_merge( $existing_icons, $config['icons'] ); } /** * check if TL license if valid (only if the user is trying to edit a form) * * @param bool $valid * * @return bool */ function tve_leads_editor_check_license( $valid ) { if ( empty( $_GET['_key'] ) ) { return $valid; } if ( ! tve_leads_license_activated() ) { add_action( 'wp_print_footer_scripts', 'tve_leads_license_warning' ); return false; } return true; } /** * Check if TCB version is valid * * @param bool $valid * * @return bool */ function tve_leads_editor_check_tcb_version( $valid ) { if ( empty( $_GET['_key'] ) ) { return $valid; } if ( ! $valid ) { return false; } if ( ! tve_leads_check_tcb_version() ) { add_action( 'wp_print_footer_scripts', 'tve_leads_tcb_version_warning' ); return false; } return true; } /** * Append any necessary actions to the Animation & Action component in TCB * * @param array $action_tabs * * @return array */ function tve_leads_editor_actions( $action_tabs ) { $classes = tve_leads_load_action_classes( array() ); $post_id = get_the_ID(); if ( empty( $post_id ) && ! empty( $_POST['post_id'] ) ) { $post_id = (int) $_POST['post_id']; } global $current_variation; if ( empty( $current_variation ) && ! empty( $_POST['_key'] ) ) { /* case: ajax load for a different state */ $post_id = $_POST['post_id']; $current_variation = tve_leads_get_form_variation( null, $_POST['_key'] ); } if ( empty( $current_variation ) ) { if ( $post_id && ! empty( $_REQUEST['_key'] ) ) { $last_edited_state_key = get_post_meta( $post_id, 'tve_last_edit_state_' . $_REQUEST['_key'], true ); if ( ! empty( $last_edited_state_key ) ) { $current_variation = tve_leads_get_form_variation( null, $last_edited_state_key ); } } } /** * fallback to the current one, if somehow the last edited is not set or is not existing anymore */ if ( empty( $current_variation ) && ! empty( $_REQUEST['_key'] ) ) { $current_variation = tve_leads_get_form_variation( null, $_REQUEST['_key'] ); } $action_tabs['popup']['actions']['thrive_leads_2_step'] = array( 'class' => $classes['thrive_leads_2_step'], 'order' => 20, ); $parent_form_type = get_post_meta( $current_variation['post_parent'], 'tve_form_type', true ); $parent_form_type = Thrive_Leads_Template_Manager::tpl_type_map( $parent_form_type ); if ( tve_leads_post_type_editable( $post_id ) ) { $action_tabs['popup']['actions']['thrive_lightbox']['available'] = false; $action_tabs['popup']['actions']['thrive_leads_2_step']['available'] = false; if ( $parent_form_type == 'lightbox' || $current_variation['form_state'] == 'lightbox' ) { $action_tabs['popup']['visible'] = false; } if ( $parent_form_type !== 'lightbox' ) { /** * Open Lightbox state (popup) */ $action_tabs['custom']['actions']['tl_state_lightbox'] = array( 'class' => $classes['tl_state_lightbox'], 'order' => 10, ); } if ( $parent_form_type === 'lightbox' || $current_variation['form_state'] !== 'lightbox' ) { $action_tabs['custom']['actions']['tl_state_switch'] = array( 'class' => $classes['tl_state_switch'], 'order' => 15, ); } $action_tabs['custom']['actions']['thrive_leads_form_close'] = array( 'class' => $classes['thrive_leads_form_close'], 'order' => 20, ); } return $action_tabs; } /** * Loads Thrive Leads classes and appends them to the default tcb action classes * * @param array $actions * * @return array */ function tve_leads_load_action_classes( $actions ) { require_once dirname( __FILE__ ) . '/event-manager/actions/Thrive_Leads_State_Switch_Action.php'; require_once dirname( __FILE__ ) . '/event-manager/actions/Thrive_Leads_State_Lightbox_Action.php'; require_once dirname( __FILE__ ) . '/event-manager/actions/Thrive_Leads_State_Lightbox_Close_Action.php'; require_once dirname( __FILE__ ) . '/event-manager/actions/Thrive_Leads_State_Screen_Filler_Close_Action.php'; require_once dirname( __FILE__ ) . '/event-manager/actions/Thrive_Leads_Two_Step_Action.php'; require_once dirname( __FILE__ ) . '/event-manager/actions/Thrive_Leads_Form_Close_Action.php'; $actions['tl_state_switch'] = 'Thrive_Leads_State_Switch_Action'; $actions['tl_state_lightbox'] = 'Thrive_Leads_State_Lightbox_Action'; $actions['tl_state_lb_close'] = 'Thrive_Leads_State_Lightbox_Close_Action'; $actions['tl_state_sf_close'] = 'Thrive_Leads_State_Screen_Filler_Close_Action'; $actions['thrive_leads_2_step'] = 'Thrive_Leads_Two_Step_Action'; $actions['thrive_leads_form_close'] = 'Thrive_Leads_Form_Close_Action'; return $actions; } /** * handles state-related actions: * add new state, change current state etc * */ function tve_leads_form_state_action() { $post_id = (int) $_POST['post_id']; $key = (int) $_POST['_key']; if ( empty( $post_id ) || ! current_user_can( 'edit_post', $post_id ) || empty( $key ) || empty( $_POST['custom'] ) ) { exit(); } add_filter( 'tcb_is_editor_page_ajax', '__return_true' ); add_filter( 'tcb_is_editor_page_raw_ajax', '__return_true' ); $variation = tve_leads_get_form_variation( $post_id, $key ); $form_type = tve_leads_get_form_type( $post_id ); if ( empty( $variation ) || empty( $form_type ) ) { exit(); } require_once dirname( dirname( __FILE__ ) ) . '/inc/classes/Thrive_Leads_State_Manager.php'; return Thrive_Leads_State_Manager::instance( $variation )->api( $_POST['custom_action'] ); } /** * * check if the user is currently previewing a form and if that's the case we need to make sure we include the TCB default CSS / js * * @param bool $enqueue_resources * * @return bool */ function tve_leads_enqueue_resources_preview( $enqueue_resources ) { if ( $enqueue_resources ) { return true; } return tve_leads_is_preview_page(); } /** * Add the asset delivery option */ function tve_leads_delivery_connection() { $connection = get_option( 'tve_api_delivery_service', false ); $email_body = get_option( 'tve_leads_asset_mail_subject', false ); $email_subject = get_option( 'tve_leads_asset_mail_body', false ); $connected_apis = Thrive_List_Manager::getAvailableAPIsByType( true, array( 'email' ) ); $asset = ! empty( $_POST['asset_option'] ) ? $_POST['asset_option'] : '0'; $asset_group = ! empty( $_POST['asset_group'] ) ? $_POST['asset_group'] : ''; if ( ! empty( $connected_apis ) && $connection !== false && $email_body !== false && $email_subject !== false ) { $args = array( 'post_type' => 'tve_lead_asset_group', 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'ASC', 'posts_per_page' => - 1, ); $posts_array = get_posts( $args ); if ( ! empty( $posts_array ) ) { $data = '
'; $data .= '
'; echo $data; } } } /** * add custom form options */ function tve_leads_add_form_options() { if ( $_POST['connection_type'] == 'api' ) { $account = ! empty( $_POST['create_account'] ) ? $_POST['create_account'] : '0'; $data = '
'; $data .= '
'; $data .= '
'; echo $data; } } /** * Tweak the main control panel configuration * * @param array $config * * @return array */ function tve_leads_main_cpanel_config( $config ) { $post_type = get_post_type(); if ( ! tve_leads_post_type_editable( $post_type ) || empty( $_GET['_key'] ) ) { return $config; } $config['disabled_controls'] = isset( $config['disabled_controls'] ) ? $config['disabled_controls'] : array(); $config['disabled_controls']['leads_shortcodes'] = true; $config['disabled_controls']['tu_shortcodes'] = true; $config['disabled_controls']['page_events'] = 1; $config['disabled_controls']['text']['more_link'] = true; $config['disabled_controls']['event_manager'] = array(); $config['thrive_leads'] = array( '_key' => $_GET['_key'], ); return $config; } /** * The only available style family is Flat in Thrive Leads * * @param array $style_families * * @return array */ function tve_leads_style_families( $style_families ) { $post_type = get_post_type(); if ( ! tve_leads_post_type_editable( $post_type ) || empty( $_GET['_key'] ) ) { return $style_families; } unset( $style_families['Classy'], $style_families['Minimal'] ); return $style_families; } /** * Includes the Thrive Leads Shortcode into the list of Elements * * @param array $element_instances * * @return array of elements */ function tve_leads_add_tcb_elements( $element_instances ) { /** * When editing a TL form, no TL element should be in the sidebar */ if ( tve_leads_post_type_editable( get_post_type() ) ) { /* add all the form types as TCB elements */ require_once plugin_dir_path( __FILE__ ) . 'elements/class-thrive-leads-base-element.php'; require_once plugin_dir_path( __FILE__ ) . 'elements/class-thrive-leads-slide-in-element.php'; require_once plugin_dir_path( __FILE__ ) . 'elements/class-thrive-leads-lightbox-element.php'; $element = new Thrive_Leads_Base_Element(); $slide_in = new Thrive_Leads_Slide_In_Element(); $lightbox = new Thrive_Leads_Lightbox_Element(); $element_instances[ $element->tag() ] = $element; $element_instances[ $slide_in->tag() ] = $slide_in; $element_instances[ $lightbox->tag() ] = $lightbox; return $element_instances; } /** * 1. Shortcode element */ if ( apply_filters( 'thrive_leads_element_shortcode', true ) ) { require_once plugin_dir_path( __FILE__ ) . 'elements/class-thrive-leads-shortcode-element.php'; $instance = new Thrive_Leads_Shortcode_Element(); $element_instances[ $instance->tag() ] = $instance; } return $element_instances; } /** * Include TCB menu elements * * @param $menu_path */ function tve_leads_add_tcb_menu_elements( $menu_path ) { $thrive_leads_shortcodes = tve_leads_get_shortcodes(); require_once dirname( dirname( __FILE__ ) ) . '/editor/elements/menus.php'; } /** * Add Thrive Box to custom link search results * * @param array $post_types * * @return array */ function tve_leads_search_thrivebox( $post_types ) { $post_types [ TVE_LEADS_POST_TWO_STEP_LIGHTBOX ] = array( 'name' => __( 'ThriveBox', 'thrive-leads' ), 'event_action' => 'thrive_leads_2_step', ); return $post_types; } /** * Enqueue the editor JS extensions for thrive leads * This is only called on TCB editor pages - and only for the main frame * * On Thrive Leads editing pages, an extra js is loaded: tl-editor * */ function tve_leads_enqueue_editor_extension() { $js_suffix = defined( 'TVE_DEBUG' ) && TVE_DEBUG ? '.min.js' : '.js'; tve_leads_enqueue_script( 'tve-leads-editor-extension', TVE_LEADS_URL . 'js/tcb-editor' . $js_suffix, array( 'tve-main' ), false, true ); if ( tve_leads_post_type_editable( get_post_type() ) ) { tve_leads_enqueue_script( 'tve-leads-editor', TVE_LEADS_URL . 'js/tl-editor' . $js_suffix, array( 'tve-leads-editor-extension' ), false, true ); tve_leads_enqueue_style( 'tve-leads-main-editor', TVE_LEADS_URL . 'editor-layouts/css/editor-main.css' ); } } /** * @param array $i18n * * @return array */ function tve_leads_js_translate( $i18n ) { $i18n = array_merge_recursive( $i18n, require plugin_dir_path( dirname( __FILE__ ) ) . 'inc/i18n.php' ); return $i18n; } /** * Fetch extra list of templates needed by Thrive Leads on editor pages * * @param array $templates list of templates from TCB * * @return array */ function tve_get_editor_backbone_templates( $templates = array() ) { $templates = array_merge( $templates, tve_dash_get_backbone_templates( plugin_dir_path( dirname( __FILE__ ) ) . 'inc/backbone', 'backbone' ) ); return $templates; } /** * Output the HTML for the leads form states */ function tve_leads_output_editor_states() { if ( ! tve_leads_post_type_editable( get_post_type() ) ) { return; } include plugin_dir_path( dirname( __FILE__ ) ) . 'editor-layouts/_form_states.php'; } /** * Tells TCB from where to include tl_shortcode component menu * * @param $file * * @return string */ function tve_leads_shortcode_menu_path( $file ) { $file = dirname( __FILE__ ) . '/menu/shortcode.php'; return $file; } /** * @param $data * * @return mixed */ function tve_leads_localize_shortcodes( $data ) { $shortcodes_posts = tve_leads_get_shortcodes(); $shortcodes = array(); foreach ( $shortcodes_posts as $item ) { $shortcode = array(); $shortcode['id'] = $item->ID; $shortcode['label'] = $item->post_title; $shortcode['title'] = $item->post_title; $shortcodes[] = $shortcode; } $data['tl_shortcodes'] = $shortcodes; return $data; } function tve_leads_localize_templates( $data ) { if ( ! tve_leads_post_type_editable( get_post_type() ) ) { return $data; } $post_id = isset( $_REQUEST['p'] ) ? intval( $_REQUEST['p'] ) : 0; $variation_key = isset( $_REQUEST['_key'] ) ? intval( $_REQUEST['_key'] ) : 0; $last_edited_state_key = get_post_meta( $post_id, 'tve_last_edit_state_' . $variation_key, true ); $variation = tve_leads_get_form_variation( $post_id, $last_edited_state_key ? $last_edited_state_key : $variation_key ); $form_type = tve_leads_get_form_type_from_variation( $variation, true, false ); $get_multi_step = ! (bool) $variation['parent_id']; $templates = Thrive_Leads_Template_Manager::get_templates( $form_type, $get_multi_step ); if ( ! empty( $templates ) ) { $data['tl_templates'] = $templates; } return $data; } /** * Enable the template tab on sidebar if the post type is one of TL post types * * @param $has_template * * @return bool */ function tve_leads_has_templates_tab( $has_template ) { if ( tve_leads_post_type_editable( get_post_type() ) ) { $has_template = true; } return $has_template; } /** * In Templates Tab from Sidebar * set the available settings menu items for current template */ function tve_leads_templates_menu() { if ( ! tve_leads_post_type_editable( get_post_type() ) ) { return; } echo tve_leads_template( 'template-settings', null, true ); } /** * TCB prints the modals' HTML on footer print scripts action and * a new file is added to the list * to be used when user wants to select a template for current variation * * @param $files * * @return array $files */ function tve_leads_modal_templates( $files ) { if ( ! tve_leads_post_type_editable( get_post_type() ) ) { return $files; } $files[] = TVE_LEADS_PATH . 'tcb-bridge/modals/tl-templates.php'; $files[] = TVE_LEADS_PATH . 'tcb-bridge/modals/tl-template-saving.php'; return $files; } /** * Check if we are currently in a editor page for a Thrive Leads form * * @param bool $can_use * * @return bool */ function tve_leads_can_use_page_events( $can_use ) { return tve_leads_post_type_editable( get_post_type() ) ? false : $can_use; } /** * On lead generation menu component add html for Asset Delivery Control */ function tve_leads_insert_asset_delivery_control() { if ( ! tve_leads_asset_delivery_setup_valid() ) { return; } echo tve_leads_template( 'asset-delivery-control', null, true ); } /** * Hook into Lead Generation Element Config * * @param $config * * @return mixed */ function tve_leads_lead_generation_config( $config ) { if ( ! tve_leads_asset_delivery_setup_valid() ) { return $config; } $options = array(); foreach ( tve_leads_get_asset_delivery_groups() as $group ) { $option = array(); $option['value'] = $group->ID; $option['name'] = $group->post_title; $options[] = $option; } $config['components']['lead_generation']['config']['AssetDelivery'] = array( 'config' => array( 'label' => __( 'Enable Asset Delivery', 'thrive-leads' ), ), ); $config['components']['lead_generation']['config']['AssetGroup'] = array( 'config' => array( 'name' => __( 'Asset Group', 'thrive-leads' ), 'label_col_x' => 5, 'options' => $options, 'consent_label' => __( 'Send asset "{asset_name}" to email address', 'thrive-leads' ), ), ); return $config; } /** * @param string $logo_url * * @return string */ function tve_leads_architect_branding( $logo_url ) { if ( tve_leads_post_type_editable( get_post_type() ) ) { $logo_url = TVE_LEADS_URL . 'admin/img/thrive-leads-logo.png'; } return $logo_url; }