Skip to content

Commit

Permalink
Merge branch 'trunk' of github.com:Automattic/WP-Job-Manager into fea…
Browse files Browse the repository at this point in the history
…ture/promoted-jobs
  • Loading branch information
renatho committed Oct 3, 2023
2 parents c06a1be + f2ff89e commit 8bd16f7
Show file tree
Hide file tree
Showing 20 changed files with 2,221 additions and 169 deletions.
17 changes: 9 additions & 8 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
Fixes #

### Changes proposed in this Pull Request
### Changes Proposed in this Pull Request

*

### Testing instructions
### Testing Instructions

*

<!-- Add the following only if there are new/updated actions or filters. Please provide a brief description of what they do and any arguments they may take. Be sure to also add the "Hooks" label to this PR. -->
### New/Updated Hooks
<!-- Add changelog entries meant for end-users. Leave empty to skip changelog. Delete section to use PR title. -->
### Release Notes

*

### New or Updated Hooks and Templates
<!-- Add notes for developers on hook/template changes. Add the following only if there are new/updated actions or filters. Please provide a brief description of what they do and any arguments they may take. Be sure to also add the "Hooks" label to this PR. -->

*

Expand All @@ -18,8 +23,4 @@ Fixes #

*

<!--
Helpful tips for screenshots:
https://en.support.wordpress.com/make-a-screenshot/
-->
### Screenshot / Video
95 changes: 50 additions & 45 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,54 @@
name: Plugin Build

on: pull_request
on:
- pull_request

jobs:
build:
name: Plugin Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Get npm cache directory
id: npm-cache
run: |
echo "::set-output name=dir::$(npm config get cache)"
- uses: actions/cache@v2
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: composer
coverage: none
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install JS dependencies
run: npm ci
- name: Install PHP dependencies
run: composer install --no-ansi --no-interaction --prefer-dist --no-progress
- name: Build Plugin
run: npm run build
- name: Decompress plugin
run: unzip wp-job-manager.zip -d wp-job-manager
- name: Store Artifact
uses: actions/upload-artifact@v2
with:
name: wp-job-manager-${{ github.event.pull_request.head.sha }}
path: ${{ github.workspace }}/wp-job-manager/
retention-days: 7

build:
name: Plugin Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Get npm cache directory
id: npm-cache
run: |
echo "::set-output name=dir::$(npm config get cache)"
- uses: actions/cache@v2
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: composer
coverage: none
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install JS dependencies
run: npm ci
- name: Install PHP dependencies
run: composer install --no-ansi --no-interaction --prefer-dist --no-progress
- name: Build Plugin
run: npm run build
- name: Decompress plugin
run: unzip wp-job-manager.zip -d wp-job-manager
- name: Store Artifact
uses: actions/upload-artifact@v2
with:
name: wp-job-manager-${{ github.event.pull_request.head.sha }}
path: ${{ github.workspace }}/wp-job-manager/
retention-days: 7
- name: Save plugin zip and add link to the PR description
env:
WPJMCOM_API_LOGIN: ${{ secrets.WPJMCOM_API_LOGIN }}
GH_TOKEN: ${{ github.token }}
run: node scripts/upload-and-link-plugin-zip.mjs --pr ${{ github.event.number }} --commit ${{ github.event.pull_request.head.sha }} ${{ github.event.pull_request.merged && '--merged' || '' }}
50 changes: 50 additions & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Create Plugin Release

on:
pull_request:
types:
- closed
branches:
- 'trunk'

jobs:
deploy:
if: github.event.pull_request.merged == true && startsWith( github.head_ref, 'release/' )
runs-on: ubuntu-latest
name: WPJM Release
steps:
- name: Comment on PR
env:
GITHUB_TOKEN: ${{ github.token }}
run: gh pr comment ${{ github.event.number }} --body "🚀 Starting release ..."
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: composer
coverage: none
- name: Install JS dependencies
run: npm ci
- name: Install PHP dependencies
run: composer install --no-ansi --no-interaction --prefer-dist --no-progress
- name: Setup Git
run: |
git config user.name "WPJM Bot"
git config user.email "<robot@wpjobmanager.com>"
- name: Create Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
node scripts/create-release.mjs wp-job-manager ${{ github.event.number }}
unzip -q wp-job-manager.zip
- name: Deploy to WordPress.org
uses: 10up/action-wordpress-plugin-deploy@abb939a0d0bfd01063e8d1933833209201557381
env:
SVN_PASSWORD: ${{ secrets.WORDPRESSORG_SVN_PASSWORD }}
SVN_USERNAME: ${{ secrets.WORDPRESSORG_SVN_USERNAME }}
BUILD_DIR: wp-job-manager
SLUG: wp-job-manager
- name: Comment on PR
env:
GITHUB_TOKEN: ${{ github.token }}
run: gh pr comment ${{ github.event.number }} --body "✅ Release ${{ github.event.release.tag_name }} deployed to WordPress.org"
32 changes: 22 additions & 10 deletions assets/js/datepicker.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
/* global job_manager_datepicker */
jQuery(document).ready(function($) {
jQuery(document).ready( function() {
var datePickerOptions = {
altFormat : 'yy-mm-dd',
};

if ( typeof job_manager_datepicker !== 'undefined' ) {
datePickerOptions.dateFormat = job_manager_datepicker.date_format;
}

$( 'input.job-manager-datepicker, input#_job_expires' ).each( function(){
var $hidden_input = $( '<input />', { type: 'hidden', name: $(this).attr( 'name' ) } ).insertAfter( $( this ) );
$(this).attr( 'name', $(this).attr( 'name' ) + '-datepicker' );
$(this).keyup( function() {
if ( '' === $(this).val() ) {
var initializeDatepicker = function ( targetInput ) {
var $target = jQuery( targetInput );
var $hidden_input = jQuery( '<input />', { type: 'hidden', name: $target.attr( 'name' ) } ).insertAfter( $target );

$target.attr( 'name', $target.attr( 'name' ) + '-datepicker' );
$target.on( 'keyup', function() {
if ( '' === $target.val() ) {
$hidden_input.val( '' );
}
} );
$(this).datepicker( $.extend( {}, datePickerOptions, { altField: $hidden_input } ) );
if ( $(this).val() ) {
var dateParts = $(this).val().split("-");
$target.datepicker( jQuery.extend( {}, datePickerOptions, { altField: $hidden_input } ) );
if ( $target.val() ) {
var dateParts = $target.val().split('-');
if ( 3 === dateParts.length ) {
var selectedDate = new Date(parseInt(dateParts[0], 10), (parseInt(dateParts[1], 10) - 1), parseInt(dateParts[2], 10));
$(this).datepicker('setDate', selectedDate);
$target.datepicker('setDate', selectedDate);
}
}
};

jQuery( 'input.job-manager-datepicker, input#_job_expires' ).each( function() {
initializeDatepicker( this );
} );


jQuery( document ).on( 'wpJobManagerFieldAdded', function ( e ) {
initializeDatepicker( e.target );
});
});
23 changes: 13 additions & 10 deletions includes/class-wp-job-manager-usage-tracking-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function get_usage_data() {
$categories = wp_count_terms( 'job_listing_category', [ 'hide_empty' => false ] );
}

return [
$usage_data = [
'employers' => self::get_employer_count(),
'job_categories' => $categories,
'job_categories_desc' => self::get_job_category_has_description_count(),
Expand Down Expand Up @@ -60,9 +60,19 @@ public static function get_usage_data() {
'jobs_part_time' => self::get_jobs_by_type_count( 'part-time' ),
'jobs_temp' => self::get_jobs_by_type_count( 'temporary' ),
'jobs_by_guests' => self::get_jobs_by_guests(),
'official_extensions' => self::get_official_extensions_count(),
'licensed_extensions' => self::get_licensed_extensions_count(),
];

$all_extenstions = self::get_official_extensions( false );
$licensed_extensions = self::get_official_extensions( true );

$usage_data['official_extensions'] = count( $all_extenstions );
$usage_data['licensed_extensions'] = count( $licensed_extensions );

foreach ( array_keys( $all_extenstions ) as $installed_plugin ) {
$usage_data[ $installed_plugin ] = isset( $licensed_extensions[ $installed_plugin ] ) ? 'licensed' : 'unlicensed';
}

return $usage_data;
}

/**
Expand Down Expand Up @@ -347,13 +357,6 @@ private static function get_official_extensions_count() {
return count( self::get_official_extensions( false ) );
}

/**
* Gets the count of all official extensions that are installed, activated, and have active license.
*/
private static function get_licensed_extensions_count() {
return count( self::get_official_extensions( true ) );
}

/**
* Checks if we have paid extensions installed and activated. Right now, all of our official extensions are paid.
*
Expand Down
26 changes: 0 additions & 26 deletions includes/class-wp-job-manager-usage-tracking.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,32 +235,6 @@ protected function opt_in_dialog_text() {
);
}

/**
* Check if we should track the status of a plugin.
*
* @param string $plugin_slug
* @return bool
*/
protected function do_track_plugin( $plugin_slug ) {
if ( 1 === preg_match( '/^wp\-job\-manager/', $plugin_slug ) ) {
return true;
}
$third_party_plugins = [
'all-in-one-seo-pack',
'polylang',
'jetpack',
'wordpress-seo', // Yoast.
'sitepress-multilingual-cms', // WPML.
'bibblio-related-posts', // Related Posts for WordPress.
];
if ( in_array( $plugin_slug, $third_party_plugins, true ) ) {
return true;
}

return false;
}


/*
* Public functions.
*/
Expand Down
14 changes: 8 additions & 6 deletions includes/helper/class-wp-job-manager-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -607,24 +607,26 @@ public function get_installed_plugins( $active_only = true, $keyed_by_filename =
$keyed_by_filename = false;
}

$wpjm_plugins = [];
$plugins = get_plugins();
$clear_plugin_cache = ! function_exists( 'did_filter' ) || did_filter( 'extra_plugin_headers' );

/**
* Clear the plugin cache on first request for installed WPJM add-on plugins when no plugins found.
* Clear the plugin cache on first request for installed WPJM add-on plugins. This happens in installations
* that get_plugins() is called before WPJM has a chance to register its custom plugin headers.
*
* @since 1.29.1
* @since $$next-version$$ Only do this when we don't see WP Job Manager in the plugins list.
* @since $$next-version$$ Only do this when get_plugins was called before this filter.
*
* @param bool $clear_plugin_cache True if we should clear the plugin cache.
*/
if ( ! self::$cleared_plugin_cache && apply_filters( 'job_manager_clear_plugin_cache', ! isset( $plugins[ JOB_MANAGER_PLUGIN_BASENAME ] ) ) ) {
if ( ! self::$cleared_plugin_cache && apply_filters( 'job_manager_clear_plugin_cache', $clear_plugin_cache ) ) {
// Reset the plugin cache on the first call. Some plugins prematurely hydrate the cache.
wp_clean_plugins_cache( false );
self::$cleared_plugin_cache = true;
$plugins = get_plugins();
}

$wpjm_plugins = [];
$plugins = get_plugins();

foreach ( $plugins as $filename => $data ) {
if ( empty( $data['WPJM-Product'] ) || ( true === $active_only && ! is_plugin_active( $filename ) ) ) {
continue;
Expand Down
18 changes: 3 additions & 15 deletions lib/usage-tracking/class-usage-tracking-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,6 @@ abstract protected function current_user_can_manage_tracking();
**/
abstract protected function opt_in_dialog_text();

/**
* Checks if we should send an activated plugin's installed version in the
* `system_log` event.
*
* @param string $plugin_slug the plugin slug to check.
*
* @return bool true if we send the version, false if not.
*/
abstract protected function do_track_plugin( $plugin_slug );

/**
* Gets the base data returned with system information.
*
Expand Down Expand Up @@ -372,11 +362,9 @@ public function get_system_data() {

$plugin_data = $this->get_plugin_data();
foreach ( $plugin_data as $plugin_name => $plugin_version ) {
if ( $this->do_track_plugin( $plugin_name ) ) {
$plugin_friendly_name = preg_replace( '/[^a-z0-9]/', '_', $plugin_name );
$plugin_key = self::PLUGIN_PREFIX . $plugin_friendly_name;
$system_data[ $plugin_key ] = $plugin_version;
}
$plugin_friendly_name = preg_replace( '/[^a-z0-9]/', '_', $plugin_name );
$plugin_key = self::PLUGIN_PREFIX . $plugin_friendly_name;
$system_data[ $plugin_key ] = $plugin_version;
}

return $system_data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ public function opt_in_dialog_text() {
return 'Please enable Usage Tracking!';
}

public function do_track_plugin( $plugin_slug ) {
if ( in_array( $plugin_slug, array( 'hello', 'test', 'my-favorite-plugin' ), true ) ) {
return true;
}
return false;
}

protected function get_plugins() {
return array(
'Hello.php' => array(
Expand Down
Loading

0 comments on commit 8bd16f7

Please sign in to comment.