I'm working on a buddypress site in which members are allowed to post an ad that appears in the member directory, provided they also set an expiration date for it. Both fields are just Extended Profile Fields; the ad is a text area and the expiration date is, of course, a date picker.
In my theme, within the members-loop.php loop, I have the following code:
// This one works
<?php $ad = bp_get_member_profile_data('field=Member Directory Ad'); ?>
// This one doesn't
<?php $ad_expiry = bp_get_member_profile_data('field=Member Directory Ad Expiration'); ?>
There is no other special code to make this happen. I see no reason why the $ad_expiry is blank for a member who definitely has it set, especially when $ad has the correct value.
Digging into the buddypress code, my extended profile datebox data is not being returned by bp_get_member_profile_data(). Inside xprofile_format_profile_field() the value is being "formatted" by bp_format_time() and the output is empty. So I guess it's a buddypress bug.
I've figured out the bug, at least. BuddyPress stores the output of the datebox as a string like "2012-07-19 00:00:00". bp_get_member_profile_data() retrieves that from the database and then passes it to xprofile_format_profile_field(), which passes it to bp_format_time(), which returns false because the value fails the is_numeric() check.
Try this workaround -
//you need to specify the $user_id
$ad_expiry = xprofile_get_field_data('Member Directory Ad Expiration', $user_id );
// reformat, if you like
$ad_expiry = strtotime($ad_expiry);
echo date('m/d/Y', $ad_expiry);
.
And thanks for the bug report on trac.
Related
When I run custom workflow in YouTrack InCloud 2017.2:
rule Test for access to issue field
when issue.becomesReported() {
Assignee = loggedInUser;
}
I got:
Cannot set value to custom field Assignee
and ticket is not created. Could anybody point me to a reason for that?
Assignee field has type user and it is actually default field.
As #LiubovDievskaia kindly noticed the loggedInUser must be a member of a group that has access to the project. The same is correct of every user that is used as rhs value in any workflow rule
I want to generate a usernames st + first two initials of their first name + their last name.
There are few modules to create username of specific pattern but none of them can accomplish my requirement. I am not Drupal module expert.
What you can do is to install the automatic username module:
Navigate to the configuration page of this module: admin/config/people/accounts/patterns
Then, in the "Other settings" section you can check the option "Evaluate PHP in pattern."
This allows you to execute PHP in the "Pattern for username" field. Two things to consider:
PHP is executed after the token replacement, this allows you to actually manipulate the strings.
You need to echo the final result.
Make sure that the php is wrapped with <?php ?> tags. Also, if you make a syntax error, it will only be seen upon registration (Or whenever the script is executed.)
Now let's say you configured your users to have a first_name field and a last_name field (with those specific field names)
Your PHP could look something like this:
<?php
$initials = substr("[user:field-first-name]", 0, 2);
echo 'str' . $initials . "[user:field-last-name]";
?>
First, Note that the token are between double quotes to make sure that what is outputted by the token is considered a string by PHP
Second, the php function substr is used to get the 2 first letters of the first name.
Now, things I don't know
I have no idea what happens if two users happen to have the same resulting username
I don't know what happen if a user enters a double quote in his name, might be dangerous, you might want to escape it with a str_replace or something like that
I'm trying to apply the page's url as a <div> id to be able to target some css on each individual page. After some characters cleanup I'm hoping to get <div id="test-page">.
I have tried pulling it in from the object that I get via
ipContent()->getBreadcrumb()
Unfortunately they are all (including one I need) protected and cannot be echoed out.
[urlPath:protected] => test-page/
Is there a function that I've missed and can use to pull that in? Or a proper method of getting it from the object? Cheers.
And of course, as soon as I posted a question I've found the answer:
I could not get the protected value from [urlPath:protected] => test-page/ when doing this:
$a = ipContent()->getBreadcrumb();
$a = $a[0];
$a = $a->urlPath;
Solution: The way you can pull this is is by replacing $a->urlPath with $a->getUrlPath().
It will work for all the elements in object. Like: $a->updatedAt; needs to be $a->getUpdatedAt();
Hi I am working with the facebook javascript sdk and I am having succcess using fbml to list the logged in users name like so...
<fb:name uid="loggedinuser" useyou="false"></fb:name>
What I would like to do next is assign this value to a php variable and insert it into my database. The problem I'm having is when I assign this value to a php variable like so...
$first_name = ('<fb:name uid="loggedinuser" useyou="false"></fb:name>');
What gets inserted into the data base is the literal expression of
<fb:name uid="loggedinuser" useyou="false"></fb:name>
instead of the users real name. Is there anyway to do this with the javascript sdk? Thanks!
You need to get the variable of
<fb:name uid="loggedinuser" useyou="false"></fb:name>
before assigning it to
$first_name
FBML data is generated on the fly, there isn't a way to transfer data over like this since FBML would load later after PHP code is completed. In addition
$first_name = ('<fb:name uid="loggedinuser" useyou="false"></fb:name>');
Would never evaluate to anything other than a string, this is just how PHP works. This one line of code cannot possibly determine the nature within based on a string.
The JavaScript SDK offers a way to do this already
FB.api('/me', function(response) {
alert('Your name is ' + response.name);
});
Though this in JavaScript so you need to send the data in a AJAX call to your PHP application. It would be much easier if you just retrieved the session information after JS SDK login and let the PHP SDK take care of the rest.
Good day! Tell me, how can I add a quick link on the home page of the administrator to configure my module?
Follow the following steps:
1) In admin section to go Administration at top menu and then click on Quick Access.
2) IN next page click on Add new and you will see a form
3) Now open admin panel in another tab and to the module page or section, of which you want to place a link in quick access.
4) Copy that complete link in note pad and remove the token section of the link. It is required to remove the token section according to Prestashop.
5) Now come back to the add new form for quick access, give your link a name and then copy that modified link to the Url field.
6) Save it and you will have that link in quick access.
The above is method is used to add it at admin. Now if you want to add it pro-grammatically you can follow the following steps.
1) In your module in the install function, user a code like below
Db::getInstance()->insert('quick_access', array('new_window' => 0, 'link' => 'link_to_your_module_page'));
//an entry is made in quick_access table, get the quick_access id to insert lang data
$id = Db::getInstance()->Insert_ID(); //this will give you last inserted ID from quick_access table which is your current quick_access id.
//now make insertions in quick_access_lang table for multi language data.
//get all your site languages, and place a foreach loop and in that loop insert
//data into the quick_access_lang table using below code
Db::getInstance()->insert('quick_access_lang', array('id_quick_access' => $id, 'id_lang' => 'lang_id', 'name' => 'name of your link'));
//Now for uninstalling module, you want to delete the link, so you need to store the quick access link id in configuration table so you can use it later.
Configuration::updateValue('MY_QUICK_ACCESS_LINK_ID', $id);
2) Now in your uninstall function in your module class, place the below code
$id = Configuration::get('MY_QUICK_ACCESS_LINK_ID'); //get id of your quick access link
Db::getInstance()->delete('quick_access', 'where id_quick_access = '.$id);
Db::getInstance()->delete('quick_access_lang', 'where id_quick_access = '.$id);
//now delete the id from config table
Configuration::deleteByName('MY_QUICK_ACCESS_LINK_ID');
Note : The above code is not tested, it may / may not need some adjustments.
Thank you
There is a hook in Prestashop DisplayAdminHomeQuickLinks it will help you to add quick link on prestashop admin panel. I have use this in my theme. http://goo.gl/0S3mn And it will help you to solve the quick link.
In Prestashop 1.6.1 (maybe earlier too) in Admin view, at the top of the page, Quick Access has the option to "Add current page to QuickAccess". So just navigate to the Configuration page you need and use it.