<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WP Scripts &#8211; Blackbams Blog</title>
	<atom:link href="https://blog.blackbam.at/category/web-development/wordpress/scripts-wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.blackbam.at</link>
	<description>development - digital arts - internet</description>
	<lastBuildDate>Thu, 26 Mar 2015 13:22:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.1</generator>
	<item>
		<title>Create a WordPress admin user from PHP</title>
		<link>https://blog.blackbam.at/2015/03/26/create-a-wordpress-admin-user-from-php/</link>
					<comments>https://blog.blackbam.at/2015/03/26/create-a-wordpress-admin-user-from-php/#respond</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Thu, 26 Mar 2015 13:22:13 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP Scripts]]></category>
		<category><![CDATA[administrator]]></category>
		<category><![CDATA[lost password]]></category>
		<category><![CDATA[user]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=2204</guid>

					<description><![CDATA[This script turned out to be useful in a lot of situations when lost an admin password and cannot restore it for some reason. Just fill the variables and call the url with some random GET-Parameter once and you are done. // insert a new administrator // add_action('init','check_insert'); function check_insert() { if(isset($_GET["jio8"]) &#038;& $_GET["jio8"]=="u7dd") { $newusername [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>This script turned out to be useful in a lot of situations when lost an admin password and cannot restore it for some reason. Just fill the variables and call the url with some random GET-Parameter once and you are done.</p>
<pre lang="php">

// insert a new administrator
// add_action('init','check_insert');

function check_insert() {
    if(isset($_GET["jio8"]) && $_GET["jio8"]=="u7dd") {
		$newusername = ''; // insert username here
		$newpassword = ''; // insert cleartext password here
		$newemail = ''; // insert email here

		// Check that user doesn't already exist
		if ( !username_exists($newusername) && !email_exists($newemail) )
		{
				// Create user and set role to administrator
				$user_id = wp_create_user( $newusername, $newpassword, $newemail);
				if ( is_int($user_id) )
				{
						$wp_user_object = new WP_User($user_id);
						$wp_user_object->set_role('administrator');
						echo 'Successfully created new admin user. Remove this function!';
				}
				else {
						echo 'Error with wp_insert_user. No users were created.';
				}
		} else {
				echo 'User not created. This user or email already exists.';
		}
    }
}

</pre>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2015%2F03%2F26%2Fcreate-a-wordpress-admin-user-from-php%2F&#038;title=Create%20a%20WordPress%20admin%20user%20from%20PHP" data-a2a-url="https://blog.blackbam.at/2015/03/26/create-a-wordpress-admin-user-from-php/" data-a2a-title="Create a WordPress admin user from PHP"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2015/03/26/create-a-wordpress-admin-user-from-php/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>WordPress Plugin: Better deactivate visual editor</title>
		<link>https://blog.blackbam.at/2012/12/01/wordpress-plugin-better-deactivate-visual-editor/</link>
					<comments>https://blog.blackbam.at/2012/12/01/wordpress-plugin-better-deactivate-visual-editor/#respond</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Sat, 01 Dec 2012 19:34:50 +0000</pubDate>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP Scripts]]></category>
		<category><![CDATA[deactivate]]></category>
		<category><![CDATA[editor]]></category>
		<category><![CDATA[visual]]></category>
		<category><![CDATA[wysiwyg]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=2011</guid>

					<description><![CDATA[As it is happens quite often that the rich editor of WordPress is a barrier concerning posts including difficult HTML, I wrote a Plugin. I am planning to release an improved version to the WordPress Plugin repository soon, but I think this works quite well for now: &#160; // Deactivate Visual Editor if option is [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>As it is happens quite often that the rich editor of WordPress is a barrier concerning posts including difficult HTML, I wrote a Plugin. I am planning to release an improved version to the WordPress Plugin repository soon, but I think this works quite well for now:</p>
<p>&nbsp;</p>
<pre lang="php">
// Deactivate Visual Editor if option is set
add_action('pre_get_posts', 'deactivate_visual_editor');

function deactivate_visual_editor() {
  global $wp_rich_edit;
  $post_id = $_GET['post'];
  
  $value = get_post_meta($post_id, 'deactivate_visual_editor', true);
  if($value == 1)
    $wp_rich_edit = false;
}


// create a box for each post / page
function cis_init(){
	add_meta_box("cis_post_settings", __("Details",TEXTDOMAIN), "cis_post_settings", "page", "normal", "high");
	add_meta_box("cis_post_settings", __("Details",TEXTDOMAIN), "cis_post_settings", "post", "normal", "high");
}

function cis_post_settings() {
    global $post;
    $custom = get_post_custom($post->ID);
	
	// maybe we want to automatize this?
?>
	<div class="inside">
		<table class="form-table" class="customEditor">
			<tr>
				<th><label for="deactivate_visual_editor">Deactivate visual editor?</label></th>
				<td>
					<input type="checkbox" name="deactivate_visual_editor" value="1" <?php if($custom["deactivate_visual_editor"][0]==1) {?>checked="checked"<?php } ?> />
				</td>
			</tr>
		</table>
	</div>
<?php
}

function save_cis_post(){
	global $post;
	
	if ( defined('DOING_AUTOSAVE') &#038;&#038; DOING_AUTOSAVE ) {
		return $post_id;
	}
	if($post->post_type == "post" || $post->post_type == "page") {
		update_post_meta($post->ID, "deactivate_visual_editor", intval($_POST["deactivate_visual_editor"]));
		
	}
}
</pre>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2012%2F12%2F01%2Fwordpress-plugin-better-deactivate-visual-editor%2F&#038;title=WordPress%20Plugin%3A%20Better%20deactivate%20visual%20editor" data-a2a-url="https://blog.blackbam.at/2012/12/01/wordpress-plugin-better-deactivate-visual-editor/" data-a2a-title="WordPress Plugin: Better deactivate visual editor"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2012/12/01/wordpress-plugin-better-deactivate-visual-editor/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Disabling (specific) WordPress update notifications in Backend for Core, Themes and Plugins</title>
		<link>https://blog.blackbam.at/2012/07/12/disabling-specific-wordpress-update-notifications-in-backend-for-core-themes-and-plugins/</link>
					<comments>https://blog.blackbam.at/2012/07/12/disabling-specific-wordpress-update-notifications-in-backend-for-core-themes-and-plugins/#comments</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Thu, 12 Jul 2012 16:28:00 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP Scripts]]></category>
		<category><![CDATA[Update notifications]]></category>
		<category><![CDATA[WordPress Plugins]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=1961</guid>

					<description><![CDATA[The automatic upgrade function of WordPress is usefull for most bloggers, as they always are reminded to keep WordPress and its extensions up to date. Anyhow, it can be very annoying for developers when customers and end-user make updates by their own, usually destroying something. It is often recomendable to disable this notifications: Sometimes a [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>The automatic upgrade function of WordPress is usefull for most bloggers, as they always are reminded to keep WordPress and its extensions up to date. Anyhow, it can be very annoying for developers when customers and end-user make updates by their own, usually destroying something.</p>
<p>It is often recomendable to disable this notifications: Sometimes a Plugin or Theme must be extended or changed by the developer &#8211; automatic upgrades would destroy these changes. Some Plugins like Mailpress do not disable the automatic upgrade, though automatic upgrading usually leeds to huge data losses  🙁 Recently I had to learn this the hard way, but this is no excuse for incomplete backups, of course.</p>
<p>However the following functions can help:</p>
<h2>1. Disable Plugin upgrades</h2>
<p>You can disable special Plugins by pasting the following code into the Plugin itself:</p>
<pre lang="php">
add_filter('site_transient_update_plugins', 'cis_remove_plugin_update');
 
function cis_remove_plugin_update($value) {
	unset($value-\>response[ plugin_basename(__FILE__) ]);
	return $value;
}
</pre>
<p>You can alternativley paste some code into your functions.php-file of your Theme:</p>
<pre lang="php">
add_filter('site_transient_update_plugins', 'cis_remove_plugin_update');
 
function cis_remove_plugin_update($value) {
	$plugin_relative_path = "plugin_relative_path"; // this could be "akismet/akismet.php" for example
	unset($value->response[ $plugin_relative_path]);
	return $value;
}

</pre>
<p>You also can disable all Plugin upgrades, for example if you want to prevent customers from doing that:</p>
<pre lang="php">
remove_action ('load-update-core.php', 'wp_update_plugins');
add_filter ('pre_site_transient_update_plugins',create_function ('$a', "return null;"));
</pre>
<h2>2. Disabling Theme Upgrades</h2>
<p>Disable all Theme updgrades:</p>
<pre lang="php">
remove_action ('load-update-core.php', 'wp_update_themes');
add_filter ('pre_site_transient_update_themes',create_function ('$a', "return null;"));
</pre>
<h2>3. Disable Core Updgrade</h2>
<p>Note: You never should disable the Core-Upgrade of WordPress, as important security upgrades will be missed. However, if you need to do it for some reason:</p>
<pre lang="php">
add_filter ('pre_site_transient_update_core',create_function ('$a', "return null;"));
</pre>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2012%2F07%2F12%2Fdisabling-specific-wordpress-update-notifications-in-backend-for-core-themes-and-plugins%2F&#038;title=Disabling%20%28specific%29%20WordPress%20update%20notifications%20in%20Backend%20for%20Core%2C%20Themes%20and%20Plugins" data-a2a-url="https://blog.blackbam.at/2012/07/12/disabling-specific-wordpress-update-notifications-in-backend-for-core-themes-and-plugins/" data-a2a-title="Disabling (specific) WordPress update notifications in Backend for Core, Themes and Plugins"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2012/07/12/disabling-specific-wordpress-update-notifications-in-backend-for-core-themes-and-plugins/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
		<item>
		<title>WordPress 3.3 &#8211; TinyMCE Advanced &#8211; qTranslate &#8211; fix style problems</title>
		<link>https://blog.blackbam.at/2012/01/28/wordpress-3-3-tinymce-advanced-qtranslate-fix-style-problems/</link>
					<comments>https://blog.blackbam.at/2012/01/28/wordpress-3-3-tinymce-advanced-qtranslate-fix-style-problems/#comments</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Sat, 28 Jan 2012 18:24:46 +0000</pubDate>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP Scripts]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=1791</guid>

					<description><![CDATA[Recently I had to fix a bunch of really annoying problems with this combination. Duplicated contents, automatically inserted line breaks and problems with the custom styles for TinyMCE really caused me to hate these Plugins. The reason for most of the problems is qTranslate though. If you experience similar problems, the following &#8220;library&#8221; will be [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Recently I had to fix a bunch of really annoying problems with this combination. Duplicated contents, automatically inserted line breaks and problems with the custom styles for TinyMCE really caused me to hate these Plugins. The reason for most of the problems is qTranslate though.</p>
<p>If you experience similar problems, the following &#8220;library&#8221; will be helpful for you. It contains a lot of functions to fix problems with this combination and to customize your backend the way you need it. Do not forget to remove the slashes in front of the required filter tags, otherwise the functions are not applied. Improvement ideas are welcome.</p>
<p><span style="font-size: large;"><strong><a href="http://wordpress.org/extend/plugins/tinymce-advanced-qtranslate-fix-editor-problems/">Download the Plugin</a></strong></span></p>
<p><strong><br />
</strong></p>
<p>Code (<span style="color: #f44;">NOTE: GeSHi prints the code with some little errors here, please download the Plugin. Thanks.</span>)</p>
<pre lang="php">




/*
Plugin Name: TinyMCE Advanced qTranslate fix editor problems
Plugin URI: https://blog.blackbam.at/2012/01/28/wordpress-3-3-tinymce-advanced-qtranslate-fix-style-problems/
Description: Remove line breaks and whitespace, enable custom stylesheets and multiple textareas. Fully customizable.
Version: 1.0.0
Author: David Stöckl
Author URI: http://www.blackbam.at/
 * 
Released and distributed under the GPLv2.
 * 
*/

/********** Administration ******************/
register_activation_hook(__FILE__,"tqfep_activate");

function tqfep_activate() {
	add_option('tqfep_styles',"");
	add_option('tqfep_fix_pre',1);
	add_option('tqfep_fix_post',1);
	add_option('tqfep_encoding','UTF-8');
	add_option('tqfep_custom_styles',';My Class=myclass;');
	register_uninstall_hook(__FILE__,"tqfep_uninstall");
}

function tqfep_uninstall() {
	// delete all options, tables, ...
	delete_option('tqfep_styles');
	delete_option('tqfep_fix_pre');
	delete_option('tqfep_fix_post');
	delete_option('tqfep_encoding');
	delete_option('tqfep_custom_styles');
}

function tqfepUpdateCheckbox($option) {
	update_option($option,intval($_POST[$option]));
}

function tqfepUpdateSelect($option,$allowed) {
	if(in_array($_POST[$option],$allowed)) {
		update_option($option,$_POST[$option]);
	}
}


// add the options page on initialization
add_action('admin_menu','tqfep_admin');

// add the actual options page
function tqfep_admin() {
	add_options_page('Fix TQ Editor','Fix TQ Editor','manage_options',__FILE__,'tqfep_backend_page');
}

// add the options page
function tqfep_backend_page() { ?>
	<div class="wrap">
		<div><?php screen_icon('options-general'); ?></div>
		<h2>Settings: TinyMCE Advanced qTranslate fix editor problems</h2>
		<?php
		if(isset($_POST['tqfep_update']) &#038;&#038; $_POST['tqfep_update']!="") {
			
			tqfepUpdateCheckbox('tqfep_fix_pre');
			tqfepUpdateCheckbox('tqfep_fix_post');
			
			tqfepUpdateSelect('tqfep_styles',array('','usual','theme_stylesheet','force_custom'));
			
			update_option('tqfep_encoding',$_POST['tqfep_encoding']);
			update_option('tqfep_custom_styles',$_POST['tqfep_custom_styles']);
			?>
			<div id="message" class="updated">Settings saved successfully</div>
		<?php }
		?>
		<form name="tqfep_update" method="post" action="">
			<div>
				<table class="form-table">
					<tr valign="top">
						<th scope="row"><?php _e('Sanitize content before editing?','ultrasimpleshop'); ?></th>
						<td>
							<input type="checkbox" name="tqfep_fix_pre" value="1" <?php if(get_option('tqfep_fix_pre')==1) {?>checked="checked" <?php } ?> />
						</td>
						<td class="description"><?php _e('Remove blank lines before editing content.','ultrasimpleshop'); ?></td>
					</tr>
					<tr valign="top">
						<th scope="row"><?php _e('Sanitize content after editing?','ultrasimpleshop'); ?></th>
						<td>
							<input type="checkbox" name="tqfep_fix_post" value="1" <?php if(get_option('tqfep_fix_post')==1) {?>checked="checked" <?php } ?> />
						</td>
						<td class="description"><?php _e('Remove blank lines after editing content.','ultrasimpleshop'); ?></td>
					</tr>
					<tr valign="top">
						<th scope="row"><?php _e('Encoding','ultrasimpleshop'); ?></th>
						<td>
							<input type="text" size="8" name="tqfep_encoding" value="<?php echo get_option('tqfep_encoding'); ?>" />
						</td>
						<td class="description"><?php _e('Usually "UTF-8"','ultrasimpleshop'); ?></td>
					</tr>
					<tr valign="top">
						<th scope="row"><?php _e('Fix TinyMCE Advanced custom stylesheets','ultrasimpleshop'); ?></th>
						<td>
							<select name="tqfep_styles">
								<option value="" <?php if(get_option('tqfep_styles')=='') {?>selected="selected"<?php } ?>><?php _e('Nothing to do','ultrasimpleshop'); ?></option>
								<option value="theme_stylesheet" <?php if(get_option('tqfep_styles')=='theme_stylesheet') {?>selected="selected"<?php } ?>><?php _e('TRY to embed theme stylesheet','ultrasimpleshop'); ?></option>
								<option value="force_custom" <?php if(get_option('tqfep_styles')=='force_custom') {?>selected="selected"<?php } ?>><?php _e('Add custom editor stylesheets dirctly','ultrasimpleshop'); ?></option>
							</select>
						</td>
						<td class="description"><?php _e('If you cannot add custom styles using "editor-style.css" via TinyMCE Advanced, you can try one of these options to add custom stylesheets.','ultrasimpleshop'); ?></td>
					</tr>
					<tr valign="top">
						<th scope="row"><?php _e('Custom Stylesheets String','ultrasimpleshop'); ?></th>
						<td>
							<input type="text" size="40" name="tqfep_custom_styles" value="<?php echo get_option('tqfep_custom_styles'); ?>" />
						</td>
						<td class="description"><?php _e('Use: ";Name of Field=CSS-class;. Works only if custom editor stylesheets are selected."','ultrasimpleshop'); ?></td>
					</tr>
				</table>
				<p></p>
				<p><input type="hidden" name="tqfep_update" value="true" />
				<input type="submit" name="Save" value="Save Settings" class="button-primary" /></p>
			</div>
		</form>
	</div>
<?php }


 
// second possibilty - styles inside editor
if(get_option('tqfep_styles')=="theme_stylesheet") {
	add_filter( 'mce_css', 'tinymce_css',5);
}
 
function ses_tinymce_css($wp) {
        $wp .= ',' . get_bloginfo('stylesheet_url');
        return $wp;
}
 
/**
 * The hard way - if other possibilities do not work
 */

if(get_option('tqfep_styles')=="force_custom") {
	add_filter('tiny_mce_before_init', 'cisStyles', 5);
}
	
function cisStyles($initialArray) {
	$modifiedArray = $initialArray;
 
	$modifiedArray['theme_advanced_styles'] .= get_option('tqfep_custom_styles');
	//strip first and last character if it matches ";"
	$modifiedArray['theme_advanced_styles'] = trim($modifiedArray['theme_advanced_styles'], ';');
	return $modifiedArray;
}
 
/** TinyMCE Advanced and qTranslate - fix editing bugs */

if(get_option('tqfep_fix_pre')==1) {
	add_filter('htmledit_pre', 'fix_p_around_languagetag');
	add_filter('richedit_pre', 'fix_p_around_languagetag');
}

if(get_option('tqfep_fix_post')==1) {
	add_filter('content_save_pre','fix_p_after_edit');
}

function fix_p_around_languagetag ($content = '') {
	$content = html_entity_decode($content);
	$content = str_replace("<!--", "<!--", $content);
	$content = str_replace("-->", "-->", $content);
	$content = preg_replace("/(-->)(\s|&nbsp;)*<p>(\s|&nbsp;)*(<\/p>)(\s|&nbsp;)*/","-->",$content); 
	$content = htmlentities($content,ENT_COMPAT | ENT_HTML401,get_option('tqfep_encoding'));
	return $content;
}

function fix_p_after_edit ($content) {
	$content = str_replace("<!--", "<!--", $content);
	$content = str_replace("-->", "-->", $content);
	$content = preg_replace("/(-->)(\s|&nbsp;)*<p>(\s|&nbsp;)*(<\/p>)(\s|&nbsp;)*/","-->",$content); 
	return $content;
} 








</pre>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2012%2F01%2F28%2Fwordpress-3-3-tinymce-advanced-qtranslate-fix-style-problems%2F&#038;title=WordPress%203.3%20%E2%80%93%20TinyMCE%20Advanced%20%E2%80%93%20qTranslate%20%E2%80%93%20fix%20style%20problems" data-a2a-url="https://blog.blackbam.at/2012/01/28/wordpress-3-3-tinymce-advanced-qtranslate-fix-style-problems/" data-a2a-title="WordPress 3.3 – TinyMCE Advanced – qTranslate – fix style problems"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2012/01/28/wordpress-3-3-tinymce-advanced-qtranslate-fix-style-problems/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
		<item>
		<title>Convert WordPress attachment URLs into file URLs</title>
		<link>https://blog.blackbam.at/2012/01/10/convert-wordpress-attachment-url-into-file-url-automatically/</link>
					<comments>https://blog.blackbam.at/2012/01/10/convert-wordpress-attachment-url-into-file-url-automatically/#respond</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Tue, 10 Jan 2012 20:44:53 +0000</pubDate>
				<category><![CDATA[WP Scripts]]></category>
		<category><![CDATA[url conversion]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=1789</guid>

					<description><![CDATA[You do not want to use Attachment-Pages in your WordPress page? Or maybe you installed a gallery Plugin and want to transform all your Attachment URLs into File-URLs now? The following script will do this for you. Just make sure, that all relevant content blocks of your database run through this script. function cis_file_links($content) { [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>You do not want to use Attachment-Pages in your WordPress page? Or maybe you installed a gallery Plugin and want to transform all your Attachment URLs into File-URLs now? The following script will do this for you. Just make sure, that all relevant content blocks of your database run through this script. </p>
<pre lang="php">
function cis_file_links($content) {
 
	$content = stripslashes($content);
 	
	$matches = array();
	$attachment_urls = preg_match_all("/href=\"([-A-Z0-9+&@#\/%?=~_|!:,.;]*)\?attachment_id=([0-9]*)\"/siU",$content,$matches);
 
	$urls = array();
	foreach($matches[2] as $attachment) {
		array_push($urls,wp_get_attachment_url($attachment));
	}
 
	// something went wrong with geting the attachments
	if(count($matches[2])!=count($urls)) {
		return $content;
	}
 
	for($i=0;$i<count($urls);$i++) {
		$repl = "href=\"".$urls[$i]."\"";
		$content = preg_replace("/href=\"([-A-Z0-9+&#038;@#\/%?=~_|!:,.;]*)\?attachment_id=([0-9]*)\"/siU",$repl,$content,1);
	}
 
	return $content;
}
</pre>
<p>If you want to apply this script to every displayed content, for example, without changing any contents of your database, add this filter to your functions.php:</p>
<pre lang="php">
add_filter('the_content','cis_file_links');
</pre>
<p>Improvement ideas are welcome.</p>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2012%2F01%2F10%2Fconvert-wordpress-attachment-url-into-file-url-automatically%2F&#038;title=Convert%20WordPress%20attachment%20URLs%20into%20file%20URLs" data-a2a-url="https://blog.blackbam.at/2012/01/10/convert-wordpress-attachment-url-into-file-url-automatically/" data-a2a-title="Convert WordPress attachment URLs into file URLs"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2012/01/10/convert-wordpress-attachment-url-into-file-url-automatically/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Order WordPress categories by custom meta value</title>
		<link>https://blog.blackbam.at/2011/10/28/order-categories-by-custom-meta-value/</link>
					<comments>https://blog.blackbam.at/2011/10/28/order-categories-by-custom-meta-value/#respond</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Thu, 27 Oct 2011 22:18:15 +0000</pubDate>
				<category><![CDATA[WP Scripts]]></category>
		<category><![CDATA[wordpress categories]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=1759</guid>

					<description><![CDATA[This little scripts help ordering WordPress categories by meta values &#8211; a thing which is not integrated into WordPress yet and which costs some time to integrate. 1. Create a meta value (or meta values) for categories to order by To order categories by a meta value the first thing which we have to do [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>This little scripts help ordering WordPress categories by meta values &#8211; a thing which is not integrated into WordPress yet and which costs some time to integrate.</p>
<h2>1. Create a meta value (or meta values) for categories to order by</h2>
<p>To order categories by a meta value the first thing which we have to do is to create a custom category meta value to order these (this first script is adapted from <a href="http://en.bainternet.info/2011/wordpress-category-extra-fields">bainternet.com</a>, where it is demonstrated in more detail).</p>
<p>&nbsp;</p>
<pre lang="php">
//add extra fields to category edit form hook
add_action ( 'add_category_form', 'extra_category_fields');
add_action ( 'edit_category_form_fields', 'extra_category_fields');
 
//add extra fields to category edit form callback function
function extra_category_fields( $tag ) {    //check for existing featured ID
 
    $t_id = $tag->term_id;
    $cat_meta = get_option("category_$t_id");
?>
 
<tr class="form-field">
	<th scope="row" valign="top">
	<label for="cat_order_val"><?php _e('Category order value'); ?></label></th>
	<td>
		<input type="text" name="cat_meta[cat_order_val]" id="cat_order_val" size="3" style="width:20%;" value="<?php echo $cat_meta['cat_order_val'] ? $cat_meta['cat_order_val'] : ''; ?>"><br />
		<span class="description"><?php _e('Enter a numeric value.'); ?></span>
	</td>
</tr>
<?php
 
}

// save extra category extra fields hook
add_action ( 'edited_category', 'save_extra_category_fileds');

   // save extra category extra fields callback function
function save_extra_category_fileds( $term_id ) {
	
    if ( isset( $_POST['cat_meta'] ) ) {
    	
        $t_id = $term_id;
        $cat_meta = get_option( "category_$t_id");
        $cat_keys = array_keys($_POST['cat_meta']);
		
        foreach ($cat_keys as $key){
            if (isset($_POST['cat_meta'][$key])){
                $cat_meta[$key] = $_POST['cat_meta'][$key];
            }
        }
			
        //save the option array
        update_option( "category_$t_id", $cat_meta );
    }
}
</pre>
<h2>2. Order the categories by the created meta value and display these</h2>
<pre lang="php">
// get the categories
$categories = get_categories();
 
$sortar = array();
foreach($categories as $ct) {
	$term_id = $ct->term_id;
	$cat_meta = get_option( "category_$term_id");
	array_push($sortar,array(intval($cat_meta['cat_order_val']),$ct));
}
 
uasort($sortar,create_function('$a,$b','return ($a[0]<=$b[0]) ? -1 : 1;'));
 
$ordered_categories = array();
 
foreach($sortar as $sor) {
	array_push($ordered_categories,$sor[1]);
}
 
foreach($ordered_categories as $oc) {
	// do whatever you want with your category objects
}
</pre>
<p>Have fun and be free to use these scripts. Improvement ideas are welcome.</p>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2011%2F10%2F28%2Forder-categories-by-custom-meta-value%2F&#038;title=Order%20WordPress%20categories%20by%20custom%20meta%20value" data-a2a-url="https://blog.blackbam.at/2011/10/28/order-categories-by-custom-meta-value/" data-a2a-title="Order WordPress categories by custom meta value"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2011/10/28/order-categories-by-custom-meta-value/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Determine if a WordPress page or category is in the current ancestor/child tree (inside/outside the loop)</title>
		<link>https://blog.blackbam.at/2011/10/08/determine-if-a-wordpress-page-or-category-is-in-the-current-ancestorchild-tree-insideoutside-the-loop/</link>
					<comments>https://blog.blackbam.at/2011/10/08/determine-if-a-wordpress-page-or-category-is-in-the-current-ancestorchild-tree-insideoutside-the-loop/#comments</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Sat, 08 Oct 2011 20:00:53 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP Scripts]]></category>
		<category><![CDATA[ancestor/child]]></category>
		<category><![CDATA[wordpress categories]]></category>
		<category><![CDATA[wordpress inheritance]]></category>
		<category><![CDATA[wordpress taxonomies]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=1722</guid>

					<description><![CDATA[It is a common problem to detect parents or childs of pages and categories in WordPress correctly. The way WordPress stores relationships in hierarchies is not that trivial sometimes, so the results when querying are a bit confusing sometimes. It took some time to determine and optimize functions which do this job good and without faults, and I want to present these. As in this function I prefer working with page IDs, as this is the savest way to identify certain pages. With little changes it should also be possible to use these using e.g. slugs. Both of these functions can be used inside and outside of "the Loop" or loops.]]></description>
										<content:encoded><![CDATA[<p>It is a common problem to detect parents or childs of pages and categories in WordPress correctly. The way WordPress stores relationships in hierarchies is not that trivial sometimes, so the results when querying are a bit confusing sometimes. It took some time to determine and optimize functions which do this job good and without faults, and I want to present these. As in this function I prefer working with page IDs, as this is the savest way to identify certain pages. With little changes it should also be possible to use these using e.g. slugs. Both of these functions can be used inside and outside of &#8220;the Loop&#8221; or loops.</p>
<h2>Check if the current page (or a given page) is in the child tree of a given page</h2>
<p>This function checks if the current page (or a given page, second parameter) is in the child tree of a given page.</p>
<pre lang="php">
/* Tests, if a page has got a certain parent anywhere in the ancestor/children tree */
function is_tree($pid, $pid2check = 0) {// $pid = The ID of the page we're looking for pages underneath
 
	global $post;
	// load details about this page
 
	// check if we should check two posts independently from the current query
	if ($pid2check < 1) {
		$pid2check = $post -> ID;
	}
 
	$anc = get_post_ancestors($pid2check);
 
	foreach ($anc as $ancestor) {
		if (is_page() && $ancestor == $pid) {
			return true;
		}
	}
 
	if (is_page() && (is_page($pid))) {
		return true;
		// we're at the page or at a sub page
	} else {
		return false;
		// we're elsewhere
	}
}
</pre>
<h2>Check if the current post (or a given post) is in the ancestor/child tree of a given category</h2>
<p>This function checks if the current post (or a given post identified by ID, second parameter) is in the ancestor/child tree of a given category.</p>
<pre lang="php">
/* Tests, if the given category is the current category, or in the ancestor/child tree of a given post or a child of it */
function is_category_or_sub($cat_id = 0, $pid = 0) {
	global $post;
 
	// check if a custom post id was given or get default (standard)
	if($pid<1) {
		$pid=$post->ID;
	}
 
	// check it for each category
    foreach (get_the_category($pid) as $cat) {
    	if ($cat_id == $cat->cat_ID || cat_is_ancestor_of($cat_id, $cat))  {
    		return true;
        }
    }
    return false;
}
</pre>
<h2>Check if a given category is in the current category tree</h2>
<p>Helpful if you have to determine the current category manually &#8211; checks if a given category is in the tree of another given category.</p>
<pre lang="php">
function in_category_tree($parent_cat,$child_or_equal_cat) {
	if($parent_cat ==$child_or_equal_cat || cat_is_ancestor_of($parent_cat, $child_or_equal_cat)) {
		return true;
	}
	return false;
}
</pre>
<h2>Custom Taxonomy hierarchy check</h2>
<p>Determine the top level taxonomy or check if a taxonomy is in the current taxonomies hirarchical tree.</p>
<pre lang="php">
function is_taxonomy_or_sub($child_or_equal_term_id,$parent_term_id,$taxonomy_name) {
       if($parent_term_id==$child_or_equal_term_id || $parent_term_id == get_top_level_term($child_or_equal_term_id,$taxonomy_name))  {
                return true;
        }
 }
 
function get_top_level_term($term_id,$taxonomy_name) {
	$term = get_term_by('id',$term_id,$taxonomy_name);
	if($term->parent>0) {
		return get_top_level_term($term->parent,$taxonomy_name);
	} else {
		return $term->term_id;
	}
}
</pre>
<p>This article is still under construction. Please report bugs, errors or improvement ideas, so we can optimize these scripts.</p>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2011%2F10%2F08%2Fdetermine-if-a-wordpress-page-or-category-is-in-the-current-ancestorchild-tree-insideoutside-the-loop%2F&#038;title=Determine%20if%20a%20WordPress%20page%20or%20category%20is%20in%20the%20current%20ancestor%2Fchild%20tree%20%28inside%2Foutside%20the%20loop%29" data-a2a-url="https://blog.blackbam.at/2011/10/08/determine-if-a-wordpress-page-or-category-is-in-the-current-ancestorchild-tree-insideoutside-the-loop/" data-a2a-title="Determine if a WordPress page or category is in the current ancestor/child tree (inside/outside the loop)"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2011/10/08/determine-if-a-wordpress-page-or-category-is-in-the-current-ancestorchild-tree-insideoutside-the-loop/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Using HTML line breaks and link sanitizer in WordPress comments</title>
		<link>https://blog.blackbam.at/2011/09/30/using-html-line-breaks-and-link-sanitizer-in-wordpress-comments/</link>
					<comments>https://blog.blackbam.at/2011/09/30/using-html-line-breaks-and-link-sanitizer-in-wordpress-comments/#respond</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Fri, 30 Sep 2011 12:43:20 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP Scripts]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[hyperlink]]></category>
		<category><![CDATA[line break]]></category>
		<category><![CDATA[sanitizer]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=1686</guid>

					<description><![CDATA[Recently we had an issue with the line-breaks in WordPress comments &#8211; the comments are saved to the database as they are submitted from the textarea in your theme, and depending on the theme so they are displayed. If your comments are displayed as HTML and there is no mechanism to add line breaks anywhere, [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Recently we had an issue with the line-breaks in WordPress comments &#8211; the comments are saved to the database as they are submitted from the textarea in your theme, and depending on the theme so they are displayed. If your comments are displayed as HTML and there is no mechanism to add line breaks anywhere, then the comments do not have any line-breaks (as HTML line breaks must be created with a br-tag or something similar).</p>
<p>&nbsp;</p>
<p>Another anoying thing is when commenters do not make links to hyperlinks, as these are not linked and clickable afterwards. We have found a solution for these problem &#8211; just copy the following script to your functions.php-file and your comments will be sanitized:</p>
<p>&nbsp;</p>
<pre lang="php">
add_filter('preprocess_comment','format_the_comment_html');
 
function format_the_comment_html($comment_data) {
	$comment_data['comment_content']=nl2br(makeClickableLinks($comment_data['comment_content']));
	return $comment_data;
}
 
function makeClickableLinks($text) {
	$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)','<a href="\\1">\\1</a>', $text);
	$text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)','\\1<a href="http://\\2">\\2</a>', $text);
	$text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})','<a href="mailto:\\1">\\1</a>', $text);
	return $text;
}
</pre>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2011%2F09%2F30%2Fusing-html-line-breaks-and-link-sanitizer-in-wordpress-comments%2F&#038;title=Using%20HTML%20line%20breaks%20and%20link%20sanitizer%20in%20WordPress%20comments" data-a2a-url="https://blog.blackbam.at/2011/09/30/using-html-line-breaks-and-link-sanitizer-in-wordpress-comments/" data-a2a-title="Using HTML line breaks and link sanitizer in WordPress comments"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2011/09/30/using-html-line-breaks-and-link-sanitizer-in-wordpress-comments/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Digging into roles and capabilities in WordPress &#8211; extension and global usage</title>
		<link>https://blog.blackbam.at/2011/07/02/digging-into-roles-and-capabilities-in-wordpress-extension-and-global-usage/</link>
					<comments>https://blog.blackbam.at/2011/07/02/digging-into-roles-and-capabilities-in-wordpress-extension-and-global-usage/#respond</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Sat, 02 Jul 2011 15:12:52 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP Scripts]]></category>
		<category><![CDATA[capabilites]]></category>
		<category><![CDATA[explanation]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[roles]]></category>
		<category><![CDATA[WordPress Plugins]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=1409</guid>

					<description><![CDATA[You may have noticed that understanding and extending roles and capabilities in WordPress can be a bit confusing as a start. On the one hand there are the default roles: (Super Admin), Administrator, Editor, Author, Contributor, Subscriber, and they all have more or less rights (=capabilities) to do actions on a WordPress website, with descending [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>You may have noticed that understanding and extending <a href="http://codex.wordpress.org/Roles_and_Capabilities">roles and capabilities in WordPress</a> can be a bit confusing as a start. On the one hand there are the default roles: (Super Admin), Administrator, Editor, Author, Contributor, Subscriber, and they all have more or less rights (=capabilities) to do actions on a WordPress website, with descending rights as they are ordered here. </p>
<p>&nbsp;</p>
<p>These roles do not exist since the early days of WordPress. They are mapped onto the traditional WordPress role system, which is a user level system from 0-10, while 10 is the highest level (all rights) and 0 is the lowest level (fewest rights). This interrelationship is shown on the following table from the Codex:</p>
<p>&nbsp;</p>
<p><a href="https://blog.blackbam.at/wp-content/uploads/2011/07/wp_role_capability_level-600x327.jpg"><img fetchpriority="high" decoding="async" src="https://blog.blackbam.at/wp-content/uploads/2011/07/wp_role_capability_level-600x327.jpg" alt="" title="WP roles and capabilities interrelationship" width="600" height="327" class="alignnone size-medium wp-image-1515" srcset="https://blog.blackbam.at/wp-content/uploads/2011/07/wp_role_capability_level-600x327.jpg 600w, https://blog.blackbam.at/wp-content/uploads/2011/07/wp_role_capability_level.jpg 772w" sizes="(max-width: 600px) 100vw, 600px" /></a></p>
<p>&nbsp;</p>
<p>Each of the user levels has a certain amount of capabilities. These capabilities exactly define what a WordPress user is allowed to do on the website. The capability &#8220;edit_posts&#8221;, for example, allows a user to edit his own published posts, the capability &#8220;add_users&#8221; allows a user to add new users to the system, and so on.</p>
<p>&nbsp;</p>
<h2>Important things to know about roles and capabilities</h2>
<p>The default system may be enough for blog systems, but not when it comes to WordPress as a CMS. The following things are important to know:</p>
<p><p>&nbsp;</p>
<ul>
<li>It is possible to create custom roles and custom capabilities (as they are registered default with <a href="http://codex.wordpress.org/Post_Types", f.e. "edit_job")>custom post types</a>)</li>
<li>One user can have more than one of the default roles, a user could be an &#8220;administrator&#8221;, &#8220;editor&#8221; and something like a custom &#8220;job_publisher&#8221; at the same time, for example. These roles are stored in the user-meta table for every user, in the field Table Prefix + capabilities.</li>
<li>You can make a semantic rule, that users on your website only are allowed to have one role at the same time, if you want to have a simplified role handling</li>
</ul>
<h2>How to extend the default role system then?</h2>
<p>You can search for functions and information how to do that in the Function Reference or using Google. I recommend the great and well-known <a href="http://wordpress.org/extend/plugins/members/">Members Plugin by Justin Tadlock</a>, which will make managing these things quite easy using the WordPress backend. Just check it out. It is described as follows:</p>
<p>&nbsp;</p>
<p><em></p>
<p>&#8220;Members is a plugin that extends your control over your blog. It&#8217;s a user, role, and content management plugin that was created to make WordPress a more powerful CMS.</p>
<p>&nbsp;</p>
<p>The foundation of the plugin is its extensive role and capability management system. This is the backbone of all the current features and planned future features.&#8221;</p>
<p></em></p>
<p>&nbsp;</p>
<h2>How can we easily get roles and work with roles in Plugins and Themes now?</h2>
<p>The following functions proved to be really useful, as they work almost anywhere you call them inside WordPress.</p>
<p>&nbsp;</p>
<div class="code_title">Returns the current users&#8217; roles on every page inside WordPress as an array</div>
<pre lang="php">
function getUserRolesAdminEdit() {
	
	$current_user = wp_get_current_user();
	
	$currentuserid = $current_user->ID;
	
	if(isset($_REQUEST['user_id']) && $_REQUEST['user_id']!="") {
		$currentuserid = $_REQUEST['user_id'];
	}
	
	$userroles = array('subscriber');
	
	$user = new WP_User( $currentuserid );
	
	if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
		$userroles=$user->roles;
	}
	
	return $userroles;
}
</pre>
<p>&nbsp;</p>
<div class="code_title">&#8230;or the current users&#8217; role as a string, if you are sure there is only one per user</div>
<pre lang="php">
function getUserRoleAdminEdit() {
	
	$current_user = wp_get_current_user();
	
	$currentuserid = $current_user->ID;
	
	if(isset($_REQUEST['user_id']) && $_REQUEST['user_id']!="") {
		$currentuserid = $_REQUEST['user_id'];
	}
	
	$userrole = 'subscriber';
	
	$user = new WP_User( $currentuserid );
	
	if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
		// only change this if one user can have more than one role, which is not expected
		$userrole=$user->roles[0];
	}
	
	return $userrole;
}
</pre>
<p>&nbsp;</p>
<div class="code_title">The following function always returns the correct user ID, which can be useful especially for admin pages</div>
<pre lang="php">
function getUserIdAdminEdit() {
	
	$current_user = wp_get_current_user();
	
	$currentuserid = $current_user->ID;
	
	if(isset($_REQUEST['user_id']) && $_REQUEST['user_id']!="") {
		$currentuserid = $_REQUEST['user_id'];
	}
	
	return $currentuserid;
}
</pre>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2011%2F07%2F02%2Fdigging-into-roles-and-capabilities-in-wordpress-extension-and-global-usage%2F&#038;title=Digging%20into%20roles%20and%20capabilities%20in%20WordPress%20%E2%80%93%20extension%20and%20global%20usage" data-a2a-url="https://blog.blackbam.at/2011/07/02/digging-into-roles-and-capabilities-in-wordpress-extension-and-global-usage/" data-a2a-title="Digging into roles and capabilities in WordPress – extension and global usage"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2011/07/02/digging-into-roles-and-capabilities-in-wordpress-extension-and-global-usage/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>WordPress improved user search (first name, last name, email) in backend</title>
		<link>https://blog.blackbam.at/2011/06/27/wordpress-improved-user-search-first-name-last-name-email-in-backend/</link>
					<comments>https://blog.blackbam.at/2011/06/27/wordpress-improved-user-search-first-name-last-name-email-in-backend/#comments</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Mon, 27 Jun 2011 22:35:01 +0000</pubDate>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP Scripts]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[search]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=1457</guid>

					<description><![CDATA[Recently, when working on a WordPress website for a huge amount of users, a customer was unsatisfyied with the WordPress backend search for users. The default backend search only is searching for your search string in usernames, but not for first name, last name or email of users. &#160; As most WordPress projects are barely [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Recently, when working on a WordPress website for a huge amount of users, a customer was unsatisfyied with the WordPress backend search for users. The default backend search only is searching for your search string in usernames, but not for first name, last name or email of users.</p>
<p>&nbsp;</p>
<p>As most WordPress projects are barely designed to have a huge amoung of users, this is not necessary in most cases. Anyway, the following code will help with this problem &#8211; add this to your functions.php-file and the WordPress user search will scan first name, last name and e-mail of every user.</p>
<p>&nbsp;</p>
<p style="text-align:center;"><a href="http://wordpress.org/extend/plugins/improved-user-search-in-backend/">Download the official WordPress Plugin</a></p>
<div class="code_title">How the Plugin basically works (code overview of Version 1.2)</div>
<pre lang="php">
 
   // the actual improvement of the query
    function user_search_by_multiple_parameters($wp_user_query) {
        if(false === strpos($wp_user_query -> query_where, '@') && !empty($_GET["s"])) {

            global $wpdb;

            $uids=array();

			// get the custom meta fields to search
			$iusib_custom_meta = get_option('iusib_meta_fields');
			$iusib_cma = array_map('trim', explode(",",$iusib_custom_meta));

			$iusib_add = "";
			// the escaped query string
			$qstr = mysql_real_escape_string($_GET["s"]);
			
			// add all custom fields into the query
			if(!empty($iusib_cma)) {
				$iusib_add = " OR meta_key='".implode("' OR meta_key='",$iusib_cma)."'";
			}

            $usermeta_affected_ids = $wpdb -> get_results("SELECT DISTINCT user_id FROM ".$wpdb->base_prefix."usermeta WHERE (meta_key='first_name' OR meta_key='last_name'".$iusib_add.") AND LOWER(meta_value) LIKE '%".$qstr."%'");

            foreach($usermeta_affected_ids as $maf) {
                array_push($uids,$maf->user_id);
            }

            $users_affected_ids = $wpdb -> get_results("SELECT DISTINCT ID FROM ".$wpdb->base_prefix."users WHERE LOWER(user_nicename) LIKE '%".$qstr."%' OR LOWER(user_email) LIKE '%".$qstr."%'");

            foreach($users_affected_ids as $maf) {
                if(!in_array($maf->ID,$uids)) {
                    array_push($uids,$maf->ID);
                }
            }
			
            $id_string = implode(",",$uids);

            $wp_user_query -> query_where = str_replace("user_nicename LIKE '%".$qstr."%'", "ID IN(".$id_string.")", $wp_user_query -> query_where);
        }
        return $wp_user_query;
    }

</pre>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2011%2F06%2F27%2Fwordpress-improved-user-search-first-name-last-name-email-in-backend%2F&#038;title=WordPress%20improved%20user%20search%20%28first%20name%2C%20last%20name%2C%20email%29%20in%20backend" data-a2a-url="https://blog.blackbam.at/2011/06/27/wordpress-improved-user-search-first-name-last-name-email-in-backend/" data-a2a-title="WordPress improved user search (first name, last name, email) in backend"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2011/06/27/wordpress-improved-user-search-first-name-last-name-email-in-backend/feed/</wfw:commentRss>
			<slash:comments>74</slash:comments>
		
		
			</item>
	</channel>
</rss>
