Snippets offer many advantages. For example:
1. You can run the code globally, not just in the posts
2. The same code is not duplicated
3. It’s easy to change the code if you have 10,000 posts and each uses a shortcode
4. It is safer, because no one but the administrator can edit this code
5. You can transfer your snippets to another site
6. The code has special formatting and syntax highlighting
7. You can disable your snippet, right away in all posts
—
I corrected your code, but there are a lot of contradictions in it. I correctly understand that the code should only work for authorized users?
The map should be shown only to those who are not teachers?
To call the shortcode of another plugin in the snippet, you must use this function:
echo do_shortcode('[us_map]');
My version of the short code:
if( is_user_logged_in() ) {
global $wpdb;
$user_id = get_current_user_id();
if( $user_id == 0 ) {
echo '';
} else {
echo '<br/>';
$category = 'teacher';
$q = $GLOBALS['wpdb']->get_results('SELECT
*, wp_frm_item_metas.meta_value AS category
FROM ' . $wpdb->prefix . 'frm_item_metas, wp_frm_items
WHERE
wp_frm_item_metas.meta_value = "teacher"
AND wp_frm_items.user_id =' . $user_id . '
AND wp_frm_item_metas.item_id = wp_frm_items.id
LIMIT 1', OBJECT);
foreach($q as $row) {
if( $row->category != 'teacher' ) {
echo 'STUDENT';
echo do_shortcode('[us_map]');
}
}
}
}
This is your code, I just changed the method of calling the shortcode map:
if ( is_user_logged_in() ) {
$user_id = get_current_user_id();
if ($user_id == 0) {
echo '';
} else {
}
echo '<br/>';
global $wpdb;
$category = 'teacher';
$q = $GLOBALS['wpdb']->get_results( 'SELECT
*, wp_frm_item_metas.meta_value AS category
FROM '. $wpdb->prefix .'frm_item_metas, wp_frm_items
WHERE
wp_frm_item_metas.meta_value = "teacher"
AND wp_frm_items.user_id ='.$user_id.'
AND wp_frm_item_metas.item_id = wp_frm_items.id
LIMIT 1', OBJECT);
foreach($q as $row)
if ($row->category != 'teacher'){
echo'STUDENT';
}
{
if ($row->category != 'teacher'){
echo do_shortcode('[us_map]');
} else {
echo do_shortcode('[us_map]');
}
}
}
-
This reply was modified 6 years, 8 months ago by
webcraftic.