Changeset 2045296
- Timestamp:
- 03/06/2019 02:07:12 PM (7 years ago)
- Location:
- wp-post-expires/trunk
- Files:
-
- 3 added
- 3 deleted
- 8 edited
-
assets/css/datepicker.min.css (deleted)
-
assets/css/images (added)
-
assets/css/images/ui-icons_454545_256x240.png (added)
-
assets/css/latoja.datepicker.css (added)
-
assets/js/datepicker.min.js (deleted)
-
assets/js/i18n (deleted)
-
assets/js/plugin-scripts.js (modified) (1 diff)
-
languages/wp-post-expires-it_IT.mo (modified) (previous)
-
languages/wp-post-expires-it_IT.po (modified) (5 diffs)
-
languages/wp-post-expires-ru_RU.mo (modified) (previous)
-
languages/wp-post-expires-ru_RU.po (modified) (7 diffs)
-
languages/wp-post-expires.pot (modified) (2 diffs)
-
readme.txt (modified) (3 diffs)
-
wp-post-expires.php (modified) (14 diffs)
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; 1 jQuery(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(); 12 7 13 varxnDatetimepicker = xnDatetimeField.datepicker({8 let xnDatetimepicker = xnDatetimeField.datepicker({ 14 9 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'); 21 12 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); 24 18 } 25 19 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') { 33 22 xnAddTextFieldWrap.slideDown('fast'); 34 xnAddTextField.prop('disabled', false);35 } else{23 xnAddTextField.prop('disabled', false); 24 } else { 36 25 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); 60 27 } 61 28 }); 62 29 }); 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 10 10 "Content-Type: text/plain; charset=UTF-8\n" 11 11 "Content-Transfer-Encoding: 8bit\n" 12 "PO-Revision-Date: 201 7-05-05 16:21+0200\n"12 "PO-Revision-Date: 2019-03-06 16:47+0300\n" 13 13 "Language-Team: \n" 14 "X-Generator: Poedit 2. 0.1\n"14 "X-Generator: Poedit 2.2.1\n" 15 15 "Last-Translator: \n" 16 16 "Plural-Forms: nplurals=2; plural=(n != 1);\n" … … 26 26 27 27 #: wp-post-expires.php:118 28 msgid "Expires :"29 msgstr "Scadenza :"28 msgid "Expires" 29 msgstr "Scadenza" 30 30 31 31 #: wp-post-expires.php:122 … … 38 38 39 39 #: wp-post-expires.php:127 40 msgid "DateTime :"41 msgstr "Data :"40 msgid "DateTime" 41 msgstr "Data" 42 42 43 43 #: wp-post-expires.php:128 … … 46 46 47 47 #: wp-post-expires.php:131 48 msgid "Action :"49 msgstr "Azione :"48 msgid "Action" 49 msgstr "Azione" 50 50 51 51 #: wp-post-expires.php:133 wp-post-expires.php:206 … … 62 62 63 63 #: wp-post-expires.php:139 64 msgid "Prefix :"65 msgstr "Prefisso :"64 msgid "Prefix" 65 msgstr "Prefisso" 66 66 67 67 #: wp-post-expires.php:140 -
wp-post-expires/trunk/languages/wp-post-expires-ru_RU.po
r1475960 r2045296 3 3 "Project-Id-Version: WP Post Expires\n" 4 4 "POT-Creation-Date: 2016-08-13 19:41+0300\n" 5 "PO-Revision-Date: 201 6-08-16 23:25+0300\n"5 "PO-Revision-Date: 2019-03-06 16:48+0300\n" 6 6 "Last-Translator: X-NicON <x-icon@ya.ru>\n" 7 7 "Language-Team: X-NicON <x-icon@ya.ru>\n" … … 10 10 "Content-Type: text/plain; charset=UTF-8\n" 11 11 "Content-Transfer-Encoding: 8bit\n" 12 "X-Generator: Poedit 1.8.8\n"12 "X-Generator: Poedit 2.2.1\n" 13 13 "X-Poedit-Basepath: ..\n" 14 14 "X-Poedit-SourceCharset: UTF-8\n" … … 37 37 38 38 #: wp-post-expires.php:117 39 msgid "Expires :"40 msgstr "Заканчивается :"39 msgid "Expires" 40 msgstr "Заканчивается" 41 41 42 42 #: wp-post-expires.php:121 … … 49 49 50 50 #: wp-post-expires.php:126 51 msgid "DateTime :"52 msgstr "Дата и время :"51 msgid "DateTime" 52 msgstr "Дата и время" 53 53 54 54 #: wp-post-expires.php:127 … … 57 57 58 58 #: wp-post-expires.php:130 59 msgid "Action :"60 msgstr " Выполнить:"59 msgid "Action" 60 msgstr "Действие" 61 61 62 62 #: wp-post-expires.php:132 wp-post-expires.php:205 63 63 msgid "Add Prefix" 64 msgstr "Добавить текст"64 msgstr "Добавить префикс" 65 65 66 66 #: wp-post-expires.php:133 wp-post-expires.php:206 … … 73 73 74 74 #: wp-post-expires.php:138 75 msgid "Prefix :"76 msgstr " Текст:"75 msgid "Prefix" 76 msgstr "Префикс" 77 77 78 78 #: wp-post-expires.php:139 … … 109 109 "Введите текст, который будет добавляться в заголовок записей с истекшим " 110 110 "сроком." 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 1 1 # Copyright (C) 2016 WP Post Expires 2 2 # This file is distributed under the same license as the WP Post Expires package. 3 #, fuzzy 3 4 msgid "" 4 5 msgstr "" 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" 8 10 "MIME-Version: 1.0\n" 9 11 "Content-Type: text/plain; charset=UTF-8\n" … … 12 14 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" 13 15 "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" 14 20 15 #: wp-post-expires.php: 6821 #: wp-post-expires.php:74 16 22 msgid "Expired:" 17 23 msgstr "" 18 24 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 26 msgid "Expires" 37 27 msgstr "" 38 28 39 29 #: wp-post-expires.php:128 30 msgid "DateTime" 31 msgstr "" 32 33 #: wp-post-expires.php:129 40 34 msgid "yyyy-mm-dd h:i" 41 35 msgstr "" 42 36 43 #: wp-post-expires.php:13 144 msgid "Action :"37 #: wp-post-expires.php:133 38 msgid "Action" 45 39 msgstr "" 46 40 47 #: wp-post-expires.php:13 3 wp-post-expires.php:20641 #: wp-post-expires.php:136 wp-post-expires.php:202 48 42 msgid "Add Prefix" 49 43 msgstr "" 50 44 51 #: wp-post-expires.php:13 4 wp-post-expires.php:20745 #: wp-post-expires.php:137 wp-post-expires.php:203 52 46 msgid "Move to drafts" 53 47 msgstr "" 54 48 55 #: wp-post-expires.php:13 5 wp-post-expires.php:20849 #: wp-post-expires.php:138 wp-post-expires.php:204 56 50 msgid "Move to trash" 57 51 msgstr "" 58 52 59 #: wp-post-expires.php:1 3960 msgid "Prefix :"53 #: wp-post-expires.php:144 54 msgid "Prefix" 61 55 msgstr "" 62 56 63 #: wp-post-expires.php:14 057 #: wp-post-expires.php:146 64 58 msgid "Prefix for post title" 65 59 msgstr "" 66 60 67 #: wp-post-expires.php:1 4368 msgid " OK"61 #: wp-post-expires.php:179 62 msgid "Settings posts expires" 69 63 msgstr "" 70 64 71 #: wp-post-expires.php:144 72 msgid "Cancel" 65 #: wp-post-expires.php:181 66 msgid "Supported post types" 67 msgstr "" 68 69 #: wp-post-expires.php:182 70 msgid "Action by default" 73 71 msgstr "" 74 72 75 73 #: wp-post-expires.php:183 76 msgid "Settings posts expires"77 msgstr ""78 79 #: wp-post-expires.php:18580 msgid "Supported post types"81 msgstr ""82 83 #: wp-post-expires.php:18684 msgid "Action by default"85 msgstr ""86 87 #: wp-post-expires.php:18788 74 msgid "Default Expired Item Prefix" 89 75 msgstr "" 90 76 91 #: wp-post-expires.php:21 477 #: wp-post-expires.php:210 92 78 msgid "Enter the text you would like prepended to expired items." 93 79 msgstr "" 94 80 95 # . Plugin Name of the plugin/theme96 msgid " WP Post Expires"81 #: wp-post-expires.php:264 82 msgid "never" 97 83 msgstr "" 98 99 #. Description of the plugin/theme100 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 3 3 Donate link: 4 4 Tags: expired post, posts expiring, expiration, expire, wordpress post expiry 5 Requires at least: 3.06 Tested up to: 4.9.47 Stable tag: 1. 15 Requires at least: 5.0 6 Tested up to: 5.1 7 Stable tag: 1.2 8 8 License: GPLv2 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 22 22 = Use in theme: = 23 23 24 ` xnpostexpires::isExpired($post_id)`24 `XNPostExpires::isExpired($post_id)` 25 25 26 ` xnpostexpires::dateExpiration($post_id, $format)`26 `XNPostExpires::dateExpiration($post_id, $date_format)` 27 27 28 28 == Screenshots == … … 41 41 42 42 == Changelog == 43 44 = 1.2 = 45 46 use DateTime Picker jQuery-ui 47 refactoring 43 48 44 49 = 1.1 = -
wp-post-expires/trunk/wp-post-expires.php
r1841789 r2045296 3 3 Plugin Name: WP Post Expires 4 4 Description: 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. 16 Author: X -NicON5 Version: 1.2 6 Author: XNicON 7 7 Author URI: https://xnicon.ru 8 8 License: GPL2 … … 10 10 Domain Path: /languages 11 11 12 Copyright 2016-201 8 X-NicON (x-icon@ya.ru)12 Copyright 2016-2019 XNicON (x-icon@ya.ru) 13 13 14 14 WP Post Expires is free software; you can redistribute it and/or modify … … 27 27 */ 28 28 29 //Legacy30 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 36 29 class XNPostExpires { 37 private $plugin_version = '1. 1';30 private $plugin_version = '1.2'; 38 31 private $url_assets; 39 public $settings = array();40 41 public static function init() {32 public $settings = []; 33 34 public static function init() { 42 35 return new self; 43 36 } 44 37 45 public function __construct() {38 public function __construct() { 46 39 load_plugin_textdomain('wp-post-expires', false, dirname(plugin_basename( __FILE__ ) ).'/languages'); 47 40 … … 49 42 $this->url_assets = plugin_dir_url( __FILE__ ).'assets/'; 50 43 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']); 62 54 } 63 55 } … … 67 59 68 60 if(empty($settings_load) || !is_array($settings_load)) { 69 $settings_load = array();61 $settings_load = []; 70 62 } 71 63 … … 88 80 } 89 81 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) { 117 110 if(!empty($post->ID)) { 118 111 $expires = get_post_meta($post->ID, 'xn-wppe-expiration', true); 119 112 $expires_select = get_post_meta($post->ID, 'xn-wppe-expiration-action', true); 120 113 $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'); 124 121 $date = !empty($expires)? date_i18n('Y-m-d H:i', strtotime($expires)) : ''; 125 122 $select = !empty($expires_select)? $expires_select : $this->settings['action']; … … 128 125 ?> 129 126 130 <div id="xn-wppe" class="misc-pub-section"> 131 <span> 132 <span class="wp-media-buttons-icon dashicons dashicons-clock"></span> 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> 163 149 <?php 164 150 } 165 151 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) ) { 169 155 return false; 170 156 } … … 174 160 $add_prefix = isset($_POST['xn-wppe-expiration-prefix'])? sanitize_text_field($_POST['xn-wppe-expiration-prefix']) : false; 175 161 176 if($expiration !== false && $action_type !== false) {162 if($expiration !== false && $action_type !== false) { 177 163 update_post_meta($post_id, 'xn-wppe-expiration', $expiration); 178 164 update_post_meta($post_id, 'xn-wppe-expiration-action', $action_type); 179 if($add_prefix !== false) {165 if($add_prefix !== false) { 180 166 update_post_meta($post_id, 'xn-wppe-expiration-prefix', $add_prefix); 181 167 } … … 187 173 } 188 174 189 public function xn_wppe_register_settings() {175 public function registerSettings() { 190 176 191 177 register_setting('reading', 'xn_wppe_settings'); … … 193 179 add_settings_section("xn_wppe_section", __('Settings posts expires', 'wp-post-expires'), null, 'reading'); 194 180 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() { 201 187 $all_post_types = get_post_types(false, 'objects'); 202 188 unset($all_post_types['nav_menu_item']); … … 212 198 } 213 199 214 public function xn_wppe_settings_field_action() {200 public function settingsFieldAction() { 215 201 echo '<select name="xn_wppe_settings[action]" id="xn_wppe_settings_action">'; 216 202 echo '<option '.($this->settings['action']=='add_prefix'?'selected':'').' value="add_prefix">'.__('Add Prefix', 'wp-post-expires').'</option>'; … … 220 206 } 221 207 222 public function xn_wppe_settings_field_prefix() {208 public function settingsFieldPrefix() { 223 209 echo '<input id="xn_wppe_settings_prefix" type="text" name="xn_wppe_settings[prefix]" value="'.$this->settings['prefix'].'" class="regular-text">'; 224 210 echo '<p class="description">'.__('Enter the text you would like prepended to expired items.', 'wp-post-expires').'</p>'; 225 211 } 226 212 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) { 252 214 $expires_prefix = get_post_meta($post_id, 'xn-wppe-expiration-prefix', true); 253 215 $prefix = !empty($expires_prefix)? esc_attr($expires_prefix).' ' : ''; … … 256 218 } 257 219 258 public function xnFilterClass($classes) {220 public function cssClassFilter($classes) { 259 221 $classes[] = 'post-expired'; 260 222 return $classes; 261 223 } 262 224 263 public function xnExpiredPost($post) {225 public function expiredPost($post) { 264 226 $post_id = $post->ID; 265 227 266 if(self::isExpired($post_id)) {228 if(self::isExpired($post_id)) { 267 229 268 230 $expires_action = get_post_meta($post_id, 'xn-wppe-expiration-action', true); … … 271 233 switch($action) { 272 234 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']); 275 237 break; 276 238 case 'to_drafts': 277 remove_action('save_post', [$this, ' xnSaveBoxFields']);239 remove_action('save_post', [$this, 'saveBoxFields']); 278 240 wp_update_post(['ID' => $post_id, 'post_status' => 'draft']); 279 241 update_post_meta($post_id, 'xn-wppe-expiration-action', 'add_prefix'); 280 242 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']); 282 244 break; 283 245 case 'to_trash': 284 remove_action('save_post', [$this, ' xnSaveBoxFields']);246 remove_action('save_post', [$this, 'saveBoxFields']); 285 247 $del_post = wp_trash_post($post_id); 286 248 //check post to trash, or deleted 287 if($del_post['post_status'] == 'trash') {249 if($del_post['post_status'] == 'trash') { 288 250 update_post_meta($post_id, 'xn-wppe-expiration-action', 'add_prefix'); 289 251 update_post_meta($post_id, 'xn-wppe-expiration-prefix', $this->settings['prefix']); 290 252 } 291 add_action('save_post', [$this, ' xnSaveBoxFields']);253 add_action('save_post', [$this, 'saveBoxFields']); 292 254 break; 293 255 } 294 256 } 295 257 } 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 } 296 281 } 297 282 add_action('plugins_loaded', ['XNPostExpires','init']);
Note: See TracChangeset
for help on using the changeset viewer.