| @@ -8,45 +8,60 @@ | ||
| 8 | 8 | */ |
| 9 | 9 | class FrmInboxController { |
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | - * Get the HTML for the inbox notice. | |
| 12 | + * @since 4.05 | |
| 13 | 13 | * |
| 14 | + * @return void | |
| 15 | + */ | |
| 16 | + public static function menu() { | |
| 17 | + $unread = self::get_notice_count(); | |
| 18 | + add_submenu_page( 'formidable', 'Formidable | ' . __( 'Inbox', 'formidable' ), __( 'Inbox', 'formidable' ) . $unread, 'frm_change_settings', 'formidable-inbox', 'FrmInboxController::inbox' ); | |
| 19 | + } | |
| 20 | + | |
| 21 | + /** | |
| 14 | 22 | * @since 4.05 |
| 15 | - * @since 6.8.4 The $filtered parameter was added. | |
| 16 | - * | |
| 17 | - * @param bool $filtered Set this to false to avoid the frm_inbox_badge filter. | |
| 18 | - * | |
| 19 | - * @return string | |
| 20 | 23 | */ |
| 21 | - public static function get_notice_count( $filtered = true ) { | |
| 24 | + private static function get_notice_count() { | |
| 22 | 25 | FrmFormMigratorsHelper::maybe_add_to_inbox(); |
| 23 | 26 | |
| 24 | 27 | $inbox = new FrmInbox(); |
| 25 | - return $inbox->unread_html( $filtered ); | |
| 28 | + return $inbox->unread_html(); | |
| 26 | 29 | } |
| 27 | 30 | |
| 28 | 31 | /** |
| 29 | - * @since 6.8 | |
| 32 | + * @since 4.06 | |
| 30 | 33 | * |
| 31 | - * @return array | |
| 34 | + * @return void | |
| 32 | 35 | */ |
| 33 | - public static function get_inbox_messages() { | |
| 36 | + public static function dismiss_all_button( $atts ) { | |
| 37 | + if ( empty( $atts['messages'] ) ) { | |
| 38 | + return; | |
| 39 | + } | |
| 40 | + | |
| 41 | + echo '<button class="frm-button-secondary" id="frm-dismiss-inbox" type="button">' . | |
| 42 | + esc_html__( 'Dismiss All', 'formidable' ) . | |
| 43 | + '</button>'; | |
| 44 | + } | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * @since 4.05 | |
| 48 | + * | |
| 49 | + * @return void | |
| 50 | + */ | |
| 51 | + public static function inbox() { | |
| 52 | + FrmAppHelper::include_svg(); | |
| 34 | 53 | self::add_tracking_request(); |
| 35 | - self::remove_free_template_message(); | |
| 54 | + self::add_free_template_message(); | |
| 36 | 55 | |
| 37 | - $inbox = new FrmInbox(); | |
| 38 | - $unread_messages = $inbox->get_messages(); | |
| 39 | - $dismissed_messages = $unread_messages; | |
| 56 | + $inbox = new FrmInbox(); | |
| 57 | + $messages = $inbox->get_messages( 'filter' ); | |
| 58 | + $messages = array_reverse( $messages ); | |
| 59 | + $user = wp_get_current_user(); | |
| 40 | 60 | |
| 41 | - $inbox->filter_messages( $unread_messages, 'filter' ); | |
| 42 | - $inbox->filter_messages( $dismissed_messages, 'dismissed' ); | |
| 61 | + wp_enqueue_script( 'frm-ac', FrmAppHelper::plugin_url() . '/js/ac.js', array(), FrmAppHelper::plugin_version(), true ); | |
| 43 | 62 | |
| 44 | - return array( | |
| 45 | - 'unread' => array_reverse( $unread_messages ), | |
| 46 | - 'dismissed' => array_reverse( $dismissed_messages ), | |
| 47 | - 'user' => wp_get_current_user(), | |
| 48 | - ); | |
| 63 | + include( FrmAppHelper::plugin_path() . '/classes/views/inbox/list.php' ); | |
| 49 | 64 | } |
| 50 | 65 | |
| 51 | 66 | /** |
| 52 | 67 | * @since 4.05 |
| @@ -54,25 +69,18 @@ | ||
| 54 | 69 | * @return void |
| 55 | 70 | */ |
| 56 | 71 | public static function dismiss_message() { |
| 57 | 72 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 58 | - FrmAppHelper::permission_check( 'frm_view_forms' ); | |
| 73 | + FrmAppHelper::permission_check( 'frm_change_settings' ); | |
| 59 | 74 | |
| 60 | 75 | $key = FrmAppHelper::get_param( 'key', '', 'post', 'sanitize_text_field' ); |
| 61 | - | |
| 62 | 76 | if ( ! empty( $key ) ) { |
| 63 | 77 | $message = new FrmInbox(); |
| 64 | 78 | $message->dismiss( $key ); |
| 65 | - | |
| 66 | 79 | if ( $key === 'review' ) { |
| 67 | 80 | $reviews = new FrmReviews(); |
| 68 | 81 | $reviews->dismiss_review(); |
| 69 | 82 | } |
| 70 | - | |
| 71 | - if ( $key === 'onboarding_wizard' ) { | |
| 72 | - // Delete the skipped option or the inbox message will continue to get added. | |
| 73 | - delete_option( FrmOnboardingWizardController::ONBOARDING_SKIPPED_OPTION ); | |
| 74 | - } | |
| 75 | 83 | } |
| 76 | 84 | |
| 77 | 85 | wp_die(); |
| 78 | 86 | } |
| @@ -83,9 +91,8 @@ | ||
| 83 | 91 | * @return void |
| 84 | 92 | */ |
| 85 | 93 | private static function add_tracking_request() { |
| 86 | 94 | $settings = FrmAppHelper::get_settings(); |
| 87 | - | |
| 88 | 95 | if ( $settings->tracking ) { |
| 89 | 96 | return; |
| 90 | 97 | } |
| 91 | 98 | |
| @@ -109,11 +116,28 @@ | ||
| 109 | 116 | * @since 4.10.03 |
| 110 | 117 | * |
| 111 | 118 | * @return void |
| 112 | 119 | */ |
| 113 | - private static function remove_free_template_message() { | |
| 114 | - if ( ! FrmAppHelper::pro_is_installed() ) { | |
| 115 | - $message = new FrmInbox(); | |
| 116 | - $message->dismiss( 'free_templates' ); | |
| 120 | + private static function add_free_template_message() { | |
| 121 | + if ( FrmAppHelper::pro_is_installed() ) { | |
| 122 | + return; | |
| 117 | 123 | } |
| 124 | + | |
| 125 | + $api = new FrmFormTemplateApi(); | |
| 126 | + if ( $api->has_free_access() ) { | |
| 127 | + return; | |
| 128 | + } | |
| 129 | + | |
| 130 | + $link = admin_url( 'admin.php?page=formidable&triggerNewFormModal=1&free-templates=1' ); | |
| 131 | + | |
| 132 | + $message = new FrmInbox(); | |
| 133 | + $message->add_message( | |
| 134 | + array( | |
| 135 | + 'key' => 'free_templates', | |
| 136 | + 'message' => 'Add your email address to get a code for 10+ free form templates.', | |
| 137 | + 'subject' => 'Get 10+ Free Form Templates', | |
| 138 | + 'cta' => '<a href="#" class="frm-button-secondary frm_inbox_dismiss">Dismiss</a> <a href="' . esc_url( $link ) . '" class="button-primary frm-button-primary">Get Now</a>', | |
| 139 | + 'type' => 'feedback', | |
| 140 | + ) | |
| 141 | + ); | |
| 118 | 142 | } |
| 119 | 143 | } |