array( 'datetime' => true, 'title' => true, ), 'span' => array( 'class' => true ), ); public static function cap() { /** * Capability required to use the CRM screens. */ return apply_filters( 'nodebook_capability', Nodebook_Team::CAP ); } public static function init() { add_action( 'admin_init', array( __CLASS__, 'guard' ), 1 ); add_action( 'admin_menu', array( __CLASS__, 'menu' ) ); add_action( 'in_admin_header', array( __CLASS__, 'quiet_notices' ), 1000 ); Nodebook_Admin_Welcome::init(); add_action( 'admin_init', array( 'Nodebook_Admin_Settings', 'register' ) ); add_action( 'admin_enqueue_scripts', array( __CLASS__, 'assets' ) ); add_filter( 'admin_body_class', array( __CLASS__, 'body_class' ) ); add_filter( 'plugin_action_links_' . plugin_basename( NODEBOOK_FILE ), array( __CLASS__, 'links' ) ); add_filter( 'set-screen-option', array( __CLASS__, 'screen_option' ), 10, 3 ); $posts = array( 'nodebook_save_contact' => array( 'Nodebook_Admin_Contact', 'save' ), 'nodebook_delete_contact' => array( 'Nodebook_Admin_Contact', 'delete' ), 'nodebook_add_note' => array( 'Nodebook_Admin_Contact', 'add_note' ), 'nodebook_delete_note' => array( 'Nodebook_Admin_Contact', 'delete_note' ), 'nodebook_contact_segs' => array( 'Nodebook_Admin_Contact', 'segments' ), 'nodebook_watch' => array( 'Nodebook_Admin_Contact', 'watch' ), 'nodebook_integration' => array( 'Nodebook_Admin_Integrations', 'save' ), 'nodebook_recipe' => array( 'Nodebook_Admin_Automations', 'save' ), 'nodebook_sync' => array( 'Nodebook_Admin_Sync', 'save' ), 'nodebook_sample' => array( 'Nodebook_Sample', 'handle' ), 'nodebook_inbound_key' => array( 'Nodebook_Admin_Settings', 'regenerate_key' ), 'nodebook_test_alert' => array( 'Nodebook_Admin_Settings', 'test_alert' ), 'nodebook_followed_up' => array( 'Nodebook_Admin_Contact', 'followed_up' ), 'nodebook_hide_setup' => array( 'Nodebook_Admin_Contact', 'hide_setup' ), 'nodebook_node_dismiss' => array( 'Nodebook_Node', 'dismiss_post' ), 'nodebook_setup_choice' => array( 'Nodebook_Setup', 'choice_post' ), 'nodebook_growth_mark' => array( 'Nodebook_Admin_Growth', 'mark_post' ), 'nodebook_app_forget' => array( 'Nodebook_Admin_Settings', 'app_forget' ), 'nodebook_owner' => array( 'Nodebook_Admin_Contact', 'owner' ), 'nodebook_status' => array( 'Nodebook_Admin_Board', 'set_status_post' ), 'nodebook_clear_reminder' => array( 'Nodebook_Admin_Contact', 'clear_reminder' ), 'nodebook_snooze' => array( 'Nodebook_Admin_Contact', 'snooze' ), 'nodebook_pin' => array( 'Nodebook_Admin_Contact', 'pin' ), 'nodebook_email_status' => array( 'Nodebook_Admin_Contact', 'email_status' ), 'nodebook_task' => array( 'Nodebook_Admin_Contact', 'task_action' ), 'nodebook_test_weekly' => array( 'Nodebook_Admin_Settings', 'test_weekly' ), 'nodebook_fields_save' => array( 'Nodebook_Admin_Fields', 'save' ), 'nodebook_field_add' => array( 'Nodebook_Admin_Fields', 'add' ), 'nodebook_field_presets' => array( 'Nodebook_Admin_Fields', 'presets' ), 'nodebook_field_promote' => array( 'Nodebook_Admin_Fields', 'promote' ), 'nodebook_segment_template' => array( 'Nodebook_Admin_Segments', 'from_template' ), 'nodebook_merge' => array( 'Nodebook_Admin_Duplicates', 'merge' ), 'nodebook_dismiss_dupe' => array( 'Nodebook_Admin_Duplicates', 'dismiss' ), 'nodebook_save_company' => array( 'Nodebook_Admin_Company', 'save' ), 'nodebook_delete_company' => array( 'Nodebook_Admin_Company', 'delete' ), 'nodebook_save_segment' => array( 'Nodebook_Admin_Segments', 'save' ), 'nodebook_delete_segment' => array( 'Nodebook_Admin_Segments', 'delete' ), 'nodebook_export' => array( 'Nodebook_Admin_Tools', 'export' ), 'nodebook_import_upload' => array( 'Nodebook_Admin_Tools', 'upload' ), 'nodebook_import_map' => array( 'Nodebook_Admin_Tools', 'map' ), 'nodebook_module' => array( 'Nodebook_Admin_Modules', 'toggle' ), 'nodebook_pipeline' => array( 'Nodebook_Admin_Pipelines', 'save' ), ); foreach ( $posts as $action => $cb ) { add_action( 'admin_post_' . $action, $cb ); } add_action( 'wp_ajax_nodebook_import_batch', array( 'Nodebook_Admin_Tools', 'ajax_batch' ) ); add_action( 'wp_ajax_nodebook_woo_backfill', array( 'Nodebook_Admin_Tools', 'ajax_backfill' ) ); add_action( 'wp_ajax_nodebook_app_code', array( 'Nodebook_Admin_Settings', 'app_code' ) ); add_action( 'wp_ajax_nodebook_growth_probe', array( 'Nodebook_Admin_Growth', 'probe_ajax' ) ); add_action( 'wp_ajax_nodebook_contact_list', array( 'Nodebook_Admin_Contact', 'list_ajax' ) ); add_action( 'wp_ajax_nodebook_send_email', array( 'Nodebook_Email', 'ajax' ) ); add_action( 'wp_ajax_nodebook_users_import', array( 'Nodebook_Admin_Tools', 'ajax_users' ) ); add_action( 'wp_ajax_nodebook_node_panel', array( 'Nodebook_Admin_Node', 'panel_ajax' ) ); add_action( 'wp_ajax_nodebook_node_later', array( 'Nodebook_Admin_Node', 'dismiss_ajax' ) ); add_action( 'admin_post_nodebook_pin_segment', array( 'Nodebook_Admin_Segments', 'pin' ) ); add_action( 'wp_ajax_nodebook_crm_import', array( 'Nodebook_Admin_Tools', 'ajax_crm_import' ) ); add_action( 'wp_ajax_nodebook_set_status', array( 'Nodebook_Admin_Board', 'set_status_ajax' ) ); Nodebook_Admin_Deals::init(); } public static function menu() { $cap = self::cap(); $due = current_user_can( $cap ) ? Nodebook_Admin_Today::badge() : 0; $badge = $due ? ' ' . number_format_i18n( $due ) . '' : ''; add_menu_page( self::brand_name(), esc_html( self::brand_name() ) . $badge, $cap, 'nodebook', array( 'Nodebook_Admin_Contact', 'page' ), 'dashicons-groups', 26 ); $contacts = add_submenu_page( 'nodebook', __( 'Contacts', 'nodebook' ), __( 'Contacts', 'nodebook' ), $cap, 'nodebook', array( 'Nodebook_Admin_Contact', 'page' ) ); add_submenu_page( 'nodebook', __( 'Today', 'nodebook' ), __( 'Today', 'nodebook' ) . $badge, $cap, 'nodebook-today', array( 'Nodebook_Admin_Today', 'page' ) ); // Deals switched off: the screens still open (links, bookmarks), they just leave the menu. add_submenu_page( Nodebook_Deals::on() ? 'nodebook' : 'options.php', __( 'Deals', 'nodebook' ), __( 'Deals', 'nodebook' ), $cap, 'nodebook-deals', array( 'Nodebook_Admin_Deals', 'page' ) ); add_submenu_page( 'nodebook', __( 'Board', 'nodebook' ), __( 'Board', 'nodebook' ), $cap, 'nodebook-board', array( 'Nodebook_Admin_Board', 'page' ) ); // The setup: no menu entry of its own. $welcome = add_submenu_page( 'options.php', __( 'Set up Nodebook', 'nodebook' ), __( 'Set up Nodebook', 'nodebook' ), 'manage_options', 'nodebook-welcome', array( 'Nodebook_Admin_Welcome', 'page' ) ); add_action( 'load-' . $welcome, static function () { // A focused screen: no notices from other plugins. remove_all_actions( 'admin_notices' ); remove_all_actions( 'all_admin_notices' ); } ); add_submenu_page( 'nodebook', __( 'Journeys', 'nodebook' ), __( 'Journeys', 'nodebook' ), $cap, 'nodebook-journeys', array( 'Nodebook_Admin_Journeys', 'page' ) ); add_submenu_page( 'nodebook', __( 'Growth', 'nodebook' ), __( 'Growth', 'nodebook' ), 'manage_options', 'nodebook-growth', array( 'Nodebook_Admin_Growth', 'page' ) ); $companies = add_submenu_page( 'nodebook', __( 'Companies', 'nodebook' ), __( 'Companies', 'nodebook' ), $cap, 'nodebook-companies', array( 'Nodebook_Admin_Company', 'page' ) ); $dupes = Nodebook_Team::restricted() ? 0 : (int) get_transient( 'nodebook_dupe_count' ); /* translators: %s: number badge */ $dupe_label = $dupes ? sprintf( __( 'Duplicates %s', 'nodebook' ), '' . number_format_i18n( $dupes ) . '' ) : __( 'Duplicates', 'nodebook' ); add_submenu_page( 'nodebook', __( 'Duplicates', 'nodebook' ), $dupe_label, $cap, 'nodebook-duplicates', array( 'Nodebook_Admin_Duplicates', 'page' ) ); add_submenu_page( 'nodebook', __( 'Segments', 'nodebook' ), __( 'Segments', 'nodebook' ), $cap, 'nodebook-segments', array( 'Nodebook_Admin_Segments', 'page' ) ); add_submenu_page( 'nodebook', __( 'Import & Export', 'nodebook' ), __( 'Import & Export', 'nodebook' ), $cap, 'nodebook-tools', array( 'Nodebook_Admin_Tools', 'page' ) ); add_submenu_page( 'nodebook', __( 'Integrations', 'nodebook' ), __( 'Integrations', 'nodebook' ), 'manage_options', 'nodebook-integrations', array( 'Nodebook_Admin_Integrations', 'page' ) ); add_submenu_page( 'nodebook', __( 'Automations', 'nodebook' ), __( 'Automations', 'nodebook' ), 'manage_options', 'nodebook-automations', array( 'Nodebook_Admin_Automations', 'page' ) ); if ( Nodebook_Deals::on() ) { add_submenu_page( 'nodebook', __( 'Pipelines', 'nodebook' ), __( 'Pipelines', 'nodebook' ), 'manage_options', Nodebook_Admin_Pipelines::PAGE, array( 'Nodebook_Admin_Pipelines', 'page' ) ); } add_submenu_page( 'nodebook', __( 'Fields', 'nodebook' ), __( 'Fields', 'nodebook' ), 'manage_options', 'nodebook-fields', array( 'Nodebook_Admin_Fields', 'page' ) ); add_submenu_page( 'nodebook', __( 'Modules', 'nodebook' ), __( 'Modules', 'nodebook' ), 'manage_options', 'nodebook-modules', array( 'Nodebook_Admin_Modules', 'page' ) ); add_submenu_page( 'nodebook', __( 'Settings', 'nodebook' ), __( 'Settings', 'nodebook' ), 'manage_options', 'nodebook-settings', array( 'Nodebook_Admin_Settings', 'page' ) ); foreach ( array( $contacts, $companies ) as $hook ) { add_action( 'load-' . $hook, array( __CLASS__, 'list_screen' ) ); } do_action( 'nodebook_admin_menu', $cap ); self::order_menu(); } /** * Sidebar order follows the app: Today, Contacts, Deals, Board, Journeys, then the rest of each part. * The first item is where "Nodebook" itself leads, so that is Today. Pages added by modules keep their place * after these. */ private static function order_menu() { global $submenu; if ( empty( $submenu['nodebook'] ) || ! is_array( $submenu['nodebook'] ) ) { return; } $order = array( 'nodebook-today', 'nodebook', 'nodebook-deals', 'nodebook-board', 'nodebook-gatherings', 'nodebook-journeys', 'nodebook-companies', 'nodebook-segments', 'nodebook-duplicates', 'nodebook-growth', 'nodebook-tools', 'nodebook-integrations', 'nodebook-automations', 'nodebook-pipelines', 'nodebook-fields', 'nodebook-modules', 'nodebook-settings' ); $rank = array_flip( $order ); $items = array_values( $submenu['nodebook'] ); $pos = array(); foreach ( $items as $i => $item ) { $pos[ $i ] = isset( $rank[ $item[2] ] ) ? $rank[ $item[2] ] : 100 + $i; } uksort( $items, static function ( $a, $b ) use ( $pos ) { return $pos[ $a ] <=> $pos[ $b ]; } ); $submenu['nodebook'] = array_values( $items ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- reordering our own submenu. } public static function list_screen() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- routing only. if ( empty( $_GET['action'] ) ) { add_screen_option( 'per_page', array( 'default' => 25, 'option' => 'nodebook_per_page', ) ); } // Fewer columns by default (people can switch them back on under Screen Options). add_filter( 'default_hidden_columns', static function ( $hidden ) { // Your own fields start hidden too: switch on the ones you want as columns. return array_merge( (array) $hidden, array( 'created', 'visits', 'email_status' ), array_keys( Nodebook_Props::defs( 'contact' ) ) ); } ); // Bulk actions are processed before output so we can redirect. $screen = get_current_screen(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- routing only. if ( empty( $_GET['action'] ) ) { // Creating the table now registers its columns, so Screen Options can list them (switch columns on/off). if ( $screen && false !== strpos( $screen->id, 'nodebook-companies' ) ) { new Nodebook_List_Companies(); } else { new Nodebook_List_Contacts(); } } if ( $screen && false !== strpos( $screen->id, 'nodebook-companies' ) ) { Nodebook_List_Companies::process_bulk(); } else { Nodebook_List_Contacts::process_bulk(); } } public static function screen_option( $status, $option, $value ) { return 'nodebook_per_page' === $option ? max( 5, min( 500, absint( $value ) ) ) : $status; } public static function links( $links ) { array_unshift( $links, '' . esc_html__( 'Settings', 'nodebook' ) . '' ); return $links; } /** * Nodebook screens are an app of their own: other plugins' banners and nags stay on their own pages. * Nodebook's own messages are printed inside the screen (notices()), not through these hooks. */ public static function quiet_notices() { if ( ! self::is_screen() || ! apply_filters( 'nodebook_quiet_notices', true ) ) { return; } foreach ( array( 'admin_notices', 'all_admin_notices', 'network_admin_notices', 'user_admin_notices' ) as $hook ) { remove_all_actions( $hook ); } } public static function is_screen() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- routing only. $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; return 0 === strpos( $page, 'nodebook' ); } public static function assets( $hook = '' ) { if ( 'index.php' === $hook ) { wp_enqueue_style( 'nodebook-admin', nodebook_asset( 'css/admin.css' ), array(), NODEBOOK_VERSION ); return; } if ( ! self::is_screen() ) { return; } wp_enqueue_style( 'nodebook-admin', nodebook_asset( 'css/admin.css' ), array(), NODEBOOK_VERSION ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- screen detection only. if ( isset( $_GET['page'] ) && 'nodebook-settings' === $_GET['page'] ) { wp_enqueue_script( 'nodebook-qrcode', nodebook_asset( 'js/vendor/qrcode.js' ), array(), '2.0.4', true ); } wp_enqueue_script( 'nodebook-admin', nodebook_asset( 'js/admin.js' ), array(), NODEBOOK_VERSION, true ); wp_localize_script( 'nodebook-admin', 'nodebookAdmin', array( 'ajax' => admin_url( 'admin-ajax.php' ), 'beacon' => rest_url( 'nodebook/v1/hit' ), 'nonce' => wp_create_nonce( 'nodebook_ajax' ), 'ops' => Nodebook_Segments::operators(), 'fields' => array_map( static function ( $f ) { return array( $f[0], $f[1] ); }, Nodebook_Segments::rule_fields() ), 'options' => array( 'status' => Nodebook_Fields::statuses(), 'segment' => wp_list_pluck( Nodebook_Segments::all( 'static' ), 'name', 'id' ), 'activity' => Nodebook_Activities::types(), 'click' => wp_list_pluck( Nodebook_Tracker::click_kinds(), 0 ), 'emailstatus' => array( 'none' => __( 'Not asked', 'nodebook' ) ) + array_slice( Nodebook_Subscription::statuses(), 1, null, true ), 'event' => Nodebook_Events::labels(), 'deal' => self::deal_options(), 'owner' => array( 'me' => __( 'Me (whoever is viewing)', 'nodebook' ), '0' => __( 'Unassigned', 'nodebook' ), ) + Nodebook_Team::users(), ), 'templates' => Nodebook_Followup::templates(), 'team' => Nodebook_Team::is_team() ? array_values( array_map( static function ( $p ) { return array( $p[0], $p[1] ); }, Nodebook_Mentions::people() ) ) : array(), // Outcome → suggested next step and when. 'nextSteps' => array( 'no_answer' => array( __( 'Try again', 'nodebook' ), 'tomorrow' ), 'left_message' => array( __( 'Call again if no reply', 'nodebook' ), '3days' ), 'quote_sent' => array( __( 'Check they received the quote', 'nodebook' ), '3days' ), 'spoke' => array( '', '' ), ), 'i18n' => array( 'confirm' => __( 'Are you sure? This cannot be undone.', 'nodebook' ), 'done' => __( 'Done.', 'nodebook' ), 'error' => __( 'Something went wrong. Please try again.', 'nodebook' ), 'noMatch' => __( 'No matches', 'nodebook' ), /* translators: %1$s: number of search results */ 'results' => __( '%1$s results', 'nodebook' ), 'newCo' => __( 'New company: it is added when you save.', 'nodebook' ), 'newPerson' => __( 'New contact: added when you save.', 'nodebook' ), /* translators: 1: created, 2: updated, 3: skipped */ 'imported' => __( '%1$s created · %2$s updated · %3$s skipped', 'nodebook' ), 'remove' => __( 'Remove condition', 'nodebook' ), 'ok' => __( 'OK', 'nodebook' ), /* translators: %s: status */ 'moved' => __( 'Moved to %s', 'nodebook' ), 'undo' => __( 'Undo', 'nodebook' ), /* translators: %1$s: list name */ 'listOn' => __( 'Added to %1$s', 'nodebook' ), /* translators: %1$s: list name */ 'listOff' => __( 'Removed from %1$s', 'nodebook' ), 'problem' => __( 'Problem', 'nodebook' ), 'cancel' => __( 'Cancel', 'nodebook' ), 'send' => __( 'Send', 'nodebook' ), 'template' => __( 'Template', 'nodebook' ), 'noTemplate' => __( 'Suggested message', 'nodebook' ), 'subject' => __( 'Subject', 'nodebook' ), 'message' => __( 'Message', 'nodebook' ), /* translators: %1$s: contact name */ 'emailTo' => __( 'Email %1$s', 'nodebook' ), 'replyHint' => __( 'Sent from your site. Replies come to your own inbox, and it goes on their timeline.', 'nodebook' ), 'mailApp' => __( 'Open in my mail app instead', 'nodebook' ), 'waInstead' => __( 'Send on WhatsApp instead', 'nodebook' ), 'site' => wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), 'me' => wp_get_current_user()->first_name ? wp_get_current_user()->first_name : wp_get_current_user()->display_name, /* translators: 1: added, 2: updated, 3: notes, 4: events */ 'crmdone' => __( 'Done: %1$s added, %2$s updated, %3$s notes, %4$s events.', 'nodebook' ), ), ) ); } /* ------------------------------------------------------------------ * * Helpers shared by screens * ------------------------------------------------------------------ */ public static function url( $page, array $args = array() ) { // Links that switch a remembered view (board/list, pipeline) carry a nonce, so only they can change it. if ( isset( $args['layout'] ) || isset( $args['pipeline'] ) ) { $args['_nbview'] = wp_create_nonce( 'nodebook_view' ); } return add_query_arg( $args, admin_url( 'admin.php?page=' . $page ) ); } /** * A view choice from the address (board/list, pipeline): array( value, may it be remembered ). * The value only changes what is shown; it is saved as the person's preference only when the link * carries a valid nonce and the person may use Nodebook. * * @param string $key Query key. * @return array{0:string,1:bool} */ public static function view_choice( $key ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only view choice; the nonce is checked below before anything is saved. $value = isset( $_GET[ $key ] ) ? sanitize_key( wp_unslash( $_GET[ $key ] ) ) : ''; $nonce = isset( $_GET['_nbview'] ) ? sanitize_text_field( wp_unslash( $_GET['_nbview'] ) ) : ''; $save = '' !== $value && '' !== $nonce && wp_verify_nonce( $nonce, 'nodebook_view' ) && current_user_can( self::cap() ); return array( $value, (bool) $save ); } /** Stop unless the current user may use the CRM. Handlers verify their nonce right after. */ public static function require_cap() { if ( ! current_user_can( self::cap() ) ) { wp_die( esc_html__( 'You are not allowed to do this.', 'nodebook' ), 403 ); } } /** Nodebook screens get their own page background. */ public static function body_class( $classes ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- screen detection only. $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; if ( 0 !== strpos( $page, 'nodebook' ) ) { return $classes; } return $classes . ' nb-screen' . ( self::app_mode() ? ' nb-appmode' : '' ); } /** Stop unless the current user may see this contact (Settings → Team: own contacts only). */ public static function require_contact( $id ) { if ( $id && ! Nodebook_Team::can_see( (int) $id ) ) { wp_die( esc_html__( 'This contact belongs to someone else on your team.', 'nodebook' ), 403 ); } } private static function deny() { if ( wp_doing_ajax() ) { wp_send_json_error( null, 403 ); } wp_die( esc_html__( 'You are not allowed to do this.', 'nodebook' ), 403 ); } /** * One gate in front of every Nodebook form and AJAX action: the contact, task or deal it touches must be * visible to the user, deleting needs the delete right, exporting the export right, importing needs * access to all contacts (an import updates contacts by email address). Runs before the handlers. */ public static function guard() { // phpcs:disable WordPress.Security.NonceVerification -- authorization only; every handler verifies its own nonce. $action = isset( $_REQUEST['action'] ) ? sanitize_key( wp_unslash( $_REQUEST['action'] ) ) : ''; // Screens: refuse someone else's contact or deal before anything is printed. $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; if ( isset( $GLOBALS['pagenow'] ) && 'admin.php' === $GLOBALS['pagenow'] && in_array( $page, array( 'nodebook', 'nodebook-deals' ), true ) && in_array( $action, array( 'view', 'edit' ), true ) && Nodebook_Team::restricted() ) { $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : 0; if ( 'nodebook' === $page ) { self::require_contact( $id ); } else { $deal = Nodebook_Deals::get( $id ); if ( $deal && ! Nodebook_Deals::can_see( $deal ) ) { wp_die( esc_html__( 'This deal belongs to someone else on your team.', 'nodebook' ), 403 ); } } return; } if ( 0 !== strpos( $action, 'nodebook_' ) || ! ( wp_doing_ajax() || ( isset( $GLOBALS['pagenow'] ) && 'admin-post.php' === $GLOBALS['pagenow'] ) ) ) { return; } $num = static function ( $k ) { return isset( $_REQUEST[ $k ] ) && is_scalar( $_REQUEST[ $k ] ) ? absint( $_REQUEST[ $k ] ) : 0; }; $contact_actions = array( 'nodebook_save_contact', 'nodebook_delete_contact', 'nodebook_add_note', 'nodebook_delete_note', 'nodebook_contact_segs', 'nodebook_watch', 'nodebook_followed_up', 'nodebook_owner', 'nodebook_status', 'nodebook_clear_reminder', 'nodebook_snooze', 'nodebook_pin', 'nodebook_email_status', 'nodebook_set_status' ); $deal_actions = array( 'nodebook_deal_save', 'nodebook_deal_close', 'nodebook_deal_delete', 'nodebook_deal_move', 'nodebook_deal_stage' ); $delete_actions = array( 'nodebook_delete_contact', 'nodebook_merge', 'nodebook_delete_company', 'nodebook_deal_delete' ); $import_actions = array( 'nodebook_import_upload', 'nodebook_import_map', 'nodebook_import_batch', 'nodebook_crm_import', 'nodebook_woo_backfill', 'nodebook_users_import' ); if ( in_array( $action, $delete_actions, true ) && ! Nodebook_Team::can_delete() ) { self::deny(); } if ( 'nodebook_export' === $action && ! Nodebook_Team::can_export() ) { self::deny(); } if ( in_array( $action, $import_actions, true ) && Nodebook_Team::restricted() ) { self::deny(); } if ( ! Nodebook_Team::restricted() ) { return; } $ids = array(); if ( in_array( $action, $contact_actions, true ) ) { $ids[] = $num( 'id' ); } elseif ( 'nodebook_task' === $action ) { // The task's own contact and the contact sent with the request must both be visible. $task = Nodebook_Tasks::get( $num( 'task' ) ); $ids[] = $task ? (int) $task['contact_id'] : 0; $ids[] = $num( 'contact' ); if ( $task && ! $task['contact_id'] && (int) $task['assignee_id'] !== get_current_user_id() ) { self::deny(); } $deal = $num( 'deal' ) ? Nodebook_Deals::get( $num( 'deal' ) ) : null; if ( $deal && ! Nodebook_Deals::can_see( $deal ) ) { self::deny(); } } elseif ( 'nodebook_merge' === $action ) { $ids[] = $num( 'keep' ); $other = isset( $_REQUEST['other'] ) ? trim( sanitize_text_field( wp_unslash( $_REQUEST['other'] ) ) ) : ''; $found = ctype_digit( $other ) ? Nodebook_Contacts::get( (int) $other ) : ( is_email( $other ) ? Nodebook_Contacts::find_by_email( $other ) : null ); $ids[] = $found ? (int) $found['id'] : 0; } elseif ( 'nodebook_dismiss_dupe' === $action ) { $ids = array( $num( 'a' ), $num( 'b' ) ); } elseif ( in_array( $action, $deal_actions, true ) ) { $deal = Nodebook_Deals::get( $num( 'id' ) ); if ( $deal && ! Nodebook_Deals::can_see( $deal ) ) { self::deny(); } } // phpcs:enable WordPress.Security.NonceVerification foreach ( array_filter( $ids ) as $id ) { if ( ! Nodebook_Team::can_see( $id ) ) { self::deny(); } } } public static function redirect( $url, $notice = '' ) { if ( $notice ) { $url = add_query_arg( 'nb_notice', $notice, $url ); } wp_safe_redirect( $url ); exit; } public static function notices() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display only. $code = isset( $_GET['nb_notice'] ) ? sanitize_key( wp_unslash( $_GET['nb_notice'] ) ) : ''; $map = array( 'saved' => array( 'success', __( 'Saved.', 'nodebook' ) ), 'syncon' => array( 'success', __( 'Connected. New subscribers and unsubscribes now go to your email tool. Send your existing subscribers with the button on the row.', 'nodebook' ) ), 'syncstart' => array( 'success', __( 'Sending your subscribers in the background. This can take a few minutes for a big list.', 'nodebook' ) ), 'syncfail' => array( 'error', __( 'Could not connect. See the message under Email tools.', 'nodebook' ) ), 'emailsent' => array( 'success', __( 'Email sent. It is on their timeline.', 'nodebook' ) ), 'sampleon' => array( 'success', __( 'Sample data added. Look around: Today, Contacts, Deals and Journeys are filled in. Remove it any time from the strip at the top.', 'nodebook' ) ), 'sampleoff' => array( 'success', __( 'Sample data removed. Your own data is untouched.', 'nodebook' ) ), 'newkey' => array( 'success', __( 'New webhook address made. The old one no longer works: update it where you use it.', 'nodebook' ) ), 'deleted' => array( 'success', __( 'Deleted.', 'nodebook' ) ), 'pipefail' => array( 'error', __( 'That did not work. Give the pipeline a name (at most 20 pipelines), and pick another pipeline for its deals.', 'nodebook' ) ), 'bulk' => array( 'success', __( 'Bulk action applied.', 'nodebook' ) ), 'note' => array( 'success', __( 'Note added.', 'nodebook' ) ), 'merged' => array( 'success', __( 'Contacts merged. The timeline, segments and old email address now belong to this contact.', 'nodebook' ) ), 'mergefail' => array( 'error', __( 'Those contacts could not be merged. Pick two different, existing contacts.', 'nodebook' ) ), 'duplicate' => array( 'error', __( 'Another contact already uses that email address.', 'nodebook' ) ), 'invalid' => array( 'error', __( 'Please enter a valid email address or phone number.', 'nodebook' ) ), 'upload' => array( 'error', __( 'The import file could not be read. Please upload a CSV file with a header row.', 'nodebook' ) ), 'expired' => array( 'error', __( 'This import has expired. Please upload the file again.', 'nodebook' ) ), 'followed' => array( 'success', __( 'Marked as followed up. They come back on the list when they show interest again.', 'nodebook' ) ), 'mailok' => array( 'success', __( 'Test alert sent. Check your inbox (and spam folder).', 'nodebook' ) ), 'mailfail' => array( 'error', __( 'WordPress could not send the email. Install an SMTP plugin so alerts reach you.', 'nodebook' ) ), 'snoozed' => array( 'success', __( 'Snoozed. They come back on the list on the day you picked.', 'nodebook' ) ), 'fieldadded' => array( 'success', __( 'Field added. Data your forms already sent under that name is moved into it.', 'nodebook' ) ), 'fieldfail' => array( 'error', __( 'That did not work: give the field a name that is not in use yet (at most 60 fields), or tick at least one form field.', 'nodebook' ) ), 'fieldmoved' => array( 'success', __( 'Done. The values now live in the field.', 'nodebook' ) ), 'fieldmoving' => array( 'success', __( 'Field made. Moving the values continues in the background.', 'nodebook' ) ), 'weeklyok' => array( 'success', __( 'Weekly summary sent. Check your inbox (and spam folder).', 'nodebook' ) ), 'template' => array( 'success', __( 'Segment created. It updates itself as contacts match.', 'nodebook' ) ), 'moduleon' => array( 'success', __( 'Module switched on.', 'nodebook' ) ), 'moduleoff' => array( 'success', __( 'Module switched off. Its data is kept.', 'nodebook' ) ), 'moduledata' => array( 'success', __( 'The module\'s data is deleted.', 'nodebook' ) ), 'dealadded' => array( 'success', __( 'Deal added. Plan the next step on the right.', 'nodebook' ) ), 'dealwon' => array( 'success', __( 'Won. Nicely done.', 'nodebook' ) ), 'teamnext' => array( 'success', __( 'Team it is. Add your teammates under Users with the role “Nodebook user”, then choose who gets new contacts under Settings → Team.', 'nodebook' ) ), 'dealcontact' => array( 'error', __( 'Pick a contact from the list, type a new email address, or leave it empty.', 'nodebook' ) ), ); /** * Notices shown after a redirect with ?nb_notice=code. Modules add their own here. * * @param array $map code => [ 'success'|'error'|'warning', message ]. */ $map = (array) apply_filters( 'nodebook_notices', $map ); if ( isset( $map[ $code ][1] ) ) { $node = 'success' === $map[ $code ][0] && Nodebook_Node::on(); echo '
' . esc_html( $map[ $code ][1] ) . '