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