Skip to content

Commit

Permalink
v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
seb86 committed Dec 13, 2022
1 parent a769208 commit 1f21267
Show file tree
Hide file tree
Showing 9 changed files with 3,247 additions and 1,684 deletions.
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Changelog for Attachment Slugs for WordPress

## v2.0.0 - 13th December 2022

### What's New?

* Just a little refresh of the plugin to keep it up to date with the latest WordPress.

> This update improves the permalinks and corrects a few mistakes. You will have to redo your attachment permalinks once updated to this version of the plugin.
## v1.0.1 - 16th February 2019

* New: Ready for WordPress 5.1 release. 🎊

## v1.0.0 - 3rd December 2018

* New: Attachments can edit their own permalink slug. 🎉
* Checked: Compatibility with WordPress 5.0
* Improved: The main file has been re-written.

> Now requires WordPress version 4.4.0 or higher.
## v0.0.2 - 16th November 2017

* FIXED: Attachment base option when saving the permalinks.
* FIXED: Undefined variable in permalink-settings.php
* RENAMED: Plugin name for better SEO results.

## v0.0.1 - 27th February 2016

* Initial Version.
41 changes: 15 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,49 @@
[![WordPress Plugin Rating](https://img.shields.io/wordpress/plugin/r/attachment-slug.svg?style=flat-square)](https://wordpress.org/support/view/plugin-reviews/attachment-slug?filter=5)
[![WordPress Plugin Downloads](https://img.shields.io/wordpress/plugin/dt/attachment-slug.svg?style=flat)](https://wordpress.org/plugins/attachment-slug/)

**Contributors:** sebd86
**Donate link:** https://sebdumont.xyz/donate/
**Tags:** attachment, attachments, attachment slug, page slug, image slug, image url, permalinks, custom permalinks
**Requires PHP:** 5.6
**Requires at least:** 4.4
**Tested up to:** 5.1
**Stable tag:** 1.0.1
**License:** GPL v2 or later

###### Follow me
##### Follow me
💻 [Website](https://sebastiendumont.com) 🐦[Twitter](https://twitter.com/sebd86)


## 🔔 Overview

Enables WordPress to allow attachments to have their own permalink structure. This makes the URLs more friendly and great for SEO results should you decide to index your attachments.
**Attachment Slugs for WordPress** enables you to add permalink support for media attachments making the attachment URLs more friendly and great for SEO results should you decide to index your attachments.

You can also edit the permalink slug of an indvidual attachment which you can not do via _Quick Edit_ like other post types. Changing the attachment title does not update the permalink slug so this handy to have should you want to rename the URL for the attachment.
You can also edit the permalink slug of an individual attachment which you can not do via _Quick Edit_ like other post types. Changing the attachment title does not update the permalink slug so this handy to have should you want to rename the URL for the attachment.

## How to edit an attachment slug?

#### ✅ Requirements
Simply go to the media library and edit the item you wish to rename. Then on the left side under "Attachment Slug" you can rename the slug. Press the "Update" button and that's it.

### ✅ Requirements

To use this plugin you will need:

* PHP v5.6
* WordPress v4.4 minimum

#### 💽 Installation
### 💽 Installation

###### Manual
#### Manual
1. Download a `.zip` file with the [latest version](https://github.com/seb86/attachment-slugs/releases).
2. Go to **WordPress Admin > Plugins > Add New**.
3. Click **Upload Plugin** at the top.
4. **Choose File** and select the `.zip` file you downloaded in **Step 1**.
5. Click **Install Now** and **Activate** the plugin.

###### Automatic
#### Automatic
1. Go to **WordPress Admin > Plugins > Add New**.
2. Search for **Attachment Slugs**
3. Click **Install Now** on the plugin and **Activate** the plugin.


#### Screenshots
### Screenshots

![Permalink Options for Attachments](https://raw.githubusercontent.com/seb86/attachment-slugs/master/.wordpress-org/assets/screenshot-1.png)

![Edit Attachment Slug](https://raw.githubusercontent.com/seb86/attachment-slugs/master/.wordpress-org/assets/screenshot-2.png)

#### 📝 Reporting Issues
### 📝 Reporting Issues

If you think you have found a bug in the extension, please [open a new issue](https://github.com/seb86/attachment-slugs/issues/new) and I will do my best to help you out.

Expand All @@ -67,21 +62,15 @@ You'll be helping to ensure I can spend the time not just fixing bugs, but keepi
Please also consider starring ✨ and sharing 👍 the project repo! This helps the project getting known and grow with the community. 🙏

I accept one-time donations and monthly via [BuyMeACoffee.com](https://www.buymeacoffee.com/sebastien)
- [My PayPal](https://www.paypal.me/codebreaker)
- [BuyMeACoffee.com](https://www.buymeacoffee.com/sebastien)
- Bitcoin (BTC): `3L4cU7VJsXBFckstfJdP2moaNhTHzVDkKQ`
- Ethereum (ETH): `0xc6a3C18cf11f5307bFa11F8BCBD51F355b6431cB`
- Litecoin (LTC): `MNNy3xBK8sM8t1YUA2iAwdi9wRvZp9yRoi`

Thank you for your support! 🙌


##### License
#### License

Attachment Slugs for WordPress is released under [GNU General Public License v3.0](http://www.gnu.org/licenses/gpl-3.0.html).


##### Credits
#### Credits

Attachment Slugs for WordPress is developed and maintained by [Sébastien Dumont](https://sebastiendumont.com/about/).

Expand Down
63 changes: 33 additions & 30 deletions admin/class-as-permalink-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*
* @author Sébastien Dumont
* @category Admin
* @package Attachment Slug/Admin
* @package Attachment Slugs/Admin
* @since 0.0.1
* @version 1.0.0
* @version 2.0.0
*/

if ( ! defined( 'ABSPATH' ) ) {
Expand All @@ -17,6 +17,13 @@

class Attachment_Slug_Admin_Permalink_Settings {

/**
* Permalink settings.
*
* @var array
*/
private $permalinks = array();

/**
* Constructor
*/
Expand All @@ -31,14 +38,18 @@ public function __construct() {
* @access public
*/
public function settings_init() {
add_settings_section( 'attachment-permalink', __( 'Attachment Permalink', 'attachment-slug' ), array( $this, 'settings' ), 'permalink' );
add_settings_section( 'attachment-permalink', __( 'Attachment permalinks', 'attachment-slug' ), array( $this, 'settings' ), 'permalink' );

$this->permalinks = Attachment_Slug::aswp_get_permalink_structure();
} // END settings_init()

/**
* Clean variables using sanitize_text_field.
*
* @access public
* @param string|array $var
*
* @param string|array $var
*
* @return string|array
*/
public function aswp_as_clean( $var ) {
Expand All @@ -53,33 +64,34 @@ public function aswp_as_clean( $var ) {
public function settings() {
echo wpautop( __( 'These settings control the permalink used specifically for attachments.', 'attachment-slug' ) );

$attachment_permalink = get_option( 'attachment_permalink' );
$base_slug = apply_filters( 'aswp_as_base_slug', 'image' );

$structures = array(
0 => '',
1 => '/' . trailingslashit( $base_slug ),
1 => trailingslashit( $base_slug ),
);
?>
<table class="form-table ac-as-permalink-structure">
<tbody>
<tr>
<th><label><input name="attachment_permalink" type="radio" value="<?php echo esc_attr( $structures[0] ); ?>" class="astog" <?php checked( $structures[0], $attachment_permalink['base'] ); ?> /> <?php _e( 'Default', 'attachment-slug' ); ?></label></th>
<th><label><input name="attachment_permalink" type="radio" value="<?php echo esc_attr( $structures[0] ); ?>" class="astog" <?php checked( $structures[0], $this->permalinks['attachment_base'] ); ?> /> <?php _e( 'Default', 'attachment-slug' ); ?></label></th>
<td><code class="default-example"><?php echo esc_html( home_url() ); ?>/?attachment=1</code> <code class="non-default-example"><?php echo esc_html( home_url() ); ?>/sample-attachment/</code></td>
</tr>
<tr>
<th><label><input name="attachment_permalink" type="radio" value="<?php echo esc_attr( $structures[1] ); ?>" class="astog" <?php checked( $structures[1], trailingslashit( $attachment_permalink['base'] ) ); ?> /> <?php _e( 'Attachment base', 'attachment-slug' ); ?></label></th>
<th><label><input name="attachment_permalink" type="radio" value="<?php echo esc_attr( $structures[1] ); ?>" class="astog" <?php checked( $structures[1], trailingslashit( $this->permalinks['attachment_base'] ) ); ?> /> <?php _e( 'Attachment base', 'attachment-slug' ); ?></label></th>
<td><code><?php echo esc_html( home_url() ); ?>/<?php echo esc_html( $base_slug ); ?>/sample-attachment/</code></td>
</tr>
<tr>
<th><label><input name="attachment_permalink" id="attachment_custom_selection" type="radio" value="custom" class="tog" <?php checked( $attachment_permalink['custom'], 1 ); ?> />
<?php _e( 'Custom Base', 'attachment-slug' ); ?></label></th>
<th><label><input name="attachment_permalink" id="attachment_custom_selection" type="radio" value="custom" class="tog" <?php checked( $this->permalinks['custom'], 1 ); ?> />
<?php _e( 'Custom base', 'attachment-slug' ); ?></label></th>
<td>
<input name="attachment_permalink_structure" id="attachment_permalink_structure" type="text" value="<?php echo esc_attr( $attachment_permalink['base'] ); ?>" class="regular-text code"> <span class="description"><?php _e( 'Enter a custom base to use. A base <strong>must</strong> be set or WordPress will use default instead.', 'attachment-slug' ); ?></span>
<code><?php echo esc_html( home_url() ); ?>/</code>
<input name="attachment_permalink_structure" id="attachment_permalink_structure" type="text" value="<?php echo esc_attr( $this->permalinks['attachment_base'] ? trailingslashit( $this->permalinks['attachment_base'] ) : '' ); ?>" class="regular-text code"> <span class="description"><?php _e( 'Enter a custom base to use. A base <strong>must</strong> be set or WordPress will use default instead.', 'attachment-slug' ); ?></span>
</td>
</tr>
</tbody>
</table>
<?php wp_nonce_field( 'ac-as-permalinks', 'ac-as-permalinks-nonce' ); ?>
<script type="text/javascript">
jQuery( function() {
jQuery('input.astog').change(function() {
Expand Down Expand Up @@ -116,34 +128,25 @@ public function settings_save() {
}

// We need to save the options ourselves.
if ( isset( $_POST['permalink_structure'] ) && isset( $_POST['attachment_permalink'] ) ) {
$permalink = get_option( 'attachment_permalink' );

if ( isset( $permalinks ) && !empty( $permalinks ) ) {
$permalink = array();
}
if ( isset( $_POST['permalink_structure'], $_POST['ac-as-permalinks-nonce'], $_POST['attachment_permalink'] ) && wp_verify_nonce( wp_unslash( $_POST['ac-as-permalinks-nonce'] ), 'ac-as-permalinks' ) ) {
Attachment_Slug::aswp_switch_to_site_locale();

// Attachment base
$attachment_permalink = self::aswp_as_clean( $_POST['attachment_permalink'] );

$permalink['custom'] = false;
$permalink = (array) get_option( 'attachment_permalink', array() );

if ( $attachment_permalink == 'custom' ) {
// Get permalink without slashes
$attachment_permalink = trim( self::aswp_as_clean( $_POST['attachment_permalink_structure'] ), '/' );
$permalink['custom'] = '';

// Prepending slash
$attachment_permalink = '/' . $attachment_permalink;
// Attachment base
$attachment_permalink = self::aswp_as_clean( wp_unslash( $_POST['attachment_permalink'] ) );

if ( 'custom' === $attachment_permalink ) {
$attachment_permalink = trim( self::aswp_as_clean( wp_unslash( $_POST['attachment_permalink_structure'] ) ) );
$permalink['custom'] = true;
} elseif ( empty( $attachment_permalink ) ) {
$attachment_permalink = false;
$permalink['custom'] = false;
}

$permalink['base'] = untrailingslashit( $attachment_permalink );
$permalink['attachment_base'] = untrailingslashit( $attachment_permalink );

update_option( 'attachment_permalink', $permalink );
Attachment_Slug::aswp_restore_locale();
}
} // END settings_save()

Expand Down
4 changes: 2 additions & 2 deletions admin/view/html-notice-requirement-wp.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
/**
* Admin View: WordPress Requirment Notice.
* Admin View: WordPress Requirement Notice.
*
* @since 1.0.0
* @author Sébastien Dumont
* @category Admin
* @package Attachment Slug/Admin/Views
* @package Attachment Slugs/Admin/Views
* @license GPL-2.0+
*/

Expand Down
Loading

0 comments on commit 1f21267

Please sign in to comment.