| @@ -5,8 +5,11 @@ | ||
| 5 | 5 | |
| 6 | 6 | class FrmFormMigratorsHelper { |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | + * @param array $form | |
| 10 | + * @param array|null $dismissed | |
| 11 | + * | |
| 9 | 12 | * @return bool |
| 10 | 13 | */ |
| 11 | 14 | private static function is_dismissed( $form, $dismissed = null ) { |
| 12 | 15 | if ( $dismissed === null ) { |
| @@ -11,14 +14,10 @@ | ||
| 11 | 14 | private static function is_dismissed( $form, $dismissed = null ) { |
| 12 | 15 | if ( $dismissed === null ) { |
| 13 | 16 | $dismissed = get_option( 'frm_dismissed' ); |
| 14 | 17 | } |
| 15 | - | |
| 16 | - if ( ! empty( $dismissed ) && in_array( $form['class'], $dismissed ) ) { | |
| 17 | - return true; | |
| 18 | - } | |
| 19 | - | |
| 20 | - return false; | |
| 18 | + // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict | |
| 19 | + return $dismissed && in_array( $form['class'], $dismissed ); | |
| 21 | 20 | } |
| 22 | 21 | |
| 23 | 22 | /** |
| 24 | 23 | * @return void |
| @@ -24,16 +23,18 @@ | ||
| 24 | 23 | * @return void |
| 25 | 24 | */ |
| 26 | 25 | public static function maybe_show_download_link() { |
| 27 | 26 | $forms = self::import_links(); |
| 27 | + | |
| 28 | 28 | foreach ( $forms as $form ) { |
| 29 | 29 | if ( ! self::is_dismissed( $form ) ) { |
| 30 | 30 | self::install_banner( $form ); |
| 31 | - } else { | |
| 32 | - echo '<span>'; | |
| 33 | - self::install_button( $form, 'auto' ); | |
| 34 | - echo '</span>'; | |
| 31 | + continue; | |
| 35 | 32 | } |
| 33 | + | |
| 34 | + echo '<span>'; | |
| 35 | + self::install_button( $form, 'auto' ); | |
| 36 | + echo '</span>'; | |
| 36 | 37 | } |
| 37 | 38 | } |
| 38 | 39 | |
| 39 | 40 | /** |
| @@ -42,13 +43,15 @@ | ||
| 42 | 43 | * @return void |
| 43 | 44 | */ |
| 44 | 45 | public static function maybe_add_to_inbox() { |
| 45 | 46 | $forms = self::import_links(); |
| 47 | + | |
| 46 | 48 | if ( ! $forms ) { |
| 47 | 49 | return; |
| 48 | 50 | } |
| 49 | 51 | |
| 50 | 52 | $inbox = new FrmInbox(); |
| 53 | + | |
| 51 | 54 | foreach ( $forms as $form ) { |
| 52 | 55 | $inbox->add_message( |
| 53 | 56 | array( |
| 54 | 57 | 'key' => $form['class'], |
| @@ -53,9 +56,9 @@ | ||
| 53 | 56 | array( |
| 54 | 57 | 'key' => $form['class'], |
| 55 | 58 | 'subject' => 'You have new importable forms', |
| 56 | 59 | 'message' => 'Did you know you can import your forms created in ' . esc_html( $form['name'] ) . '?', |
| 57 | - 'cta' => '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-import' ) ) . '" class="button-primary frm-button-primary">' . esc_html__( 'Learn More', 'formidable' ) . '</a>', | |
| 60 | + 'cta' => '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-import' ) ) . '" class="button-primary frm-button-primary">' . esc_html__( 'Learn More', 'formidable' ) . '</a>', // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 58 | 61 | 'icon' => 'frm_cloud_upload_solid_icon', |
| 59 | 62 | 'type' => 'news', |
| 60 | 63 | ) |
| 61 | 64 | ); |
| @@ -70,8 +73,9 @@ | ||
| 70 | 73 | return array(); |
| 71 | 74 | } |
| 72 | 75 | |
| 73 | 76 | $forms = array(); |
| 77 | + | |
| 74 | 78 | foreach ( self::importable_forms() as $form ) { |
| 75 | 79 | if ( class_exists( $form['class'] ) || ! is_plugin_active( $form['plugin'] ) ) { |
| 76 | 80 | // Either the importer is installed or the source plugin isn't. |
| 77 | 81 | continue; |
| @@ -82,8 +86,9 @@ | ||
| 82 | 86 | $form['link'] = $installer->get_activate_link(); |
| 83 | 87 | |
| 84 | 88 | $forms[] = $form; |
| 85 | 89 | } |
| 90 | + | |
| 86 | 91 | return $forms; |
| 87 | 92 | } |
| 88 | 93 | |
| 89 | 94 | /** |
| @@ -107,13 +112,19 @@ | ||
| 107 | 112 | ), |
| 108 | 113 | ); |
| 109 | 114 | } |
| 110 | 115 | |
| 116 | + /** | |
| 117 | + * @param array $install | |
| 118 | + * | |
| 119 | + * @return string|null | |
| 120 | + */ | |
| 111 | 121 | private static function install_banner( $install ) { |
| 112 | 122 | if ( empty( $install['link'] ) ) { |
| 113 | 123 | return ''; |
| 114 | 124 | } |
| 115 | 125 | |
| 126 | + // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 116 | 127 | ?> |
| 117 | 128 | <div class="frm-feature-banner"> |
| 118 | 129 | <a href="#" class="dismiss alignright" id="<?php echo esc_attr( $install['class'] ); ?>" title="<?php esc_attr_e( 'Dismiss this message', 'formidable' ); ?>"> |
| 119 | 130 | <?php FrmAppHelper::icon_by_class( 'frmfont frm_close_icon', array( 'aria-label' => 'Dismiss' ) ); ?> |
| @@ -124,8 +135,10 @@ | ||
| 124 | 135 | <p>Did you know you can import your forms created in <?php echo esc_html( $install['name'] ); ?>?</p> |
| 125 | 136 | <?php self::install_button( $install ); ?> |
| 126 | 137 | </div> |
| 127 | 138 | <?php |
| 139 | + // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 140 | + return null; | |
| 128 | 141 | } |
| 129 | 142 | |
| 130 | 143 | /** |
| 131 | 144 | * @param array $install |
| @@ -135,16 +148,17 @@ | ||
| 135 | 148 | */ |
| 136 | 149 | private static function install_button( $install, $label = '' ) { |
| 137 | 150 | $primary = 'button-secondary frm-button-secondary '; |
| 138 | 151 | |
| 139 | - if ( empty( $label ) ) { | |
| 152 | + if ( ! $label ) { | |
| 140 | 153 | $label = __( 'Get Started', 'formidable' ); |
| 141 | 154 | $primary = 'button-primary frm-button-primary '; |
| 142 | 155 | } |
| 143 | 156 | |
| 157 | + // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 144 | 158 | if ( $install['installed'] ) { |
| 145 | 159 | ?> |
| 146 | - <a rel="<?php echo esc_attr( $install['importer'] ); ?>" class="button frm-activate-addon <?php echo esc_attr( $primary . ( empty( $install['link'] ) ? 'frm_hidden' : '' ) ); ?>"> | |
| 160 | + <a rel="<?php echo esc_attr( $install['importer'] ); ?>" class="button frm-activate-addon <?php echo esc_attr( $primary . ( ! empty( $install['link'] ) ? '' : 'frm_hidden' ) ); ?>"><?php // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?> | |
| 147 | 161 | <?php |
| 148 | 162 | if ( $label === 'auto' ) { |
| 149 | 163 | /* translators: %s: Name of the plugin */ |
| 150 | 164 | $label = sprintf( __( 'Activate %s', 'formidable' ), $install['name'] ); |
| @@ -150,9 +164,9 @@ | ||
| 150 | 164 | $label = sprintf( __( 'Activate %s', 'formidable' ), $install['name'] ); |
| 151 | 165 | } |
| 152 | 166 | } else { |
| 153 | 167 | ?> |
| 154 | - <a rel="<?php echo esc_attr( $install['package'] ); ?>" class="frm-install-addon button <?php echo esc_attr( $primary ); ?>" aria-label="<?php esc_attr_e( 'Install', 'formidable' ); ?>"> | |
| 168 | + <a rel="<?php echo esc_attr( $install['package'] ); ?>" class="frm-install-addon button <?php echo esc_attr( $primary ); ?>" aria-label="<?php esc_attr_e( 'Install', 'formidable' ); ?>"><?php // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?> | |
| 155 | 169 | <?php |
| 156 | 170 | if ( $label === 'auto' ) { |
| 157 | 171 | /* translators: %s: Name of the plugin */ |
| 158 | 172 | $label = sprintf( __( 'Install %s Importer', 'formidable' ), $install['name'] ); |
| @@ -161,8 +175,9 @@ | ||
| 161 | 175 | ?> |
| 162 | 176 | <?php echo esc_html( $label ); ?> |
| 163 | 177 | </a> |
| 164 | 178 | <?php |
| 179 | + // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 165 | 180 | } |
| 166 | 181 | |
| 167 | 182 | /** |
| 168 | 183 | * @return void |
| @@ -169,12 +184,14 @@ | ||
| 169 | 184 | */ |
| 170 | 185 | public static function dismiss_migrator() { |
| 171 | 186 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 172 | 187 | $dismissed = get_option( 'frm_dismissed' ); |
| 173 | - if ( empty( $dismissed ) ) { | |
| 188 | + | |
| 189 | + if ( ! $dismissed ) { | |
| 174 | 190 | $dismissed = array(); |
| 175 | 191 | } |
| 192 | + | |
| 176 | 193 | $dismissed[] = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' ); |
| 177 | - update_option( 'frm_dismissed', array_filter( $dismissed ), 'no' ); | |
| 194 | + update_option( 'frm_dismissed', array_filter( $dismissed ), false ); | |
| 178 | 195 | wp_die(); |
| 179 | 196 | } |
| 180 | 197 | } |