Skip to content

Commit

Permalink
Merge pull request #5 from tarosky/feature/phpunit-in-docker
Browse files Browse the repository at this point in the history
Update 1.2.1
  • Loading branch information
fumikito authored Jul 3, 2024
2 parents 51cf936 + 8865a75 commit 1a62f01
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 150 deletions.
10 changes: 2 additions & 8 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@
},
"globals": {
"wp": false,
"jQuery": false,
"angular": false,
"Hametuha": true,
"wpApiSettings": false,
"ga": false,
"Hashboard": true,
"Vue": false
"jQuery": false
},
"extends": [
"plugin:@wordpress/eslint-plugin/recommended"
"plugin:@wordpress/eslint-plugin/recommended-with-formatting"
],
"rules": {
"no-alert": "off",
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/wordpress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,17 @@ jobs:
- name: Check JS & CSS syntax
run: npm run lint

status-check:
name: Status Check
needs: [ test, assets ]
runs-on: ubuntu-latest
steps:
- name: Status Check
run: echo "All tests passed!"

release:
name: Deploy WordPress.org
needs: [ test, assets ]
needs: [ status-check ]
if: contains(github.ref, 'tags/')
runs-on: ubuntu-latest
steps:
Expand Down
11 changes: 4 additions & 7 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
{
"plugins": [
".",
"https://downloads.wordpress.org/plugin/classic-editor.latest-stable.zip"
"https://downloads.wordpress.org/plugin/classic-editor.latest-stable.zip",
"https://downloads.wordpress.org/plugin/taro-ad-fields.latest-stable.zip",
"https://downloads.wordpress.org/plugin/query-monitor.latest-stable.zip"
],
"themes": [
"https://downloads.wordpress.org/theme/twentytwenty.latest-stable.zip"
],
"config": {
"WP_DEBUG": true,
"SCRIPT_DEBUG": true,
"WP_DEBUG_LOG": true
}
]
}
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Contributors: tarosky,Takahashi_Fumiki
Tags: post, media, expiration
Requires at least: 5.9
Requires PHP: 7.2
Tested up to: 6.1
Tested up to: 6.5
Stable tag: nightly
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.txt
Expand Down Expand Up @@ -69,6 +69,11 @@ add_filter( 'tscp_cron_interval', function() {

## Changelog

### 1.2.1

* Available post type are expanded to all post types with <code>show_ui = true</code>.
* Remove <code>withState</code> from editor script.

### 1.2.0

* Bump required PHP version.
Expand All @@ -85,4 +90,4 @@ add_filter( 'tscp_cron_interval', function() {

### 1.0.0

* Initial release.
* Initial release.
62 changes: 29 additions & 33 deletions assets/js/editor-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
* Editor input.
*
* @handle tscp-editor-input
* @deps wp-plugins, wp-edit-post, wp-components, wp-data, wp-api-fetch, wp-i18n, wp-compose, wp-element
* @deps wp-plugins, wp-edit-post, wp-components, wp-data, wp-api-fetch, wp-i18n, wp-element
*/

/* global TscpEditorInput: false */

const { registerPlugin } = wp.plugins;
const { PluginPostStatusInfo } = wp.editPost;
const { ToggleControl, TextControl, Spinner } = wp.components;
const { withState } = wp.compose;
const { useEffect } = wp.element;
const { useEffect, useState } = wp.element;
const { select, dispatch } = wp.data;
const { apiFetch } = wp;
const { __, sprintf } = wp.i18n;
Expand Down Expand Up @@ -41,17 +40,17 @@ const notify = ( message, status = 'success' ) => {
dispatch( 'core/notices' ).removeNotice( notice.id );
}, 2000 );
} );
}
};

let storedUpdated = null;

const TscpPostExpireBox = withState( {
active: false,
date: '',
loading: true,
timer: null,
} )( ( { setState, loading, active, date, timer } ) => {
const TscpPostExpireBox = () => {
// Nescessary variables.
const postType = select( 'core/editor' ).getCurrentPostType();
const [ active, setActive ] = useState( false );
const [ date, setDate ] = useState( '' );
const [ loading, setLoading ] = useState( false );
const [ timer, setTimer ] = useState( null );
if ( 0 > TscpEditorInput.postTypes.indexOf( postType ) ) {
// This is not supported.
return null;
Expand All @@ -62,42 +61,41 @@ const TscpPostExpireBox = withState( {
const sync = ( a, d ) => {
if ( timer ) {
clearTimeout( timer );
setTimer( null );
}
setTimeout( () => {
setTimer( setTimeout( () => {
apiFetch( {
path,
method: 'post',
data: {
should: a,
expires: d,
}
},
} ).then( ( res ) => {
notify( res.message );
} ).catch( ( res ) => {
notify( res.message, 'error' );
} );
}, 500 );
}, 500 ) );
};

// Initialize.
// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect( () => {
if ( storedUpdated === null ) {
storedUpdated = '';
apiFetch( {
path
} ).then( res => {
setState( {
loading: false,
active: res.should_expires,
date: toLocalDate( res.expires ),
} );
} ).catch( res => {
setState( { loading: false }, () => {
notify( res.message, 'error' );
} );
path,
} ).then( ( res ) => {
setLoading( false );
setActive( res.should_expires );
setDate( toLocalDate( res.expires ) );
} ).catch( ( res ) => {
setLoading( false );
notify( res.message, 'error' );
} );
}
} );
}, [] );

return (
<PluginPostStatusInfo className="tscp-time-input">
Expand All @@ -111,23 +109,21 @@ const TscpPostExpireBox = withState( {
label={ __( 'Expires at specified time', 'tscp' ) }
checked={ active }
onChange={ ( isActive ) => {
setState( { active: isActive }, () => {
sync( isActive, toDate( date ) );
} )
setActive( isActive );
sync( isActive, toDate( date ) );
} }
/>
{ active && (
<TextControl label={ __( 'Expires At', 'tscp' ) } className="tscp-time-input-date" type="datetime-local"
value={ date }
onChange={ ( newDate => {
setState( { date: newDate }, () => {
sync( active, toDate( newDate ) );
} );
onChange={ ( ( newDate ) => {
setDate( newDate );
sync( active, toDate( newDate ) );
} ) }
/>
) }
</PluginPostStatusInfo>
);
} );
};

registerPlugin( 'tscp-post-expire-box', { render: TscpPostExpireBox } );
29 changes: 23 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,38 @@
"email": "[email protected]"
}
],
"repositories":[
{
"type":"composer",
"url":"https://wpackagist.org",
"only": [
"wpackagist-plugin/*",
"wpackagist-theme/*"
]
}
],
"require": {
"php": ">=7.2"
},
"require-dev": {
"phpunit/phpunit": ">=6",
"squizlabs/php_codesniffer": "^3.0",
"wp-coding-standards/wpcs": "^2.0",
"wp-coding-standards/wpcs": "^3.0",
"yoast/phpunit-polyfills": "^1.0",
"phpcompatibility/php-compatibility": "^9.3",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0"

"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"wpackagist-plugin/taro-ad-fields": "^1.2"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
"dealerdirect/phpcodesniffer-composer-installer": true,
"composer/installers": true
}
}
},
"extra": {
"installer-paths": {
"vendor/plugins/{$name}/": [
"type:wordpress-plugin"
]
}
}
}
3 changes: 2 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ gulp.task( 'eslint', function () {
task = task.pipe( $.plumber() );
}
return task.pipe( $.eslint( { useEslintrc: true } ) )
.pipe( $.eslint.format() );
.pipe( $.eslint.format() )
.pipe( $.eslint.failAfterError() );
} );

// Copy bundles.
Expand Down
17 changes: 8 additions & 9 deletions includes/block-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Register block editor assets.
*/
add_action( 'enqueue_block_editor_assets', function() {
add_action( 'enqueue_block_editor_assets', function () {
// Register script
wp_enqueue_script( 'tscp-editor-input', tscp_asset_url( 'js/editor-input.js' ), [ 'wp-plugins', 'wp-edit-post', 'wp-components', 'wp-data', 'wp-i18n', 'wp-compose', 'wp-element', 'wp-api-fetch' ], tscp_version(), true );
wp_enqueue_style( 'tscp-editor-input', tscp_asset_url( 'css/editor-input.css' ), [ 'wp-components' ], tscp_version() );
Expand All @@ -23,24 +23,24 @@
/**
* Register REST API for custom fields.
*/
add_action( 'rest_api_init', function() {
add_action( 'rest_api_init', function () {

$permission_callback = function( WP_REST_Request $request ) {
$permission_callback = function ( WP_REST_Request $request ) {
return current_user_can( 'edit_post', $request->get_param( 'post_id' ) );
};

$args = [
'post_type' => [
'required' => true,
'type' => 'string',
'validate_callback' => function( $post_type ) {
'validate_callback' => function ( $post_type ) {
return tscp_post_type_can_expire( $post_type );
},
],
'post_id' => [
'required' => true,
'type' => 'int',
'validate_callback' => function( $post_id ) {
'validate_callback' => function ( $post_id ) {
return is_numeric( $post_id ) && get_post( $post_id );
},
],
Expand All @@ -51,7 +51,7 @@
'methods' => 'GET',
'args' => $args,
'permission_callback' => $permission_callback,
'callback' => function( WP_REST_Request $request ) {
'callback' => function ( WP_REST_Request $request ) {
$post_id = $request->get_param( 'post_id' );
return new WP_REST_Response( [
'should_expires' => (bool) get_post_meta( $post_id, '_tscp_should_expire', true ),
Expand All @@ -69,13 +69,13 @@
'expires' => [
'required' => true,
'type' => 'string',
'validate_callback' => function( $date ) {
'validate_callback' => function ( $date ) {
return empty( $date ) || preg_match( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/u', $date );
},
],
] ),
'permission_callback' => $permission_callback,
'callback' => function( WP_REST_Request $request ) {
'callback' => function ( WP_REST_Request $request ) {
$post_id = $request->get_param( 'post_id' );
$should_expire = $request->get_param( 'should' );
$expires_at = $request->get_param( 'expires' );
Expand All @@ -97,5 +97,4 @@
},
],
] );

} );
Loading

0 comments on commit 1a62f01

Please sign in to comment.