Exemplo n.º 1
2
function q_create_profilepage($userid)
{
    $quser = get_userdata($userid);
    $userpost = array('post_title' => $quser->display_name, 'post_content' => $quser->user_description, 'post_status' => 'publish', 'post_author' => $quser->ID, 'post_date' => $quser->registered, 'post_type' => 'quser');
    $postid = wp_insert_post($userpost);
    update_user_meta($userid, 'q_profilepage_id', $postid);
}
Exemplo n.º 2
0
function affiliate_wp_install()
{
    // Create affiliate caps
    $roles = new Affiliate_WP_Capabilities();
    $roles->add_caps();
    $affiliate_wp_install = new stdClass();
    $affiliate_wp_install->affiliates = new Affiliate_WP_DB_Affiliates();
    $affiliate_wp_install->affiliate_meta = new Affiliate_WP_Affiliate_Meta_DB();
    $affiliate_wp_install->referrals = new Affiliate_WP_Referrals_DB();
    $affiliate_wp_install->visits = new Affiliate_WP_Visits_DB();
    $affiliate_wp_install->creatives = new Affiliate_WP_Creatives_DB();
    $affiliate_wp_install->settings = new Affiliate_WP_Settings();
    $affiliate_wp_install->affiliates->create_table();
    $affiliate_wp_install->affiliate_meta->create_table();
    $affiliate_wp_install->referrals->create_table();
    $affiliate_wp_install->visits->create_table();
    $affiliate_wp_install->creatives->create_table();
    if (!get_option('affwp_is_installed')) {
        $affiliate_area = wp_insert_post(array('post_title' => __('Affiliate Area', 'affiliate-wp'), 'post_content' => '[affiliate_area]', 'post_status' => 'publish', 'post_author' => 1, 'post_type' => 'page', 'comment_status' => 'closed'));
        $options = $affiliate_wp_install->settings->get_all();
        $options['affiliates_page'] = $affiliate_area;
        update_option('affwp_settings', $options);
    }
    update_option('affwp_is_installed', '1');
    update_option('affwp_version', AFFILIATEWP_VERSION);
    // Clear rewrite rules
    flush_rewrite_rules();
    // Bail if activating from network, or bulk
    if (is_network_admin() || isset($_GET['activate-multi'])) {
        return;
    }
    // Add the transient to redirect
    set_transient('_affwp_activation_redirect', true, 30);
}
Exemplo n.º 3
0
 /**
  * Create or edit a a project
  *
  * @param null|int $project_id
  * @return int
  */
 function create($project_id = 0, $posted = array())
 {
     $is_update = $project_id ? true : false;
     $data = array('post_title' => $posted['project_name'], 'post_content' => $posted['project_description'], 'post_type' => 'project', 'post_status' => 'publish');
     if ($is_update) {
         $data['ID'] = $project_id;
         $project_id = wp_update_post($data);
     } else {
         $project_id = wp_insert_post($data);
     }
     if ($project_id) {
         $this->insert_project_user_role($posted, $project_id);
         wp_set_post_terms($project_id, $posted['project_cat'], 'project_category', false);
         if ($is_update) {
             do_action('cpm_project_update', $project_id, $data);
         } else {
             update_post_meta($project_id, '_project_archive', 'no');
             update_post_meta($project_id, '_project_active', 'yes');
             $settings = $this->settings_user_permission();
             update_post_meta($project_id, '_settings', $settings);
             do_action('cpm_project_new', $project_id, $data);
         }
     }
     return $project_id;
 }
Exemplo n.º 4
0
/**
 * Create a page and store the ID in an option.
 *
 * @access public
 * @param mixed $slug Slug for the new page
 * @param mixed $option Option name to store the page's ID
 * @param string $page_title (default: '') Title for the new page
 * @param string $page_content (default: '') Content for the new page
 * @param int $post_parent (default: 0) Parent for the new page
 * @return int page ID
 */
function wc_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0)
{
    global $wpdb;
    $option_value = get_option($option);
    if ($option_value > 0 && get_post($option_value)) {
        return -1;
    }
    $page_found = null;
    if (strlen($page_content) > 0) {
        // Search for an existing page with the specified page content (typically a shortcode)
        $page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type='page' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%"));
    } else {
        // Search for an existing page with the specified page slug
        $page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type='page' AND post_name = %s LIMIT 1;", $slug));
    }
    if ($page_found) {
        if (!$option_value) {
            update_option($option, $page_found);
        }
        return $page_found;
    }
    $page_data = array('post_status' => 'publish', 'post_type' => 'page', 'post_author' => 1, 'post_name' => $slug, 'post_title' => $page_title, 'post_content' => $page_content, 'post_parent' => $post_parent, 'comment_status' => 'closed');
    $page_id = wp_insert_post($page_data);
    if ($option) {
        update_option($option, $page_id);
    }
    return $page_id;
}
 /**
  * Activates the module
  *
  * Callback for "tml_activate_themed-profiles/themed-profiles.php" hook in method Theme_My_Login_Modules_Admin::activate_module()
  *
  * @see Theme_My_Login_Modules_Admin::activate_module()
  * @since 6.0
  * @access public
  */
 public function activate()
 {
     if (!($page_id = Theme_My_Login::get_page_id('profile'))) {
         $page_id = wp_insert_post(array('post_title' => __('Your Profile'), 'post_status' => 'publish', 'post_type' => 'page', 'post_content' => '[theme-my-login]', 'comment_status' => 'closed', 'ping_status' => 'closed'));
         update_post_meta($page_id, '_tml_action', 'profile');
     }
 }
Exemplo n.º 6
0
function generatePayment($data)
{
    if (empty($data['amount'])) {
        $data['amount'] = 10;
    }
    $return['result'] = true;
    $donationOptions = get_theme_mod('donation_options');
    $paypalEmail = $donationOptions['email'];
    $donor_data['post_title'] = $data['first_name'] . ' ' . $data['last_name'];
    $donor_data['post_type'] = 'donor';
    $donor_id = wp_insert_post($donor_data);
    update_post_meta($donor_id, 'donor_email', $data['email']);
    update_post_meta($donor_id, 'donor_phone', $data['phone']);
    update_post_meta($donor_id, 'donor_address', $data['address']);
    update_post_meta($donor_id, 'donor_note', $data['notes']);
    update_post_meta($donor_id, 'donor_amount', $data['amount']);
    if (!empty($data['sign_up'])) {
        update_post_meta($donor_id, 'donor_subscribe', $data['sign_up']);
    }
    if ($data['donation_id'] == 0) {
        update_post_meta($donor_id, 'donor_donation', '');
        $returnUrl = home_url();
        $items['item_name'] = __('Site Donation', STM_DOMAIN);
    } else {
        update_post_meta($donor_id, 'donor_donation', get_the_title($data['donation_id']));
        $returnUrl = get_permalink($data['donation_id']);
        $items['item_name'] = get_the_title($data['donation_id']);
    }
    $items['item_number'] = $data['donation_id'];
    $items['amount'] = $data['amount'];
    $items = http_build_query($items);
    $return = 'https://' . paypal_url() . '/cgi-bin/webscr?cmd=_xclick&business=' . $paypalEmail . '&' . $items . '&no_shipping=1&no_note=1&currency_code=' . $donationOptions['currency'] . '&bn=PP%2dBuyNowBF&charset=UTF%2d8&invoice=' . $donor_id . '&return=' . $returnUrl . '&rm=2&notify_url=' . $returnUrl;
    return $return;
}
Exemplo n.º 7
0
 function setUp()
 {
     parent::setUp();
     $this->post_date_ts = strtotime('+1 day');
     $this->post_data = array('post_type' => 'page', 'post_title' => rand_str(), 'post_content' => rand_str(2000), 'post_excerpt' => rand_str(100), 'post_author' => $this->make_user_by_role('author'), 'post_date' => strftime("%Y-%m-%d %H:%M:%S", $this->post_date_ts));
     $this->post_id = wp_insert_post($this->post_data);
 }
Exemplo n.º 8
0
 public function make_up_room()
 {
     //$post_arr=$arr;
     $post_arr->post_title = "Test123";
     $post_arr->post_slug = "Test123";
     $post_arr->post_status = "draft";
     $post_arr->post_type = "make_up_room";
     $post = wp_insert_post($post_arr, $wp_error);
     return array('post' => $post);
     /*     global $json_api;
         if (!current_user_can('edit_posts')) {
           $json_api->error("You need to login with a user that has 'edit_posts' capacity.");
         }
         if (!$json_api->query->nonce) {
           $json_api->error("You must include a 'nonce' value to create posts. Use the `get_nonce` Core API method.");
         }
         $nonce_id = $json_api->get_nonce_id('posts', 'create_post');
         if (!wp_verify_nonce($json_api->query->nonce, $nonce_id)) {
           $json_api->error("Your 'nonce' value was incorrect. Use the 'get_nonce' API method.");
         }
         nocache_headers();
         $post = new JSON_API_Post();
         $id = $post->create($_REQUEST);
         if (empty($id)) {
           $json_api->error("Could not create post.");
         }
         return array(
           'post' => $post
         );*/
 }
Exemplo n.º 9
0
/**
 * Converts the old WCS2 data to the new WCS3 format.
 * 
 * @param array $data: data array as returned from wcs3_get_static_wcs2_data
 */
function wcs3_create_new_wcs3_static_data($data)
{
    foreach ($data as $post_type => $content) {
        if ($post_type == 'classes') {
            foreach ($data['classes'] as $key => $class) {
                $new_post = array('post_content' => $class['class_description'], 'post_title' => $class['class_name'], 'post_type' => 'wcs3_class', 'post_status' => 'publish');
                $data['classes'][$key]['new_id'] = wp_insert_post($new_post);
            }
        } else {
            if ($post_type == 'instructors') {
                foreach ($data['instructors'] as $key => $inst) {
                    $new_post = array('post_content' => $inst['instructor_description'], 'post_title' => $inst['instructor_name'], 'post_type' => 'wcs3_instructor', 'post_status' => 'publish');
                    $data['instructors'][$key]['new_id'] = wp_insert_post($new_post);
                }
            } else {
                if ($post_type == 'classrooms') {
                    foreach ($data['classrooms'] as $key => $loc) {
                        $new_post = array('post_content' => $loc['classroom_description'], 'post_title' => $loc['classroom_name'], 'post_type' => 'wcs3_location', 'post_status' => 'publish');
                        $data['classrooms'][$key]['new_id'] = wp_insert_post($new_post);
                    }
                }
            }
        }
    }
    // Return data with new IDs.
    return $data;
}
Exemplo n.º 10
0
 function manager_admin_init()
 {
     if (isset($_POST['key']) && $_POST['key'] == "ioamediamanager") {
         $type = $_POST['type'];
         switch ($type) {
             case "create":
                 $slider_title = $_POST['value'];
                 $slider_post = array('post_title' => $slider_title, 'post_type' => 'slider');
                 $id = wp_insert_post($slider_post);
                 echo "\r\n\r\n\t\t\t\t\t\t<div class='slider-item clearfix'>\r\n\t\t\t\t\t\t\t     \t\t<a href='" . admin_url() . "admin.php?page=ioamed&edit_id={$id}' class='edit-icon pencil-3icon- ioa-front-icon'></a>\r\n\t\t\t\t\t\t\t     \t\t<h6>" . $slider_title . "</h6>\r\n\t\t\t\t\t\t\t     \t\t<span class='shortcode'> " . __('Shortcode', 'ioa') . " [slider id='{$id}'] </span>\r\n\t\t\t\t\t\t\t\t\t\t<a href='{$id}' class='close cancel-circled-2icon- ioa-front-icon'></a>\r\n\t\t\t\t\t\t</div> \r\n\t\t\t\t\t";
                 break;
             case "update":
                 $id = $_POST['id'];
                 $ioa_options = $slides = '';
                 if (isset($_POST['options'])) {
                     $ioa_options = $_POST['options'];
                 }
                 if (isset($_POST['slides'])) {
                     $slides = $_POST['slides'];
                 }
                 wp_publish_post($id);
                 update_post_meta($id, "options", $ioa_options);
                 update_post_meta($id, "slides", $slides);
                 break;
             case "delete":
                 $id = $_POST['id'];
                 wp_delete_post($id, true);
         }
         die;
     }
 }
Exemplo n.º 11
0
function lp_duplicate_post_create_duplicate($post, $status = '', $parent_id = '', $blank = false)
{
    $prefix = "";
    $suffix = "";
    if (!is_object($post) && is_numeric($post)) {
        $post = get_post($post);
    }
    $status = $post->post_status;
    /* We don't want to clone revisions */
    if ($post->post_type == 'revision') {
        return;
    }
    if ($post->post_type != 'attachment') {
        $prefix = "Copy of ";
        $suffix = "";
        $status = 'pending';
    }
    $new_post_author = lp_duplicate_post_get_current_user();
    if ($blank == false) {
        $new_post = array('menu_order' => $post->menu_order, 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'post_author' => $new_post_author->ID, 'post_content' => $post->post_content, 'post_excerpt' => $post->post_excerpt, 'post_mime_type' => $post->post_mime_type, 'post_parent' => $new_post_parent = empty($parent_id) ? $post->post_parent : $parent_id, 'post_password' => $post->post_password, 'post_status' => $status, 'post_title' => $prefix . $post->post_title . $suffix, 'post_type' => $post->post_type);
        $new_post['post_date'] = $new_post_date = $post->post_date;
        $new_post['post_date_gmt'] = get_gmt_from_date($new_post_date);
    } else {
        $new_post = array('menu_order' => $post->menu_order, 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'post_author' => $new_post_author->ID, 'post_content' => "", 'post_excerpt' => "", 'post_mime_type' => $post->post_mime_type, 'post_status' => $status, 'post_title' => __("New Blank Landing Page", 'landing-pages'), 'post_type' => $post->post_type, 'post_date' => date('Y-m-d H:i:s'));
    }
    $new_post_id = wp_insert_post($new_post);
    $meta_data = lp_get_post_meta_all($post->ID);
    foreach ($meta_data as $key => $value) {
        update_post_meta($new_post_id, $key, $value);
    }
    return $new_post_id;
}
Exemplo n.º 12
0
 function maybe_import_post($guid, $post_arr)
 {
     $results = array();
     if ($this->post_exists($guid)) {
         $results[] = "<p>{$guid} already exists</p>";
     } else {
         $results[] = "<p>{$guid} does not alread exist</p>";
         $post_title = $post_arr['title'];
         $post_content = $post_arr['content'];
         $author_exists = $this->author_exists($post_arr['author']);
         if (!$author_exists) {
             $results[] = "<p>{$guid} author does not already exist</p>";
             $author_id = $this->import_author($post_arr['author']);
             if (!empty($author_id)) {
                 $results[] = "<p>{$guid} author added as author_id {$author_id}</p>";
             }
         } else {
             $results[] = "<p>{$guid} author already exists as id {$author_exists}</p>";
             $author_id = $author_exists;
             add_user_to_blog(get_current_blog_id(), $author_id, 'subscriber');
         }
         $post_excerpt = $post_arr['description'];
         $args = array('post_title' => $post_title, 'post_content' => $post_content, 'post_author' => $author_id, 'post_excerpt' => $post_excerpt);
         $new_post_id = wp_insert_post($args);
         if (!empty($new_post_id)) {
             $results[] = "<p>{$guid} was inserted as post ID {$new_post_id}</p>";
             add_post_meta($new_post_id, SJF_GF . "-guid", $guid, TRUE);
         } else {
             $results[] = "<p>{$guid} could not be inserted</p>";
         }
     }
     return $results;
 }
Exemplo n.º 13
0
 /**
  * Returns post ID of custom post type 'contesthopper' with 'auto-draft' status. If none exists, it creates new one.
  * @return int Contest ID
  */
 public static function get_new_id()
 {
     global $wpdb;
     $args = array('post_type' => CH_Manager::post_type, 'post_status' => 'auto-draft');
     $query = new WP_Query($args);
     if (count($query->posts) == 0) {
         $new_id = wp_insert_post($args);
         $datetimes = self::get_default_times();
         update_post_meta($new_id, 'ch_disclaimer_rules_type', 'none');
         update_post_meta($new_id, 'ch_media_description_layout', 'media-top');
         update_post_meta($new_id, 'ch_widget_size', '640');
         update_post_meta($new_id, 'ch_headline_color', '#ffffff');
         update_post_meta($new_id, 'ch_headline_font', 'arial');
         update_post_meta($new_id, 'ch_description_color', '#000000');
         update_post_meta($new_id, 'ch_description_font', 'arial');
         update_post_meta($new_id, 'ch_title_background_color', '#40b3df');
         update_post_meta($new_id, 'ch_background_color', '#ffffff');
         update_post_meta($new_id, 'ch_border_color', '#2a71a2');
         update_post_meta($new_id, 'ch_winners_num', '1');
         update_post_meta($new_id, 'ch_referral_entries', '1');
         update_post_meta($new_id, 'ch_timezone', $datetimes['timezone']);
         update_post_meta($new_id, 'ch_date_start', $datetimes['start']);
         update_post_meta($new_id, 'ch_date_end', $datetimes['end']);
         update_post_meta($new_id, 'ch_submit_text', __('Join sweepstakes', 'contesthopper'));
         update_post_meta($new_id, 'ch_from_email', '"Contesthopper" <' . get_option('admin_email') . '>');
         return $new_id;
     }
     return $query->posts[0]->ID;
     // return existing auto-draft ID
 }
Exemplo n.º 14
0
 function saveData($items, $thisPage, $pages)
 {
     $complete = true;
     foreach ($items as $item) {
         $cons = "SELECT * FROM wp_postmeta WHERE meta_key = 'fr-id' AND meta_value = '" . $item->id . "'";
         $result = mysql_query($cons) or die(mysql_error());
         if (mysql_num_rows($result)) {
             $complete = false;
             echo "<br> Aborting: photo already loaded " . $item->id;
             break;
         } else {
             echo "<br> Importing picture " . $item->id;
             $date = gmdate("Y-m-d H:i:s", $item->dateupload);
             $my_post_test = array('post_title' => $item->title, 'post_content' => $item->description->_content, 'post_status' => 'publish', 'post_author' => 1, 'post_type' => "fr-pic", 'post_date' => $date);
             $post_id = wp_insert_post($my_post_test, $wp_error);
             add_post_meta($post_id, 'fr-id', $item->id);
             add_post_meta($post_id, 'small-pic', $item->url_s);
             add_post_meta($post_id, 'big-pic', $item->url_l);
         }
     }
     if ($thisPage < $pages && $complete) {
         $this->fetchData($thisPage + 1);
     } else {
         echo "<br> FLICKR JOB COMPLETED";
     }
 }
Exemplo n.º 15
0
 /**
  * Clones provided page ID
  * @param  int $pageId
  * @return int
  */
 public function clonePage($pageId)
 {
     $oldPost = get_post($pageId);
     if (null === $oldPost) {
         return 0;
     }
     if ('revision' === $oldPost->post_type) {
         return 0;
     }
     $currentUser = wp_get_current_user();
     $newPost = array('menu_order' => $oldPost->menu_order, 'comment_status' => $oldPost->comment_status, 'ping_status' => $oldPost->ping_status, 'post_author' => $currentUser->ID, 'post_content' => $oldPost->post_content, 'post_excerpt' => $oldPost->post_excerpt, 'post_mime_type' => $oldPost->post_mime_type, 'post_parent' => $oldPost->post_parent, 'post_password' => $oldPost->post_password, 'post_status' => $oldPost->post_status, 'post_title' => '(dup) ' . $oldPost->post_title, 'post_type' => $oldPost->post_type, 'post_date' => $oldPost->post_date, 'post_date_gmt' => get_gmt_from_date($oldPost->post_date));
     $newId = wp_insert_post($newPost);
     /*
      * Generating unique slug
      */
     if ($newPost['post_status'] == 'publish' || $newPost['post_status'] == 'future') {
         $postName = wp_unique_post_slug($oldPost->post_name, $newId, $newPost['post_status'], $oldPost->post_type, $newPost['post_parent']);
         $newPost = array();
         $newPost['ID'] = $newId;
         $newPost['post_name'] = $postName;
         wp_update_post($newPost);
     }
     $this->cloneMeta($pageId, $newId);
     $this->cloneOpData($pageId, $newId);
     return $newId;
 }
Exemplo n.º 16
0
        /**
         * import function.
         *
         * @access public
         * @param array $array
         * @param array $columns
         * @return void
         */
        function import($array = array(), $columns = array('post_title'))
        {
            $this->imported = $this->skipped = 0;
            if (!is_array($array) || !sizeof($array)) {
                $this->footer();
                die;
            }
            $rows = array_chunk($array, sizeof($columns));
            foreach ($rows as $row) {
                $row = array_filter($row);
                if (empty($row)) {
                    continue;
                }
                $meta = array();
                foreach ($columns as $index => $key) {
                    $meta[$key] = sp_array_value($row, $index);
                }
                $name = sp_array_value($meta, 'post_title');
                if (!$name) {
                    $this->skipped++;
                    continue;
                }
                $args = array('post_type' => 'sp_sponsor', 'post_status' => 'publish', 'post_title' => $name);
                $id = wp_insert_post($args);
                // Update URL
                update_post_meta($id, 'sp_url', sp_array_value($meta, 'sp_url'));
                $this->imported++;
            }
            // Show Result
            echo '<div class="updated settings-error below-h2"><p>
				' . sprintf(__('Import complete - imported <strong>%s</strong> sponsors and skipped <strong>%s</strong>.', 'prosports'), $this->imported, $this->skipped) . '
			</p></div>';
            $this->import_end();
        }
Exemplo n.º 17
0
 public function create_idx_pages()
 {
     $saved_links = $this->idx_api->idx_api_get_savedlinks();
     $system_links = $this->idx_api->idx_api_get_systemlinks();
     if (!is_array($system_links) || !is_array($saved_links)) {
         return;
     }
     $idx_links = array_merge($saved_links, $system_links);
     $existing_page_urls = $this->get_existing_idx_page_urls();
     foreach ($idx_links as $link) {
         if (!in_array($link->url, $existing_page_urls)) {
             if (!empty($link->name)) {
                 $name = $link->name;
             } else {
                 if ($link->linkTitle) {
                     $name = $link->linkTitle;
                 }
             }
             $post = array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_name' => $link->url, 'post_content' => '', 'post_status' => 'publish', 'post_title' => $name, 'post_type' => 'idx_page');
             // filter sanitize_tite so it returns the raw title
             add_filter('sanitize_title', array($this, 'sanitize_title_filter'), 10, 2);
             wp_insert_post($post);
         }
     }
 }
Exemplo n.º 18
0
 /**
  * Saves the term selected on the edit user/profile page in the admin. This function is triggered when the page
  * is updated.  We just grab the posted data and use wp_set_object_terms() to save it.
  *
  * @param int $user_id The ID of the user to save the terms for.
  */
 public function wepn_save_user_city_group_category($user_id)
 {
     if (!WEPN_Helper::check_user_role('vendor', $user_id)) {
         return;
     }
     global $wpdb;
     $company_name = esc_attr($_POST['company_name']);
     $company_id = get_user_meta($user_id, 'company', true);
     if ($company_id && is_numeric($company_id)) {
         wp_update_post(array('ID' => $company_id, 'post_title' => $company_name, 'post_author' => $user_id, 'post_type' => 'vendor', 'post_status' => 'publish'));
     } else {
         $company_id = $wpdb->get_var("SELECT ID FROM wp_posts WHERE post_title = '" . $company_name . "'");
         if (!empty($company_name) && !$company_id) {
             $company_id = wp_insert_post(array('post_title' => $company_name, 'post_author' => $user_id, 'post_type' => 'vendor', 'post_status' => 'publish'));
             update_user_meta($user_id, 'company', $company_id);
         }
     }
     // Update Post Meta
     update_post_meta($company_id, 'vendor', $user_id);
     //Only administrator can change this section
     if (current_user_can('manage_options')) {
         $city = $_POST['city'];
         $group = $_POST['group'];
         $category = $_POST['category'];
         $group_slug = sanitize_title($group);
         $category_slug = sanitize_title($category);
         $other_categories = (array) (!empty($_POST['categories']) ? $_POST['categories'] : array());
         // Remove existing post and term relatinships
         $old_tax = get_post_meta($company_id, 'city', true);
         wp_delete_object_term_relationships($company_id, $old_tax);
         if (!in_array($category, $other_categories)) {
             $other_categories = array_merge($other_categories, array($category));
         }
         if (count($other_categories) > 0) {
             $terms = array();
             foreach ($other_categories as $term_title) {
                 if (empty($term_title)) {
                     continue;
                 }
                 $term_slug = sanitize_title($term_title);
                 if (!($term = term_exists($term_title, $city))) {
                     $term = wp_insert_term($term_title, $city, array('slug' => $term_slug));
                 }
                 if (!is_wp_error($term)) {
                     $terms[] = $term['term_id'];
                 }
             }
             wp_set_post_terms($company_id, $terms, $city, false);
         }
         // Update custom permalink
         update_post_meta($company_id, 'custom_permalink', $city . '/' . $group_slug . '/' . $category_slug . '/' . sanitize_title($company_name));
         update_post_meta($company_id, 'region', $group_slug);
         update_post_meta($company_id, 'city', $city);
         update_post_meta($company_id, 'category', $category_slug);
         // Update user meta
         update_user_meta($user_id, 'city', $city);
         update_user_meta($user_id, 'group', $group_slug);
         update_user_meta($user_id, 'category', $category_slug);
     }
 }
 /**
  * Log when a user is logged in
  *
  * @param $user_login
  * @param $user
  */
 public function spamlytics_user_logout($user_login, $user)
 {
     $post_id = wp_insert_post(array('post_title' => 'LOGOUT', 'post_content' => 'User ' . $user_login . ' logged out from ' . $_SERVER['REMOTE_ADDR'], 'post_status' => 'inherit', 'post_type' => 'spamlytics_log'));
     update_post_meta($post_id, 'ip_address', $_SERVER['REMOTE_ADDR']);
     update_post_meta($post_id, 'type', 'LOGOUT');
     update_post_meta($post_id, 'spam_type', 'User');
 }
Exemplo n.º 20
0
 /**
  * Save the Import
  */
 private function saveImport()
 {
     $title = __('Import on ', 'wpsimplelocator') . date_i18n('Y-m-d H:m:s', time());
     $importpost = array('post_title' => $title, 'post_status' => 'publish', 'post_type' => 'wpslimport');
     $post_id = wp_insert_post($importpost);
     add_post_meta($post_id, 'wpsl_import_data', $this->transient);
 }
Exemplo n.º 21
0
 /**
  * Create a submission.
  * 
  * @access public
  * @since 2.7
  * @return int $sub_id
  */
 public function create($form_id = '')
 {
     // Create Submission
     $post = array('post_status' => 'publish', 'post_type' => 'nf_sub');
     $sub_id = wp_insert_post($post);
     // Add our form ID to the submission
     Ninja_Forms()->sub($sub_id)->update_form_id($form_id);
     // Get the current sequential ID
     $form = ninja_forms_get_form_by_id($form_id);
     if (isset($form['data']['last_sub'])) {
         $seq_num = $form['data']['last_sub'] + 1;
     } else {
         // If we don't have a starting number, start at 1
         $seq_num = 1;
     }
     $seq_num = apply_filters('nf_sub_seq_num', $seq_num, $form_id);
     // Add the sequential ID to the post meta
     Ninja_Forms()->sub($sub_id)->update_seq_num($seq_num);
     // Update our form data with the new "last seq id."
     $form['data']['last_sub'] = $seq_num;
     $args = array('update_array' => array('data' => serialize($form['data'])), 'where' => array('id' => $form_id));
     ninja_forms_update_form($args);
     // Update our sub count
     Ninja_Forms()->form($form_id)->sub_count = $seq_num - 1;
     return $sub_id;
 }
Exemplo n.º 22
0
 public function add_album_archive_page()
 {
     if (get_page_by_title('Galleries') == false) {
         $page = array('post_title' => 'Galleries', 'post_content' => '', 'post_status' => 'publish', 'post_author' => 1, 'post_type' => 'page', 'post_slug' => 'gallery');
         $page_id = wp_insert_post($page);
     }
 }
function bbconnect_create_search_post()
{
    // RUN A SECURITY CHECK
    if (!wp_verify_nonce($_POST['bbconnect_report_nonce'], 'bbconnect-report-nonce')) {
        die('terribly sorry.');
    }
    global $current_user;
    if (!empty($_POST)) {
        $post = array('post_content' => serialize($_POST['data']['search']), 'post_title' => $_POST['data']['postTitle'], 'post_status' => 'publish', 'post_type' => 'savedsearch', 'post_author' => $current_user->ID);
        $wp_error = wp_insert_post($post, $wp_error);
        if (!is_array($wp_error)) {
            add_post_meta($wp_error, 'private', $_POST['data']['privateV']);
            add_post_meta($wp_error, 'segment', $_POST['data']['segment']);
            add_post_meta($wp_error, 'category', $_POST['data']['category']);
            if (false === $recently_saved) {
                $recently_saved = array();
            }
            set_transient('bbconnect_' . $current_user->ID . '_last_saved', $wp_error, 3600);
            echo '<div class="updated update-nag"  style="width:95%; border-left: 4px solid #7ad03a;"><p>Search has been saved as <a href="/post.php?post=' . $wp_error . '&action=edit">savedsearch-' . $wp_error . '</a></p></div>' . "\n";
        } else {
            echo '<div class="updated"><p>Search has not been saved' . var_dump($wp_error) . '</a></p></div>' . "\n";
        }
    }
    die;
}
Exemplo n.º 24
0
 public static function create($slug)
 {
     $args = array('post_name' => $slug, 'post_title' => $slug, 'post_type' => 'plugin', 'post_status' => 'publish');
     $post_id = wp_insert_post($args);
     $post = get_post($post_id);
     return $post;
 }
 /**
  * Create a single webhook.
  *
  * @param WP_REST_Request $request Full details about the request.
  * @return WP_Error|WP_REST_Response
  */
 public function create_item($request)
 {
     if (!empty($request['id'])) {
         return new WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400));
     }
     // Validate topic.
     if (empty($request['topic']) || !wc_is_webhook_valid_topic(strtolower($request['topic']))) {
         return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_topic", __('Webhook topic is required and must be valid.', 'woocommerce'), array('status' => 400));
     }
     // Validate delivery URL.
     if (empty($request['delivery_url']) || !wc_is_valid_url($request['delivery_url'])) {
         return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_delivery_url", __('Webhook delivery URL must be a valid URL starting with http:// or https://.', 'woocommerce'), array('status' => 400));
     }
     $post = $this->prepare_item_for_database($request);
     if (is_wp_error($post)) {
         return $post;
     }
     $post->post_type = $this->post_type;
     $post_id = wp_insert_post($post, true);
     if (is_wp_error($post_id)) {
         if (in_array($post_id->get_error_code(), array('db_insert_error'))) {
             $post_id->add_data(array('status' => 500));
         } else {
             $post_id->add_data(array('status' => 400));
         }
         return $post_id;
     }
     $post->ID = $post_id;
     $webhook = new WC_Webhook($post_id);
     // Set topic.
     $webhook->set_topic($request['topic']);
     // Set delivery URL.
     $webhook->set_delivery_url($request['delivery_url']);
     // Set secret.
     $webhook->set_secret(!empty($request['secret']) ? $request['secret'] : '');
     // Set status.
     if (!empty($request['status'])) {
         $webhook->update_status($request['status']);
     }
     $post = get_post($post_id);
     $this->update_additional_fields_for_object($post, $request);
     /**
      * Fires after a single item is created or updated via the REST API.
      *
      * @param WP_Post         $post      Inserted object.
      * @param WP_REST_Request $request   Request object.
      * @param boolean         $creating  True when creating item, false when updating.
      */
     do_action("woocommerce_rest_insert_{$this->post_type}", $post, $request, true);
     $request->set_param('context', 'edit');
     $response = $this->prepare_item_for_response($post, $request);
     $response = rest_ensure_response($response);
     $response->set_status(201);
     $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $post_id)));
     // Send ping.
     $webhook->deliver_ping();
     // Clear cache.
     delete_transient('woocommerce_webhook_ids');
     return $response;
 }
Exemplo n.º 26
0
 public function setUp()
 {
     global $wpdb;
     parent::setUp();
     register_taxonomy('edu_test_tax_1', 'post');
     register_taxonomy('edu_test_tax_2', 'post');
     $t1 = wp_insert_term('Edu', 'edu_test_tax_1');
     $t2 = wp_insert_term('Edu', 'edu_test_tax_2');
     $t3 = wp_insert_term('Edu', 'ib_educator_category');
     $t4 = wp_insert_term('Mathematics', 'ib_educator_category');
     // Arbitrary term.
     $wpdb->update($wpdb->term_taxonomy, array('term_id' => $t1['term_id']), array('term_taxonomy_id' => $t2['term_taxonomy_id']), array('%d'), array('%d'));
     $wpdb->update($wpdb->term_taxonomy, array('term_id' => $t1['term_id']), array('term_taxonomy_id' => $t3['term_taxonomy_id']), array('%d'), array('%d'));
     $t2['term_id'] = $t1['term_id'];
     $t3['term_id'] = $t1['term_id'];
     // Create membership.
     $post_id = wp_insert_post(array('post_type' => 'ib_edu_membership', 'post_name' => 'edu-membership-1', 'post_title' => 'edu membership 1', 'post_status' => 'publish'));
     $ms = Edr_Memberships::get_instance();
     $meta = $ms->get_membership_meta();
     $meta['price'] = '10.05';
     $meta['period'] = '';
     $meta['duration'] = '';
     $meta['categories'] = array($t3['term_id'], $t4['term_id']);
     update_post_meta($post_id, '_ib_educator_membership', $meta);
     $this->posts[] = $post_id;
     $this->terms = array('term1' => $t1, 'term2' => $t2, 'term3' => $t3, 'term4' => $t4);
 }
Exemplo n.º 27
0
 /**
  * Adds the post to the relevant site
  *
  * @param $post
  *
  * @param $blog
  *
  * @return int|\WP_Error
  */
 public function add_post($post, $blog)
 {
     if (!$blog || $this->post_exists($post, $blog)) {
         return FALSE;
     }
     $original_post_id = $post->ID;
     // store temp so that we can return it to the original post
     $source_content_id = Wpml2mlp_Helper::get_default_post_ID($post);
     $meta = get_post_meta($post->ID);
     $post->ID = NULL;
     // reset the post_id, new one will be created
     switch_to_blog((int) $blog['blog_id']);
     $new_post_id = wp_insert_post((array) $post);
     if ($new_post_id > 0) {
         foreach ($meta as $key => $value) {
             update_post_meta($new_post_id, $key, $value[0]);
         }
     }
     restore_current_blog();
     if (0 < $new_post_id) {
         $this->content_relations->set_relation(Wpml2mlp_Helper::get_default_blog(), (int) $blog['blog_id'], $source_content_id, $new_post_id, $post->post_type);
     }
     $post->ID = $original_post_id;
     return $new_post_id;
 }
 public function fetch($client_id, $tag)
 {
     global $wpdb;
     $instagram = new \Instagram\Instagram();
     $instagram->setClientId($client_id);
     $min_tag_id = get_option("last_instagram_tag_{$tag}_id", 0);
     $tag = $instagram->getTag($tag);
     $media = $tag->getMedia(array('min_tag_id' => $min_tag_id));
     update_option("last_instagram_tag_{$tag}_id", $media->getNextMaxTagId());
     foreach ($media as $m) {
         $query = "SELECT posts.* FROM " . $wpdb->posts . " AS posts\n        INNER JOIN " . $wpdb->postmeta . " AS wpostmeta ON wpostmeta.post_id = posts.ID\n        AND wpostmeta.meta_key = 'degg_instagram_id'\n        AND wpostmeta.meta_value = '{$m->getID()}'";
         $posts = $wpdb->get_results($query, ARRAY_A);
         if (!$posts) {
             $id = wp_insert_post(array('post_title' => "{$m->getUser()} on {$m->getCreatedTime('M jS Y @ g:ia')}", 'post_content' => "<img src='{$m->getThumbnail()->url}' title='Posted by {$m->getUser()} on {$m->getCreatedTime('M jS Y @ g:ia')}'>", 'post_type' => 'degg_instagram'));
             add_post_meta($id, 'degg_instagram_id', "{$m->getID()}", true);
             add_post_meta($id, 'degg_instagram_title', "Posted by {$m->getUser()} on {$m->getCreatedTime('M jS Y @ g:ia')}", true);
             add_post_meta($id, 'degg_instagram_user', "{$m->getUser()}", true);
             add_post_meta($id, 'degg_instagram_caption', "{$m->getCaption()}", true);
             add_post_meta($id, 'degg_instagram_link', "{$m->getLink()}", true);
             add_post_meta($id, 'degg_instagram_thumbnail', $m->getThumbnail(), true);
             add_post_meta($id, 'degg_instagram_standard_res', $m->getStandardRes(), true);
             add_post_meta($id, 'degg_instagram_low_res', $m->getLowRes(), true);
             wp_publish_post($id);
         }
     }
 }
Exemplo n.º 29
0
/**
 * Runs on plugin activations
 * - Transfer any settings which may have been set in the Lite version of the plugin
 * - Creates a post type 'mc4wp-form' and enters the form mark-up from the Lite version
 */
function mc4wp_pro_install()
{
    // check if PRO option exists and contains data entered by user
    $pro_options = get_option('mc4wp', false);
    if ($pro_options !== false) {
        return false;
    }
    $default_options = array();
    $default_options['general'] = array('api_key' => '', 'license_key' => '');
    $default_options['checkbox'] = array('label' => 'Sign me up for the newsletter!', 'precheck' => 1, 'css' => 0, 'show_at_comment_form' => 0, 'show_at_registration_form' => 0, 'show_at_multisite_form' => 0, 'show_at_buddypress_form' => 0, 'show_at_edd_checkout' => 0, 'show_at_woocommerce_checkout' => 0, 'show_at_bbpress_forms' => 0, 'lists' => array(), 'double_optin' => 1, 'send_welcome' => 0);
    $default_options['form'] = array('css' => 0, 'custom_theme_color' => '#1af', 'ajax' => 1, 'double_optin' => 1, 'update_existing' => 0, 'replace_interests' => 1, 'send_welcome' => 0, 'text_success' => 'Thank you, your sign-up request was successful! Please check your e-mail inbox.', 'text_error' => 'Oops. Something went wrong. Please try again later.', 'text_invalid_email' => 'Please provide a valid email address.', 'text_already_subscribed' => 'Given email address is already subscribed, thank you!', 'redirect' => '', 'hide_after_success' => 0, 'send_email_copy' => 0);
    $lite_settings = array('general' => (array) get_option('mc4wp_lite'), 'checkbox' => (array) get_option('mc4wp_lite_checkbox'), 'form' => (array) get_option('mc4wp_lite_form'));
    foreach ($default_options as $group_key => $options) {
        foreach ($options as $option_key => $option_value) {
            if (isset($lite_settings[$group_key][$option_key]) && !empty($lite_settings[$group_key][$option_key])) {
                $default_options[$group_key][$option_key] = $lite_settings[$group_key][$option_key];
            }
        }
    }
    // Transfer form from Lite, but only if no Pro forms exist yet.
    $forms = get_posts(array('post_type' => 'mc4wp-form', 'post_status' => 'publish'));
    if (false == $forms) {
        // no forms found, try to transfer from lite.
        $form_markup = isset($lite_settings['form']['markup']) ? $lite_settings['form']['markup'] : "<p>\n\t<label for=\"mc4wp_email\">Email address: </label>\n\t<input type=\"email\" id=\"mc4wp_email\" name=\"EMAIL\" required placeholder=\"Your email address\" />\n</p>\n\n<p>\n\t<input type=\"submit\" value=\"Sign up\" />\n</p>";
        $form_ID = wp_insert_post(array('post_type' => 'mc4wp-form', 'post_title' => 'Sign-Up Form #1', 'post_content' => $form_markup, 'post_status' => 'publish'));
        $lists = isset($lite_settings['form']['lists']) ? $lite_settings['form']['lists'] : array();
        update_post_meta($form_ID, '_mc4wp_settings', array('lists' => $lists));
        update_option('mc4wp_default_form_id', $form_ID);
    }
    // store options
    update_option('mc4wp', $default_options['general']);
    update_option('mc4wp_checkbox', $default_options['checkbox']);
    update_option('mc4wp_form', $default_options['form']);
}
function ajax_contact_form()
{
    $response = array();
    $navn = isset($_POST['navn']) ? wp_strip_all_tags($_POST['navn']) : false;
    $email = isset($_POST['email']) ? wp_strip_all_tags($_POST['email']) : false;
    $firma = isset($_POST['firma']) ? wp_strip_all_tags($_POST['firma']) : false;
    $telefon = isset($_POST['telefon']) ? wp_strip_all_tags($_POST['telefon']) : false;
    $about = isset($_POST['about']) ? wp_strip_all_tags($_POST['about']) : false;
    $kommentar = isset($_POST['kommentar']) ? esc_textarea($_POST['kommentar']) : false;
    if (!$navn) {
        $response['error'] = 'Indtast et navn';
    } else {
        if (!$email) {
            $response['error'] = 'Indtast en email';
        }
    }
    if (!isset($response['error'])) {
        $post_vars = array('post_title' => $navn . ' [' . $email . ']', 'post_status' => 'publish', 'post_type' => 'form');
        $response['post_id'] = wp_insert_post($post_vars, true);
        if (is_wp_error($response['post_id'])) {
            $response['error'] = $return->get_error_message();
        }
    }
    if (!isset($response['error'])) {
        update_post_meta($response['post_id'], 'form_navn', $navn);
        update_post_meta($response['post_id'], 'form_email', $email);
        update_post_meta($response['post_id'], 'form_firma', $firma);
        update_post_meta($response['post_id'], 'form_telefon', $telefon);
        update_post_meta($response['post_id'], 'form_about', $about);
        update_post_meta($response['post_id'], 'form_kommentar', $kommentar);
        $response['success'] = '<article><h2>Tak for din henvendelse</h2><p>Vi vil besvare den hurtigst muligt.</p><article>';
        sendEmail(get_theme_mod('info_name'), get_theme_mod('info_email'), get_theme_mod('info_email'), 'Ny henvendelse fra ' . $navn, $kommentar);
    }
    wp_die(json_encode($response));
}