示例#1
0
function ojsimport_tools_page()
{
    //must check that the user has the required capability
    if (!current_user_can('manage_options')) {
        wp_die(__('You do not have sufficient permissions to access this page.'));
    }
    echo "<h2>" . __('ojs Import', 'menu-ojsimport') . "</h2>";
    $hidden_field_name = 'ojsimport_submit_hidden';
    // See if the user has posted us some information
    // If they did, this hidden field will be set to 'Y'
    if (isset($_POST[$hidden_field_name]) && $_POST[$hidden_field_name] == 'Y') {
        $class = "updated";
        if ($_POST['Import']) {
            $ret = ojsimport::import_all();
            if (is_wp_error($ret)) {
                $message = $ret->get_error_message();
                $class = "error";
            } else {
                $message = 'Successfully imported.' . "</br>" . $ret;
            }
        } else {
            if ($_POST['Delete']) {
                $ret = ojsimport::delete_all_imported();
                if (is_wp_error($ret)) {
                    $message = $ret->get_error_message();
                    $class = "error";
                } else {
                    $message = 'successfully deleted all imported posts.';
                }
            }
        }
        // Put the result  message on the screen
        ?>
<div id="message" class="<?php 
        echo $class;
        ?>
"><p><strong><?php 
        _e($message, 'menu-ojsimport');
        ?>
</strong></p></div>
<?php 
    }
    // tools form
    ?>

<form name="form1" method="post" action="">
<input type="hidden" name="<?php 
    echo $hidden_field_name;
    ?>
" value="Y">

<p class="submit">
<input type="submit" name="Import" class="button-primary" value="<?php 
    esc_attr_e('Import from ojs');
    ?>
" />
<input type="submit" name="Delete" class="button-secondary" value="<?php 
    esc_attr_e('Delete all imported');
    ?>
" />
</p>

</form>
</div>

<?php 
}