Skip to content

Commit 29b66e3

Browse files
authored
Merge pull request #14 from threadi/feature/updateReadme0324
updated readme & optimized some things
2 parents dda2f9a + 52b9e3f commit 29b66e3

File tree

4 files changed

+48
-29
lines changed

4 files changed

+48
-29
lines changed

admin/js.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
const { __ } = wp.i18n;
22

33
jQuery(document).ready(function(){
4-
jQuery(".auto_category a").click(function(){
5-
change_publish_states(jQuery(this));
6-
});
74
jQuery(".auto_category a.default_category").parents("tr").addClass('default_category');
5+
jQuery( document ).on( "ajaxComplete", function( event, xhr, settings ) {
6+
autocategory_set_event();
7+
});
8+
autocategory_set_event();
89
});
910

10-
function change_publish_states(el){
11+
/**
12+
* Set event for table.
13+
*/
14+
function autocategory_set_event() {
15+
jQuery(".auto_category a").click(function(){
16+
autocategory_change_publish_states(jQuery(this));
17+
});
18+
}
19+
20+
/**
21+
* Change the states.
22+
*
23+
* @param el
24+
*/
25+
function autocategory_change_publish_states(el){
1126
jQuery.getJSON(ajaxurl,
1227
{
1328
term_id: el.data("termid"),
@@ -17,12 +32,12 @@ function change_publish_states(el){
1732
function(data) {
1833
if (data.error){
1934
alert(data.error);
20-
}else{
35+
} else {
2136
if( data.result ) {
22-
var oldDefault = jQuery("#tag-" + data.old_default_category_id + " .auto_category > a.default_category");
37+
let oldDefault = jQuery("#tag-" + data.old_default_category_id + " .auto_category > a.default_category");
2338
oldDefault.parents('tr').removeClass('default_category');
2439
oldDefault.removeClass('default_category').text(__('Set as default', 'auto-category-for-posts'));
25-
var newDefault = jQuery("#tag-" + data.new_default_category_id + " .auto_category > a");
40+
let newDefault = jQuery("#tag-" + data.new_default_category_id + " .auto_category > a");
2641
newDefault.addClass('default_category').text(__('Default category', 'auto-category-for-posts'));
2742
newDefault.parents('tr').addClass('default_category');
2843
}

auto-category-for-posts.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ function auto_category_update_check(): void {
5151
* @param WP_Post $post The Post-object.
5252
* @param bool $update Whether the post has been updated (true) or added/inserts (false).
5353
* @return void
54-
* @noinspection PhpUnused
5554
*/
5655
function auto_category_save_post( int $post_id, WP_Post $post, bool $update ): void {
5756
// Only for new posts.
@@ -83,21 +82,24 @@ function auto_category_save_post( int $post_id, WP_Post $post, bool $update ): v
8382
* @param array $actions List of actions.
8483
* @param WP_Term $tag The term.
8584
* @return array
86-
* @noinspection PhpUnused
8785
*/
8886
function auto_category_add_term_action( array $actions, WP_Term $tag ): array {
89-
if ( 'category' === $tag->taxonomy ) :
90-
$tax = get_taxonomy( 'category' );
91-
if ( current_user_can( $tax->cap->manage_terms ) ) {
92-
$text = __( 'Set as default', 'auto-category-for-posts' );
93-
$value = '';
94-
if ( absint( get_option( AUTOCATEGORY_OPTIONNAME ) ) === $tag->term_id ) {
95-
$text = __( 'Default category', 'auto-category-for-posts' );
96-
$value = ' class="default_category"';
97-
}
98-
$actions['auto_category'] = '<a href="#"' . $value . ' data-termid="' . $tag->term_id . '" data-nonce="' . wp_create_nonce( 'auto_category_change_state' ) . '">' . $text . '</a>';
99-
}
100-
endif;
87+
// bail if it is not the category taxonomy.
88+
if ( 'category' !== $tag->taxonomy ) {
89+
return $actions;
90+
}
91+
92+
// get taxonomy as object.
93+
$tax = get_taxonomy('category');
94+
if (current_user_can($tax->cap->manage_terms)) {
95+
$text = __('Set as default', 'auto-category-for-posts');
96+
$value = '';
97+
if (absint(get_option(AUTOCATEGORY_OPTIONNAME)) === $tag->term_id) {
98+
$text = __('Default category', 'auto-category-for-posts');
99+
$value = ' class="default_category"';
100+
}
101+
$actions['auto_category'] = '<a href="#"' . $value . ' data-termid="' . $tag->term_id . '" data-nonce="' . wp_create_nonce('auto_category_change_state') . '">' . esc_html( $text ) . '</a>';
102+
}
101103
return $actions;
102104
}
103105
add_filter( 'tag_row_actions', 'auto_category_add_term_action', 10, 2 );
@@ -144,7 +146,6 @@ function auto_category_load_ajax(): void {
144146
* Set new auto category by AJAX.
145147
*
146148
* @return void
147-
* @noinspection PhpUnused
148149
*/
149150
function auto_category_ajax(): void {
150151
$result = array(
@@ -188,7 +189,6 @@ function auto_category_ajax(): void {
188189
}
189190
}
190191
// return the result.
191-
echo wp_json_encode( $result );
192-
exit;
192+
wp_send_json( $result );
193193
}
194194
add_action( 'wp_ajax_auto_category_change_state', 'auto_category_ajax' );

build/build.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@
3535
</target>
3636

3737
<!-- create release-zip -->
38-
<target name="build" description="builds a new release" depends="json-translations, setVersionNumber">
38+
<target name="build" description="builds a new release" depends="setVersionNumber">
3939
<delete file="${build.dir}/${plugin.slug}_${plugin.version}.zip"/>
4040
<zip destfile="${build.dir}/${plugin.slug}_${plugin.version}.zip">
4141
<zipfileset dir="${src.dir}/admin" prefix="${plugin.slug}/admin" />
42-
<zipfileset dir="${src.dir}/languages" includes="*.json" prefix="${plugin.slug}/languages" />
4342
<zipfileset dir="${src.dir}" includes="uninstall.php,readme.txt" prefix="${plugin.slug}" />
4443
<zipfileset dir="${src.dir}" includes="${plugin.slug}-release.php" fullpath="${plugin.slug}/${plugin.slug}.php" />
4544
</zip>

readme.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
Contributors: threadi
33
Tags: category, auto category, posts
44
Requires at least: 5.8
5-
Tested up to: 6.4
5+
Tested up to: 6.5
66
Requires PHP: 7.4
77
License: GPL-2.0-or-later
88
License URI: https://www.gnu.org/licenses/gpl-2.0.html
9-
Stable tag: 1.0.7
9+
Stable tag: 1.0.8
1010

1111
== Description ==
1212

13-
This plugin adds the possibility to set a default category for posts within the category overview. The selected category will be set for each new post already when it is called for the first time and not after its first saving.
13+
Define a default category for each new post. This will already be set during creation of the post. You must not choose the category yourself. Use your time for the content of your posts and not for their configuration.
1414

1515
== Installation ==
1616

@@ -47,3 +47,8 @@ This plugin adds the possibility to set a default category for posts within the
4747
* Updated compatibility-flag for WordPress 6.4
4848
* Compatible with WordPress Coding Standards 3.0
4949
* Removed language-files from plugin (except the json-files for Block Editor)
50+
51+
= 1.0.8 =
52+
* Small optimizations
53+
* Removed JSON-language files from plugin
54+
* Updated compatibility-flag for WordPress 6.5

0 commit comments

Comments
 (0)