Skip to content

Update get_attachment_link() to return image URL when attachment pages are turned off.#6728

Open
deepakrohillas wants to merge 17 commits intoWordPress:trunkfrom
deepakrohillas:61133_get_attachment_link
Open

Update get_attachment_link() to return image URL when attachment pages are turned off.#6728
deepakrohillas wants to merge 17 commits intoWordPress:trunkfrom
deepakrohillas:61133_get_attachment_link

Conversation

@deepakrohillas
Copy link

… add_action()

`error.message` LIKE 'Uncaught exception 'Error' with message 'Call to undefined function add_action()' in /var/www/wp-content/plugins/hello.php:69%' AND `error.class` = 'Error' AND transactionUiName = '/wp-content/plugins/hello.php'

'request_uri': '/wp-content/plugins/hello.php'
…dolly_uncaught_exception

Fix Uncaught exception Error with message 'Call to undefined function…
@github-actions
Copy link

github-actions bot commented Jun 4, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props deepakrohilla, peterwilsoncc.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link

github-actions bot commented Jun 4, 2024

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copy link
Contributor

@peterwilsoncc peterwilsoncc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the changes you've made can be earlier in the function and bypass the check for a parent.

I'd suggest placing the new condition immediately after the call the get_post():

	$post = get_post( $post );
	// Return image URL if attachment pages are disabled.
	if ( $post && '0' === get_option( 'wp_attachment_pages_enabled' ) ) {
		return wp_get_attachment_url( $post->ID );
	}

This change will probably cause a few unit tests to fail as the value of get_attachment_link() will no longer meet the expected value. These tests should be updated to check the correct value is returned if the attachment pages are enabled, and if they are not.

I'd suggest duplicating the existing tests, once to run with pages enabled, and one to run with them disabled.

@deepakrohillas
Copy link
Author

@peterwilsoncc : Thanks for the review. Suggested changes has been done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants