Wordpress & Gravity Forms - Why Is My For Only Display Form Admin & Not Post Author On FrontEnd? - wordpress

I'm building a directory listings website where local businesses can add and edit their listings from the front-end of the website. I'm running into an issue where only administrators are able to view the form on the front end, but the listing author can't. Here is my conditional code:
<?php if(current_user_can( 'edit_others_posts', $post->ID ) || ($post->post_author == $current_user->ID)) { ?>
<?php
echo do_shortcode('[gravityform id="17" update=" '. $post->ID . '" title="false" ajax="true" description="false"]');
?>
<?php } ?>
I was able to find a fix yesterday. Apparently, to allow front-end edits to listings - you have to hook into a gravity forms settings and tell it to do so. Otherwise, non-admins won't be able to view the form.
// Allow gravity form editing on the front end
add_filter('gform_update_post/public_edit', '__return_true');

Related

How to Disable Woocommerce My Account Autodirect

I'd like to customize the Woocommerce login/register page using an editor plugin which requires you to be logged into the Wordpress Dashboard. The problem is Woocommerce directs to the My Account page if the user is logged in. Is there a snippet I could temporarily run that will tell Woocommerce to load the login/register page instead of the My Account page if the user is logged in?
I found a solution thanks to a reply Oliver Vogel made to someone else asking the same question here. Thanks Oliver! This is Oliver's Post
For non-technical people like me who are trying to edit the Woocommerce Login / Register page while being logged into the Wordpress dashboard, insert this snippet into the functions.php file preferably with a nice plugin like Code Snippets. It will create a shortcode called [woo-login]. Create a new web page and add the [woo-login] shortcode to it and the Woo login page will open even when you are logged in.
add_shortcode('woo-login', 'my_login');
function my_login() {
if (is_user_logged_in()) {
ob_start();
echo '<div class="woocommerce">';
wc_get_template('myaccount/form-login.php');
echo '</div>';
return ob_get_clean();
} else {
ob_start();
echo '<div class="woocommerce">';
wc_get_template('myaccount/form-login.php');
echo '</div>';
return ob_get_clean();
}
}

How to create separate log-in and registration pages in WooCommerce

I want to seperate the login and registration page for woocommerce.
(there is a different solution that I don't get to work here:
Separate registration page in WooCommerce website)
I duplicated the form-login.php and renamed it to register.php
In the register.php template I deleted the login-content.
I want to add a page to wordpress and add the register.php template with a SHORTCODE to that page. How do I do this??
Then I could add a Register Link to the Login Page with
<?php _e( ' Register' ); ?>
and the new shortcode register page is loaded.
mmmhhh...
what do I have to add to the duplicated login /now register.php, that it can be loaded to any page with a SHORTCODE? that would be interesting.
Thanks for helping out!Best wishes, Mika
A more straightforward way to do this is to save the contents of the original form-login.php as form-login-single.php, and then replace the file form-login.php with:
<?php
if( isset($_GET['action']) == 'register' ) {
wc_get_template( 'myaccount/form-register.php' );
} else {
wc_get_template( 'myaccount/form-login-single.php' );
}
This way you don't need to modify your functions.php further, plus you don't run into any trouble with double-rendering of the register form that I got when using #Hassan-ALi's method.
You can create a copy of the Woocommerce form-login.php and name it form-register.php. The form-login.php is located in /woocommerce/templates/myaccount/ folder.
Then in the form-login.php you can create a link to the form-register.php using this code
register
// Separete Login form and registration form
add_action('woocommerce_before_customer_login_form','load_registration_form', 2);
function load_registration_form(){
if(isset($_GET['action'])=='register'){
woocommerce_get_template( 'myaccount/form-registration.php' );
}
}

Wordpress Page ID within Shortcode

I am using a plugin called: InPost Gallery. I have added the shortcode to a template file but the shortcode needs the post ID to find the images related to the page. Is it possible to get the post id added to a shortcode in a template file?
This is what I have at the moment:
<?php echo do_shortcode("[inpost_nivo slide_width='600px' slide_height='auto' thumb_width='75' thumb_height='75' post_id="28" skin='light' transition_effect='random' transition_speed='600' autoslide='5000' control_nav='1' control_nav_thumbs='1' direction_nav='1' direction_nav_hide='0' controlNavThumbs='0' random_start='0' pause_on_hover='1' show_description='1' box_rows='4' box_cols='8' slices='15' start_slide='0' id='' random='0' group='0' show_in_popup='0' album_cover='' album_cover_width='200' album_cover_height='200' popup_width='800' popup_max_height='600' popup_title='Gallery' type='nivo'][/inpost_nivo]"); ?>
You can see the post_id is set to 28. This needs to change depending on the page currently being viewed.
If this is possible it would be a great help to hear your suggestions.
Many thanks
If it's within the loop, you can for example use:
<?php
// Display shortcode for current post:
$s = sprintf( '[inpost_nivo post_id="%d"]', get_the_ID() );
echo do_shortcode( $s );
?>
You could also try to skip the post_id attribute, and see if it has the same default setup.

make wordpress posts change content dynamically

Is there a way to customise a wordpress blog post so that it changes slightly based on the User?
eg. when showing a post around Salary and Bonuses on the company blog, I'd like to customise some of the text based on the employee level (director, Executive etc) - for example:
a paragraph of text about pension contribution should only appear to
directors reading the page
the bonus amount should change based on employee level.
I don't want to create several pages per category (eg. one page for the directors, one for the execs etc) - I would like to have just one blog post with some variable fields?
The codex has a great function outlined, current_user_can
http://codex.wordpress.org/Function_Reference/current_user_can
As well as WP_User_Query
http://codex.wordpress.org/Class_Reference/WP_User_Query
You can use both of these to accomplish your goal.
I needed to do something similar, I came up with custom roles based on the plugin "Capability Manager Enhanced".
In a file you can check the roles like:
<? if ( is_user_logged_in() ) : ?>
<?
global $current_user;
get_currentuserinfo();
$roles = $current_user->roles; //$roles is an array
if ( is_user_logged_in() && in_array("custom_role", $roles) ) {
echo('WORK HARDER!');
} else {
echo('NO CAKE FOR YOU!');
}
?>
<?php endif; ?>

Link to registration page in Wordpress

There is
wp_login_url, wp_logout_url, but what what about registration url?
Is there standard way to get link to registration? I need to display a link to registration page with further redirect to previous page.
PS I am using my theme login.
The following will return the registration url:
<?php
echo site_url('/wp-login.php?action=register');
?>
UPDATE:
To get the registration url with a redirect to the current page use:
<?php
echo site_url('/wp-login.php?action=register&redirect_to=' . get_permalink());
?>
Since 3.6, there is now a func:
http://codex.wordpress.org/Function_Reference/wp_registration_url
<?php echo wp_registration_url(); ?>
You can override it with the register_url filter.
add_filter( 'register_url', 'custom_register_url' );
function custom_register_url( $register_url )
{
$register_url = get_permalink( $register_page_id );
return $register_url;
}
I know this is an old question, but for anyone picking it up use wp_register().
It automatically determines if you're logged in and supplies either a link to the admin section of the site, or a link to the register form.
It also respects the settings in Settings -> General -> Membership (Anyone Can Register?)
If I understand correctly you are asking for default Word Press registration page. That would be www.domainname.com/wp-signup.php
<?php echo wp_registration_url(); ?>
https://codex.wordpress.org/Function_Reference/wp_registration_url
2 points here
Make sure you have turn on the "Anyone can register" in the setting page
if you host in a subfolder, make sure you include
Without subfolder:
Register
OR
Register
With subfolder
Register
In case of hosting your wordpress site in a subfolder (e.g.: mysite.com/myblog) you also need to include your site's url as follows:
<?php echo get_site_url() . "/wp-login.php?action=register" ?>
--> http://mysite.com/myblog/wp-login.php?action=register
Otherwise you will be redirected to a non-existing page
--> http://mysite.com/wp-login.php?action=register
1st of all I'm a WP newbe.
wp_registration_url can redirect the new user back to the page he came from, buy without enforcing login on the way (I dont use auto login because i want the user to authenticate the mail).
i use instead (sample with Allow PHP in posts plugin):
Register
hope it helps...
You can use wp_registration_url() any where you want to add link to wordpress registration
to add the redirection url use apply_filters()
<a href="<?php wp_registration_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ); ?>" >click to register</a>

Resources