Thrive Themes * Description: Live front end editor for your WordPress content * Text domain: thrive-cb * Domain Path: /languages * Requires PHP: 8.1 */ defined( 'TVE_EDITOR_URL' ) || define( 'TVE_EDITOR_URL', plugin_dir_url( __FILE__ ) ); if ( ! defined( 'TVE_TCB_CORE_INCLUDED' ) ) { require_once plugin_dir_path( __FILE__ ) . 'plugin-core.php'; } if ( ! defined( 'TVE_PLUGIN_FILE' ) ) { define( 'TVE_PLUGIN_FILE', __FILE__ ); } defined( 'TVE_IN_ARCHITECT' ) || define( 'TVE_IN_ARCHITECT', true ); /** * Classes that should only be available when TCB is used stand-alone */ if ( ! class_exists( 'TCB_Post' ) ) { /** * Case: TL v1, TCB v2 */ require_once plugin_dir_path( __FILE__ ) . 'inc/classes/class-tcb-post.php'; } /** * Init the UpdateCheck at init action because * Dashboard loads its class at plugins_loaded */ add_action( 'init', 'tve_update_checker' ); /** * admin licensing menu link */ add_action( 'wp_enqueue_scripts', 'tve_frontend_enqueue_scripts' ); // add filter for including the TCB meta into the search functionality - this is only required on the TCB editor add_filter( 'posts_clauses', 'tve_process_search_clauses', null, 2 ); add_filter( 'get_the_content_limit', 'tve_genesis_get_post_excerpt', 10, 4 ); // automatically modify lightbox title if the title of the associated landing page is modified - applies ony to TCB add_action( 'save_post', 'tve_save_post_callback' ); /* filter that allows adding custom icon packs to the "Choose icon" lightbox in the TCB editor */ add_filter( 'tcb_get_extra_icons', 'tve_landing_page_extra_icon_packs', 10, 2 ); /* filter that allows adding custom fonts to the "choose custom font" menu item */ add_filter( 'tcb_extra_custom_fonts', 'tve_get_extra_custom_fonts', 10, 2 ); /* action that fires when the custom fonts css should be included in the page */ add_action( 'tcb_extra_fonts_css', 'tve_output_extra_custom_fonts_css' ); /** fires when all plugins are loaded - used for intermediate filter setup / plugin overrides */ add_action( 'plugins_loaded', 'tve_plugins_loaded_hook' ); //after the plugin is loaded load the dashboard version file add_action( 'plugins_loaded', 'tve_load_dash_version' ); add_action( 'wp_head', 'tve_load_custom_css', 100, 0 ); /** * Architect Product must be included only if Architect is active and needs to be added all the time to be able to check external capabilities for access manager */ add_filter( 'tve_dash_installed_products', 'tcb_add_to_dashboard_list' ); add_filter( 'tve_dash_email_data', 'tve_extend_email_tags', 10, 2 ); /** * Add class to the body when gutenberg/gutenberg.php is active */ add_filter( 'admin_body_class', 'tve_add_gutenberg_active_class' ); /** * Add email-tags if it is necessary for email sending * * @param array $data * @param array $arguments * * @return array */ function tve_extend_email_tags( $data, $arguments ) { $required_tags = [ 'page_slug', 'form_identifier' ]; $tags = array(); foreach ( $required_tags as $tag ) { if ( ! empty( $arguments[ $tag ] ) ) { $tags[] = $arguments[ $tag ]; } } $data['email_tags'] = $tags; return $data; } /** * include the TCB saved meta into query search fields * * WordPress actually allows inserting post META fields in the search query, * but it will always build the clauses with AND (between post content and post meta) e.g.: * WHERE (posts.title LIKE '%xx%' OR posts.post_content) AND (postsmeta.meta_key = 'tve_save_post' AND postsmeta.meta_value LIKE '%xx%') * * - we cannot use this, so we hook into the final pieces of the built SQL query - we need a solution like this: * WHERE ( (posts.title LIKE '%xx%' OR posts.post_content OR (postsmeta.meta_key = 'tve_save_post' AND postsmeta.meta_value LIKE '%xx%') ) * * @param array $pieces * @param WP_Query $wp_query * * @return array */ function tve_process_search_clauses( $pieces, $wp_query ) { if ( empty( $pieces ) || is_admin() || ! $wp_query->is_search() ) { return $pieces; } /** @var wpdb $wpdb */ global $wpdb; $query = ''; $q = $wp_query->query_vars; $n = ! empty( $q['exact'] ) ? '' : '%'; if ( ! empty( $q['search_terms'] ) ) { foreach ( $q['search_terms'] as $term ) { $term = $wpdb->esc_like( $term ); $like = $n . $term . $n; $query .= "((tve_pm.meta_key = 'tve_updated_post')"; $query .= $wpdb->prepare( ' AND (tve_pm.meta_value LIKE %s)) OR ', $like ); } } if ( ! empty( $query ) ) { // add to where clause $pieces['where'] = str_replace( "((({$wpdb->posts}.post_title LIKE '{$n}", "( {$query} (({$wpdb->posts}.post_title LIKE '{$n}", $pieces['where'] ); $pieces['join'] .= " LEFT JOIN {$wpdb->postmeta} AS tve_pm ON ({$wpdb->posts}.ID = tve_pm.post_id)"; if ( empty( $pieces['groupby'] ) ) { $pieces['groupby'] = "{$wpdb->posts}.ID"; } } return ( $pieces ); } /** * Handler for "get_the_content_limit" action applied by genesis themes * * Called on pages with posts list * If posts was created with TCB the more_element link is searched. If it is found the content before it is returned. * If more_element is not found the post's content added from admin is appended with TCB content then truncation is applied * * @param string $output Truncated content post by genesis * @param string $content the stripped and truncated genesis content * @param string $link the read more link * @param int $max_characters the maximum number of characters to truncate to * * @return string $content */ function tve_genesis_get_post_excerpt( $output, $content, $link, $max_characters ) { global $post; $post_id = get_the_ID(); if ( ! tve_check_in_loop( $post_id ) ) { tve_load_custom_css( $post_id ); } if ( ! is_singular() ) { $more_found = tve_get_post_meta( get_the_ID(), 'tve_content_more_found', true ); $content_before_more = tve_get_post_meta( get_the_ID(), 'tve_content_before_more', true ); if ( ! empty( $content_before_more ) && $more_found ) { $more_link = apply_filters( 'the_content_more_link', '' . __( 'Continue Reading', 'thrive-cb' ) . '', __( 'Continue Reading', 'thrive-cb' ) ); $content = '