Plugin Directory

Changeset 2045296


Ignore:
Timestamp:
03/06/2019 02:07:12 PM (7 years ago)
Author:
X-NicON
Message:

dump 1.2

Location:
wp-post-expires/trunk
Files:
3 added
3 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • wp-post-expires/trunk/assets/js/plugin-scripts.js

    r1841789 r2045296  
    1 jQuery(function($){
    2     var xnSelectField      = $('#xn-wppe-select-action');
    3     var xnAddTextFieldWrap = $('#xn-wppe-add-prefix-wrap');
    4     var xnAddTextField     = $('#xn-wppe-add-prefix');
    5     var xnEditBtn          = $('#xn-wppe-edit');
    6     var xnHideBtn          = $('.xn-wppe-hide-expiration');
    7     var xnAllFields        = $('#xn-wppe-fields');
    8     var xnDatetimeField    = $('#xn-wppe-datetime');
    9     var xnDatetimePreview  = $('#xn-wppe-currentsetdt');
    10     var xnPrevDatetime     = xnDatetimeField.val();
    11     var xnSetLang; for(xnSetLang in $.fn.datepicker.language); xnSetLang;
     1jQuery(function($) {
     2    let xnSelectField      = $('#xn-wppe-select-action');
     3    let xnAddTextFieldWrap = $('#xn-wppe-add-prefix-wrap');
     4    let xnAddTextField     = $('#xn-wppe-add-prefix');
     5    let xnDatetimeField    = $('#xn-wppe-datetime');
     6    let xnPrevDatetime     = xnDatetimeField.val();
    127
    13     var xnDatetimepicker = xnDatetimeField.datepicker({
     8    let xnDatetimepicker = xnDatetimeField.datepicker({
    149        minDate: new Date(),
    15         dateFormat: 'yyyy-mm-dd',
    16         timepicker: true,
    17         timeFormat:'hh:ii',
    18         position: "bottom right",
    19         language: xnSetLang
    20     }).data('datepicker');
     10        dateFormat: 'yy-mm-dd 00:00',
     11    }).datepicker('widget');
    2112
    22     if($(window).width() < 768 ){
    23         xnDatetimepicker.update('position','bottom left');
     13    xnDatetimepicker.wrap('<div class="datepicker ll-skin-latoja"/>');
     14
     15    if (xnSelectField.val() != 'add_prefix') {
     16        xnAddTextFieldWrap.slideUp();
     17        xnAddTextField.prop('disabled', true);
    2418    }
    2519
    26     if(xnSelectField.val() != 'add_prefix'){
    27         xnAddTextFieldWrap.slideUp();
    28         xnAddTextField.prop('disabled',true);
    29     }
    30 
    31     xnSelectField.bind('change',function(){
    32         if($(this).val() == 'add_prefix'){
     20    xnSelectField.on('change', function() {
     21        if ($(this).val() == 'add_prefix') {
    3322            xnAddTextFieldWrap.slideDown('fast');
    34             xnAddTextField.prop('disabled',false);
    35         }else{
     23            xnAddTextField.prop('disabled', false);
     24        } else {
    3625            xnAddTextFieldWrap.slideUp('fast');
    37             xnAddTextField.prop('disabled',true);
    38         }
    39     });
    40 
    41     xnEditBtn.bind('click',function(e){
    42         e.preventDefault();
    43         xnEditBtn.hide();
    44         xnAllFields.slideDown('fast');
    45     });
    46 
    47     xnHideBtn.bind('click',function(e){
    48         e.preventDefault();
    49         xnEditBtn.show();
    50         xnAllFields.slideUp('fast');
    51 
    52         if(!$(this).hasClass('cancel')){
    53             if(xnDatetimeField.val().length > 0){
    54                 xnDatetimePreview.text(xnDatetimeField.val());
    55             }else{
    56                 xnDatetimePreview.text(xnDatetimePreview.data('never'));
    57             }
    58         }else{
    59             xnDatetimeField.val(xnPrevDatetime);
     26            xnAddTextField.prop('disabled', true);
    6027        }
    6128    });
    6229});
     30
     31( function( wp ) {
     32    let el = wp.element.createElement;
     33
     34    function Component() {
     35        return el(wp.element.Fragment,
     36            {},
     37            el(wp.editPost.PluginPostStatusInfo,
     38                {},
     39                'Истекает: 21.07.2019 08:00',
     40            )
     41        );
     42    }
     43
     44    wp.plugins.registerPlugin('plugin-name', {
     45        render: Component
     46    });
     47
     48} )( window.wp );
  • wp-post-expires/trunk/languages/wp-post-expires-it_IT.po

    r1688090 r2045296  
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "PO-Revision-Date: 2017-05-05 16:21+0200\n"
     12"PO-Revision-Date: 2019-03-06 16:47+0300\n"
    1313"Language-Team: \n"
    14 "X-Generator: Poedit 2.0.1\n"
     14"X-Generator: Poedit 2.2.1\n"
    1515"Last-Translator: \n"
    1616"Plural-Forms: nplurals=2; plural=(n != 1);\n"
     
    2626
    2727#: wp-post-expires.php:118
    28 msgid "Expires:"
    29 msgstr "Scadenza:"
     28msgid "Expires"
     29msgstr "Scadenza"
    3030
    3131#: wp-post-expires.php:122
     
    3838
    3939#: wp-post-expires.php:127
    40 msgid "DateTime:"
    41 msgstr "Data:"
     40msgid "DateTime"
     41msgstr "Data"
    4242
    4343#: wp-post-expires.php:128
     
    4646
    4747#: wp-post-expires.php:131
    48 msgid "Action:"
    49 msgstr "Azione:"
     48msgid "Action"
     49msgstr "Azione"
    5050
    5151#: wp-post-expires.php:133 wp-post-expires.php:206
     
    6262
    6363#: wp-post-expires.php:139
    64 msgid "Prefix:"
    65 msgstr "Prefisso:"
     64msgid "Prefix"
     65msgstr "Prefisso"
    6666
    6767#: wp-post-expires.php:140
  • wp-post-expires/trunk/languages/wp-post-expires-ru_RU.po

    r1475960 r2045296  
    33"Project-Id-Version: WP Post Expires\n"
    44"POT-Creation-Date: 2016-08-13 19:41+0300\n"
    5 "PO-Revision-Date: 2016-08-16 23:25+0300\n"
     5"PO-Revision-Date: 2019-03-06 16:48+0300\n"
    66"Last-Translator: X-NicON <x-icon@ya.ru>\n"
    77"Language-Team: X-NicON <x-icon@ya.ru>\n"
     
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "X-Generator: Poedit 1.8.8\n"
     12"X-Generator: Poedit 2.2.1\n"
    1313"X-Poedit-Basepath: ..\n"
    1414"X-Poedit-SourceCharset: UTF-8\n"
     
    3737
    3838#: wp-post-expires.php:117
    39 msgid "Expires:"
    40 msgstr "Заканчивается:"
     39msgid "Expires"
     40msgstr "Заканчивается"
    4141
    4242#: wp-post-expires.php:121
     
    4949
    5050#: wp-post-expires.php:126
    51 msgid "DateTime:"
    52 msgstr "Дата и время:"
     51msgid "DateTime"
     52msgstr "Дата и время"
    5353
    5454#: wp-post-expires.php:127
     
    5757
    5858#: wp-post-expires.php:130
    59 msgid "Action:"
    60 msgstr "Выполнить:"
     59msgid "Action"
     60msgstr "Действие"
    6161
    6262#: wp-post-expires.php:132 wp-post-expires.php:205
    6363msgid "Add Prefix"
    64 msgstr "Добавить текст"
     64msgstr "Добавить префикс"
    6565
    6666#: wp-post-expires.php:133 wp-post-expires.php:206
     
    7373
    7474#: wp-post-expires.php:138
    75 msgid "Prefix:"
    76 msgstr "Текст:"
     75msgid "Prefix"
     76msgstr "Префикс"
    7777
    7878#: wp-post-expires.php:139
     
    109109"Введите текст, который будет добавляться в заголовок записей с истекшим "
    110110"сроком."
    111 
    112 #~ msgid "Add Text"
    113 #~ msgstr "Добавить текст"
    114 
    115 #~ msgid "Text:"
    116 #~ msgstr "Текст:"
    117 
    118 #~ msgid "Text add to post title"
    119 #~ msgstr "Добавить текст в заголовок"
  • wp-post-expires/trunk/languages/wp-post-expires.pot

    r1475960 r2045296  
    11# Copyright (C) 2016 WP Post Expires
    22# This file is distributed under the same license as the WP Post Expires package.
     3#, fuzzy
    34msgid ""
    45msgstr ""
    5 "Project-Id-Version: WP Post Expires 1.0\n"
    6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wp-post-expires\n"
    7 "POT-Creation-Date: 2016-08-16 20:21:59+00:00\n"
     6"Project-Id-Version: WP Post Expires 1.2\n"
     7"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wp-post-"
     8"expires\n"
     9"POT-Creation-Date: 2019-03-06 16:51+0300\n"
    810"MIME-Version: 1.0\n"
    911"Content-Type: text/plain; charset=UTF-8\n"
     
    1214"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
    1315"Language-Team: LANGUAGE <LL@li.org>\n"
     16"X-Generator: Poedit 2.2.1\n"
     17"X-Poedit-Basepath: ..\n"
     18"X-Poedit-KeywordsList: __;_e\n"
     19"X-Poedit-SearchPath-0: .\n"
    1420
    15 #: wp-post-expires.php:68
     21#: wp-post-expires.php:74
    1622msgid "Expired:"
    1723msgstr ""
    1824
    19 #: wp-post-expires.php:109 wp-post-expires.php:119
    20 msgid "never"
    21 msgstr ""
    22 
    23 #: wp-post-expires.php:118
    24 msgid "Expires:"
    25 msgstr ""
    26 
    27 #: wp-post-expires.php:122
    28 msgid "Edit"
    29 msgstr ""
    30 
    31 #: wp-post-expires.php:123
    32 msgid "Edit date and time"
    33 msgstr ""
    34 
    35 #: wp-post-expires.php:127
    36 msgid "DateTime:"
     25#: wp-post-expires.php:98
     26msgid "Expires"
    3727msgstr ""
    3828
    3929#: wp-post-expires.php:128
     30msgid "DateTime"
     31msgstr ""
     32
     33#: wp-post-expires.php:129
    4034msgid "yyyy-mm-dd h:i"
    4135msgstr ""
    4236
    43 #: wp-post-expires.php:131
    44 msgid "Action:"
     37#: wp-post-expires.php:133
     38msgid "Action"
    4539msgstr ""
    4640
    47 #: wp-post-expires.php:133 wp-post-expires.php:206
     41#: wp-post-expires.php:136 wp-post-expires.php:202
    4842msgid "Add Prefix"
    4943msgstr ""
    5044
    51 #: wp-post-expires.php:134 wp-post-expires.php:207
     45#: wp-post-expires.php:137 wp-post-expires.php:203
    5246msgid "Move to drafts"
    5347msgstr ""
    5448
    55 #: wp-post-expires.php:135 wp-post-expires.php:208
     49#: wp-post-expires.php:138 wp-post-expires.php:204
    5650msgid "Move to trash"
    5751msgstr ""
    5852
    59 #: wp-post-expires.php:139
    60 msgid "Prefix:"
     53#: wp-post-expires.php:144
     54msgid "Prefix"
    6155msgstr ""
    6256
    63 #: wp-post-expires.php:140
     57#: wp-post-expires.php:146
    6458msgid "Prefix for post title"
    6559msgstr ""
    6660
    67 #: wp-post-expires.php:143
    68 msgid "OK"
     61#: wp-post-expires.php:179
     62msgid "Settings posts expires"
    6963msgstr ""
    7064
    71 #: wp-post-expires.php:144
    72 msgid "Cancel"
     65#: wp-post-expires.php:181
     66msgid "Supported post types"
     67msgstr ""
     68
     69#: wp-post-expires.php:182
     70msgid "Action by default"
    7371msgstr ""
    7472
    7573#: wp-post-expires.php:183
    76 msgid "Settings posts expires"
    77 msgstr ""
    78 
    79 #: wp-post-expires.php:185
    80 msgid "Supported post types"
    81 msgstr ""
    82 
    83 #: wp-post-expires.php:186
    84 msgid "Action by default"
    85 msgstr ""
    86 
    87 #: wp-post-expires.php:187
    8874msgid "Default Expired Item Prefix"
    8975msgstr ""
    9076
    91 #: wp-post-expires.php:214
     77#: wp-post-expires.php:210
    9278msgid "Enter the text you would like prepended to expired items."
    9379msgstr ""
    9480
    95 #. Plugin Name of the plugin/theme
    96 msgid "WP Post Expires"
     81#: wp-post-expires.php:264
     82msgid "never"
    9783msgstr ""
    98 
    99 #. Description of the plugin/theme
    100 msgid ""
    101 "A simple plugin allow to set the posts, the time after which will be "
    102 "performed one of 3 actions: \"Add prefix to title\", \"Move to drafts\", "
    103 "\"Move to trash\"."
    104 msgstr ""
  • wp-post-expires/trunk/readme.txt

    r1841789 r2045296  
    33Donate link:
    44Tags: expired post, posts expiring, expiration, expire, wordpress post expiry
    5 Requires at least: 3.0
    6 Tested up to: 4.9.4
    7 Stable tag: 1.1
     5Requires at least: 5.0
     6Tested up to: 5.1
     7Stable tag: 1.2
    88License: GPLv2
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    2222= Use in theme: =
    2323
    24 `xnpostexpires::isExpired($post_id)`
     24`XNPostExpires::isExpired($post_id)`
    2525
    26 `xnpostexpires::dateExpiration($post_id, $format)`
     26`XNPostExpires::dateExpiration($post_id, $date_format)`
    2727
    2828== Screenshots ==
     
    4141
    4242== Changelog ==
     43
     44= 1.2 =
     45
     46use DateTime Picker jQuery-ui
     47refactoring
    4348
    4449= 1.1 =
  • wp-post-expires/trunk/wp-post-expires.php

    r1841789 r2045296  
    33Plugin Name: WP Post Expires
    44Description: A simple plugin allow to set the posts, the time after which will be performed one of 3 actions: "Add prefix to title", "Move to drafts", "Move to trash".
    5 Version:     1.1
    6 Author:      X-NicON
     5Version:     1.2
     6Author:      XNicON
    77Author URI:  https://xnicon.ru
    88License:     GPL2
     
    1010Domain Path: /languages
    1111
    12 Copyright 2016-2018  X-NicON  (x-icon@ya.ru)
     12Copyright 2016-2019  XNicON  (x-icon@ya.ru)
    1313
    1414WP Post Expires is free software; you can redistribute it and/or modify
     
    2727*/
    2828
    29 //Legacy
    30 class XN_WP_Post_Expires {
    31     public static function xn_wppe_is_expired($post_id = 0){
    32         return XNPostExpires::isExpired($post_id);
    33     }
    34 }
    35 
    3629class XNPostExpires {
    37     private $plugin_version = '1.1';
     30    private $plugin_version = '1.2';
    3831    private $url_assets;
    39     public $settings = array();
    40 
    41     public static function init(){
     32    public $settings = [];
     33
     34    public static function init() {
    4235        return new self;
    4336    }
    4437
    45     public function __construct(){
     38    public function __construct() {
    4639        load_plugin_textdomain('wp-post-expires', false, dirname(plugin_basename( __FILE__ ) ).'/languages');
    4740
     
    4942        $this->url_assets = plugin_dir_url( __FILE__ ).'assets/';
    5043
    51         add_action('the_post', [$this, 'xnExpiredPost']);
    52 
    53         if(current_user_can('manage_options')){
    54             add_action('admin_init', array($this,'xn_wppe_register_settings'));
    55         }
    56 
    57         if(current_user_can('edit_posts')){
    58             add_action('load-post-new.php', array($this, 'xnScripts'));
    59             add_action('load-post.php', array($this, 'xnScripts'));
    60             add_action('post_submitbox_misc_actions', array($this, 'xnAddBoxFields'));
    61             add_action('save_post', [$this, 'xnSaveBoxFields']);
     44        add_action('the_post', [$this, 'expiredPost']);
     45
     46        if(current_user_can('manage_options')) {
     47            add_action('admin_init', [$this, 'registerSettings']);
     48        }
     49
     50        if(current_user_can('edit_posts')) {
     51            add_action('enqueue_block_editor_assets', [$this, 'loadScripts']);
     52            add_action('add_meta_boxes', [$this, 'addMetaBox']);
     53            add_action('save_post', [$this, 'saveBoxFields']);
    6254        }
    6355    }
     
    6759
    6860        if(empty($settings_load) || !is_array($settings_load)) {
    69             $settings_load = array();
     61            $settings_load = [];
    7062        }
    7163
     
    8880    }
    8981
    90     public function xnScripts() {
    91         $wplang      = explode('-', get_bloginfo('language'));
    92         $supported = array('cs', 'da', 'de', 'es', 'fi', 'fr', 'hu', 'nl', 'pl', 'pt','ro','zh', 'it', 'sk');
    93         $dtplang     = 'en';
    94 
    95         if($wplang[0] == 'ru'){
    96             $dtplang = false;
    97         }elseif(in_array($wplang[0], $supported)){
    98             $dtplang = $wplang[0];
    99         }
    100 
    101         wp_enqueue_style('xn-wppe-dtpicker', $this->url_assets.'css/datepicker.min.css', [], $this->plugin_version);
    102 
    103         wp_enqueue_script('xn-wppe-dtpicker-js', $this->url_assets.'js/datepicker.min.js', ['jquery'], $this->plugin_version);
    104         if($dtplang != false){
    105             wp_enqueue_script('xn-wppe-dtpicker-lang-js', $this->url_assets.'js/i18n/datepicker.'.$dtplang.'.js', ['xn-wppe-dtpicker-js'], $this->plugin_version);
    106         }
    107         wp_enqueue_script('xn-wppe-plugin-js', $this->url_assets.'js/plugin-scripts.js', ['xn-wppe-dtpicker-js'], $this->plugin_version);
    108     }
    109 
    110     public function xnAddBoxFields() {
    111         global $post;
    112 
    113         if(!array_key_exists($post->post_type, $this->settings['post_types'])){
    114             return;
    115         }
    116 
     82    public function loadScripts() {
     83        wp_enqueue_script('jquery-ui-core', ['jquery']);
     84        wp_enqueue_script('jquery-ui-datepicker', ['jquery-ui-core', 'jquery']);
     85        wp_enqueue_style('jquery-ui', 'https://cdn.jsdelivr.net/npm/jquery-ui-dist@1.12.1/jquery-ui.min.css', [], $this->plugin_version);
     86        wp_enqueue_style('xn-dtpicker-skin', $this->url_assets.'css/latoja.datepicker.css', ['jquery-ui'], $this->plugin_version);
     87        wp_enqueue_script('xn-plugin-js', $this->url_assets.'js/plugin-scripts.js', [
     88            'jquery-ui-datepicker',
     89            'wp-plugins',
     90            'wp-edit-post',
     91            'wp-element',
     92            'wp-components'
     93        ], $this->plugin_version);
     94    }
     95
     96    public function addMetaBox() {
     97        add_meta_box('xn_box_expiration',
     98            __('Expires', 'wp-post-expires'),
     99            [$this, 'addBoxFields'],
     100            array_keys($this->settings['post_types']),
     101            'side',
     102            'high',
     103            [
     104                '__back_compat_meta_box' => false
     105            ]
     106        );
     107    }
     108
     109    public function addBoxFields($post) {
    117110        if(!empty($post->ID)) {
    118111            $expires        = get_post_meta($post->ID, 'xn-wppe-expiration', true);
    119112            $expires_select = get_post_meta($post->ID, 'xn-wppe-expiration-action', true);
    120113            $expires_prefix = get_post_meta($post->ID, 'xn-wppe-expiration-prefix', false);
    121         }
    122 
    123         $label  = !empty($expires)? date_i18n('M j, Y @ G:i', strtotime($expires)) : __('never', 'wp-post-expires');
     114        } else {
     115            $expires        = '';
     116            $expires_select = '';
     117            $expires_prefix = '';
     118        }
     119
     120        //$label  = !empty($expires)? date_i18n('M j, Y @ G:i', strtotime($expires)) : __('never', 'wp-post-expires');
    124121        $date   = !empty($expires)? date_i18n('Y-m-d H:i', strtotime($expires)) : '';
    125122        $select = !empty($expires_select)? $expires_select : $this->settings['action'];
     
    128125    ?>
    129126
    130         <div id="xn-wppe" class="misc-pub-section">
    131             <span>
    132                 <span class="wp-media-buttons-icon dashicons dashicons-clock"></span>&nbsp;
    133                 <?php _e('Expires:', 'wp-post-expires'); ?>
    134                 <b id="xn-wppe-currentsetdt" data-never="<?php _e('never', 'wp-post-expires'); ?>"><?php echo $label; ?></b>
    135             </span>
    136             <a href="#" id="xn-wppe-edit" class="xn-wppe-edit hide-if-no-js">
    137                 <span aria-hidden="true"><?php _e('Edit', 'wp-post-expires'); ?></span>
    138                 <span class="screen-reader-text">(<?php _e('Edit date and time', 'wp-post-expires'); ?>)</span>
    139             </a>
    140             <div id="xn-wppe-fields" class="hide-if-js">
    141                 <p>
    142                     <label for="xn-wppe-datetime"><?php _e('DateTime:', 'wp-post-expires'); ?></label>
    143                     <input type="text" name="xn-wppe-expiration" id="xn-wppe-datetime" value="<?php echo $date; ?>" placeholder="<?php _e('yyyy-mm-dd h:i','wp-post-expires'); ?>">
    144                 </p>
    145                 <p>
    146                     <label for="xn-wppe-select-action"><?php _e('Action:', 'wp-post-expires'); ?></label>
    147                     <select name="xn-wppe-expiration-action" id="xn-wppe-select-action">
    148                         <option <?php echo $select=='add_prefix'?'selected':'';?> value="add_prefix"><?php _e('Add Prefix', 'wp-post-expires'); ?></option>
    149                         <option <?php echo $select=='to_drafts'?'selected':'';?> value="to_drafts"><?php _e('Move to drafts', 'wp-post-expires'); ?></option>
    150                         <option <?php echo $select=='to_trash'?'selected':'';?> value="to_trash"><?php _e('Move to trash', 'wp-post-expires'); ?></option>
    151                     </select>
    152                 </p>
    153                 <p id="xn-wppe-add-prefix-wrap">
    154                     <label for="xn-wppe-add-prefix"><?php _e('Prefix:', 'wp-post-expires'); ?></label>
    155                     <input type="text" name="xn-wppe-expiration-prefix" id="xn-wppe-add-prefix" value="<?php echo $prefix; ?>" placeholder="<?php _e('Prefix for post title', 'wp-post-expires'); ?>">
    156                 </p>
    157                 <p>
    158                     <a href="#" class="xn-wppe-hide-expiration button secondary"><?php _e('OK', 'wp-post-expires'); ?></a>
    159                     <a href="#" class="xn-wppe-hide-expiration cancel"><?php _e('Cancel', 'wp-post-expires'); ?></a>
    160                 </p>
    161             </div>
    162         </div>
     127        <div class="components-panel__row">
     128            <div><?php _e('DateTime', 'wp-post-expires'); ?></div>
     129            <div><input type="text" name="xn-wppe-expiration" id="xn-wppe-datetime" style="width:100%" value="<?php echo $date; ?>" placeholder="<?php _e('yyyy-mm-dd h:i','wp-post-expires'); ?>"></div>
     130        </div>
     131
     132        <div class="components-panel__row">
     133            <div><?php _e('Action', 'wp-post-expires'); ?></div>
     134            <div>
     135                <select name="xn-wppe-expiration-action" id="xn-wppe-select-action">
     136                    <option <?php echo $select=='add_prefix'?'selected':'';?> value="add_prefix"><?php _e('Add Prefix', 'wp-post-expires'); ?></option>
     137                    <option <?php echo $select=='to_drafts'?'selected':'';?> value="to_drafts"><?php _e('Move to drafts', 'wp-post-expires'); ?></option>
     138                    <option <?php echo $select=='to_trash'?'selected':'';?> value="to_trash"><?php _e('Move to trash', 'wp-post-expires'); ?></option>
     139                </select>
     140            </div>
     141        </div>
     142
     143        <div class="components-panel__row" id="xn-wppe-add-prefix-wrap">
     144            <div><?php _e('Prefix', 'wp-post-expires'); ?></div>
     145            <div>
     146                <input type="text" name="xn-wppe-expiration-prefix" id="xn-wppe-add-prefix" style="width:100%" value="<?php echo $prefix; ?>" placeholder="<?php _e('Prefix for post title', 'wp-post-expires'); ?>">
     147            </div>
     148        </div>
    163149    <?php
    164150    }
    165151
    166     public function xnSaveBoxFields($post_id = 0){
    167 
    168         if( defined('DOING_AUTOSAVE') || defined('DOING_AJAX') || wp_is_post_revision($post_id) ){
     152    public function saveBoxFields($post_id = 0) {
     153
     154        if( defined('DOING_AUTOSAVE') || defined('DOING_AJAX') || wp_is_post_revision($post_id) ) {
    169155            return false;
    170156        }
     
    174160        $add_prefix  = isset($_POST['xn-wppe-expiration-prefix'])?  sanitize_text_field($_POST['xn-wppe-expiration-prefix']) : false;
    175161
    176         if($expiration !== false && $action_type !== false){
     162        if($expiration !== false && $action_type !== false) {
    177163            update_post_meta($post_id, 'xn-wppe-expiration', $expiration);
    178164            update_post_meta($post_id, 'xn-wppe-expiration-action', $action_type);
    179             if($add_prefix !== false){
     165            if($add_prefix !== false) {
    180166                update_post_meta($post_id, 'xn-wppe-expiration-prefix', $add_prefix);
    181167            }
     
    187173    }
    188174
    189     public function xn_wppe_register_settings() {
     175    public function registerSettings() {
    190176
    191177        register_setting('reading', 'xn_wppe_settings');
     
    193179        add_settings_section("xn_wppe_section", __('Settings posts expires', 'wp-post-expires'), null, 'reading');
    194180
    195         add_settings_field('xn_wppe_settings_posttype', __('Supported post types', 'wp-post-expires'), array($this, 'xn_wppe_settings_field_posttype'), 'reading', "xn_wppe_section");
    196         add_settings_field('xn_wppe_settings_action', __('Action by default', 'wp-post-expires'), array($this, 'xn_wppe_settings_field_action'), 'reading', "xn_wppe_section");
    197         add_settings_field('xn_wppe_settings_prefix', __('Default Expired Item Prefix', 'wp-post-expires'), array($this, 'xn_wppe_settings_field_prefix'), 'reading', "xn_wppe_section");
    198     }
    199 
    200     public function xn_wppe_settings_field_posttype() {
     181        add_settings_field('xn_wppe_settings_posttype', __('Supported post types', 'wp-post-expires'), [$this, 'settingsFieldPosttype'], 'reading', "xn_wppe_section");
     182        add_settings_field('xn_wppe_settings_action', __('Action by default', 'wp-post-expires'), [$this, 'settingsFieldAction'], 'reading', "xn_wppe_section");
     183        add_settings_field('xn_wppe_settings_prefix', __('Default Expired Item Prefix', 'wp-post-expires'), [$this, 'settingsFieldPrefix'], 'reading', "xn_wppe_section");
     184    }
     185
     186    public function settingsFieldPosttype() {
    201187        $all_post_types = get_post_types(false, 'objects');
    202188        unset($all_post_types['nav_menu_item']);
     
    212198    }
    213199
    214     public function xn_wppe_settings_field_action() {
     200    public function settingsFieldAction() {
    215201        echo '<select name="xn_wppe_settings[action]" id="xn_wppe_settings_action">';
    216202            echo '<option '.($this->settings['action']=='add_prefix'?'selected':'').' value="add_prefix">'.__('Add Prefix', 'wp-post-expires').'</option>';
     
    220206    }
    221207
    222     public function xn_wppe_settings_field_prefix() {
     208    public function settingsFieldPrefix() {
    223209        echo '<input id="xn_wppe_settings_prefix" type="text" name="xn_wppe_settings[prefix]" value="'.$this->settings['prefix'].'" class="regular-text">';
    224210        echo '<p class="description">'.__('Enter the text you would like prepended to expired items.', 'wp-post-expires').'</p>';
    225211    }
    226212
    227     public static function isExpired($post_id = 0){
    228 
    229         $expires = get_post_meta($post_id, 'xn-wppe-expiration', true);
    230 
    231         if(!empty($expires)) {
    232             $current = new DateTime();
    233             $current->setTimestamp(current_time('timestamp'));
    234             $expiration = new DateTime($expires);
    235 
    236             if($current >= $expiration){
    237                 return true;
    238             }
    239         }
    240         return false;
    241     }
    242 
    243     public static function dateExpiration($post_id = 0, $format = false){
    244         $expires = get_post_meta($post_id, 'xn-wppe-expiration', true);
    245         if($format === false){
    246             $format = get_option('date_format');
    247         }
    248         return !empty($expires)? date_i18n( $format, strtotime($expires) ) : __('never', 'wp-post-expires');
    249     }
    250 
    251     public function xnFilterTitle($title = '', $post_id = 0) {
     213    public function textTitleFilter($title = '', $post_id = 0) {
    252214        $expires_prefix = get_post_meta($post_id, 'xn-wppe-expiration-prefix', true);
    253215        $prefix = !empty($expires_prefix)? esc_attr($expires_prefix).'&nbsp;' : '';
     
    256218    }
    257219
    258     public function xnFilterClass($classes) {
     220    public function cssClassFilter($classes) {
    259221        $classes[] = 'post-expired';
    260222        return $classes;
    261223    }
    262224
    263     public function xnExpiredPost($post) {
     225    public function expiredPost($post) {
    264226        $post_id = $post->ID;
    265227
    266         if(self::isExpired($post_id)){
     228        if(self::isExpired($post_id)) {
    267229
    268230            $expires_action = get_post_meta($post_id, 'xn-wppe-expiration-action', true);
     
    271233            switch($action) {
    272234                case 'add_prefix':
    273                     add_filter('the_title', [$this, 'xnFilterTitle'], 10, 2);
    274                     add_filter('post_class', [$this, 'xnFilterClass']);
     235                    add_filter('the_title', [$this, 'textTitleFilter'], 10, 2);
     236                    add_filter('post_class', [$this, 'cssClassFilter']);
    275237                break;
    276238                case 'to_drafts':
    277                     remove_action('save_post', [$this, 'xnSaveBoxFields']);
     239                    remove_action('save_post', [$this, 'saveBoxFields']);
    278240                    wp_update_post(['ID' => $post_id, 'post_status' => 'draft']);
    279241                    update_post_meta($post_id, 'xn-wppe-expiration-action', 'add_prefix');
    280242                    update_post_meta($post_id, 'xn-wppe-expiration-prefix', $this->settings['prefix']);
    281                     add_action('save_post', [$this, 'xnSaveBoxFields']);
     243                    add_action('save_post', [$this, 'saveBoxFields']);
    282244                break;
    283245                case 'to_trash':
    284                     remove_action('save_post', [$this, 'xnSaveBoxFields']);
     246                    remove_action('save_post', [$this, 'saveBoxFields']);
    285247                    $del_post = wp_trash_post($post_id);
    286248                    //check post to trash, or deleted
    287                     if($del_post['post_status'] == 'trash'){
     249                    if($del_post['post_status'] == 'trash') {
    288250                        update_post_meta($post_id, 'xn-wppe-expiration-action', 'add_prefix');
    289251                        update_post_meta($post_id, 'xn-wppe-expiration-prefix', $this->settings['prefix']);
    290252                    }
    291                     add_action('save_post', [$this, 'xnSaveBoxFields']);
     253                    add_action('save_post', [$this, 'saveBoxFields']);
    292254                break;
    293255            }
    294256        }
    295257    }
     258
     259    public static function dateExpiration($post_id = 0, $format = false) {
     260        $expires = get_post_meta($post_id, 'xn-wppe-expiration', true);
     261        if($format === false) {
     262            $format = get_option('date_format');
     263        }
     264        return !empty($expires)? date_i18n( $format, strtotime($expires) ) : __('never', 'wp-post-expires');
     265    }
     266
     267    public static function isExpired($post_id = 0) {
     268        $expires = get_post_meta($post_id, 'xn-wppe-expiration', true);
     269
     270        if(!empty($expires)) {
     271            $current = new DateTime();
     272            $current->setTimestamp(current_time('timestamp'));
     273            $expiration = new DateTime($expires);
     274
     275            if($current >= $expiration) {
     276                return true;
     277            }
     278        }
     279        return false;
     280    }
    296281}
    297282add_action('plugins_loaded', ['XNPostExpires','init']);
Note: See TracChangeset for help on using the changeset viewer.