示例#1
0
/**
 * Save the post popup form
 */
function ajax_tp_saveEditPopup()
{
    if (!current_user_can('edit_posts')) {
        die;
    }
    if (!wp_verify_nonce($_REQUEST['tinypass_nonce'], 'tinypass_options')) {
        die('Security check failed');
    }
    tinypass_include();
    $storage = new TPStorage();
    $errors = array();
    $ss = $storage->getSiteSettings();
    $ps = $ss->validatePostSettings($_POST['tinypass'], $errors);
    $storage->savePostSettings($_POST['post_ID'], $ps);
    if (count($errors)) {
        echo "var a; tinypass.clearError(); ";
        foreach ($errors as $field => $msg) {
            echo "tinypass.doError('{$field}', \"{$msg}\");";
        }
        die;
    }
    $ps = $storage->getPostSettings($_POST['post_ID']);
    echo tinypass_post_options_summary($ps);
    die;
}
/**
 * Page integration - when a page is saved check for the checkbox to enable/disable Tinypass
 */
function tinypass_post_saved($postID)
{
    if (isset($_REQUEST['tp-post-save-nonce']) && wp_verify_nonce($_REQUEST['tp-post-save-nonce'], 'tp-post-save-nonce')) {
        tinypass_include();
        $storage = new TPStorage();
        $ps = $storage->getPostSettings($postID);
        if (isset($_POST['tinypass']) && isset($_POST['tinypass']['enabled'])) {
            $ps->setEnabled(true);
        } else {
            $ps->setEnabled(false);
        }
        $storage->savePostSettings($postID, $ps);
    }
}