Plugin Directory

Changeset 3111435


Ignore:
Timestamp:
07/03/2024 04:39:45 AM (21 months ago)
Author:
Tarosky
Message:

Update to version 1.2.1 from GitHub

Location:
taro-clockwork-post
Files:
18 edited
1 copied

Legend:

Unmodified
Added
Removed
  • taro-clockwork-post/tags/1.2.1/assets/js/editor-input.js

    r2609804 r3111435  
    33 *
    44 * @handle tscp-editor-input
    5  * @deps wp-plugins, wp-edit-post, wp-components, wp-data, wp-api-fetch, wp-i18n, wp-compose, wp-element
     5 * @deps wp-plugins, wp-edit-post, wp-components, wp-data, wp-api-fetch, wp-i18n, wp-element
    66 */
    77
     
    1111const { PluginPostStatusInfo } = wp.editPost;
    1212const { ToggleControl, TextControl, Spinner } = wp.components;
    13 const { withState } = wp.compose;
    14 const { useEffect } = wp.element;
     13const { useEffect, useState } = wp.element;
    1514const { select, dispatch } = wp.data;
    1615const { apiFetch } = wp;
     
    4241        }, 2000 );
    4342    } );
    44 }
     43};
    4544
    4645let storedUpdated = null;
    4746
    48 const TscpPostExpireBox = withState( {
    49     active: false,
    50     date: '',
    51     loading: true,
    52     timer: null,
    53 } )( ( { setState, loading, active, date, timer } ) => {
     47const TscpPostExpireBox = () => {
     48    // Nescessary variables.
    5449    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 );
    5554    if ( 0 > TscpEditorInput.postTypes.indexOf( postType ) ) {
    5655        // This is not supported.
     
    6362        if ( timer ) {
    6463            clearTimeout( timer );
     64            setTimer( null );
    6565        }
    66         setTimeout( () => {
     66        setTimer( setTimeout( () => {
    6767            apiFetch( {
    6868                path,
     
    7171                    should: a,
    7272                    expires: d,
    73                 }
     73                },
    7474            } ).then( ( res ) => {
    7575                notify( res.message );
     
    7777                notify( res.message, 'error' );
    7878            } );
    79         }, 500 );
     79        }, 500 ) );
    8080    };
    8181
    8282    // Initialize.
     83    // eslint-disable-next-line react-hooks/rules-of-hooks
    8384    useEffect( () => {
    8485        if ( storedUpdated === null ) {
    8586            storedUpdated = '';
    8687            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' );
    9896            } );
    9997        }
    100     } );
     98    }, [] );
    10199
    102100    return (
     
    112110                checked={ active }
    113111                onChange={ ( isActive ) => {
    114                     setState( { active: isActive }, () => {
    115                         sync( isActive, toDate( date ) );
    116                     } )
     112                    setActive( isActive );
     113                    sync( isActive, toDate( date ) );
    117114                } }
    118115            />
     
    120117                <TextControl label={ __( 'Expires At', 'tscp' ) } className="tscp-time-input-date" type="datetime-local"
    121118                    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 ) );
    126122                    } ) }
    127123                />
     
    129125        </PluginPostStatusInfo>
    130126    );
    131 } );
     127};
    132128
    133129registerPlugin( 'tscp-post-expire-box', { render: TscpPostExpireBox } );
  • taro-clockwork-post/tags/1.2.1/dist/js/editor-input.js

    r2609804 r3111435  
    11/*! 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  
    33 *
    44 * @handle tscp-editor-input
    5  * @deps wp-plugins, wp-edit-post, wp-components, wp-data, wp-api-fetch, wp-i18n, wp-compose, wp-element
     5 * @deps wp-plugins, wp-edit-post, wp-components, wp-data, wp-api-fetch, wp-i18n, wp-element
    66 */
  • taro-clockwork-post/tags/1.2.1/gulpfile.js

    r2609804 r3111435  
    7272    }
    7373    return task.pipe( $.eslint( { useEslintrc: true } ) )
    74         .pipe( $.eslint.format() );
     74        .pipe( $.eslint.format() )
     75        .pipe( $.eslint.failAfterError() );
    7576} );
    7677
  • taro-clockwork-post/tags/1.2.1/includes/block-editor.php

    r2897651 r3111435  
    99 * Register block editor assets.
    1010 */
    11 add_action( 'enqueue_block_editor_assets', function() {
     11add_action( 'enqueue_block_editor_assets', function () {
    1212    // Register script
    1313    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 );
     
    2424 * Register REST API for custom fields.
    2525 */
    26 add_action( 'rest_api_init', function() {
     26add_action( 'rest_api_init', function () {
    2727
    28     $permission_callback = function( WP_REST_Request $request ) {
     28    $permission_callback = function ( WP_REST_Request $request ) {
    2929        return current_user_can( 'edit_post', $request->get_param( 'post_id' ) );
    3030    };
     
    3434            'required'          => true,
    3535            'type'              => 'string',
    36             'validate_callback' => function( $post_type ) {
     36            'validate_callback' => function ( $post_type ) {
    3737                return tscp_post_type_can_expire( $post_type );
    3838            },
     
    4141            'required'          => true,
    4242            'type'              => 'int',
    43             'validate_callback' => function( $post_id ) {
     43            'validate_callback' => function ( $post_id ) {
    4444                return is_numeric( $post_id ) && get_post( $post_id );
    4545            },
     
    5252            'args'                => $args,
    5353            'permission_callback' => $permission_callback,
    54             'callback'            => function( WP_REST_Request $request ) {
     54            'callback'            => function ( WP_REST_Request $request ) {
    5555                $post_id = $request->get_param( 'post_id' );
    5656                return new WP_REST_Response( [
     
    7070                    'required'          => true,
    7171                    'type'              => 'string',
    72                     'validate_callback' => function( $date ) {
     72                    'validate_callback' => function ( $date ) {
    7373                        return empty( $date ) || preg_match( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/u', $date );
    7474                    },
     
    7676            ] ),
    7777            'permission_callback' => $permission_callback,
    78             'callback'            => function( WP_REST_Request $request ) {
     78            'callback'            => function ( WP_REST_Request $request ) {
    7979                $post_id       = $request->get_param( 'post_id' );
    8080                $should_expire = $request->get_param( 'should' );
     
    9898        ],
    9999    ] );
    100 
    101100} );
  • taro-clockwork-post/tags/1.2.1/includes/meta-box.php

    r2609804 r3111435  
    66 */
    77
    8 add_action( 'admin_enqueue_scripts', function() {
     8add_action( 'admin_enqueue_scripts', function () {
    99    wp_enqueue_style( 'tscp-admin-helper', tscp_asset_url( 'css/admin.css' ), [], tscp_version() );
    1010} );
    1111
    1212// Register meta box for specified posts
    13 add_action( 'add_meta_boxes', function( $post_type ) {
     13add_action( 'add_meta_boxes', function ( $post_type ) {
    1414    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 ) {
    1616            wp_nonce_field( 'tscp_date', '_tscpnonce', false );
    1717            $date_time = get_post_meta( $post->ID, '_tscp_expires', true );
     
    3737                    $year_input  = sprintf( '<input type="text" name="tscp-year" class="tscp-long" value="%s" />', esc_attr( $year ) );
    3838                    $month_input = '<select name="tscp-month" class="tscp-month">';
    39                     for ( $i = 1; $i <= 12; $i ++ ) {
     39                    for ( $i = 1; $i <= 12; $i++ ) {
    4040                        $month_str = mysql2date( 'M', str_replace( '-00-', sprintf( '-%02d-', $i ), date_i18n( 'Y-00-d' ) ) );
    4141                        // 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 );
    4343                    }
    4444                    $month_input .= '</select>';
     
    7777 * @param WP_Post $post Post object.
    7878 */
    79 add_action( 'save_post', function( $post_id, $post ) {
     79add_action( 'save_post', function ( $post_id, $post ) {
    8080    if ( ! tscp_post_type_can_expire( $post->post_type ) ) {
    8181        return;
     
    105105
    106106// Register post custom column
    107 add_action( 'admin_init', function() {
     107add_action( 'admin_init', function () {
    108108    $post_types = array_filter( (array) get_option( 'tscp_post_types', [ 'post' ] ), 'post_type_exists' );
    109109    // 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 ) {
    111111        if ( in_array( $post_type, $post_types, true ) ) {
    112112            $new_columns = [];
     
    123123    }, 10, 2 );
    124124    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 ) {
    126126            switch ( $column ) {
    127127                case 'expires':
  • taro-clockwork-post/tags/1.2.1/includes/setting.php

    r2609804 r3111435  
    77
    88// Register setting fields
    9 add_action( 'admin_init', function() {
     9add_action( 'admin_init', function () {
    1010    add_settings_section(
    1111        'tscp_setting',
    1212        __( 'Post Expiration Setting', 'tscp' ),
    13         function() {
     13        function () {
    1414            printf(
    1515                '<p class="description">%s</p>',
     
    2424        'tscp_post_types',
    2525        __( '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 ) {
    3234                printf(
    3335                    '<label style="display: inline-block; margin: 0 1em 1em 0;"><input type="checkbox" name="tscp_post_types[]" value="%s" %s /> %s</label>',
     
    4547    // Automatic save.
    4648    register_setting( 'reading', 'tscp_post_types' );
    47 
    4849} );
    49 
    50 
  • taro-clockwork-post/tags/1.2.1/readme.txt

    r2897651 r3111435  
    66Requires at least: 5.9 
    77Requires PHP: 7.2 
    8 Tested up to: 6.1 
     8Tested up to: 6.5 
    99Stable tag: nightly 
    1010License: GPLv3 or later 
     
    7070== Changelog ==
    7171
     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
    7277= 1.2.0 =
    7378
  • taro-clockwork-post/tags/1.2.1/taro-clockwork-post.php

    r2897651 r3111435  
    55Description: You can expire post with specified date.
    66Author: TAROSKY INC. <mng_wpcom@tarosky.co.jp>
    7 Version: 1.2.0
     7Version: 1.2.1
    88Author URI: https://tarosky.co.jp
    99Text Domain: tscp
     
    2424 */
    2525function tscp_plugins_loaded() {
    26     load_plugin_textdomain( 'tscp', false, basename( dirname( __FILE__ ) ) . '/languages' );
     26    load_plugin_textdomain( 'tscp', false, basename( __DIR__ ) . '/languages' );
    2727    if ( version_compare( phpversion(), '5.6.0', '<' ) ) {
    2828        add_action( 'admin_notices', 'tscp_plugin_notice' );
  • taro-clockwork-post/trunk/assets/js/editor-input.js

    r2609804 r3111435  
    33 *
    44 * @handle tscp-editor-input
    5  * @deps wp-plugins, wp-edit-post, wp-components, wp-data, wp-api-fetch, wp-i18n, wp-compose, wp-element
     5 * @deps wp-plugins, wp-edit-post, wp-components, wp-data, wp-api-fetch, wp-i18n, wp-element
    66 */
    77
     
    1111const { PluginPostStatusInfo } = wp.editPost;
    1212const { ToggleControl, TextControl, Spinner } = wp.components;
    13 const { withState } = wp.compose;
    14 const { useEffect } = wp.element;
     13const { useEffect, useState } = wp.element;
    1514const { select, dispatch } = wp.data;
    1615const { apiFetch } = wp;
     
    4241        }, 2000 );
    4342    } );
    44 }
     43};
    4544
    4645let storedUpdated = null;
    4746
    48 const TscpPostExpireBox = withState( {
    49     active: false,
    50     date: '',
    51     loading: true,
    52     timer: null,
    53 } )( ( { setState, loading, active, date, timer } ) => {
     47const TscpPostExpireBox = () => {
     48    // Nescessary variables.
    5449    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 );
    5554    if ( 0 > TscpEditorInput.postTypes.indexOf( postType ) ) {
    5655        // This is not supported.
     
    6362        if ( timer ) {
    6463            clearTimeout( timer );
     64            setTimer( null );
    6565        }
    66         setTimeout( () => {
     66        setTimer( setTimeout( () => {
    6767            apiFetch( {
    6868                path,
     
    7171                    should: a,
    7272                    expires: d,
    73                 }
     73                },
    7474            } ).then( ( res ) => {
    7575                notify( res.message );
     
    7777                notify( res.message, 'error' );
    7878            } );
    79         }, 500 );
     79        }, 500 ) );
    8080    };
    8181
    8282    // Initialize.
     83    // eslint-disable-next-line react-hooks/rules-of-hooks
    8384    useEffect( () => {
    8485        if ( storedUpdated === null ) {
    8586            storedUpdated = '';
    8687            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' );
    9896            } );
    9997        }
    100     } );
     98    }, [] );
    10199
    102100    return (
     
    112110                checked={ active }
    113111                onChange={ ( isActive ) => {
    114                     setState( { active: isActive }, () => {
    115                         sync( isActive, toDate( date ) );
    116                     } )
     112                    setActive( isActive );
     113                    sync( isActive, toDate( date ) );
    117114                } }
    118115            />
     
    120117                <TextControl label={ __( 'Expires At', 'tscp' ) } className="tscp-time-input-date" type="datetime-local"
    121118                    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 ) );
    126122                    } ) }
    127123                />
     
    129125        </PluginPostStatusInfo>
    130126    );
    131 } );
     127};
    132128
    133129registerPlugin( 'tscp-post-expire-box', { render: TscpPostExpireBox } );
  • taro-clockwork-post/trunk/dist/js/editor-input.js

    r2609804 r3111435  
    11/*! 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  
    33 *
    44 * @handle tscp-editor-input
    5  * @deps wp-plugins, wp-edit-post, wp-components, wp-data, wp-api-fetch, wp-i18n, wp-compose, wp-element
     5 * @deps wp-plugins, wp-edit-post, wp-components, wp-data, wp-api-fetch, wp-i18n, wp-element
    66 */
  • taro-clockwork-post/trunk/gulpfile.js

    r2609804 r3111435  
    7272    }
    7373    return task.pipe( $.eslint( { useEslintrc: true } ) )
    74         .pipe( $.eslint.format() );
     74        .pipe( $.eslint.format() )
     75        .pipe( $.eslint.failAfterError() );
    7576} );
    7677
  • taro-clockwork-post/trunk/includes/block-editor.php

    r2897651 r3111435  
    99 * Register block editor assets.
    1010 */
    11 add_action( 'enqueue_block_editor_assets', function() {
     11add_action( 'enqueue_block_editor_assets', function () {
    1212    // Register script
    1313    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 );
     
    2424 * Register REST API for custom fields.
    2525 */
    26 add_action( 'rest_api_init', function() {
     26add_action( 'rest_api_init', function () {
    2727
    28     $permission_callback = function( WP_REST_Request $request ) {
     28    $permission_callback = function ( WP_REST_Request $request ) {
    2929        return current_user_can( 'edit_post', $request->get_param( 'post_id' ) );
    3030    };
     
    3434            'required'          => true,
    3535            'type'              => 'string',
    36             'validate_callback' => function( $post_type ) {
     36            'validate_callback' => function ( $post_type ) {
    3737                return tscp_post_type_can_expire( $post_type );
    3838            },
     
    4141            'required'          => true,
    4242            'type'              => 'int',
    43             'validate_callback' => function( $post_id ) {
     43            'validate_callback' => function ( $post_id ) {
    4444                return is_numeric( $post_id ) && get_post( $post_id );
    4545            },
     
    5252            'args'                => $args,
    5353            'permission_callback' => $permission_callback,
    54             'callback'            => function( WP_REST_Request $request ) {
     54            'callback'            => function ( WP_REST_Request $request ) {
    5555                $post_id = $request->get_param( 'post_id' );
    5656                return new WP_REST_Response( [
     
    7070                    'required'          => true,
    7171                    'type'              => 'string',
    72                     'validate_callback' => function( $date ) {
     72                    'validate_callback' => function ( $date ) {
    7373                        return empty( $date ) || preg_match( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/u', $date );
    7474                    },
     
    7676            ] ),
    7777            'permission_callback' => $permission_callback,
    78             'callback'            => function( WP_REST_Request $request ) {
     78            'callback'            => function ( WP_REST_Request $request ) {
    7979                $post_id       = $request->get_param( 'post_id' );
    8080                $should_expire = $request->get_param( 'should' );
     
    9898        ],
    9999    ] );
    100 
    101100} );
  • taro-clockwork-post/trunk/includes/meta-box.php

    r2609804 r3111435  
    66 */
    77
    8 add_action( 'admin_enqueue_scripts', function() {
     8add_action( 'admin_enqueue_scripts', function () {
    99    wp_enqueue_style( 'tscp-admin-helper', tscp_asset_url( 'css/admin.css' ), [], tscp_version() );
    1010} );
    1111
    1212// Register meta box for specified posts
    13 add_action( 'add_meta_boxes', function( $post_type ) {
     13add_action( 'add_meta_boxes', function ( $post_type ) {
    1414    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 ) {
    1616            wp_nonce_field( 'tscp_date', '_tscpnonce', false );
    1717            $date_time = get_post_meta( $post->ID, '_tscp_expires', true );
     
    3737                    $year_input  = sprintf( '<input type="text" name="tscp-year" class="tscp-long" value="%s" />', esc_attr( $year ) );
    3838                    $month_input = '<select name="tscp-month" class="tscp-month">';
    39                     for ( $i = 1; $i <= 12; $i ++ ) {
     39                    for ( $i = 1; $i <= 12; $i++ ) {
    4040                        $month_str = mysql2date( 'M', str_replace( '-00-', sprintf( '-%02d-', $i ), date_i18n( 'Y-00-d' ) ) );
    4141                        // 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 );
    4343                    }
    4444                    $month_input .= '</select>';
     
    7777 * @param WP_Post $post Post object.
    7878 */
    79 add_action( 'save_post', function( $post_id, $post ) {
     79add_action( 'save_post', function ( $post_id, $post ) {
    8080    if ( ! tscp_post_type_can_expire( $post->post_type ) ) {
    8181        return;
     
    105105
    106106// Register post custom column
    107 add_action( 'admin_init', function() {
     107add_action( 'admin_init', function () {
    108108    $post_types = array_filter( (array) get_option( 'tscp_post_types', [ 'post' ] ), 'post_type_exists' );
    109109    // 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 ) {
    111111        if ( in_array( $post_type, $post_types, true ) ) {
    112112            $new_columns = [];
     
    123123    }, 10, 2 );
    124124    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 ) {
    126126            switch ( $column ) {
    127127                case 'expires':
  • taro-clockwork-post/trunk/includes/setting.php

    r2609804 r3111435  
    77
    88// Register setting fields
    9 add_action( 'admin_init', function() {
     9add_action( 'admin_init', function () {
    1010    add_settings_section(
    1111        'tscp_setting',
    1212        __( 'Post Expiration Setting', 'tscp' ),
    13         function() {
     13        function () {
    1414            printf(
    1515                '<p class="description">%s</p>',
     
    2424        'tscp_post_types',
    2525        __( '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 ) {
    3234                printf(
    3335                    '<label style="display: inline-block; margin: 0 1em 1em 0;"><input type="checkbox" name="tscp_post_types[]" value="%s" %s /> %s</label>',
     
    4547    // Automatic save.
    4648    register_setting( 'reading', 'tscp_post_types' );
    47 
    4849} );
    49 
    50 
  • taro-clockwork-post/trunk/readme.txt

    r2897651 r3111435  
    66Requires at least: 5.9 
    77Requires PHP: 7.2 
    8 Tested up to: 6.1 
     8Tested up to: 6.5 
    99Stable tag: nightly 
    1010License: GPLv3 or later 
     
    7070== Changelog ==
    7171
     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
    7277= 1.2.0 =
    7378
  • taro-clockwork-post/trunk/taro-clockwork-post.php

    r2897651 r3111435  
    55Description: You can expire post with specified date.
    66Author: TAROSKY INC. <mng_wpcom@tarosky.co.jp>
    7 Version: 1.2.0
     7Version: 1.2.1
    88Author URI: https://tarosky.co.jp
    99Text Domain: tscp
     
    2424 */
    2525function tscp_plugins_loaded() {
    26     load_plugin_textdomain( 'tscp', false, basename( dirname( __FILE__ ) ) . '/languages' );
     26    load_plugin_textdomain( 'tscp', false, basename( __DIR__ ) . '/languages' );
    2727    if ( version_compare( phpversion(), '5.6.0', '<' ) ) {
    2828        add_action( 'admin_notices', 'tscp_plugin_notice' );
Note: See TracChangeset for help on using the changeset viewer.