Example #1
0
/**
 * Install
 *
 * Runs on plugin install by setting up the post types,
 * flushing rewrite rules and also populates the settings fields.
 * After successful install, the user is redirected to the wpaam Welcome screen.
 *
 * @since 1.0
 * @global $wpaam_options
 * @global $wp_version
 * @return void
 */
function wpaam_install()
{
    global $wpaam_options, $wp_version;
    // Check PHP Version and deactivate & die if it doesn't meet minimum requirements.
    if (version_compare(PHP_VERSION, '5.3', '<')) {
        deactivate_plugins(plugin_basename(WPAAM_PLUGIN_FILE));
        wp_die(sprintf(__('This plugin requires a minimum PHP Version 5.3 to be installed on your host. <a href="%s" target="_blank">Click here to read how you can update your PHP version</a>.', 'wpaam'), 'http://www.wpupdatephp.com/contact-host/') . '<br/><br/>' . '<small><a href="' . admin_url() . '">' . __('Back to your website.', 'wpaam') . '</a></small>');
    }
    // Install default pages
    //wpaam_generate_pages();
    // Setup default emails content
    $default_emails = array();
    // Delete the option
    delete_option('wpaam_emails');
    // Let's set some default options
    wpaam_update_option('enable_honeypot', true);
    // enable antispam honeypot by default.
    wpaam_update_option('email_template', 'none');
    // set no template as default.
    wpaam_update_option('from_email', get_option('admin_email'));
    // set admin email as default.
    wpaam_update_option('from_name', get_option('blogname'));
    // set blogname as default mail from.
    wpaam_update_option('guests_can_view_profiles', true);
    wpaam_update_option('members_can_view_profiles', true);
    update_option('users_can_register', true);
    // Enable registrations.
    update_option('wpaam_permalink', 'user_id');
    // Set default user permalinks
    // Clear the permalinks
    flush_rewrite_rules();
    // Create groups table and 1st group
    wpaam_install_groups();
    // Create fields table and primary fields
    wpaam_install_fields();
    // Store plugin installation date
    add_option('wpaam_activation_date', strtotime("now"));
    // Add Upgraded From Option
    $current_version = get_option('wpaam_version');
    if ($current_version) {
        update_option('wpaam_version_upgraded_from', $current_version);
    }
    // Update current version
    update_option('wpaam_version', WPAAM_VERSION);
    update_option('wpaam_did_121_update', true);
    // Add the transient to redirect
    set_transient('_wpaam_activation_redirect', true, 30);
}
Example #2
0
/**
 * Generates core pages and updates settings panel with the newly created pages.
 *
 * @since 1.0.0
 * @return void
 */
function wpaam_generate_pages($redirect = false)
{
    // Generate login page
    if (!wpaam_get_option('login_page')) {
        $login = wp_insert_post(array('post_title' => __('Login', 'wpaam'), 'post_content' => '[wpaam_login_form]', 'post_status' => 'publish', 'post_author' => 1, 'post_type' => 'page', 'comment_status' => 'closed'));
        wpaam_update_option('login_page', $login);
    }
    // Generate registration page
    if (!wpaam_get_option('registration_page')) {
        $register = wp_insert_post(array('post_title' => __('Register', 'wpaam'), 'post_content' => '[wpaam_register form_id="" login_link="yes" psw_link="yes" register_link="no" ]', 'post_status' => 'publish', 'post_author' => 1, 'post_type' => 'page', 'comment_status' => 'closed'));
        wpaam_update_option('registration_page', $register);
    }
    // Generate user account page
    if (!wpaam_get_option('account_page')) {
        $account = wp_insert_post(array('post_title' => __('Account', 'wpaam'), 'post_content' => '[wpaam_account]', 'post_status' => 'publish', 'post_author' => 1, 'post_type' => 'page', 'comment_status' => 'closed'));
        wpaam_update_option('account_page', $account);
    }
    //Generate user client management page
    if (!wpaam_get_option('clients_page')) {
        $clients = wp_insert_post(array('post_title' => __('Clients', 'wpaam'), 'post_content' => '[wpaam_clients]', 'post_status' => 'publish', 'post_author' => 1, 'post_type' => 'page', 'comment_status' => 'closed'));
        wpaam_update_option('clients_page', $clients);
    }
    // Generate user products management  page
    if (!wpaam_get_option('products_page')) {
        $products = wp_insert_post(array('post_title' => __('Products', 'wpaam'), 'post_content' => '[wpaam_products]', 'post_status' => 'publish', 'post_author' => 1, 'post_type' => 'page', 'comment_status' => 'closed'));
        wpaam_update_option('products_page', $products);
    }
    // Generate user quotations management  page
    if (!wpaam_get_option('quotations_page')) {
        $quotations = wp_insert_post(array('post_title' => __('Quotations', 'wpaam'), 'post_content' => '[wpaam_quotations]', 'post_status' => 'publish', 'post_author' => 1, 'post_type' => 'page', 'comment_status' => 'closed'));
        wpaam_update_option('quotations_page', $quotations);
    }
    // Generate user invoices management  page
    if (!wpaam_get_option('invoices_page')) {
        $invoices = wp_insert_post(array('post_title' => __('Invoices', 'wpaam'), 'post_content' => '[wpaam_invoices]', 'post_status' => 'publish', 'post_author' => 1, 'post_type' => 'page', 'comment_status' => 'closed'));
        wpaam_update_option('invoices_page', $invoices);
    }
    // Generate user creditmemos management  page
    if (!wpaam_get_option('creditmemos_page')) {
        $creditmemos = wp_insert_post(array('post_title' => __('Credit Memo', 'wpaam'), 'post_name' => 'creditmemos', 'post_content' => '[wpaam_creditmemos]', 'post_status' => 'publish', 'post_author' => 1, 'post_type' => 'page', 'comment_status' => 'closed'));
        wpaam_update_option('creditmemos_page', $creditmemos);
    }
    if ($redirect) {
        wp_redirect(admin_url('users.php?page=wpaam-settings&tab=general&setup_done=true'));
        exit;
    }
}