diff --git a/functions.php b/functions.php index d27cbbb..caa0885 100644 --- a/functions.php +++ b/functions.php @@ -294,6 +294,10 @@ function flash_scripts() { require get_template_directory() . '/inc/admin/class-flash-theme-review-notice.php'; require get_template_directory() . '/inc/admin/class-flash-tdi-notice.php'; require get_template_directory() . '/inc/admin/class-flash-dashboard.php'; + require get_template_directory() . '/inc/admin/class-flash-notice.php'; + require get_template_directory() . '/inc/admin/class-flash-welcome-notice.php'; + require get_template_directory() . '/inc/admin/class-flash-upgrade.php'; + } /** diff --git a/gulpfile.js b/gulpfile.js index 2689c74..3c5548d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -10,121 +10,128 @@ * * Load gulp and it's plugin. */ -var gulp = require( 'gulp' ); +var gulp = require('gulp'); // CSS Plugins -var autoprefixer = require( 'gulp-autoprefixer' ); // Prefixes CSS. -var uglifycss = require( 'gulp-uglifycss' ); // Minifies CSS. -var rtlcss = require( 'gulp-rtlcss' ); // Generates RTL CSS. -var sass = require( 'gulp-sass' ); // Compiles sass into CSS. +var autoprefixer = require('gulp-autoprefixer'); // Prefixes CSS. +var uglifycss = require('gulp-uglifycss'); // Minifies CSS. +var rtlcss = require('gulp-rtlcss'); // Generates RTL CSS. +var sass = require('gulp-sass'); // Compiles sass into CSS. // JS Plugins -var uglify = require( 'gulp-uglify' ); // Minify JS. +var uglify = require('gulp-uglify'); // Minify JS. // Utility Plugins -var browserSync = require( 'browser-sync' ).create(); // Reloads browser. -var imagemin = require( 'gulp-imagemin' ); // Minifies Images. -var rename = require( 'gulp-rename' ); // Renames files. -var wpPot = require( 'gulp-wp-pot' ); // Generates translation file. -var zip = require( 'gulp-zip' ); // Compresses into zip file. -var notify = require( 'gulp-notify' ); // Sends notification. +var browserSync = require('browser-sync').create(); // Reloads browser. +var imagemin = require('gulp-imagemin'); // Minifies Images. +var rename = require('gulp-rename'); // Renames files. +var wpPot = require('gulp-wp-pot'); // Generates translation file. +var zip = require('gulp-zip'); // Compresses into zip file. +var notify = require('gulp-notify'); // Sends notification. // Linter Plugins -var stylelint = require( 'gulp-stylelint' ); // Checks for the CSS errors. -var eslint = require( 'gulp-eslint' ); // Checks for the JS errors. -var phpcs = require( 'gulp-phpcs' ); //Checks for the php errors and WordPress standards. +var stylelint = require('gulp-stylelint'); // Checks for the CSS errors. +var eslint = require('gulp-eslint'); // Checks for the JS errors. +var phpcs = require('gulp-phpcs'); //Checks for the php errors and WordPress standards. /** * Project information. */ var info = { - name: 'Flash', - slug: 'flash', - url: 'https://themegrill.com/themes/flash/', - author: 'ThemeGrill', - authorUrl: 'https://themegrill.com/', - authorEmail: 'themegrill@gmail.com', - teamEmail: '', - localUrl: 'flash.local' + name: 'Flash', + slug: 'flash', + url: 'https://themegrill.com/themes/flash/', + author: 'ThemeGrill', + authorUrl: 'https://themegrill.com/', + authorEmail: 'themegrill@gmail.com', + teamEmail: '', + localUrl: 'flash.local' }; /** * Defines paths */ var paths = { - scss: { - src: './assets/sass/**/*.scss', - dest: './' - }, - - css: { - src: [ './assets/css/*.css', '!./assets/css/*.min.css' ], - dest: './assets/css' - }, - - rtlcss: { - src: [ './style.css' ], - dest: './' - }, - - prefixStyles: { - src: './*.css', - dest: './' - }, - - lintFiles: { - php: [ - './*.php', - './inc/**/*.php', - '!./inc/kirki/**', - '!./inc/tgm-plugin-activation/**', - './inc/widgets/*.php', - './template-parts/**/*.php' - ], - styles: [ './assets/sass/**/*.scss' ], - js: [ './assets/js/*-custom.js', '!./assets/js/*.min.js' ] - }, - - js: { - src: [ './assets/js/*.js', '!./assets/js/*.min.js' ], - dest: './assets/js/' - }, - - php: { - src: [ - './*.php', - './inc/*.php', - './inc/customizer/**/*.php', - './template-parts/**/*.php' - ] - }, - - img: { - src: [ './assets/img/**' ], - dest: './assets/img' - }, - - zip: { - src: [ - '**', - '!vendor', - '!vendor/**', - '!node_modules', - '!node_modules/**', - '!assets/sass', - '!assets/sass/**', - '!dest.xml', - '!dist', - '!dist/**', - '!*.json', - '!*.md', - '!gulpfile.js', - '!composer.lock', - '!phpcs.xml' - ], - dest: './dist' - } + scss: { + src: './assets/sass/**/*.scss', + dest: './' + }, + + css: { + src: ['./assets/css/*.css', '!./assets/css/*.min.css'], + dest: './assets/css' + }, + + adminscss: { + src: './inc/admin/sass/admin.scss', + dest: './inc/admin/css/' + }, + + + rtlcss: { + src: ['./style.css'], + dest: './' + }, + + prefixStyles: { + src: './*.css', + dest: './' + }, + + + lintFiles: { + php: [ + './*.php', + './inc/**/*.php', + '!./inc/kirki/**', + '!./inc/tgm-plugin-activation/**', + './inc/widgets/*.php', + './template-parts/**/*.php' + ], + styles: ['./assets/sass/**/*.scss'], + js: ['./assets/js/*-custom.js', '!./assets/js/*.min.js'] + }, + + js: { + src: ['./assets/js/*.js', '!./assets/js/*.min.js'], + dest: './assets/js/' + }, + + php: { + src: [ + './*.php', + './inc/*.php', + './inc/customizer/**/*.php', + './template-parts/**/*.php' + ] + }, + + img: { + src: ['./assets/img/**'], + dest: './assets/img' + }, + + zip: { + src: [ + '**', + '!vendor', + '!vendor/**', + '!node_modules', + '!node_modules/**', + '!assets/sass', + '!assets/sass/**', + '!dest.xml', + '!dist', + '!dist/**', + '!*.json', + '!*.md', + '!gulpfile.js', + '!composer.lock', + '!phpcs.xml' + ], + dest: './dist' + } }; /** @@ -134,203 +141,218 @@ var paths = { */ // Style tasks -var styles = gulp.series( compileSass, prefixStyles, generateRTLCSS, browserSyncStream ); +var styles = gulp.series(compileSass, prefixStyles, generateRTLCSS, browserSyncStream); // Start a front-end development server. -var server = gulp.series( browserSyncStart, watch ); +var server = gulp.series(browserSyncStart, watch); // Test code -var test = gulp.series( lintPHP, lintJS, lintStyle ); +var test = gulp.series(lintPHP, lintJS, lintStyle); // Build -var build = gulp.series( test, minifyCSS, minifyJs, minifyImg, generatePotFile, compressZip ); +var build = gulp.series(test, minifyCSS, minifyJs, minifyImg, generatePotFile, compressZip); // Start browserSync -function browserSyncStart( cb ) { - browserSync.init( - { - proxy: info.localUrl - }, - cb - ); +function browserSyncStart(cb) { + browserSync.init({ + proxy: info.localUrl + }, + cb + ); } // Reloads the browser -function browserSyncReload( cb ) { - browserSync.reload(); - cb(); +function browserSyncReload(cb) { + browserSync.reload(); + cb(); } // Streams the browser. -function browserSyncStream( cb ) { - browserSync.stream(); - cb(); +function browserSyncStream(cb) { + browserSync.stream(); + cb(); } // Compiles SCSS into CSS. function compileSass() { - return gulp - .src( paths.scss.src ) - .pipe( - sass( { - indentType: 'tab', - indentWidth: 1, - outputStyle: 'expanded', - linefeed: 'crlf' - } ) - ) - .pipe( gulp.dest( paths.scss.dest ) ) - .on( 'error', notify.onError() ); + return gulp + .src(paths.scss.src) + .pipe( + sass({ + indentType: 'tab', + indentWidth: 1, + outputStyle: 'expanded', + linefeed: 'crlf' + }) + ) + .pipe(gulp.dest(paths.scss.dest)) + .on('error', notify.onError()); } // Prefixes CSS. function prefixStyles() { - return gulp - .src( paths.prefixStyles.src ) - .pipe( - autoprefixer( { - browsers: [ 'last 2 versions' ], - cascade: false - } ) - ) - .pipe( gulp.dest( paths.prefixStyles.dest ) ) - .pipe( browserSync.stream() ) - .on( 'error', notify.onError() ); + return gulp + .src(paths.prefixStyles.src) + .pipe( + autoprefixer({ + browsers: ['last 2 versions'], + cascade: false + }) + ) + .pipe(gulp.dest(paths.prefixStyles.dest)) + .pipe(browserSync.stream()) + .on('error', notify.onError()); } // Generates RTL CSS file. function generateRTLCSS() { - return gulp - .src( paths.rtlcss.src ) - .pipe( rtlcss() ) - .pipe( rename( { suffix: '-rtl' } ) ) - .pipe( gulp.dest( paths.rtlcss.dest ) ) - .on( 'error', notify.onError() ); + return gulp + .src(paths.rtlcss.src) + .pipe(rtlcss()) + .pipe(rename({ suffix: '-rtl' })) + .pipe(gulp.dest(paths.rtlcss.dest)) + .on('error', notify.onError()); } // Minify css file function minifyCSS() { - return gulp - .src( paths.css.src ) - .pipe( uglifycss() ) - .pipe( rename( { suffix: '.min' } ) ) - .pipe( gulp.dest( paths.css.dest ) ); + return gulp + .src(paths.css.src) + .pipe(uglifycss()) + .pipe(rename({ suffix: '.min' })) + .pipe(gulp.dest(paths.css.dest)); } // Runs all the task of style. function styles() { - return gulp.series( compileSass, prefixStyles, generateRTLCSS ); + return gulp.series(compileSass, prefixStyles, generateRTLCSS); } +// Compiles AdminSass into AdminCSS +function compileAdminSass() { + return gulp.src(paths.adminscss.src) + .pipe(sass({ + indentType: 'tab', + indentWidth: 1, + outputStyle: 'expanded', + linefeed: 'crlf' + }).on('error', sass.logError)) + .pipe(gulp.dest(paths.adminscss.dest)) + .pipe(browserSync.stream()); +} // Lint php through phpcs and PHPCompatibility function lintPHP() { - return gulp - .src( paths.lintFiles.php ) - .pipe( - phpcs( { - bin: 'vendor/bin/phpcs', - standard: 'phpcs.xml', - warningSeverity: 0 - } ) - ) - .pipe( phpcs.reporter( 'log' ) ) - .pipe( phpcs.reporter( 'fail', { failOnFirst: false } ) ) - .on( 'error', notify.onError() ); + return gulp + .src(paths.lintFiles.php) + .pipe( + phpcs({ + bin: 'vendor/bin/phpcs', + standard: 'phpcs.xml', + warningSeverity: 0 + }) + ) + .pipe(phpcs.reporter('log')) + .pipe(phpcs.reporter('fail', { failOnFirst: false })) + .on('error', notify.onError()); } // Lint scss,css file through stylelint function lintStyle() { - return gulp - .src( paths.lintFiles.styles ) - .pipe( - stylelint( { - failAfterError: true, - reporters: [ { formatter: 'string', console: true } ] - } ) - ) - .on( 'error', notify.onError() ); + return gulp + .src(paths.lintFiles.styles) + .pipe( + stylelint({ + failAfterError: true, + reporters: [{ formatter: 'string', console: true }] + }) + ) + .on('error', notify.onError()); } + // Lint js files through eslint function lintJS() { - return gulp - .src( paths.lintFiles.js ) - .pipe( eslint() ) - .pipe( eslint.format() ) - .on( 'error', notify.onError() ); + return gulp + .src(paths.lintFiles.js) + .pipe(eslint()) + .pipe(eslint.format()) + .on('error', notify.onError()); } // Minfies image files. function minifyImg() { - return gulp - .src( paths.img.src ) - .pipe( imagemin() ) - .pipe( gulp.dest( paths.img.dest ) ) - .on( 'error', notify.onError() ); + return gulp + .src(paths.img.src) + .pipe(imagemin()) + .pipe(gulp.dest(paths.img.dest)) + .on('error', notify.onError()); } // Minifies the js files. function minifyJs() { - return gulp - .src( paths.js.src ) - .pipe( uglify() ) - .pipe( rename( { suffix: '.min' } ) ) - .pipe( gulp.dest( paths.js.dest ) ) - .on( 'error', notify.onError() ); + return gulp + .src(paths.js.src) + .pipe(uglify()) + .pipe(rename({ suffix: '.min' })) + .pipe(gulp.dest(paths.js.dest)) + .on('error', notify.onError()); } // Generates translation file. function generatePotFile() { - return gulp - .src( paths.php.src ) - .pipe( - wpPot( { - domain: info.slug, - package: info.name, - bugReport: info.authorEmail, - team: info.teamEmail - } ) - ) - .pipe( gulp.dest( 'languages/' + info.slug + '.pot' ) ) - .on( 'error', notify.onError() ); + return gulp + .src(paths.php.src) + .pipe( + wpPot({ + domain: info.slug, + package: info.name, + bugReport: info.authorEmail, + team: info.teamEmail + }) + ) + .pipe(gulp.dest('languages/' + info.slug + '.pot')) + .on('error', notify.onError()); } // Compress theme into a zip file. function compressZip() { - return gulp - .src( paths.zip.src ) - .pipe( zip( info.slug + '.zip' ) ) - .pipe( gulp.dest( paths.zip.dest ) ) - .on( 'error', notify.onError() ) - .pipe( notify( { - message: 'Great! Package is ready', - title: 'Build successful' - } - ) ); + return gulp + .src(paths.zip.src) + .pipe(zip(info.slug + '.zip')) + .pipe(gulp.dest(paths.zip.dest)) + .on('error', notify.onError()) + .pipe(notify({ + message: 'Great! Package is ready', + title: 'Build successful' + })); } // Watch for file changes function watch() { - gulp.watch( paths.scss.src, styles ); - gulp.watch( [ paths.js.src, paths.php.src ], browserSyncReload ); + gulp.watch(paths.scss.src, styles); + gulp.watch(paths.adminscss.src, compileAdminSass); + gulp.watch(paths.js.src, browserSyncReload); + gulp.watch(paths.php.src, browserSyncReload); + + } // Builds the package. function build() { - return gulp.series( - lintPHP, - lintJS, - lintStyle, - compileSass, - prefixStyles, - generateRTLCSS, - minifyCSS, - minifyImg, - minifyJs, - generatePotFile, - compressZip - ); + return gulp.series( + lintPHP, + lintJS, + lintStyle, + compileSass, + prefixStyles, + generateRTLCSS, + minifyCSS, + minifyImg, + minifyJs, + generatePotFile, + compressZip + ); } // define tasks @@ -338,6 +360,7 @@ exports.browserSyncStart = browserSyncStart; exports.browserSyncReload = browserSyncReload; exports.browserSyncStream = browserSyncStream; exports.compileSass = compileSass; +exports.compileAdminSass = compileAdminSass; exports.prefixStyles = prefixStyles; exports.generateRTLCSS = generateRTLCSS; exports.minifyCSS = minifyCSS; @@ -353,4 +376,4 @@ exports.styles = styles; exports.test = test; exports.server = server; exports.test = test; -exports.build = build; +exports.build = build; \ No newline at end of file diff --git a/inc/admin/class-flash-notice.php b/inc/admin/class-flash-notice.php new file mode 100644 index 0000000..dc94dfc --- /dev/null +++ b/inc/admin/class-flash-notice.php @@ -0,0 +1,93 @@ +name = $name; + $this->type = $type; + $this->dismiss_url = $dismiss_url; + $this->temporary_dismiss_url = $temporary_dismiss_url; + $this->pricing_url = 'https://themegrill.com/pricing/?utm_source=flash-dashboard-message&utm_medium=view-pricing-link&utm_campaign=upgrade'; + $this->current_user_id = get_current_user_id(); + + // Notice markup. + add_action( 'admin_notices', array( $this, 'notice' ) ); + + $this->dismiss_notice(); + $this->dismiss_notice_temporary(); + } + + public function notice() { + if ( ! $this->is_dismiss_notice() ) { + $this->notice_markup(); + } + } + + private function is_dismiss_notice() { + return apply_filters( 'flash_' . $this->name . '_notice_dismiss', true ); + } + + public function notice_markup() { + echo ''; + } + + /** + * Hide a notice if the GET variable is set. + */ + public function dismiss_notice() { + if ( isset( $_GET['flash_notice_dismiss'] ) && isset( $_GET['_flash_upgrade_notice_dismiss_nonce'] ) ) { // WPCS: input var ok. + if ( ! wp_verify_nonce( wp_unslash( $_GET['_flash_upgrade_notice_dismiss_nonce'] ), 'flash_upgrade_notice_dismiss_nonce' ) ) { // phpcs:ignore WordPress.VIP.ValidatedSanitizedInput.InputNotSanitized + wp_die( __( 'Action failed. Please refresh the page and retry.', 'flash' ) ); // WPCS: xss ok. + } + + if ( ! current_user_can( 'publish_posts' ) ) { + wp_die( __( 'Cheatin’ huh?', 'flash' ) ); // WPCS: xss ok. + } + + $dismiss_notice = sanitize_text_field( wp_unslash( $_GET['flash_notice_dismiss'] ) ); + + // Hide. + if ( $dismiss_notice === $_GET['flash_notice_dismiss'] ) { + add_user_meta( get_current_user_id(), 'flash_' . $dismiss_notice . '_notice_dismiss', 'yes', true ); + } + } + } + + public function dismiss_notice_temporary() { + if ( isset( $_GET['flash_notice_dismiss_temporary'] ) && isset( $_GET['_flash_upgrade_notice_dismiss_temporary_nonce'] ) ) { // WPCS: input var ok. + if ( ! wp_verify_nonce( wp_unslash( $_GET['_flash_upgrade_notice_dismiss_temporary_nonce'] ), 'flash_upgrade_notice_dismiss_temporary_nonce' ) ) { // phpcs:ignore WordPress.VIP.ValidatedSanitizedInput.InputNotSanitized + wp_die( __( 'Action failed. Please refresh the page and retry.', 'flash' ) ); // WPCS: xss ok. + } + + if ( ! current_user_can( 'publish_posts' ) ) { + wp_die( __( 'Cheatin’ huh?', 'flash' ) ); // WPCS: xss ok. + } + + $dismiss_notice = sanitize_text_field( wp_unslash( $_GET['flash_notice_dismiss_temporary'] ) ); + + // Hide. + if ( $dismiss_notice === $_GET['flash_notice_dismiss_temporary'] ) { + add_user_meta( get_current_user_id(), 'flash_' . $dismiss_notice . '_notice_dismiss_temporary', 'yes', true ); + } + } + } +} diff --git a/inc/admin/class-flash-theme-review-notice.php b/inc/admin/class-flash-theme-review-notice.php index d5c8cba..7781d0f 100644 --- a/inc/admin/class-flash-theme-review-notice.php +++ b/inc/admin/class-flash-theme-review-notice.php @@ -66,7 +66,7 @@ public function flash_theme_review_notice() { * 2. If the user has ignored the message partially for 15 days. * 3. Dismiss always if clicked on 'I Already Did' button. */ - if ( ( get_option( 'flash_theme_installed_time' ) > strtotime( '-15 day' ) ) || ( $ignored_notice_partially > strtotime( '-15 day' ) ) || ( $ignored_notice ) ) { + if ( ( get_option( 'flash_theme_installed_time' ) > strtotime( '0 day' ) ) || ( $ignored_notice_partially > strtotime( '0 day' ) ) || ( $ignored_notice ) ) { return; } ?> diff --git a/inc/admin/class-flash-upgrade.php b/inc/admin/class-flash-upgrade.php new file mode 100644 index 0000000..aea43a7 --- /dev/null +++ b/inc/admin/class-flash-upgrade.php @@ -0,0 +1,108 @@ +set_notice_time(); + + $this->set_temporary_dismiss_notice_time(); + + $this->set_dismiss_notice(); + } + + private function set_notice_time() { + if (!get_option('flash_upgrade_notice_start_time')) { + update_option('flash_upgrade_notice_start_time', time()); + } + } + + private function set_temporary_dismiss_notice_time() { + if (isset($_GET['flash_notice_dismiss_temporary']) && 'upgrade' === $_GET['flash_notice_dismiss_temporary']) { + update_user_meta($this->current_user_id, 'flash_upgrade_notice_dismiss_temporary_start_time', time()); + } + } + + public function set_dismiss_notice() { + + /** + * Do not show notice if: + * + * 1. It has not been 5 days since the theme is activated. + * 2. If the user has ignored the message partially for 2 days. + * 3. Dismiss always if clicked on 'Dismiss' button. + */ + if ( get_option('flash_upgrade_notice_start_time') > strtotime('0 day') + || get_user_meta(get_current_user_id(), 'flash_upgrade_notice_dismiss', true) + || get_user_meta(get_current_user_id(), 'flash_upgrade_notice_dismiss_temporary_start_time', true) > strtotime('0 day') + ) { + add_filter('flash_upgrade_notice_dismiss', '__return_true'); + } else { + add_filter('flash_upgrade_notice_dismiss', '__return_false'); + } + } + + public function notice_markup() { +?> +
+ ' . esc_html($current_user->display_name) . '',
+ 'flash',
+ 'upgrade15',
+ '15%'
+ );
+ ?>
+