setting. "form:cf7" toggles one form plugin. */ private static function switches() { return array( 'any_form', 'capture_registrations', 'bookings' ); } /** * Tile colours for integrations, so each keeps the same look. Initials stand in for logos. * * @param string $key Integration key. */ private static function tone( $key ) { $tones = array( 'cf7' => '#2E6BB5', 'wpforms' => '#E27730', 'gravity' => '#F15A2B', 'ninja' => '#EF4748', 'elementor' => '#92003B', 'fluent' => '#1A7EFB', 'formidable' => '#4199FD', 'motopress' => '#2B6CB0', 'latepoint' => '#1D7BFF', 'amelia' => '#1A84EE', 'ssa' => '#0C9A8C', 'woo' => '#7F54B3', 'wp' => '#3858E9', 'any' => '#636366', 'fluentcrm' => '#6366F1', 'groundhogg' => '#F58220', 'jetpackcrm' => '#069E08', 'webhook' => '#30B0C7', 'phone' => '#34C759', 'ai' => '#AF52DE', 'nodebook' => '#1C1C1E', 'bookings' => '#FF9500', ); return $tones[ $key ] ?? '#8E8E93'; } /** Two letters for a tile: "Contact Form 7" โ "CF", "WooCommerce" โ "Wo". */ private static function initials( $name ) { $words = preg_split( '/[\s\-]+/u', trim( (string) $name ), -1, PREG_SPLIT_NO_EMPTY ); if ( count( $words ) > 1 ) { return mb_strtoupper( mb_substr( $words[0], 0, 1 ) . mb_substr( $words[1], 0, 1 ) ); } return mb_substr( (string) $name, 0, 2 ); } /** * Submissions, bookings or orders that came in through a source in the last 30 days. * * @param string $source Source label stored on the activity (e.g. "Contact Form 7"). * @param array $types Activity types. */ private static function count( $source, array $types ) { global $wpdb; $since = gmdate( 'Y-m-d H:i:s', time() - 30 * DAY_IN_SECONDS ); $like = '%' . $wpdb->esc_like( '"source":' . wp_json_encode( $source ) ) . '%'; $rows = array(); foreach ( $types as $type ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- the plugin's own table. $rows[] = (int) $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(*) FROM %i WHERE type = %s AND created_at >= %s AND data LIKE %s', Nodebook_Activities::table(), $type, $since, $like ) ); } return array_sum( $rows ); } /** Orders on the timeline in the last 30 days. */ private static function orders() { global $wpdb; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- the plugin's own table. return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM %i WHERE type = 'order' AND created_at >= %s", Nodebook_Activities::table(), gmdate( 'Y-m-d H:i:s', time() - 30 * DAY_IN_SECONDS ) ) ); } /** New contacts that came from WordPress sign-ups in the last 30 days. */ private static function signups() { global $wpdb; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- the plugin's own table. return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM %i WHERE type = 'signup' AND created_at >= %s", Nodebook_Activities::table(), gmdate( 'Y-m-d H:i:s', time() - 30 * DAY_IN_SECONDS ) ) ); } /** * "12 submissions in the last 30 days" or "No submissions in the last 30 days". * * @param int $n Number. * @param string $kind submission, booking, order or signup. */ private static function came( $n, $kind ) { $n = (int) $n; switch ( $kind ) { case 'booking': /* translators: %s: number */ return $n ? sprintf( _n( '%s booking in the last 30 days', '%s bookings in the last 30 days', $n, 'nodebook' ), number_format_i18n( $n ) ) : __( 'No bookings in the last 30 days', 'nodebook' ); case 'order': /* translators: %s: number */ return $n ? sprintf( _n( '%s order in the last 30 days', '%s orders in the last 30 days', $n, 'nodebook' ), number_format_i18n( $n ) ) : __( 'No orders in the last 30 days', 'nodebook' ); case 'signup': /* translators: %s: number */ return $n ? sprintf( _n( '%s sign-up in the last 30 days', '%s sign-ups in the last 30 days', $n, 'nodebook' ), number_format_i18n( $n ) ) : __( 'No sign-ups in the last 30 days', 'nodebook' ); default: /* translators: %s: number */ return $n ? sprintf( _n( '%s submission in the last 30 days', '%s submissions in the last 30 days', $n, 'nodebook' ), number_format_i18n( $n ) ) : __( 'No submissions in the last 30 days', 'nodebook' ); } } public static function page() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Only administrators can change integrations.', 'nodebook' ), 403 ); } $s = Nodebook_Settings::all(); $forms = array(); $later = array(); foreach ( Nodebook_Forms::integrations() as $key => $int ) { if ( call_user_func( $int[1] ) ) { $forms[ $key ] = $int[0]; } else { $later[] = $int[0]; } } $books = array(); $blate = array(); foreach ( Nodebook_Bookings::integrations() as $key => $int ) { if ( call_user_func( $int[1] ) ) { $books[ $key ] = $int[0]; } else { $blate[] = $int[0]; } } $crms = array(); foreach ( Nodebook_Import::available() as $key => $cls ) { $crms[ $key ] = call_user_func( array( $cls, 'label' ) ); } // Headline: how many are on, and what came in. $on = 0; $total = 0; foreach ( $forms as $key => $name ) { $on += in_array( $key, (array) $s['forms'], true ) ? 1 : 0; $total += self::count( $name, array( 'form' ) ); } foreach ( $books as $name ) { $on += ! empty( $s['bookings'] ) ? 1 : 0; $total += self::count( $name, array( 'booking', 'appointment' ) ); } $woo = Nodebook_Woocommerce::active(); if ( $woo ) { $on += 'off' !== Nodebook_Woocommerce::mode() ? 1 : 0; $total += self::orders(); } $on += ! empty( $s['any_form'] ) ? 1 : 0; $on += ! empty( $s['capture_registrations'] ) ? 1 : 0; $total += self::signups(); Nodebook_Admin::header( __( 'Integrations', 'nodebook' ), array(), array( 'sub' => __( 'What Nodebook is connected to. Switch things on or off here; the details live in Settings.', 'nodebook' ) ) ); echo '
'; // Forms. self::group_start( 'forms', __( 'Forms', 'nodebook' ) ); foreach ( $forms as $key => $name ) { $is = in_array( $key, (array) $s['forms'], true ); self::row( $key, $name, $is ? self::came( self::count( $name, array( 'form' ) ), 'submission' ) : __( 'Off: submissions are not saved', 'nodebook' ), 'form:' . $key, $is ); } self::row( 'any', __( 'Any other form', 'nodebook' ), __( 'Theme, page-builder and hand-made HTML forms with an email or phone field', 'nodebook' ), 'any_form', ! empty( $s['any_form'] ) ); if ( $later ) { self::note( /* translators: %s: list of plugins */ sprintf( __( 'Also works with %s: captured as soon as one is installed.', 'nodebook' ), implode( ', ', $later ) ) ); } self::group_end( Nodebook_Admin::url( 'nodebook-settings' ) . '#nb-capture', __( 'Field matching and what to do with existing contacts', 'nodebook' ) ); // Bookings. self::group_start( 'bookings', __( 'Bookings and appointments', 'nodebook' ) ); if ( $books ) { self::row( 'bookings', __( 'Bookings on the timeline', 'nodebook' ), __( 'Bookings and appointments become contacts, with the property, service or room they booked.', 'nodebook' ), 'bookings', ! empty( $s['bookings'] ) ); foreach ( $books as $key => $name ) { self::row( $key, $name, ! empty( $s['bookings'] ) ? self::came( self::count( $name, array( 'booking', 'appointment' ) ), 'booking' ) : __( 'Off: bookings are not saved', 'nodebook' ), '', ! empty( $s['bookings'] ) ); } } else { self::note( __( 'No booking plugin found.', 'nodebook' ) ); } if ( $blate ) { self::note( /* translators: %s: list of plugins */ sprintf( __( 'Also works with %s.', 'nodebook' ), implode( ', ', $blate ) ) ); } self::group_end( '', '' ); // Shop and site. self::group_start( 'site', __( 'Shop and site', 'nodebook' ) ); if ( $woo ) { $modes = array( 'orders' => __( 'Every buyer becomes a contact at checkout', 'nodebook' ), 'paid' => __( 'Buyers become contacts once an order is paid', 'nodebook' ), 'existing' => __( 'Orders are added to people already in Nodebook', 'nodebook' ), 'off' => __( 'Off: nothing from WooCommerce', 'nodebook' ), ); $mode = Nodebook_Woocommerce::mode(); self::row( 'woo', 'WooCommerce', ( $modes[ $mode ] ?? '' ) . ( 'off' !== $mode ? ' ยท ' . self::came( self::orders(), 'order' ) : '' ), '', 'off' !== $mode, array( __( 'Change', 'nodebook' ) => Nodebook_Admin::url( 'nodebook-settings' ) . '#nb-woo' ) ); } self::row( 'wp', __( 'WordPress sign-ups', 'nodebook' ), ! empty( $s['capture_registrations'] ) ? self::came( self::signups(), 'signup' ) : __( 'Off: new users are not added', 'nodebook' ), 'capture_registrations', ! empty( $s['capture_registrations'] ), array( __( 'Import existing users', 'nodebook' ) => Nodebook_Admin::url( 'nodebook-tools' ) . '#nb-users' ) ); self::group_end( '', '' ); // Connect anything. self::group_start( 'connect', __( 'Connect anything', 'nodebook' ) ); echo '