He realizado un Plugin y a la hora de subirlo al repositorio oficial de Wordpress entre otras cosas he recibido este mensaje:
When you hardcode in paths, or assume that everyone has WordPress in the root of their domain, you cause anyone using 'Giving WordPress it's own directory' (a VERY common setup) to break. In addition, WordPress allows users to change the name of wp-content, so you would break anyone who choses to do so.
Please review http://codex.wordpress.org/Determining_Plugin_and_Content_Directories and update your plugin accordingly. And don't worry about supporting WordPress 2.x or lower. We don't encourage it nor expect you to do so, so save yourself some time and energy.
Example:
if( suwp_pathname == 'wp-admin' ) { doc_pathname = '/wp-admin/admin-ajax.php'; } else { doc_pathname = '/' + suwp_pathname + '/wp-admin/admin-ajax.php'; }
Pensaba que mi código era correcto pero parece que hardcodeo la dirección y no se como realizarlo de forma correcta.
Los ficheros afectados pueden ser polr.php
y polr.js
(No se si hay que realizar cambios en los dos o con el js sería suficiente).
Parte de polr.php
function polr_init() {
wp_register_script( 'polr-js', plugins_url( '/polr.js', __FILE__ ), array('jquery') );
//load scripts
wp_enqueue_script('jquery');
wp_enqueue_script('polr-js');
global $post;
$post_id = $post->ID;
wp_localize_script('polr-js', 'MyAjax', array(
'post_id' => $post_id,
'action'=> 'polr_get_url'
));
}
add_action( 'add_meta_boxes', 'polr_init' );
polr.js
jQuery(document).ready(function($) {
jQuery("#button_polr_get_url").click(function(){
var doc_pathname = '';
var suwp_pathname = document.location.pathname.split('/')[1];
// add the path element, if necessary
if( suwp_pathname == 'wp-admin' ) {
doc_pathname = '/wp-admin/admin-ajax.php';
} else {
doc_pathname = '/' + suwp_pathname + '/wp-admin/admin-ajax.php';
}
var url = document.location.protocol + '//' + document.location.host + doc_pathname;
jQuery.ajax({
type: 'POST',
url: url,
dataType: 'text',
data: {
postID: MyAjax.post_id, // From PHP
action: MyAjax.action // From PHP-tik
},
success: function(data, textStatus, XMLHttpRequest){
$('#polr_shortened_url').val(data);
},
error: function(MLHttpRequest, textStatus, errorThrown){
alert(errorThrown);
}
});
});
});