Pro: hard-coded /wp-admin links going to 404 on WP with custom admin dir

[ad_1]

Hey, we have the Pro version, great plugin, loving all the features. Great work!

One issue we’re facing is — for security reasons, we’ve changed /wp-admin to a custom dir path.

But Coupon Affiliates Pro has a lot of hard-coded links that point to /wp-admin. I did a search and found about 146 references in the plugin to /wp-admin.

WordPress has admin_url(...) for generating links to pages within /wp-admin, which creates URL with the correct path. See documentation:

I would make the changes in code on our end, but they will be overwritten if there’s an update.

I’ve tried using .htaccess to resolve the discrepancy, but that won’t work, because we end up with a redirect loop (since the physical folder is still named wp-admin, to allow WordPress updates to work normally).

Can you please get those URLs updated to use admin_url(...)?

Example:

ie. Our URL looks like:

[ View Creatives ] button points to:

Existing code:

<a href="https://projectdmc.org/wp-admin/edit.php?post_type=wcu-creatives" target="_blank" class="wcu-addons-box-view-details" target="_blank" style="margin-left: 0; padding: 7px 20px;">
  <?php echo __( 'VIEW CREATIVES', 'woo-coupon-usage' ); ?> <i class="fas fa-eye" style="background: transparent; margin: 0;"></i>
</a>

Suggested code:

<a href="https://projectdmc.org/support/topic/pro-hard-coded-wp-admin-links-going-to-404-on-wp-with-custom-admin-dir/<?php echo admin_url("https://projectdmc.org/support/topic/pro-hard-coded-wp-admin-links-going-to-404-on-wp-with-custom-admin-dir/edit.php?post_type=wcu-creatives"); ?>" target="_blank" class="wcu-addons-box-view-details" target="_blank" style="margin-left: 0; padding: 7px 20px;">
  <?php echo __( 'VIEW CREATIVES', 'woo-coupon-usage' ); ?> <i class="fas fa-eye" style="background: transparent; margin: 0;"></i>
</a>

Or, the lazy way to do it, use relative URLs (just remove /wp-admin/), ie:

<a href="https://projectdmc.org/support/topic/pro-hard-coded-wp-admin-links-going-to-404-on-wp-with-custom-admin-dir/edit.php?post_type=wcu-creatives" target="_blank" class="wcu-addons-box-view-details" target="_blank" style="margin-left: 0; padding: 7px 20px;">

Setup for testing custom wp-admin dir:

Add to /wp-config.php:

define( 'WP_ADMIN_DIR', 'mycustomdir' );
define( 'ADMIN_COOKIE_PATH', '/' . WP_ADMIN_DIR );

Add to /.htaccess:

RewriteEngine On
RewriteRule ^mycustomdir$ /mycustomdir/ [R=301,L]
RewriteRule ^mycustomdir(/)?(.*) wp-admin/$2?%{QUERY_STRING} [L]

Add PHP snippet (ie. functions.php or using WP Code snippets plugin):

function rename_wpadmin_folder($url, $path, $orig_scheme) {
  return preg_replace('/(wp-admin)/', WP_ADMIN_DIR, $url, 1);
}
add_filter('site_url', 'rename_wpadmin_folder', 10, 3);
  • This topic was modified 1 hour, 9 minutes ago by authentico.
  • This topic was modified 1 hour, 7 minutes ago by authentico.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer