<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
	<title>Dreamhart.org - Topic: PHP/Wordpress Help?</title>
	<link>https://dreamhart.org/forum/bug-reports/phpwordpress-help/</link>
	<description><![CDATA[Let us act our dreams with open eyes, and make them possible.]]></description>
	<generator>Simple:Press Version 5.7.5.3</generator>
	<atom:link href="https://dreamhart.org/forum/bug-reports/phpwordpress-help/rss/" rel="self" type="application/rss+xml" />
        <item>
        	<title>Jarandhel Dreamsinger on PHP/Wordpress Help?</title>
        	<link>https://dreamhart.org/forum/bug-reports/phpwordpress-help/#p404</link>
        	<category>Bug Reports</category>
        	<guid isPermaLink="true">https://dreamhart.org/forum/bug-reports/phpwordpress-help/#p404</guid>
        	        	<description><![CDATA[<p>And the actual code:</p>
<p>from projectmanager.php, the actions which call the register user function (the first is the app&#039;s original one, the second is the one added by me which works 100% of the time but requires the user to update their profile):</p>
<p><input type='button' class='sfcodeselect' name='sfselectit7250' value='Select Code' data-codeid='sfcode7250' /></p>
<div class='sfcode' id='sfcode7250'>		add_action( &#039;user_register&#039;, array(&#38;$projectmanager, &#039;registerUser&#039;) );<br />
		add_action( &#039;profile_update&#039;, array(&#38;$projectmanager, &#039;registerUser&#039;) );</div>
<p> </p>
<p>from core.php, the registerUser function:</p>
<p><input type='button' class='sfcodeselect' name='sfselectit2359' value='Select Code' data-codeid='sfcode2359' /></p>
<div class='sfcode' id='sfcode2359'>/**<br />
	 * registrer new user<br />
	 *<br />
	 * @param int $user_id<br />
	 * @return void<br />
	 */<br />
	function registerUser( $user_id )<br />
	{<br />
		require_once( PROJECTMANAGER_PATH.&#039;/admin/admin.php&#039; );<br />
		$admin = new ProjectManagerAdminPanel();<br />
		$user = new WP_User($user_id);<br />
		if ( $user-&#62;has_cap(&#039;projectmanager_user&#039;) ) {<br />
			foreach ( $this-&#62;getProjects() AS $project ) {<br />
				if ( 1 == $project-&#62;profile_hook )<br />
					$admin-&#62;addDataset( $project-&#62;id, $user-&#62;first_name, array(), false, $user_id );<br />
			}<br />
		}<br />
	}</div>
<p> </p>
<p>And from admin.php, the addDataset function called by registerUser:</p>
<p><input type='button' class='sfcodeselect' name='sfselectit6114' value='Select Code' data-codeid='sfcode6114' /></p>
<div class='sfcode' id='sfcode6114'>/**<br />
	 * add new dataset<br />
	 *<br />
	 * @param int $project_id<br />
	 * @param string $name<br />
	 * @param array $cat_ids<br />
	 * @param array $dataset_meta<br />
	 * @param false&#124;int $user_id<br />
	 * @return string<br />
	 */<br />
	function addDataset( $project_id, $name, $cat_ids, $dataset_meta = false, $user_id = false )<br />
	{<br />
		global $wpdb, $current_user, $projectmanager;<br />
		if ( $user_id &#38;&#38; $this-&#62;datasetExists($project_id, $user_id) ) {<br />
			$this-&#62;setMessage( __( &#039;You cannot add two datasets with same User ID.&#039;, &#039;projectmanager&#039; ), true );<br />
			return false;<br />
		}<br />
		$projectmanager-&#62;initialize($project_id);<br />
		$this-&#62;project_id = $project_id;<br />
		$project = $this-&#62;project = $projectmanager-&#62;getProject($project_id);<br />
		if ( !$user_id ) $user_id = $current_user-&#62;ID;<br />
		// Negative check on capability: user can&#039;t edit datasets<br />
		if ( !current_user_can(&#039;edit_datasets&#039;) &#38;&#38; !current_user_can(&#039;projectmanager_user&#039;) &#38;&#38; !current_user_can(&#039;import_datasets&#039;) ) {<br />
			$this-&#62;setMessage( __("You don&#039;t have permission to perform this task", &#039;projectmanager&#039;), true );<br />
			return;<br />
		}<br />
		// user has only cap &#039;projectmanager_user&#039; but not &#039;edit_other_datasets&#039; and &#039;edit_datasets&#039;<br />
		if ( current_user_can(&#039;projectmanager_user&#039;) &#38;&#38; !current_user_can(&#039;edit_other_datasets&#039;) &#38;&#38; !current_user_can(&#039;edit_datasets&#039;) &#38;&#38; !current_user_can(&#039;import_datasets&#039;) ) {<br />
			// and dataset with this user ID already exists<br />
			if ( $this-&#62;datasetExists($project_id, $user_id) ) {<br />
				$this-&#62;setMessage( __("You don&#039;t have permission to perform this task", &#039;projectmanager&#039;), true );<br />
				return;<br />
			}<br />
		}<br />
		$wpdb-&#62;query( $wpdb-&#62;prepare( "INSERT INTO {$wpdb-&#62;projectmanager_dataset} (name, cat_ids, project_id, user_id) VALUES (&#039;%s&#039;, &#039;%s&#039;, &#039;%d&#039;, &#039;%d&#039;)", $name, maybe_serialize($cat_ids), $project_id, $user_id ) );<br />
		$dataset_id = $wpdb-&#62;insert_id;<br />
 </p>
<p>		if ( $dataset_meta ) {<br />
			foreach ( $dataset_meta AS $meta_id =&#62; $meta_value ) {<br />
				$formfield = parent::getFormFields($meta_id);</p>
<p>				// Manage file upload<br />
				if ( &#039;file&#039; == $formfield-&#62;type &#124;&#124; &#039;image&#039; == $formfield-&#62;type &#124;&#124; &#039;video&#039; == $formfield-&#62;type ) {<br />
					$file = array(&#039;name&#039; =&#62; $_FILES[&#039;form_field&#039;][&#039;name&#039;][$meta_id], &#039;tmp_name&#039; =&#62; $_FILES[&#039;form_field&#039;][&#039;tmp_name&#039;][$meta_id], &#039;size&#039; =&#62; $_FILES[&#039;form_field&#039;][&#039;size&#039;][$meta_id], &#039;type&#039; =&#62; $_FILES[&#039;form_field&#039;][&#039;type&#039;][$meta_id]);<br />
					if ( !empty($file[&#039;name&#039;]) )<br />
						$this-&#62;uploadFile($file);<br />
					$meta_value = basename($file[&#039;name&#039;]);<br />
					// Create Thumbails for Image<br />
					if ( &#039;image&#039; == $formfield-&#62;type &#38;&#38; !empty($meta_value) ) {<br />
						$new_file = parent::getFilePath().&#039;/&#039;.$meta_value;<br />
						$image = new ProjectManagerImage($new_file);<br />
						// Resize original file and create thumbnails<br />
						$dims = array( &#039;width&#039; =&#62; $project-&#62;medium_size[&#039;width&#039;], &#039;height&#039; =&#62; $project-&#62;medium_size[&#039;height&#039;] );<br />
						$image-&#62;createThumbnail( $dims, $new_file, $project-&#62;chmod );<br />
						$dims = array( &#039;width&#039; =&#62; $project-&#62;thumb_size[&#039;width&#039;], &#039;height&#039; =&#62; $project-&#62;thumb_size[&#039;height&#039;] );<br />
						$image-&#62;createThumbnail( $dims, parent::getFilePath().&#039;/thumb.&#039;.$meta_value, $project-&#62;chmod );</p>
<p>						$dims = array( &#039;width&#039; =&#62; 80, &#039;height&#039; =&#62; 50 );<br />
						$image-&#62;createThumbnail( $dims, parent::getFilePath().&#039;/tiny.&#039;.$meta_value, $project-&#62;chmod );<br />
					}<br />
				} elseif ( &#039;numeric&#039; == $formfield-&#62;type &#124;&#124; &#039;currency&#039; == $formfiel-&#62;type ) {<br />
					$meta_value += 0; // convert value to numeric type<br />
				}</p>
<p>				if ( is_array($meta_value) ) {<br />
					// form field value is a date<br />
					if ( array_key_exists(&#039;day&#039;, $meta_value) &#38;&#38; array_key_exists(&#039;month&#039;, $meta_value) &#38;&#38; array_key_exists(&#039;year&#039;, $meta_value) ) {<br />
						$meta_value = sprintf("%s-%s-%s", $meta_value[&#039;year&#039;], $meta_value[&#039;month&#039;], $meta_value[&#039;day&#039;]);<br />
					} elseif ( array_key_exists(&#039;hour&#039;, $meta_value) &#38;&#38; array_key_exists(&#039;minute&#039;, $meta_value) ) {<br />
						$meta_value = sprintf("%s:%s", $meta_value[&#039;hour&#039;], $meta_value[&#039;minute&#039;]);<br />
					}<br />
				}<br />
				$wpdb-&#62;query( $wpdb-&#62;prepare( "INSERT INTO {$wpdb-&#62;projectmanager_datasetmeta} (form_id, dataset_id, value) VALUES (&#039;%d&#039;, &#039;%d&#039;, &#039;%s&#039;)", $meta_id, $dataset_id, maybe_serialize($meta_value) ) );<br />
			}</p>
<p>			// Check for unsubmitted form data, e.g. checkbox list<br />
			if ($form_fields = parent::getFormFields()) {<br />
				foreach ( $form_fields AS $form_field ) {<br />
					if ( !array_key_exists($form_field-&#62;id, $dataset_meta) ) {<br />
						$wpdb-&#62;query( $wpdb-&#62;prepare( "INSERT INTO {$wpdb-&#62;projectmanager_datasetmeta} (form_id, dataset_id, value) VALUES (&#039;%d&#039;, &#039;%d&#039;, &#039;&#039;)", $dataset_id, $form_field-&#62;id ) );<br />
					}<br />
				}<br />
			}<br />
		} else {<br />
			// Populate empty meta value for new registered user<br />
			foreach ( $projectmanager-&#62;getFormFields() AS $formfield ) {<br />
				$wpdb-&#62;query( $wpdb-&#62;prepare( "INSERT INTO {$wpdb-&#62;projectmanager_datasetmeta} (form_id, dataset_id, value) VALUES (&#039;%d&#039;, &#039;%d&#039;, &#039;&#039;)", $formfield-&#62;id, $dataset_id ) );<br />
			}<br />
		}<br />
		if ( isset($_FILES[&#039;projectmanager_image&#039;]) &#38;&#38; $_FILES[&#039;projectmanager_image&#039;][&#039;name&#039;] != &#039;&#039;  )<br />
			$this-&#62;uploadImage($dataset_id, $_FILES[&#039;projectmanager_image&#039;]);</p>
<p>		$this-&#62;setMessage( __( &#039;New dataset added to the database.&#039;, &#039;projectmanager&#039; ) );</p>
<p>		do_action(&#039;projectmanager_add_dataset&#039;, $dataset_id);<br />
	}</p>
</div>
]]></description>
        	        	<pubDate>Fri, 25 Jun 2010 14:20:56 -0400</pubDate>
        </item>
        <item>
        	<title>Jarandhel Dreamsinger on PHP/Wordpress Help?</title>
        	<link>https://dreamhart.org/forum/bug-reports/phpwordpress-help/#p397</link>
        	<category>Bug Reports</category>
        	<guid isPermaLink="true">https://dreamhart.org/forum/bug-reports/phpwordpress-help/#p397</guid>
        	        	<description><![CDATA[<p>Ok, this is driving me out of my gourd so I&#039;m going to post about it here and maybe someone will read it who understands this stuff better than I do (I do not claim any actual ability to program in PHP):</p>
<p>I am running the plugin <a href="http://wordpress.org/extend/plugins/projectmanager/" target="_blank">Project Manager</a> for WordPress.  It&#039;s a very nice plugin that (among other things) allows for extending user profiles with extra data that can then be displayed in a searchable table.  It&#039;s what the <a href="/links/kindir/" target="_blank">Otherkin Directory</a> section of the site is being built on.  And mostly, it&#039;s working great.</p>
<p>The problem comes in with the creation of new users.  It&#039;s supposed to create a new dataset automatically whenever a new user is created whose role allows them to use the profile hook.  The default role on this website for new users does allow them to use that hook.  And when I create a new account from the admin panel, it works fine.</p>
<p>However, when I create a new account as if I was a new user registering on the site?  No new dataset is created.</p>
<p>Sounds like a permission issue, right?  Well, here&#039;s where it gets weirder.</p>
<p>Right now, the plugin is hooking into the action user_register, which is called whenever a new user account is created (either by the admin or by a new user registering).  When that action occurs, the plugin runs a function to create a new dataset.</p>
<p>If I make a copy of that function call, and tell it to hook into the action profile_update, which is called whenever a user updates their profile, newly created users (including the ones for whom the user_register hook failed once already) have a dataset created for them if there is not one associated with their account already.  This hook works 100% of the time.</p>
<p>Same user, same permissions.  Two hooks that should both be called 100% of the time.  Only one is working reliably on the user side.  Thoughts?  I don&#039;t even know what could be causing this behavior at this point.  I also tried hooking it into wp_new_user_notification and get_user_meta, both of which seemed to work but only intermittently, if that provides any useful data.  Frankly the intermittent aspect just confuses me even more.</p>
<p>Btw, I have also tested this on a clean install of wordpress with no other plugins active and experienced the same issues.  So right away we should be able to rule out plugin conflicts or anything that would be particular to my setup.</p>
]]></description>
        	        	<pubDate>Fri, 25 Jun 2010 10:13:28 -0400</pubDate>
        </item>
</channel>
</rss>
<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Object Caching 27/383 objects using Memcached
Page Caching using Disk: Enhanced (Page is feed) 
Lazy Loading (feed)

Served from: dreamhart.org @ 2026-11-23 18:56:19 by W3 Total Cache
-->