1
votes

UPDATED: Changed inner div content

Please, understand than I'm new to wordpress and php.

I added a media button to my media buttons in the admin by adding the following code to functions.php file:

function add_custom_media_button() {
    echo '<a href="#TB_inline?inlineId=custommedia_container" id="insert-my-media" class="button thickbox">Add custom media</a>';
}
add_action('media_buttons', 'add_custom_media_button', 15);

add_action( 'admin_footer',  'add_inline_popup_content' );
function add_inline_popup_content() {
    $cu = wp_get_current_user();
    $cusername = $cu->user_login;
    echo '<div id="custommedia_container" style="display:none;">';
    echo '<iframe class="mediaselectoriframe" title="Archivado" width="100%" height="99%" title="cosas" src="http://nephila.cloudapp.net/GAdEWeb/wpsearch.aspx?wpuser=' . $cusername . '&wplang=' . $clocale . '" frameborder="0"></iframe>';
    echo '</div>';
}

Now, this is working on Create Post page, but is not anywhere else.

I can see my button in Edit post, Create page and Edit page, but there's nothing inside the thickbox.

UPDATE: Still haven't been able to fix this problem. I've tried changing everything and nothing has improved. I'd really appreciate if someone could give me a hint, I don't seem to find any info about this, but I can't believe I'm the only one that has ever had this problem

2
Why are you adding this code to admin.php? - Daniel C
Well, I was looking for a way to add a thickbox where I could put different media content and found a web where they said this would work. I tried and it worked (or I thought so) at the first attempt. Is there anything wrong with it? I don't really understand how wordpress works, but I thought my code meant something like "add this button to wherever there is a media button, make it open a thickbox when clicked, and place the div with this id inside that thickbox". Am I mistaken? - Iskalla

2 Answers

1
votes

As far as your code not working, you have and error in your echo statement:

echo 'I'm ' . $cusername . ' and I'm testing my media thickbox';

You're single quotes are not properly escaped, so you're most likely generating an error message, which is why your thickbox is blank (WSOD). It should look like this:

echo 'I\'m ' . $cusername . ' and I\'m testing my media thickbox';

Or like this:

echo "I'm $cusername and I'm testing my media thickbox";

As far as how WordPress works... any code you add to manipulate the way the admin interface, or the front end interface, works should be added to your theme's functions.php file, or to a plugin. Changing WordPress core files is a very bad habit to get into because as soon as there is a new update, all of your changes will be overwritten.

In your case, you are adding this code to admin.php, which is inside the wp-admin folder, which is considered a core WordPress folder and file. You basically never want to touch anything inside wp-admin or wp-includes (or even on the root, except for the wp-config.php and possibly .htaccess if you know what you're doing). The wp-content folder is the only folder that will never get touched in a WordPress upgrade. This is why you want to add your code here, and not through the core files.

Move your code above to your theme's functions.php file, and it will still work the same. Make corrections to your echo statement as I have recommended, and you should see the content in the thickbox appear. Let me know if you have any other questions on how WordPress should work, and I'll be happy to help answer them!

0
votes

I ended up solving this by changing my two functions to only one, and setting the "button" to show the iframe directly, like this:

function add_custom_media_button() {
    $cu = wp_get_current_user();
    $cusername = $cu->user_login;
    $clocale = get_locale();
    echo '<a href="http://nephila.cloudapp.net/GAdEWeb/wpsearch.aspx?wpuser=' . $cusername . '&wplang=' . $clocale . '&TB_iframe=true&width=800&height=600" id="insert-my-media" class="button thickbox">Add custom media</a>';
}
add_action('media_buttons', 'add_custom_media_button', 15);