mangosaft
mangosaft

Reputation: 31

Create a simple Wordpress plugin page with iframe?

I am creating a plugin page for Wordpress. This plugin page contains an iframe. But a suggested php method (instead of iframe html method) of yours would be nice too.

What is a problem is that this plugin page not responding. Because this plugin page has not created its own admin menu. What is wrong with this plugin page?

Here is code:

<?php
/*
Plugin Name: Leo
Plugin URI: http://www.example.com
Description: Blabla
Author: Leo
Version: 1.1
Author URI: http://www.example.com

function schedule() {
  ?>
    <h1>schedule</h1>
    <a href="/wp-admin/admin.php?page=schedulesite">Show schedule</a><br />
  <?PHP
}

function schedulesite() {
  echo "<iframe style="width:100%;height:800px;border=0;"
src="http://www.example.com/schedule.php"></iframe>";
}


function scheduleAddMenu() {
  add_menu_page('schedule', 'schedule', 10, __FILE__, 'schedule');
  add_submenu_page(__FILE__, 'Show schedule', 'Show schedule', 10, 'schedulesite', 'schedulesite');
}
?>

Upvotes: 0

Views: 2643

Answers (3)

AD Henrique
AD Henrique

Reputation: 195

If someone else is with the same doubt of the OP, follows steps.

You have some typos in your file.
Firstly, look to the header. You did not close the comment block. Add a simple */ at the end of the header. It is something like:

/*
Plugin Name: Leo
Plugin URI: http://www.example.com
Description: Blabla
Author: Leo
Version: 1.1
Author URI: http://www.example.com
*/

Secondly, in function schedule(), remove /wp-admin/ from ulr in href property. Like this:

function schedule() {   
  ?>
    <h1>schedule</h1>
    <a href="admin.php?page=schedulesite">Show schedule</a><br/>
  <?php
}

Thirdly, in function schedulesite(), add escape characters before the double quotes. Like this:

function schedulesite() {
  echo "<iframe style=\"width:100%;height:800px;border=0;\"
src=\"http://www.example.com/schedule.php\"></iframe>";
}

Fourthly and most important, you need to give a hook to the menu_admin. The hooks are part of the entire WordPress Core.

About hooks: Plugin API/Hooks
About admin_menu hook: Plugin API/Action Reference/admin menu

So, add at the end of your plugin, a simple hook like this:

add_action('admin_menu', 'scheduleAddMenu');

And your plugin will be able to work!
Note: Perhaps, you need to go to the plugins page and activate your plugin!

Upvotes: 0

Meier
Meier

Reputation: 3890

Your function scheduleAddMenu() is never called. You can just add a statement to call it at the end of the file.

Upvotes: 1

Steve
Steve

Reputation: 91

Not sure if you fixed this or not, but you need to correct this function:

function schedulesite() {
  echo "<iframe style="width:100%;height:800px;border=0;"
src="http://www.example.com/schedule.php"></iframe>";
}

Change it to:

function schedulesite() {
  echo '<iframe style="width:100%;height:800px;border=0;"
src="http://www.example.com/schedule.php"></iframe>';
}

You have double quotes (") around the string, when you should have single quotes (')

Upvotes: 2

Related Questions