Пример #1
0
 /**
  * Generates a postname hash for an optin.
  *
  * @since 2.0.0
  *
  * @return string The optin slug.
  */
 public function generate_postname_hash()
 {
     return optin_monster_ajax_generate_postname_hash();
 }
Пример #2
0
/**
 * Creates a new optin based on the theme selection of the user.
 *
 * @since 2.0.0
 */
function optin_monster_ajax_create_optin()
{
    // Run a security check first.
    check_ajax_referer('optin-monster-create', 'nonce');
    // Prepare variables.
    $theme = stripslashes($_POST['theme']);
    $type = stripslashes($_POST['type']);
    $title = stripslashes($_POST['title']);
    // Create the new optin based on the selection of the user.
    $data = array('post_name' => optin_monster_ajax_generate_postname_hash() . '-' . $type, 'post_type' => 'optin', 'post_status' => 'publish', 'post_title' => $title, 'menu_order' => -1);
    $optin_id = wp_insert_post($data);
    // Save the optin metadata for the theme, type and title.
    $meta = array('type' => $type, 'theme' => $theme);
    update_post_meta($optin_id, '_om_meta', $meta);
    // Flush any optin caches.
    Optin_Monster_Common::get_instance()->flush_optin_caches($optin_id, $data['post_name']);
    // Send back a redirect link.
    die(json_encode(add_query_arg(array('om_view' => 'edit', 'om_optin_id' => $optin_id), admin_url('admin.php?page=optin-monster-settings'))));
}