Changeset 3111435
- Timestamp:
- 07/03/2024 04:39:45 AM (21 months ago)
- Location:
- taro-clockwork-post
- Files:
-
- 18 edited
- 1 copied
-
tags/1.2.1 (copied) (copied from taro-clockwork-post/trunk)
-
tags/1.2.1/assets/js/editor-input.js (modified) (9 diffs)
-
tags/1.2.1/dist/js/editor-input.js (modified) (1 diff)
-
tags/1.2.1/dist/js/editor-input.js.LICENSE.txt (modified) (1 diff)
-
tags/1.2.1/gulpfile.js (modified) (1 diff)
-
tags/1.2.1/includes/block-editor.php (modified) (8 diffs)
-
tags/1.2.1/includes/meta-box.php (modified) (5 diffs)
-
tags/1.2.1/includes/setting.php (modified) (3 diffs)
-
tags/1.2.1/readme.txt (modified) (2 diffs)
-
tags/1.2.1/taro-clockwork-post.php (modified) (2 diffs)
-
trunk/assets/js/editor-input.js (modified) (9 diffs)
-
trunk/dist/js/editor-input.js (modified) (1 diff)
-
trunk/dist/js/editor-input.js.LICENSE.txt (modified) (1 diff)
-
trunk/gulpfile.js (modified) (1 diff)
-
trunk/includes/block-editor.php (modified) (8 diffs)
-
trunk/includes/meta-box.php (modified) (5 diffs)
-
trunk/includes/setting.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/taro-clockwork-post.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
taro-clockwork-post/tags/1.2.1/assets/js/editor-input.js
r2609804 r3111435 3 3 * 4 4 * @handle tscp-editor-input 5 * @deps wp-plugins, wp-edit-post, wp-components, wp-data, wp-api-fetch, wp-i18n, wp- compose, wp-element5 * @deps wp-plugins, wp-edit-post, wp-components, wp-data, wp-api-fetch, wp-i18n, wp-element 6 6 */ 7 7 … … 11 11 const { PluginPostStatusInfo } = wp.editPost; 12 12 const { ToggleControl, TextControl, Spinner } = wp.components; 13 const { withState } = wp.compose; 14 const { useEffect } = wp.element; 13 const { useEffect, useState } = wp.element; 15 14 const { select, dispatch } = wp.data; 16 15 const { apiFetch } = wp; … … 42 41 }, 2000 ); 43 42 } ); 44 } 43 }; 45 44 46 45 let storedUpdated = null; 47 46 48 const TscpPostExpireBox = withState( { 49 active: false, 50 date: '', 51 loading: true, 52 timer: null, 53 } )( ( { setState, loading, active, date, timer } ) => { 47 const TscpPostExpireBox = () => { 48 // Nescessary variables. 54 49 const postType = select( 'core/editor' ).getCurrentPostType(); 50 const [ active, setActive ] = useState( false ); 51 const [ date, setDate ] = useState( '' ); 52 const [ loading, setLoading ] = useState( false ); 53 const [ timer, setTimer ] = useState( null ); 55 54 if ( 0 > TscpEditorInput.postTypes.indexOf( postType ) ) { 56 55 // This is not supported. … … 63 62 if ( timer ) { 64 63 clearTimeout( timer ); 64 setTimer( null ); 65 65 } 66 setTime out( () => {66 setTimer( setTimeout( () => { 67 67 apiFetch( { 68 68 path, … … 71 71 should: a, 72 72 expires: d, 73 } 73 }, 74 74 } ).then( ( res ) => { 75 75 notify( res.message ); … … 77 77 notify( res.message, 'error' ); 78 78 } ); 79 }, 500 ) ;79 }, 500 ) ); 80 80 }; 81 81 82 82 // Initialize. 83 // eslint-disable-next-line react-hooks/rules-of-hooks 83 84 useEffect( () => { 84 85 if ( storedUpdated === null ) { 85 86 storedUpdated = ''; 86 87 apiFetch( { 87 path 88 } ).then( res => { 89 setState( { 90 loading: false, 91 active: res.should_expires, 92 date: toLocalDate( res.expires ), 93 } ); 94 } ).catch( res => { 95 setState( { loading: false }, () => { 96 notify( res.message, 'error' ); 97 } ); 88 path, 89 } ).then( ( res ) => { 90 setLoading( false ); 91 setActive( res.should_expires ); 92 setDate( toLocalDate( res.expires ) ); 93 } ).catch( ( res ) => { 94 setLoading( false ); 95 notify( res.message, 'error' ); 98 96 } ); 99 97 } 100 } );98 }, [] ); 101 99 102 100 return ( … … 112 110 checked={ active } 113 111 onChange={ ( isActive ) => { 114 setState( { active: isActive }, () => { 115 sync( isActive, toDate( date ) ); 116 } ) 112 setActive( isActive ); 113 sync( isActive, toDate( date ) ); 117 114 } } 118 115 /> … … 120 117 <TextControl label={ __( 'Expires At', 'tscp' ) } className="tscp-time-input-date" type="datetime-local" 121 118 value={ date } 122 onChange={ ( newDate => { 123 setState( { date: newDate }, () => { 124 sync( active, toDate( newDate ) ); 125 } ); 119 onChange={ ( ( newDate ) => { 120 setDate( newDate ); 121 sync( active, toDate( newDate ) ); 126 122 } ) } 127 123 /> … … 129 125 </PluginPostStatusInfo> 130 126 ); 131 } );127 }; 132 128 133 129 registerPlugin( 'tscp-post-expire-box', { render: TscpPostExpireBox } ); -
taro-clockwork-post/tags/1.2.1/dist/js/editor-input.js
r2609804 r3111435 1 1 /*! License information can be found in editor-input.js.LICENSE.txt */ 2 (()=>{ var e=wp.plugins.registerPlugin,t=wp.editPost.PluginPostStatusInfo,n=wp.components,i=n.ToggleControl,c=n.TextControl,o=n.Spinner,a=wp.compose.withState,s=wp.element.useEffect,r=wp.data,p=r.select,d=r.dispatch,l=wp.apiFetch,u=wp.i18n,g=u.__,m=u.sprintf,f=function(e){return e.match(/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):\d{2}/)?m("%04d-%02d-%02dT%02d:%02d",RegExp.$1,RegExp.$2,RegExp.$3,RegExp.$4,RegExp.$5):""},h=function(e){return e.match(/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/)?m("%04d-%02d-%02d %02d:%02d:59",RegExp.$1,RegExp.$2,RegExp.$3,RegExp.$4,RegExp.$5):""},x=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"success";d("core/notices").createNotice(t,e,{type:"snackbar",isDismissible:!0}).then((function(e){var t=e.notice;setTimeout((function(){d("core/notices").removeNotice(t.id)}),2e3)}))},E=null;e("tscp-post-expire-box",{render:a({active:!1,date:"",loading:!0,timer:null})((function(e){var n=e.setState,a=e.loading,r=e.active,d=e.date,u=e.timer,R=p("core/editor").getCurrentPostType();if(0>TscpEditorInput.postTypes.indexOf(R))return null;var v=p("core/editor").getCurrentPostId(),$=m("clockwork/v1/%1$s/%2$d/expiration",R,v),w=function(e,t){u&&clearTimeout(u),setTimeout((function(){l({path:$,method:"post",data:{should:e,expires:t}}).then((function(e){x(e.message)})).catch((function(e){x(e.message,"error")}))}),500)};return s((function(){null===E&&(E="",l({path:$}).then((function(e){n({loading:!1,active:e.should_expires,date:f(e.expires)})})).catch((function(e){n({loading:!1},(function(){x(e.message,"error")}))})))})),React.createElement(t,{className:"tscp-time-input"},a&&React.createElement("p",{style:{position:"absolute",top:0,right:0}},React.createElement(o,null)),React.createElement(i,{className:"tscp-time-input-toggle",label:g("Expires at specified time","tscp"),checked:r,onChange:function(e){n({active:e},(function(){w(e,h(d))}))}}),r&&React.createElement(c,{label:g("Expires At","tscp"),className:"tscp-time-input-date",type:"datetime-local",value:d,onChange:function(e){n({date:e},(function(){w(r,h(e))}))}}))}))})})();2 (()=>{function e(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i,c,a=[],l=!0,u=!1;try{if(i=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;l=!1}else for(;!(l=(r=i.call(n)).done)&&(a.push(r.value),a.length!==t);l=!0);}catch(e){u=!0,o=e}finally{try{if(!l&&null!=n.return&&(c=n.return(),Object(c)!==c))return}finally{if(u)throw o}}return a}}(e,n)||function(e,n){if(e){if("string"==typeof e)return t(e,n);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?t(e,n):void 0}}(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var n=wp.plugins.registerPlugin,r=wp.editPost.PluginPostStatusInfo,o=wp.components,i=o.ToggleControl,c=o.TextControl,a=o.Spinner,l=wp.element,u=l.useEffect,s=l.useState,p=wp.data,d=p.select,f=p.dispatch,m=wp.apiFetch,g=wp.i18n,h=g.__,x=g.sprintf,y=function(e){return e.match(/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/)?x("%04d-%02d-%02d %02d:%02d:59",RegExp.$1,RegExp.$2,RegExp.$3,RegExp.$4,RegExp.$5):""},E=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"success";f("core/notices").createNotice(t,e,{type:"snackbar",isDismissible:!0}).then((function(e){var t=e.notice;setTimeout((function(){f("core/notices").removeNotice(t.id)}),2e3)}))},v=null;n("tscp-post-expire-box",{render:function(){var t=d("core/editor").getCurrentPostType(),n=e(s(!1),2),o=n[0],l=n[1],p=e(s(""),2),f=p[0],g=p[1],b=e(s(!1),2),R=b[0],$=b[1],w=e(s(null),2),T=w[0],S=w[1];if(0>TscpEditorInput.postTypes.indexOf(t))return null;var A=d("core/editor").getCurrentPostId(),C=x("clockwork/v1/%1$s/%2$d/expiration",t,A),I=function(e,t){T&&(clearTimeout(T),S(null)),S(setTimeout((function(){m({path:C,method:"post",data:{should:e,expires:t}}).then((function(e){E(e.message)})).catch((function(e){E(e.message,"error")}))}),500))};return u((function(){null===v&&(v="",m({path:C}).then((function(e){$(!1),l(e.should_expires),g(function(e){return e.match(/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):\d{2}/)?x("%04d-%02d-%02dT%02d:%02d",RegExp.$1,RegExp.$2,RegExp.$3,RegExp.$4,RegExp.$5):""}(e.expires))})).catch((function(e){$(!1),E(e.message,"error")})))}),[]),React.createElement(r,{className:"tscp-time-input"},R&&React.createElement("p",{style:{position:"absolute",top:0,right:0}},React.createElement(a,null)),React.createElement(i,{className:"tscp-time-input-toggle",label:h("Expires at specified time","tscp"),checked:o,onChange:function(e){l(e),I(e,y(f))}}),o&&React.createElement(c,{label:h("Expires At","tscp"),className:"tscp-time-input-date",type:"datetime-local",value:f,onChange:function(e){g(e),I(o,y(e))}}))}})})(); -
taro-clockwork-post/tags/1.2.1/dist/js/editor-input.js.LICENSE.txt
r2609804 r3111435 3 3 * 4 4 * @handle tscp-editor-input 5 * @deps wp-plugins, wp-edit-post, wp-components, wp-data, wp-api-fetch, wp-i18n, wp- compose, wp-element5 * @deps wp-plugins, wp-edit-post, wp-components, wp-data, wp-api-fetch, wp-i18n, wp-element 6 6 */ -
taro-clockwork-post/tags/1.2.1/gulpfile.js
r2609804 r3111435 72 72 } 73 73 return task.pipe( $.eslint( { useEslintrc: true } ) ) 74 .pipe( $.eslint.format() ); 74 .pipe( $.eslint.format() ) 75 .pipe( $.eslint.failAfterError() ); 75 76 } ); 76 77 -
taro-clockwork-post/tags/1.2.1/includes/block-editor.php
r2897651 r3111435 9 9 * Register block editor assets. 10 10 */ 11 add_action( 'enqueue_block_editor_assets', function () {11 add_action( 'enqueue_block_editor_assets', function () { 12 12 // Register script 13 13 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 ); … … 24 24 * Register REST API for custom fields. 25 25 */ 26 add_action( 'rest_api_init', function () {26 add_action( 'rest_api_init', function () { 27 27 28 $permission_callback = function ( WP_REST_Request $request ) {28 $permission_callback = function ( WP_REST_Request $request ) { 29 29 return current_user_can( 'edit_post', $request->get_param( 'post_id' ) ); 30 30 }; … … 34 34 'required' => true, 35 35 'type' => 'string', 36 'validate_callback' => function ( $post_type ) {36 'validate_callback' => function ( $post_type ) { 37 37 return tscp_post_type_can_expire( $post_type ); 38 38 }, … … 41 41 'required' => true, 42 42 'type' => 'int', 43 'validate_callback' => function ( $post_id ) {43 'validate_callback' => function ( $post_id ) { 44 44 return is_numeric( $post_id ) && get_post( $post_id ); 45 45 }, … … 52 52 'args' => $args, 53 53 'permission_callback' => $permission_callback, 54 'callback' => function ( WP_REST_Request $request ) {54 'callback' => function ( WP_REST_Request $request ) { 55 55 $post_id = $request->get_param( 'post_id' ); 56 56 return new WP_REST_Response( [ … … 70 70 'required' => true, 71 71 'type' => 'string', 72 'validate_callback' => function ( $date ) {72 'validate_callback' => function ( $date ) { 73 73 return empty( $date ) || preg_match( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/u', $date ); 74 74 }, … … 76 76 ] ), 77 77 'permission_callback' => $permission_callback, 78 'callback' => function ( WP_REST_Request $request ) {78 'callback' => function ( WP_REST_Request $request ) { 79 79 $post_id = $request->get_param( 'post_id' ); 80 80 $should_expire = $request->get_param( 'should' ); … … 98 98 ], 99 99 ] ); 100 101 100 } ); -
taro-clockwork-post/tags/1.2.1/includes/meta-box.php
r2609804 r3111435 6 6 */ 7 7 8 add_action( 'admin_enqueue_scripts', function () {8 add_action( 'admin_enqueue_scripts', function () { 9 9 wp_enqueue_style( 'tscp-admin-helper', tscp_asset_url( 'css/admin.css' ), [], tscp_version() ); 10 10 } ); 11 11 12 12 // Register meta box for specified posts 13 add_action( 'add_meta_boxes', function ( $post_type ) {13 add_action( 'add_meta_boxes', function ( $post_type ) { 14 14 if ( tscp_post_type_can_expire( $post_type ) ) { 15 add_action( 'post_submitbox_misc_actions', function ( $post ) {15 add_action( 'post_submitbox_misc_actions', function ( $post ) { 16 16 wp_nonce_field( 'tscp_date', '_tscpnonce', false ); 17 17 $date_time = get_post_meta( $post->ID, '_tscp_expires', true ); … … 37 37 $year_input = sprintf( '<input type="text" name="tscp-year" class="tscp-long" value="%s" />', esc_attr( $year ) ); 38 38 $month_input = '<select name="tscp-month" class="tscp-month">'; 39 for ( $i = 1; $i <= 12; $i ++ ) {39 for ( $i = 1; $i <= 12; $i++ ) { 40 40 $month_str = mysql2date( 'M', str_replace( '-00-', sprintf( '-%02d-', $i ), date_i18n( 'Y-00-d' ) ) ); 41 41 // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison 42 $month_input .= sprintf( '<option value="%02d" %s>%s</option>', $i, selected( $i == $month, true, false ), $month_str );42 $month_input .= sprintf( '<option value="%02d" %s>%s</option>', $i, selected( $i, $month, false ), $month_str ); 43 43 } 44 44 $month_input .= '</select>'; … … 77 77 * @param WP_Post $post Post object. 78 78 */ 79 add_action( 'save_post', function ( $post_id, $post ) {79 add_action( 'save_post', function ( $post_id, $post ) { 80 80 if ( ! tscp_post_type_can_expire( $post->post_type ) ) { 81 81 return; … … 105 105 106 106 // Register post custom column 107 add_action( 'admin_init', function () {107 add_action( 'admin_init', function () { 108 108 $post_types = array_filter( (array) get_option( 'tscp_post_types', [ 'post' ] ), 'post_type_exists' ); 109 109 // Register post column 110 add_filter( 'manage_posts_columns', function ( $columns, $post_type ) use ( $post_types ) {110 add_filter( 'manage_posts_columns', function ( $columns, $post_type ) use ( $post_types ) { 111 111 if ( in_array( $post_type, $post_types, true ) ) { 112 112 $new_columns = []; … … 123 123 }, 10, 2 ); 124 124 foreach ( $post_types as $post_type ) { 125 add_action( "manage_{$post_type}_posts_custom_column", function ( $column, $post_id ) use ( $post_type ) {125 add_action( "manage_{$post_type}_posts_custom_column", function ( $column, $post_id ) use ( $post_type ) { 126 126 switch ( $column ) { 127 127 case 'expires': -
taro-clockwork-post/tags/1.2.1/includes/setting.php
r2609804 r3111435 7 7 8 8 // Register setting fields 9 add_action( 'admin_init', function () {9 add_action( 'admin_init', function () { 10 10 add_settings_section( 11 11 'tscp_setting', 12 12 __( 'Post Expiration Setting', 'tscp' ), 13 function () {13 function () { 14 14 printf( 15 15 '<p class="description">%s</p>', … … 24 24 'tscp_post_types', 25 25 __( 'Post Types', 'tscp' ), 26 function() { 27 $post_types = tscp_post_types(); 28 foreach ( get_post_types( [ 'public' => true ], OBJECT ) as $post_type ) { 29 if ( 'attachment' === $post_type->name ) { 30 continue; 31 } 26 function () { 27 $post_types = tscp_post_types(); 28 $available_post_type_list = get_post_types( [ 'show_ui' => true ], OBJECT ); 29 $available_post_type_list = array_values( array_filter( $available_post_type_list, function ( WP_Post_Type $post_type ) { 30 return ! in_array( $post_type->name, [ 'attachment', 'wp_navigation', 'wp_block' ], true ); 31 } ) ); 32 $available_post_type_list = apply_filters( 'tscp_available_post_type_list', $available_post_type_list ); 33 foreach ( $available_post_type_list as $post_type ) { 32 34 printf( 33 35 '<label style="display: inline-block; margin: 0 1em 1em 0;"><input type="checkbox" name="tscp_post_types[]" value="%s" %s /> %s</label>', … … 45 47 // Automatic save. 46 48 register_setting( 'reading', 'tscp_post_types' ); 47 48 49 } ); 49 50 -
taro-clockwork-post/tags/1.2.1/readme.txt
r2897651 r3111435 6 6 Requires at least: 5.9 7 7 Requires PHP: 7.2 8 Tested up to: 6. 18 Tested up to: 6.5 9 9 Stable tag: nightly 10 10 License: GPLv3 or later … … 70 70 == Changelog == 71 71 72 = 1.2.1 = 73 74 * Available post type are expanded to all post types with <code>show_ui = true</code>. 75 * Remove <code>withState</code> from editor script. 76 72 77 = 1.2.0 = 73 78 -
taro-clockwork-post/tags/1.2.1/taro-clockwork-post.php
r2897651 r3111435 5 5 Description: You can expire post with specified date. 6 6 Author: TAROSKY INC. <mng_wpcom@tarosky.co.jp> 7 Version: 1.2. 07 Version: 1.2.1 8 8 Author URI: https://tarosky.co.jp 9 9 Text Domain: tscp … … 24 24 */ 25 25 function tscp_plugins_loaded() { 26 load_plugin_textdomain( 'tscp', false, basename( dirname( __FILE__ )) . '/languages' );26 load_plugin_textdomain( 'tscp', false, basename( __DIR__ ) . '/languages' ); 27 27 if ( version_compare( phpversion(), '5.6.0', '<' ) ) { 28 28 add_action( 'admin_notices', 'tscp_plugin_notice' ); -
taro-clockwork-post/trunk/assets/js/editor-input.js
r2609804 r3111435 3 3 * 4 4 * @handle tscp-editor-input 5 * @deps wp-plugins, wp-edit-post, wp-components, wp-data, wp-api-fetch, wp-i18n, wp- compose, wp-element5 * @deps wp-plugins, wp-edit-post, wp-components, wp-data, wp-api-fetch, wp-i18n, wp-element 6 6 */ 7 7 … … 11 11 const { PluginPostStatusInfo } = wp.editPost; 12 12 const { ToggleControl, TextControl, Spinner } = wp.components; 13 const { withState } = wp.compose; 14 const { useEffect } = wp.element; 13 const { useEffect, useState } = wp.element; 15 14 const { select, dispatch } = wp.data; 16 15 const { apiFetch } = wp; … … 42 41 }, 2000 ); 43 42 } ); 44 } 43 }; 45 44 46 45 let storedUpdated = null; 47 46 48 const TscpPostExpireBox = withState( { 49 active: false, 50 date: '', 51 loading: true, 52 timer: null, 53 } )( ( { setState, loading, active, date, timer } ) => { 47 const TscpPostExpireBox = () => { 48 // Nescessary variables. 54 49 const postType = select( 'core/editor' ).getCurrentPostType(); 50 const [ active, setActive ] = useState( false ); 51 const [ date, setDate ] = useState( '' ); 52 const [ loading, setLoading ] = useState( false ); 53 const [ timer, setTimer ] = useState( null ); 55 54 if ( 0 > TscpEditorInput.postTypes.indexOf( postType ) ) { 56 55 // This is not supported. … … 63 62 if ( timer ) { 64 63 clearTimeout( timer ); 64 setTimer( null ); 65 65 } 66 setTime out( () => {66 setTimer( setTimeout( () => { 67 67 apiFetch( { 68 68 path, … … 71 71 should: a, 72 72 expires: d, 73 } 73 }, 74 74 } ).then( ( res ) => { 75 75 notify( res.message ); … … 77 77 notify( res.message, 'error' ); 78 78 } ); 79 }, 500 ) ;79 }, 500 ) ); 80 80 }; 81 81 82 82 // Initialize. 83 // eslint-disable-next-line react-hooks/rules-of-hooks 83 84 useEffect( () => { 84 85 if ( storedUpdated === null ) { 85 86 storedUpdated = ''; 86 87 apiFetch( { 87 path 88 } ).then( res => { 89 setState( { 90 loading: false, 91 active: res.should_expires, 92 date: toLocalDate( res.expires ), 93 } ); 94 } ).catch( res => { 95 setState( { loading: false }, () => { 96 notify( res.message, 'error' ); 97 } ); 88 path, 89 } ).then( ( res ) => { 90 setLoading( false ); 91 setActive( res.should_expires ); 92 setDate( toLocalDate( res.expires ) ); 93 } ).catch( ( res ) => { 94 setLoading( false ); 95 notify( res.message, 'error' ); 98 96 } ); 99 97 } 100 } );98 }, [] ); 101 99 102 100 return ( … … 112 110 checked={ active } 113 111 onChange={ ( isActive ) => { 114 setState( { active: isActive }, () => { 115 sync( isActive, toDate( date ) ); 116 } ) 112 setActive( isActive ); 113 sync( isActive, toDate( date ) ); 117 114 } } 118 115 /> … … 120 117 <TextControl label={ __( 'Expires At', 'tscp' ) } className="tscp-time-input-date" type="datetime-local" 121 118 value={ date } 122 onChange={ ( newDate => { 123 setState( { date: newDate }, () => { 124 sync( active, toDate( newDate ) ); 125 } ); 119 onChange={ ( ( newDate ) => { 120 setDate( newDate ); 121 sync( active, toDate( newDate ) ); 126 122 } ) } 127 123 /> … … 129 125 </PluginPostStatusInfo> 130 126 ); 131 } );127 }; 132 128 133 129 registerPlugin( 'tscp-post-expire-box', { render: TscpPostExpireBox } ); -
taro-clockwork-post/trunk/dist/js/editor-input.js
r2609804 r3111435 1 1 /*! License information can be found in editor-input.js.LICENSE.txt */ 2 (()=>{ var e=wp.plugins.registerPlugin,t=wp.editPost.PluginPostStatusInfo,n=wp.components,i=n.ToggleControl,c=n.TextControl,o=n.Spinner,a=wp.compose.withState,s=wp.element.useEffect,r=wp.data,p=r.select,d=r.dispatch,l=wp.apiFetch,u=wp.i18n,g=u.__,m=u.sprintf,f=function(e){return e.match(/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):\d{2}/)?m("%04d-%02d-%02dT%02d:%02d",RegExp.$1,RegExp.$2,RegExp.$3,RegExp.$4,RegExp.$5):""},h=function(e){return e.match(/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/)?m("%04d-%02d-%02d %02d:%02d:59",RegExp.$1,RegExp.$2,RegExp.$3,RegExp.$4,RegExp.$5):""},x=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"success";d("core/notices").createNotice(t,e,{type:"snackbar",isDismissible:!0}).then((function(e){var t=e.notice;setTimeout((function(){d("core/notices").removeNotice(t.id)}),2e3)}))},E=null;e("tscp-post-expire-box",{render:a({active:!1,date:"",loading:!0,timer:null})((function(e){var n=e.setState,a=e.loading,r=e.active,d=e.date,u=e.timer,R=p("core/editor").getCurrentPostType();if(0>TscpEditorInput.postTypes.indexOf(R))return null;var v=p("core/editor").getCurrentPostId(),$=m("clockwork/v1/%1$s/%2$d/expiration",R,v),w=function(e,t){u&&clearTimeout(u),setTimeout((function(){l({path:$,method:"post",data:{should:e,expires:t}}).then((function(e){x(e.message)})).catch((function(e){x(e.message,"error")}))}),500)};return s((function(){null===E&&(E="",l({path:$}).then((function(e){n({loading:!1,active:e.should_expires,date:f(e.expires)})})).catch((function(e){n({loading:!1},(function(){x(e.message,"error")}))})))})),React.createElement(t,{className:"tscp-time-input"},a&&React.createElement("p",{style:{position:"absolute",top:0,right:0}},React.createElement(o,null)),React.createElement(i,{className:"tscp-time-input-toggle",label:g("Expires at specified time","tscp"),checked:r,onChange:function(e){n({active:e},(function(){w(e,h(d))}))}}),r&&React.createElement(c,{label:g("Expires At","tscp"),className:"tscp-time-input-date",type:"datetime-local",value:d,onChange:function(e){n({date:e},(function(){w(r,h(e))}))}}))}))})})();2 (()=>{function e(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i,c,a=[],l=!0,u=!1;try{if(i=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;l=!1}else for(;!(l=(r=i.call(n)).done)&&(a.push(r.value),a.length!==t);l=!0);}catch(e){u=!0,o=e}finally{try{if(!l&&null!=n.return&&(c=n.return(),Object(c)!==c))return}finally{if(u)throw o}}return a}}(e,n)||function(e,n){if(e){if("string"==typeof e)return t(e,n);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?t(e,n):void 0}}(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var n=wp.plugins.registerPlugin,r=wp.editPost.PluginPostStatusInfo,o=wp.components,i=o.ToggleControl,c=o.TextControl,a=o.Spinner,l=wp.element,u=l.useEffect,s=l.useState,p=wp.data,d=p.select,f=p.dispatch,m=wp.apiFetch,g=wp.i18n,h=g.__,x=g.sprintf,y=function(e){return e.match(/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/)?x("%04d-%02d-%02d %02d:%02d:59",RegExp.$1,RegExp.$2,RegExp.$3,RegExp.$4,RegExp.$5):""},E=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"success";f("core/notices").createNotice(t,e,{type:"snackbar",isDismissible:!0}).then((function(e){var t=e.notice;setTimeout((function(){f("core/notices").removeNotice(t.id)}),2e3)}))},v=null;n("tscp-post-expire-box",{render:function(){var t=d("core/editor").getCurrentPostType(),n=e(s(!1),2),o=n[0],l=n[1],p=e(s(""),2),f=p[0],g=p[1],b=e(s(!1),2),R=b[0],$=b[1],w=e(s(null),2),T=w[0],S=w[1];if(0>TscpEditorInput.postTypes.indexOf(t))return null;var A=d("core/editor").getCurrentPostId(),C=x("clockwork/v1/%1$s/%2$d/expiration",t,A),I=function(e,t){T&&(clearTimeout(T),S(null)),S(setTimeout((function(){m({path:C,method:"post",data:{should:e,expires:t}}).then((function(e){E(e.message)})).catch((function(e){E(e.message,"error")}))}),500))};return u((function(){null===v&&(v="",m({path:C}).then((function(e){$(!1),l(e.should_expires),g(function(e){return e.match(/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):\d{2}/)?x("%04d-%02d-%02dT%02d:%02d",RegExp.$1,RegExp.$2,RegExp.$3,RegExp.$4,RegExp.$5):""}(e.expires))})).catch((function(e){$(!1),E(e.message,"error")})))}),[]),React.createElement(r,{className:"tscp-time-input"},R&&React.createElement("p",{style:{position:"absolute",top:0,right:0}},React.createElement(a,null)),React.createElement(i,{className:"tscp-time-input-toggle",label:h("Expires at specified time","tscp"),checked:o,onChange:function(e){l(e),I(e,y(f))}}),o&&React.createElement(c,{label:h("Expires At","tscp"),className:"tscp-time-input-date",type:"datetime-local",value:f,onChange:function(e){g(e),I(o,y(e))}}))}})})(); -
taro-clockwork-post/trunk/dist/js/editor-input.js.LICENSE.txt
r2609804 r3111435 3 3 * 4 4 * @handle tscp-editor-input 5 * @deps wp-plugins, wp-edit-post, wp-components, wp-data, wp-api-fetch, wp-i18n, wp- compose, wp-element5 * @deps wp-plugins, wp-edit-post, wp-components, wp-data, wp-api-fetch, wp-i18n, wp-element 6 6 */ -
taro-clockwork-post/trunk/gulpfile.js
r2609804 r3111435 72 72 } 73 73 return task.pipe( $.eslint( { useEslintrc: true } ) ) 74 .pipe( $.eslint.format() ); 74 .pipe( $.eslint.format() ) 75 .pipe( $.eslint.failAfterError() ); 75 76 } ); 76 77 -
taro-clockwork-post/trunk/includes/block-editor.php
r2897651 r3111435 9 9 * Register block editor assets. 10 10 */ 11 add_action( 'enqueue_block_editor_assets', function () {11 add_action( 'enqueue_block_editor_assets', function () { 12 12 // Register script 13 13 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 ); … … 24 24 * Register REST API for custom fields. 25 25 */ 26 add_action( 'rest_api_init', function () {26 add_action( 'rest_api_init', function () { 27 27 28 $permission_callback = function ( WP_REST_Request $request ) {28 $permission_callback = function ( WP_REST_Request $request ) { 29 29 return current_user_can( 'edit_post', $request->get_param( 'post_id' ) ); 30 30 }; … … 34 34 'required' => true, 35 35 'type' => 'string', 36 'validate_callback' => function ( $post_type ) {36 'validate_callback' => function ( $post_type ) { 37 37 return tscp_post_type_can_expire( $post_type ); 38 38 }, … … 41 41 'required' => true, 42 42 'type' => 'int', 43 'validate_callback' => function ( $post_id ) {43 'validate_callback' => function ( $post_id ) { 44 44 return is_numeric( $post_id ) && get_post( $post_id ); 45 45 }, … … 52 52 'args' => $args, 53 53 'permission_callback' => $permission_callback, 54 'callback' => function ( WP_REST_Request $request ) {54 'callback' => function ( WP_REST_Request $request ) { 55 55 $post_id = $request->get_param( 'post_id' ); 56 56 return new WP_REST_Response( [ … … 70 70 'required' => true, 71 71 'type' => 'string', 72 'validate_callback' => function ( $date ) {72 'validate_callback' => function ( $date ) { 73 73 return empty( $date ) || preg_match( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/u', $date ); 74 74 }, … … 76 76 ] ), 77 77 'permission_callback' => $permission_callback, 78 'callback' => function ( WP_REST_Request $request ) {78 'callback' => function ( WP_REST_Request $request ) { 79 79 $post_id = $request->get_param( 'post_id' ); 80 80 $should_expire = $request->get_param( 'should' ); … … 98 98 ], 99 99 ] ); 100 101 100 } ); -
taro-clockwork-post/trunk/includes/meta-box.php
r2609804 r3111435 6 6 */ 7 7 8 add_action( 'admin_enqueue_scripts', function () {8 add_action( 'admin_enqueue_scripts', function () { 9 9 wp_enqueue_style( 'tscp-admin-helper', tscp_asset_url( 'css/admin.css' ), [], tscp_version() ); 10 10 } ); 11 11 12 12 // Register meta box for specified posts 13 add_action( 'add_meta_boxes', function ( $post_type ) {13 add_action( 'add_meta_boxes', function ( $post_type ) { 14 14 if ( tscp_post_type_can_expire( $post_type ) ) { 15 add_action( 'post_submitbox_misc_actions', function ( $post ) {15 add_action( 'post_submitbox_misc_actions', function ( $post ) { 16 16 wp_nonce_field( 'tscp_date', '_tscpnonce', false ); 17 17 $date_time = get_post_meta( $post->ID, '_tscp_expires', true ); … … 37 37 $year_input = sprintf( '<input type="text" name="tscp-year" class="tscp-long" value="%s" />', esc_attr( $year ) ); 38 38 $month_input = '<select name="tscp-month" class="tscp-month">'; 39 for ( $i = 1; $i <= 12; $i ++ ) {39 for ( $i = 1; $i <= 12; $i++ ) { 40 40 $month_str = mysql2date( 'M', str_replace( '-00-', sprintf( '-%02d-', $i ), date_i18n( 'Y-00-d' ) ) ); 41 41 // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison 42 $month_input .= sprintf( '<option value="%02d" %s>%s</option>', $i, selected( $i == $month, true, false ), $month_str );42 $month_input .= sprintf( '<option value="%02d" %s>%s</option>', $i, selected( $i, $month, false ), $month_str ); 43 43 } 44 44 $month_input .= '</select>'; … … 77 77 * @param WP_Post $post Post object. 78 78 */ 79 add_action( 'save_post', function ( $post_id, $post ) {79 add_action( 'save_post', function ( $post_id, $post ) { 80 80 if ( ! tscp_post_type_can_expire( $post->post_type ) ) { 81 81 return; … … 105 105 106 106 // Register post custom column 107 add_action( 'admin_init', function () {107 add_action( 'admin_init', function () { 108 108 $post_types = array_filter( (array) get_option( 'tscp_post_types', [ 'post' ] ), 'post_type_exists' ); 109 109 // Register post column 110 add_filter( 'manage_posts_columns', function ( $columns, $post_type ) use ( $post_types ) {110 add_filter( 'manage_posts_columns', function ( $columns, $post_type ) use ( $post_types ) { 111 111 if ( in_array( $post_type, $post_types, true ) ) { 112 112 $new_columns = []; … … 123 123 }, 10, 2 ); 124 124 foreach ( $post_types as $post_type ) { 125 add_action( "manage_{$post_type}_posts_custom_column", function ( $column, $post_id ) use ( $post_type ) {125 add_action( "manage_{$post_type}_posts_custom_column", function ( $column, $post_id ) use ( $post_type ) { 126 126 switch ( $column ) { 127 127 case 'expires': -
taro-clockwork-post/trunk/includes/setting.php
r2609804 r3111435 7 7 8 8 // Register setting fields 9 add_action( 'admin_init', function () {9 add_action( 'admin_init', function () { 10 10 add_settings_section( 11 11 'tscp_setting', 12 12 __( 'Post Expiration Setting', 'tscp' ), 13 function () {13 function () { 14 14 printf( 15 15 '<p class="description">%s</p>', … … 24 24 'tscp_post_types', 25 25 __( 'Post Types', 'tscp' ), 26 function() { 27 $post_types = tscp_post_types(); 28 foreach ( get_post_types( [ 'public' => true ], OBJECT ) as $post_type ) { 29 if ( 'attachment' === $post_type->name ) { 30 continue; 31 } 26 function () { 27 $post_types = tscp_post_types(); 28 $available_post_type_list = get_post_types( [ 'show_ui' => true ], OBJECT ); 29 $available_post_type_list = array_values( array_filter( $available_post_type_list, function ( WP_Post_Type $post_type ) { 30 return ! in_array( $post_type->name, [ 'attachment', 'wp_navigation', 'wp_block' ], true ); 31 } ) ); 32 $available_post_type_list = apply_filters( 'tscp_available_post_type_list', $available_post_type_list ); 33 foreach ( $available_post_type_list as $post_type ) { 32 34 printf( 33 35 '<label style="display: inline-block; margin: 0 1em 1em 0;"><input type="checkbox" name="tscp_post_types[]" value="%s" %s /> %s</label>', … … 45 47 // Automatic save. 46 48 register_setting( 'reading', 'tscp_post_types' ); 47 48 49 } ); 49 50 -
taro-clockwork-post/trunk/readme.txt
r2897651 r3111435 6 6 Requires at least: 5.9 7 7 Requires PHP: 7.2 8 Tested up to: 6. 18 Tested up to: 6.5 9 9 Stable tag: nightly 10 10 License: GPLv3 or later … … 70 70 == Changelog == 71 71 72 = 1.2.1 = 73 74 * Available post type are expanded to all post types with <code>show_ui = true</code>. 75 * Remove <code>withState</code> from editor script. 76 72 77 = 1.2.0 = 73 78 -
taro-clockwork-post/trunk/taro-clockwork-post.php
r2897651 r3111435 5 5 Description: You can expire post with specified date. 6 6 Author: TAROSKY INC. <mng_wpcom@tarosky.co.jp> 7 Version: 1.2. 07 Version: 1.2.1 8 8 Author URI: https://tarosky.co.jp 9 9 Text Domain: tscp … … 24 24 */ 25 25 function tscp_plugins_loaded() { 26 load_plugin_textdomain( 'tscp', false, basename( dirname( __FILE__ )) . '/languages' );26 load_plugin_textdomain( 'tscp', false, basename( __DIR__ ) . '/languages' ); 27 27 if ( version_compare( phpversion(), '5.6.0', '<' ) ) { 28 28 add_action( 'admin_notices', 'tscp_plugin_notice' );
Note: See TracChangeset
for help on using the changeset viewer.