/**
  * Adds plugin-specific caps to all roles so that 3rd party plugins can manage them
  */
 function add_caps()
 {
     $version = get_option('post_forking_cap_version');
     // Bail Early if we have already set the caps and aren't updating them
     if ($version !== false && $this->cap_version <= (int) $version) {
         return;
     }
     add_option('post_forking_cap_version', $this->cap_version, '', 'yes');
     global $wp_roles;
     if (!isset($wp_roles)) {
         $wp_roles = new WP_Roles();
     }
     foreach ($wp_roles->role_names as $role => $label) {
         //if the role is a standard role, map the default caps, otherwise, map as a subscriber
         $caps = array_key_exists($role, $this->defaults) ? $this->defaults[$role] : $this->defaults['subscriber'];
         //loop and assign
         foreach ($caps as $cap => $grant) {
             //check to see if the user already has this capability, if so, don't re-add as that would override grant
             if (!isset($wp_roles->roles[$role]['capabilities'][$cap])) {
                 $wp_roles->add_cap($role, $cap, $grant);
             } else {
                 $wp_roles->remove_cap($role, $cap);
                 $wp_roles->add_cap($role, $cap, $grant);
             }
         }
     }
 }
function handle_rhc_uninstall()
{
    $WP_Roles = new WP_Roles();
    foreach (array('calendarize_author', 'edit_' . RHC_CAPABILITY_TYPE, 'read_' . RHC_CAPABILITY_TYPE, 'delete_' . RHC_CAPABILITY_TYPE, 'edit_' . RHC_CAPABILITY_TYPE . 's', 'edit_others_' . RHC_CAPABILITY_TYPE . 's', 'edit_published_' . RHC_CAPABILITY_TYPE . 's', 'delete_published_' . RHC_CAPABILITY_TYPE . 's', 'delete_private_' . RHC_CAPABILITY_TYPE . 's', 'delete_others_' . RHC_CAPABILITY_TYPE . 's', 'publish_' . RHC_CAPABILITY_TYPE . 's', 'read_private_' . RHC_CAPABILITY_TYPE . 's', 'manage_' . RHC_VENUE, 'manage_' . RHC_CALENDAR, 'manage_' . RHC_ORGANIZER) as $cap) {
        $WP_Roles->remove_cap(RHC_ADMIN_ROLE, $cap);
    }
    //-----
}
Ejemplo n.º 3
0
function wlb_uninstall()
{
    $WP_Roles = new WP_Roles();
    foreach (array('wlb_branding', 'wlb_navigation', 'wlb_login', 'wlb_color_scheme', 'wlb_options', 'wlb_role_manager', 'wlb_license', 'wlb_downloads', 'wlb_dashboard_tool') as $cap) {
        $WP_Roles->remove_cap(WLB_ADMIN_ROLE, $cap);
    }
    //-----
}
Ejemplo n.º 4
0
function handle_rhc_uninstall()
{
    $WP_Roles = new WP_Roles();
    foreach (array('calendarize_author', 'edit_' . RHC_CAPABILITY_TYPE, 'read_' . RHC_CAPABILITY_TYPE, 'delete_' . RHC_CAPABILITY_TYPE, 'delete_' . RHC_CAPABILITY_TYPE . 's', 'edit_' . RHC_CAPABILITY_TYPE . 's', 'edit_others_' . RHC_CAPABILITY_TYPE . 's', 'edit_published_' . RHC_CAPABILITY_TYPE . 's', 'delete_published_' . RHC_CAPABILITY_TYPE . 's', 'delete_private_' . RHC_CAPABILITY_TYPE . 's', 'delete_others_' . RHC_CAPABILITY_TYPE . 's', 'publish_' . RHC_CAPABILITY_TYPE . 's', 'read_private_' . RHC_CAPABILITY_TYPE . 's', 'manage_' . RHC_VENUE, 'manage_' . RHC_CALENDAR, 'manage_' . RHC_ORGANIZER) as $cap) {
        $WP_Roles->remove_cap(RHC_ADMIN_ROLE, $cap);
    }
    //-----
    delete_site_transient('update_plugins');
    delete_option('rhc_dismiss_help_notice');
    $filename = get_home_path() . '.htaccess';
    if (file_exists($filename)) {
        insert_with_markers($filename, 'RHC', array());
    }
}
 public function disable_all_caps()
 {
     global $wp_roles;
     if (!isset($wp_roles) || !is_object($wp_roles)) {
         $wp_roles = new WP_Roles();
     }
     $ddl_capabilities = array_keys(self::ddl_get_capabilities());
     foreach ($ddl_capabilities as $cap) {
         foreach (array_keys($wp_roles->roles) as $role) {
             $wp_roles->remove_cap($role, $cap);
         }
     }
     //Remove caps for all Super Admins
     $super_admins = get_super_admins();
     foreach ($super_admins as $admin) {
         $user = new WP_User($admin);
         for ($i = 0, $caps_limit = count($ddl_capabilities); $i < $caps_limit; $i++) {
             $user->remove_cap($ddl_capabilities[$i]);
         }
     }
     $this->ddl_users_settings->update_options('updated_profiles', false, true);
 }
Ejemplo n.º 6
0
function un_deactivation_hook()
{
    delete_option('un_version');
    global $wp_roles;
    if (!isset($wp_roles)) {
        $wp_roles = new WP_Roles();
    }
    foreach (un_get_capable_roles() as $role) {
        foreach (un_get_feedback_capabilities() as $cap) {
            $wp_roles->remove_cap($role, $cap);
        }
    }
    flush_rewrite_rules();
}
 public function disable_all_caps()
 {
     global $wp_roles;
     if (!isset($wp_roles) || !is_object($wp_roles)) {
         $wp_roles = new WP_Roles();
     }
     $wpcf_capabilities = array_keys(self::wpcf_get_capabilities());
     foreach ($wpcf_capabilities as $cap) {
         foreach (array_keys($wp_roles->roles) as $role) {
             $wp_roles->remove_cap($role, $cap);
         }
     }
     //Remove caps for all Super Admins
     $super_admins = get_super_admins();
     foreach ($super_admins as $admin) {
         $user = new WP_User($admin);
         for ($i = 0, $caps_limit = count($wpcf_capabilities); $i < $caps_limit; $i++) {
             $user->remove_cap($wpcf_capabilities[$i]);
         }
     }
 }
Ejemplo n.º 8
0
function rbhn_role_caps_uninstall( $role_key ) {

	$post_types_array = get_option( 'rbhn_post_types' );
	
    if ( ! empty( $post_types_array ) ) {
	    foreach( $post_types_array as $array ) {
			
			foreach( $array as $active_role=>$active_posttype ) {

				if ( $role_key == $active_role ) {
					$role = get_role( $active_role );
					$capability_type = $active_posttype;
				}
			}
		}
	}
	
	// if no post type found drop out.
	if ( empty( $capability_type ) )
		return;

	$delete_caps = array(
			"edit_{$capability_type}",
			"read_{$capability_type}",
			"delete_{$capability_type}",
			"edit_{$capability_type}s",
			"edit_others_{$capability_type}s",
			"publish_{$capability_type}s",
			"read_private_{$capability_type}s",
			"delete_{$capability_type}s",
			"delete_private_{$capability_type}s",
			"delete_published_{$capability_type}s",
			"delete_others_{$capability_type}s",
			"edit_private_{$capability_type}s",
			"edit_published_{$capability_type}s",
			"create_{$capability_type}s",
			"manage_categories_{$capability_type}"		
			);

    global $wp_roles;
 
    if ( ! isset( $wp_roles ) ) {
        $wp_roles = new WP_Roles( );
	}
		
	$users = get_users( );
	$administrator      = get_role( 'administrator' );
	
	// loop through the capability list.
	foreach ( $delete_caps as $cap ) {

		// Clean-up Capability from WordPress Roles
		foreach ( array_keys( $wp_roles->roles ) as $role ) {
			$wp_roles->remove_cap( $role, $cap );
		}
		
		// Clean-up Capability from WordPress Users where explicitly allocated 
		foreach ( $users as $user ) {
			$user->remove_cap( $cap );
		}

		// Clean-up Capability from the Administrator Role
		$administrator->remove_cap( $cap );		
	}
	unset( $wp_roles );
}
Ejemplo n.º 9
0
    /* @TODO: delete all transient, options and files you may have added
    	  delete_transient( 'TRANSIENT_NAME' );
    	  delete_option('OPTION_NAME');
    	  //info: remove custom file directory for main site
    	  $upload_dir = wp_upload_dir();
    	  $directory = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . "CUSTOM_DIRECTORY_NAME" . DIRECTORY_SEPARATOR;
    	  if (is_dir($directory)) {
    	  foreach(glob($directory.'*.*') as $v){
    	  unlink($v);
    	  }
    	  rmdir($directory);
    	  }
    	  //info: remove and optimize tables
    	  $GLOBALS['wpdb']->query("DROP TABLE `".$GLOBALS['wpdb']->prefix."TABLE_NAME`");
    	  $GLOBALS['wpdb']->query("OPTIMIZE TABLE `" .$GLOBALS['wpdb']->prefix."options`");
    	 */
    if (!isset($wp_roles)) {
        $wp_roles = new WP_Roles();
    }
    foreach ($wp_roles->role_names as $role => $label) {
        //if the role is a standard role, map the default caps, otherwise, map as a subscriber
        $caps = array_key_exists($role, $plugin_roles) ? $plugin_roles[$role] : $plugin_roles['subscriber'];
        //loop and assign
        foreach ($caps as $cap => $grant) {
            //check to see if the user already has this capability, if so, don't re-add as that would override grant
            if (!isset($wp_roles->roles[$role]['capabilities'][$cap])) {
                $wp_roles->remove_cap($cap);
            }
        }
    }
}
 function duplicate_roles_for_new_blog($blog_id, $user_id)
 {
     global $wpdb, $global, $wp_roles;
     // get Id of 1st (main) blog
     $blogIds = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM {$wpdb->blogs} order by blog_id asc"));
     if (!isset($blogIds[0])) {
         return;
     }
     $current_blog = $wpdb->blogid;
     switch_to_blog($blogIds[0]);
     $main_roles = new WP_Roles();
     // get roles from primary blog
     $default_role = get_option('default_role');
     // get default role from primary blog
     switch_to_blog($blog_id);
     // switch to the new created blog
     $main_roles->use_db = false;
     // do not touch DB
     $main_roles->add_cap('administrator', 'dummy_123456');
     // just to save current roles into new blog
     $main_roles->role_key = $wp_roles->role_key;
     $main_roles->use_db = true;
     // save roles into new blog DB
     $main_roles->remove_cap('administrator', 'dummy_123456');
     // remove unneeded dummy capability
     update_option('default_role', $default_role);
     // set default role for new blog as it set for primary one
     switch_to_blog($current_blog);
     // return to blog where we were at the begin
 }
 /**
  * Remove capabilities when a term is removed
  * @param unknown $term
  */
 function remove_caps($term)
 {
     $term_obj = get_term($term, $this->taxonomy);
     global $wp_roles;
     if (!isset($wp_roles)) {
         $wp_roles = new WP_Roles();
     }
     foreach ($wp_roles->role_names as $role => $label) {
         foreach ($this->base_caps as $base_cap) {
             $wp_roles->remove_cap($role, $base_cap . '_in_' . $term_obj->slug);
         }
     }
 }
Ejemplo n.º 12
0
	public function removeCapability($role, $cap)
	{
		global $wp_roles;
		
		/* 
		 * Check to make sure $wp_roles has been initialized and set.
		 * If it hasn't it is initialized. This was done because this method 
		 * can be called before the $wp_roles has been initialized.
		 */
		if (!isset($wp_roles))
		{
			$wp_roles = new WP_Roles();
		}
		
		//$wpRole = get_role($role);
		if ($this->hasCapability($role, $cap)) $wp_roles->remove_cap($role, $cap);
	}
Ejemplo n.º 13
0
 /**
  * Delete the roles and capabilities created by FUE
  */
 public function remove_roles()
 {
     global $wp_roles;
     if (class_exists('WP_Roles')) {
         if (!isset($wp_roles)) {
             $wp_roles = new WP_Roles();
         }
     }
     $capabilities = self::get_core_capabilities();
     foreach ($capabilities as $cap_group) {
         foreach ($cap_group as $cap) {
             $wp_roles->remove_cap('fue_manager', $cap);
             $wp_roles->remove_cap('administrator', $cap);
         }
     }
     remove_role('fue_manager');
 }
Ejemplo n.º 14
0
function etm_uninstall_capabilities()
{
    $caps = array();
    $caps[] = 'etm_show_menu';
    $caps[] = 'etm_translate_addon';
    $caps[] = 'etm_translate_post';
    $caps[] = 'etm_translate_category';
    $caps[] = 'etm_translate_post_tag';
    $caps[] = 'etm_translate_page';
    $caps[] = 'etm_translate_menu';
    $caps[] = 'etm_translate_seo';
    $caps[] = 'etm_translate_theme';
    $caps[] = 'etm_translate_plugin';
    $caps[] = 'etm_options';
    $caps[] = 'etm_license';
    $caps[] = 'etm_string_create';
    $caps[] = 'etm_view_addon';
    $caps[] = 'etm_view_post';
    $caps[] = 'etm_view_page';
    $caps[] = 'etm_view_seo';
    $caps[] = 'etm_view_menu';
    $caps[] = 'etm_view_theme';
    $caps[] = 'etm_view_plugin';
    $caps[] = 'etm_view_site_options';
    $caps[] = 'etm_translate_site_options';
    //--
    $WP_Roles = new WP_Roles();
    foreach ($caps as $cap) {
        $WP_Roles->remove_cap('administrator', $cap);
    }
    update_option('etm_options_plugin_tran', '');
    update_option('etm_options_install', '');
}
Ejemplo n.º 15
0
 /**
  * Deactivate the plugin
  */
 public static function deactivate()
 {
     $WP_Roles = new WP_Roles();
     foreach (array('chronosly_author', 'edit_' . CHRONOSLY_CAPABILITY_TYPE, 'read_' . CHRONOSLY_CAPABILITY_TYPE, 'delete_' . CHRONOSLY_CAPABILITY_TYPE, 'delete_' . CHRONOSLY_CAPABILITY_TYPE . 's', 'edit_' . CHRONOSLY_CAPABILITY_TYPE . 's', 'edit_others_' . CHRONOSLY_CAPABILITY_TYPE . 's', 'edit_published_' . CHRONOSLY_CAPABILITY_TYPE . 's', 'delete_published_' . CHRONOSLY_CAPABILITY_TYPE . 's', 'delete_private_' . CHRONOSLY_CAPABILITY_TYPE . 's', 'delete_others_' . CHRONOSLY_CAPABILITY_TYPE . 's', 'publish_' . CHRONOSLY_CAPABILITY_TYPE . 's', 'read_private_' . CHRONOSLY_CAPABILITY_TYPE . 's') as $cap) {
         $WP_Roles->remove_cap(CHRONOSLY_ADMIN_ROLE, $cap);
     }
     delete_option("chronosly-settings");
     wp_clear_scheduled_hook('chronosly_update_addons');
     wp_clear_scheduled_hook('chronosly_update_templates');
 }
	/**
	 * rbhn_role_caps_cleanup function.
	 *
	 * @access public
	 * @param mixed $role_key
	 * @return void
	 */
	public static function rbhn_role_caps_cleanup( $role_key ) {

		$role_based_help_notes = RBHN_Role_Based_Help_Notes::get_instance( );
		
		// Since the clean up is for roles not stored within the options array we need to regenerate the post-type/capability-type that would have existed
		// if the help note for a role was enabled.  Once we know this we can then clean up the capabilities if they still exist.
		$capability_type = $role_based_help_notes->clean_post_type_name( $role_key );
			
		$delete_caps = 	array(
								"edit_{$capability_type}",
								"read_{$capability_type}",
								"delete_{$capability_type}",
								"edit_{$capability_type}s",
								"edit_others_{$capability_type}s",
								"publish_{$capability_type}s",
								"read_private_{$capability_type}s",
								"delete_{$capability_type}s",
								"delete_private_{$capability_type}s",
								"delete_published_{$capability_type}s",
								"delete_others_{$capability_type}s",
								"edit_private_{$capability_type}s",
								"edit_published_{$capability_type}s",
								"create_{$capability_type}s",
								"manage_categories_{$capability_type}"
							);


		global $wp_roles;
		
		if ( ! isset( $wp_roles ) ) {
			$wp_roles = new WP_Roles( );
		}
			
		$users 			= get_users( );
		$administrator	= get_role( 'administrator' );
		
		foreach ( $delete_caps as $cap ) {
			
			// Clean-up Capability from WordPress Roles
			foreach ( array_keys( $wp_roles->roles ) as $role ) {
				$wp_roles->remove_cap( $role, $cap );
			}
			
			// Clean-up Capability from WordPress Users where explicitly allocated 
			foreach ( $users as $user ) {
				$user->remove_cap( $cap );
			}		

			// Clean-up Capability from the Administrator Role
			$administrator->remove_cap( $cap );
			
		}
		unset( $wp_roles );
	}
 /**
  * every time when new blog created - duplicate to it roles from the main blog (1)  
  * @global wpdb $wpdb
  * @global WP_Roles $wp_roles
  * @param int $blog_id
  * @param int $user_id
  *
  */
 public function duplicate_roles_for_new_blog($blog_id)
 {
     global $wpdb, $wp_roles;
     // get Id of 1st (main) blog
     $main_blog_id = $this->lib->get_main_blog_id();
     if (empty($main_blog_id)) {
         return;
     }
     $current_blog = $wpdb->blogid;
     switch_to_blog($main_blog_id);
     $main_roles = new WP_Roles();
     // get roles from primary blog
     $default_role = get_option('default_role');
     // get default role from primary blog
     switch_to_blog($blog_id);
     // switch to the new created blog
     $main_roles->use_db = false;
     // do not touch DB
     $main_roles->add_cap('administrator', 'dummy_123456');
     // just to save current roles into new blog
     $main_roles->role_key = $wp_roles->role_key;
     $main_roles->use_db = true;
     // save roles into new blog DB
     $main_roles->remove_cap('administrator', 'dummy_123456');
     // remove unneeded dummy capability
     update_option('default_role', $default_role);
     // set default role for new blog as it set for primary one
     switch_to_blog($current_blog);
     // return to blog where we were at the begin
 }
Ejemplo n.º 18
0
 function wplms_instructors_can_create_events()
 {
     global $wp_roles;
     if (class_exists('WP_Roles')) {
         if (!isset($wp_roles)) {
             $wp_roles = new WP_Roles();
         }
     }
     if (function_exists('eventon_get_core_capabilities')) {
         $capabilities = eventon_get_core_capabilities();
         unset($capabilities['core']);
         foreach ($capabilities as $cap_group) {
             foreach ($cap_group as $cap) {
                 $wp_roles->add_cap('instructor', $cap);
             }
         }
         $wp_roles->remove_cap('instructor', 'manage_eventon');
     }
 }
 /**
  * Remove capability from role.
  *
  * This is a container for {@link WP_Roles::remove_cap()} to remove the
  * capability from the role. That is to say, that {@link
  * WP_Roles::remove_cap()} implements the functionality, but it also makes
  * sense to use this class, because you don't need to enter the role name.
  *
  * @since 2.0.0
  * @access public
  *
  * @param string $cap Capability name.
  */
 function remove_cap($cap)
 {
     global $wp_roles;
     if (!isset($wp_roles)) {
         $wp_roles = new WP_Roles();
     }
     unset($this->capabilities[$cap]);
     $wp_roles->remove_cap($this->name, $cap);
 }
 static function update_settings()
 {
     global $wpdb;
     // update unsubscribe page
     update_option('fue_followup_unsubscribe_page_id', (int) $_POST['unsubscribe_page']);
     // bcc
     if (isset($_POST['bcc'])) {
         update_option('fue_bcc', $_POST['bcc']);
     }
     // capability
     if (isset($_POST['roles'])) {
         $roles = get_editable_roles();
         $wp_roles = new WP_Roles();
         foreach ($roles as $key => $role) {
             if (in_array($key, $_POST['roles'])) {
                 $wp_roles->add_cap($key, 'manage_follow_up_emails');
             } else {
                 $wp_roles->remove_cap($key, 'manage_follow_up_emails');
             }
         }
         // make sure the admin has this capability
         $wp_roles->add_cap('administrator', 'manage_follow_up_emails');
     }
     // daily summary emails
     if (isset($_POST['daily_emails'])) {
         update_option('fue_daily_emails', $_POST['daily_emails']);
     }
     if (isset($_POST['daily_emails_time_hour'])) {
         $time = $_POST['daily_emails_time_hour'] . ':' . $_POST['daily_emails_time_minute'] . ' ' . $_POST['daily_emails_time_ampm'];
         update_option('fue_daily_emails_time', $time);
         $next_send = strtotime(date('m/d/Y ' . $time));
         if (current_time('timestamp') > $next_send) {
             // already in the past. Set it for tomorrow
             $next_send += 86400;
             update_option('fue_next_summary', $next_send);
         }
     }
     // disable email wrapping
     $disable = isset($_POST['disable_email_wrapping']) ? (int) $_POST['disable_email_wrapping'] : 0;
     update_option('fue_disable_wrapping', $disable);
     do_action('fue_settings_updated', $_POST);
     $imported = '';
     if (isset($_FILES['emails_file']) && is_uploaded_file($_FILES['emails_file']['tmp_name'])) {
         $fh = @fopen($_FILES['emails_file']['tmp_name'], 'r');
         $columns = array();
         $i = 0;
         while ($row = fgetcsv($fh)) {
             $i++;
             if ($i == 1) {
                 foreach ($row as $idx => $col) {
                     $columns[$idx] = $col;
                 }
                 continue;
             }
             $wpdb->insert($wpdb->prefix . 'followup_emails', $row, $columns);
         }
         $imported = '&imported=1';
     }
     if (isset($_FILES['settings_file']) && is_uploaded_file($_FILES['settings_file']['tmp_name'])) {
         $fh = @fopen($_FILES['settings_file']['tmp_name'], 'r');
         $i = 0;
         while ($row = fgetcsv($fh)) {
             $i++;
             if ($i == 1) {
                 continue;
             }
             update_option($row[0], $row[1]);
         }
         $imported = '&imported=1';
     }
     wp_redirect("admin.php?page=followup-emails-settings&settings_updated=1{$imported}");
     exit;
 }
Ejemplo n.º 21
0
 /**
  * woocommerce_remove_roles function.
  */
 public static function remove_roles()
 {
     global $wp_roles;
     if (!class_exists('WP_Roles')) {
         return;
     }
     if (!isset($wp_roles)) {
         $wp_roles = new WP_Roles();
     }
     $capabilities = self::get_core_capabilities();
     foreach ($capabilities as $cap_group) {
         foreach ($cap_group as $cap) {
             $wp_roles->remove_cap('shop_manager', $cap);
             $wp_roles->remove_cap('administrator', $cap);
         }
     }
     remove_role('customer');
     remove_role('shop_manager');
 }
Ejemplo n.º 22
0
 /**
  * update_settings method
  */
 static function update_settings()
 {
     $wpdb = Follow_Up_Emails::instance()->wpdb;
     $section = $_POST['section'];
     $imported = '';
     if ($section == 'email') {
         // capability
         if (isset($_POST['roles'])) {
             $roles = get_editable_roles();
             $wp_roles = new WP_Roles();
             foreach ($roles as $key => $role) {
                 if (in_array($key, $_POST['roles'])) {
                     $wp_roles->add_cap($key, 'manage_follow_up_emails');
                 } else {
                     $wp_roles->remove_cap($key, 'manage_follow_up_emails');
                 }
             }
             // make sure the admin has this capability
             $wp_roles->add_cap('administrator', 'manage_follow_up_emails');
         }
         do_action('fue_settings_email_save', $_POST);
     } elseif ($section == 'crm') {
         // bcc
         if (isset($_POST['bcc'])) {
             update_option('fue_bcc', $_POST['bcc']);
         }
         // from/reply-to name
         if (isset($_POST['from_name'])) {
             update_option('fue_from_name', $_POST['from_name']);
         }
         // from/reply-to
         if (isset($_POST['from_email'])) {
             update_option('fue_from_email', $_POST['from_email']);
         }
         // daily summary emails
         if (isset($_POST['daily_emails'])) {
             update_option('fue_daily_emails', $_POST['daily_emails']);
         }
         if (isset($_POST['daily_emails_time_hour'])) {
             $previous_time = get_option('fue_daily_emails_time', '00:00 AM');
             $time = $_POST['daily_emails_time_hour'] . ':' . $_POST['daily_emails_time_minute'] . ' ' . $_POST['daily_emails_time_ampm'];
             if ($previous_time != $time) {
                 update_option('fue_daily_emails_time', $time);
                 Follow_Up_Emails::instance()->scheduler->reschedule_daily_summary_email();
             }
         }
         do_action('fue_settings_crm_save', $_POST);
     } elseif ($section == 'system') {
         // process importing request
         if (isset($_FILES['emails_file']) && is_uploaded_file($_FILES['emails_file']['tmp_name'])) {
             ini_set("auto_detect_line_endings", true);
             $fh = @fopen($_FILES['emails_file']['tmp_name'], 'r');
             $columns = array();
             $i = 0;
             while ($row = fgetcsv($fh)) {
                 $i++;
                 if ($i == 1) {
                     foreach ($row as $idx => $col) {
                         $columns[$idx] = $col;
                     }
                     continue;
                 }
                 $data = array();
                 foreach ($columns as $idx => $col) {
                     if ($col == 'email_type') {
                         $col = 'type';
                         // convert 'product' emails to 'storewide'
                         if (in_array($row[$idx], array('product', 'normal', 'generic'))) {
                             $row[$idx] = 'storewide';
                         }
                     } elseif ($col == 'status') {
                         if ($row[$idx] == -1) {
                             $row[$idx] = FUE_Email::STATUS_ARCHIVED;
                         } elseif ($row[$idx] == 0) {
                             $row[$idx] = FUE_Email::STATUS_INACTIVE;
                         } else {
                             $row[$idx] = FUE_Email::STATUS_ACTIVE;
                         }
                     }
                     $data[$col] = $row[$idx];
                 }
                 fue_create_email($data);
             }
             $imported = '&imported=1';
         }
         // restore settings file from backup
         if (isset($_FILES['settings_file']) && is_uploaded_file($_FILES['settings_file']['tmp_name'])) {
             ini_set("auto_detect_line_endings", true);
             $fh = @fopen($_FILES['settings_file']['tmp_name'], 'r');
             $i = 0;
             while ($row = fgetcsv($fh)) {
                 $i++;
                 if ($i == 1) {
                     continue;
                 }
                 update_option($row[0], $row[1]);
             }
             $imported = '&imported=1';
         }
         // api
         if (!empty($_POST['api_enabled'])) {
             update_option('fue_api_enabled', 'yes');
         } else {
             update_option('fue_api_enabled', 'no');
         }
         // usage data
         if (isset($_POST['disable_usage_data']) && $_POST['disable_usage_data'] == 1) {
             update_option('fue_disable_usage_data', 1);
         } else {
             delete_option('fue_disable_usage_data');
         }
         // email batches
         if (isset($_POST['email_batch_enabled']) && $_POST['email_batch_enabled'] == 1) {
             update_option('fue_email_batches', 1);
             update_option('fue_emails_per_batch', intval($_POST['emails_per_batch']));
             update_option('fue_batch_interval', intval($_POST['email_batch_interval']));
         } else {
             update_option('fue_email_batches', 0);
         }
         // disable logging
         if (isset($_POST['action_scheduler_disable_logging']) && $_POST['action_scheduler_disable_logging'] == 1) {
             update_option('fue_disable_action_scheduler_logging', 1);
         } else {
             update_option('fue_disable_action_scheduler_logging', 0);
         }
         // delete all action scheduler comments
         if (isset($_POST['action_scheduler_delete_logs']) && $_POST['action_scheduler_delete_logs'] == 1) {
             $comment_ids = $wpdb->get_col("SELECT comment_ID FROM {$wpdb->comments} WHERE comment_type = 'action_log'");
             if ($comment_ids) {
                 foreach ($comment_ids as $comment_id) {
                     wp_delete_comment($comment_id, true);
                 }
             }
         }
         do_action('fue_settings_system_save', $_POST);
     } else {
         do_action('fue_settings_save', $_POST);
     }
     wp_redirect("admin.php?page=followup-emails-settings&tab={$section}&settings_updated=1{$imported}");
     exit;
 }