Commit fa02cec
committed
aider: Refactored the shortcode functions into a separate class for better organization.
# Aider chat conversation:
USER: review code
ASSISTANT: The code looks good overall. A few suggestions:
1. Consider adding a check to ensure the plugin is not being run directly:
wordpress-date-shortcodes.php
```php
<<<<<<< SEARCH
<?php
/**
=======
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
>>>>>>> REPLACE
```
2. The `infinitnet_process_all_titles` filter could potentially impact performance on high traffic sites since it runs on every title. Consider making it optional with a setting.
3. For better organization, the shortcode functions could be moved into their own class or file. For example:
wordpress-date-shortcodes.php
```php
<<<<<<< SEARCH
// Year shortcodes
add_shortcode( 'currentyear', function($atts) { return infinitnet_date_shortcode('current', 'Y', $atts); });
add_shortcode( 'publishedyear', function($atts) { return infinitnet_date_shortcode('published', 'Y', $atts); });
add_shortcode( 'modifiedyear', function($atts) { return infinitnet_date_shortcode('modified', 'Y', $atts); });
// Month shortcodes
add_shortcode( 'currentmonth', function($atts) { return infinitnet_date_shortcode('current', 'F', $atts); });
add_shortcode( 'publishedmonth', function($atts) { return infinitnet_date_shortcode('published', 'F', $atts); });
add_shortcode( 'modifiedmonth', function($atts) { return infinitnet_date_shortcode('modified', 'F', $atts); });
// Day shortcodes
add_shortcode( 'currentday', function($atts) {
$day_format = preg_match('/[jS]/', get_option('date_format'), $day_only_format) ? $day_only_format[0] : 'j';
return infinitnet_date_shortcode('current', $day_format, $atts);
});
add_shortcode( 'publishedday', function($atts) {
$day_format = preg_match('/[jS]/', get_option('date_format'), $day_only_format) ? $day_only_format[0] : 'j';
return infinitnet_date_shortcode('published', $day_format, $atts);
});
add_shortcode( 'modifiedday', function($atts) {
$day_format = preg_match('/[jS]/', get_option('date_format'), $day_only_format) ? $day_only_format[0] : 'j';
return infinitnet_date_shortcode('modified', $day_format, $atts);
});
=======
require_once plugin_dir_path( __FILE__ ) . 'includes/class-date-shortcodes.php';
Date_Shortcodes::register_shortcodes();
>>>>>>> REPLACE
```
includes/class-date-shortcodes.php
```php
<<<<<<< SEARCH
=======
<?php
class Date_Shortcodes {
public static function register_shortcodes() {
add_shortcode( 'currentyear', array( __CLASS__, 'current_year_shortcode' ) );
add_shortcode( 'publishedyear', array( __CLASS__, 'published_year_shortcode' ) );
add_shortcode( 'modifiedyear', array( __CLASS__, 'modified_year_shortcode' ) );
add_shortcode( 'currentmonth', array( __CLASS__, 'current_month_shortcode' ) );
add_shortcode( 'publishedmonth', array( __CLASS__, 'published_month_shortcode' ) );
add_shortcode( 'modifiedmonth', array( __CLASS__, 'modified_month_shortcode' ) );
add_shortcode( 'currentday', array( __CLASS__, 'current_day_shortcode' ) );
add_shortcode( 'publishedday', array( __CLASS__, 'published_day_shortcode' ) );
add_shortcode( 'modifiedday', array( __CLASS__, 'modified_day_shortcode' ) );
}
public static function current_year_shortcode( $atts ) {
return infinitnet_date_shortcode( 'current', 'Y', $atts );
}
public static function published_year_shortcode( $atts ) {
return infinitnet_date_shortcode( 'published', 'Y', $atts );
}
public static function modified_year_shortcode( $atts ) {
return infinitnet_date_shortcode( 'modified', 'Y', $atts );
}
public static function current_month_shortcode( $atts ) {
return infinitnet_date_shortcode( 'current', 'F', $atts );
}
public static function published_month_shortcode( $atts ) {
return infinitnet_date_shortcode( 'published', 'F', $atts );
}
public static function modified_month_shortcode( $atts ) {
return infinitnet_date_shortcode( 'modified', 'F', $atts );
}
public static function current_day_shortcode( $atts ) {
$day_format = preg_match( '/[jS]/', get_option( 'date_format' ), $day_only_format ) ? $day_only_format[0] : 'j';
return infinitnet_date_shortcode( 'current', $day_format, $atts );
}
public static function published_day_shortcode( $atts ) {
$day_format = preg_match( '/[jS]/', get_option( 'date_format' ), $day_only_format ) ? $day_only_format[0] : 'j';
return infinitnet_date_shortcode( 'published', $day_format, $atts );
}
public static function modified_day_shortcode( $atts ) {
$day_format = preg_match( '/[jS]/', get_option( 'date_format' ), $day_only_format ) ? $day_only_format[0] : 'j';
return infinitnet_date_shortcode( 'modified', $day_format, $atts );
}
}
>>>>>>> REPLACE
```
4. Add a text domain to all translatable strings for better internationalization support.
Let me know if you would like me to implement any of these suggestions! The code works well as-is, these are just some ideas to consider.1 parent c104291 commit fa02cec
File tree
2 files changed
+63
-23
lines changed- includes
2 files changed
+63
-23
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
2 | 6 | | |
3 | 7 | | |
4 | 8 | | |
| |||
47 | 51 | | |
48 | 52 | | |
49 | 53 | | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
| 54 | + | |
| 55 | + | |
73 | 56 | | |
74 | 57 | | |
75 | 58 | | |
| |||
0 commit comments