PHP - Filtering A Wordpress Admin Post List By Role
Hello all! So glad I found this forum. I would appreciate some assistance please. I'm working on a filter for a Custom Post Type . I need it to filter the list depending on the user's role. The way this should work is the following...
* Users in roles "formusers1" and "formusers2" can post. Users can only see their own posts. So far I can filter by roles "formusers1" and "formusers2" using `$query->set('author', $current_user->ID);` . However, when try to filter the list for role "formchecker1" I see posts from all roles. What am I doing wrong? Here's the rest of the code. Thanks for checking out!
```
function filter_posts_list($query) {
//MY VARIABLES
//FILTERING
if (current_user_can('formchecker2') && ('edit.php' == $pagenow) && $typenow == 'mycustomcpt' ) {
if ((current_user_can('formusers1') || current_user_can('formusers2')) && ('edit.php' == $pagenow) && $typenow == 'mycustomcpt') { Similar TutorialsHope someone here can help me. Ive been commissioned to convert a template to wordpress that includes a portfolio... I built a portfolio page from a custom post type. that works. Items are categorized with a custom taxonomy named port_cats. that works also On the portfolio page, there is tabbed content built with jquery to show and hide items by category. So theres a category nav menu, plus each item wrapped in classes to show and hide. Im stuck on plugging this in correctly, and am SO CLOSE. I have the category nav list working, but having trouble getting worpress to read the correct category slug inside the loop. Heres how the jquery needs to work: for the menu: Code: [Select] <li><a href="#" rel="category-slug">Category Name</a></li> to hide and show the items: Code: [Select] <ul> <li class="category-slug"> title/thumb/content </li> </ul> Heres my code: Code: [Select] <ul class="select"> <?php //list custom portfolio categories $taxonomy = 'port_cats'; // define portfolio categories from taxonomies in functions.php $tax_terms = get_terms($taxonomy); foreach ($tax_terms as $tax_term) { echo '<li><a href="#" rel="' . $tax_term->slug . '">' . $tax_term->name.'</a></li>'; } ?> </ul> <ul class="display"> <?php // ADD PORTFOLIO $loop = new WP_Query(array('post_type' => 'portfolio', 'posts_per_page' => 6)); while ( $loop->have_posts() ) : $loop->the_post(); $custom = get_post_custom($post->ID); $screenshot_url = $custom["screenshot_url"][0]; $website_url = $custom["website_url"][0]; ?> <li class="<?php echo $tax_term->slug; ?> "> <a href="<?=$website_url?>"><?php the_post_thumbnail(); ?></a> <?php the_title(); ?> <?php the_content(); ?> <a href="<?=$website_url?>Learn more</a> </li> <?php endwhile; ?> </ul> Whats happening is that worpdress is repeating the last category slug on every display item... can anyone tell me what i have wrong here??? THANK YOU! Trisha Hello! I am a 17 year old beginner Php student and I am currently creating a page for which I would like to create a blog management admin interface. I went very well, I can already add the categories to the database, through the admin interface or I can list them on the website. However, there would be a problem with creating a Blog post. Because I use the same create () function as for adding a category, but unfortunately the Blog Post does not add to the database. I don't get any php error code just when I try to list the post id after the create function. Instead of a value of 1, I get a 0. I enclose the code of the blog post and its control, as well as the data of my database!
Blog Posting form admin html and php code (ujblogposzt.php) ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<?php require_once('templates/head.php') ?> <!-- includes database and user controll -->
<?php include('app/controllers/posztok.php');?> <!-- Add new blog post controll file -->
<!-- Main content -->
<div class="card-footer">
</div>
<!-- bs-custom-file-input --> <?php require_once('templates/footer.php') ?>
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Blogpost controll code (posztok.php)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<?php
if (isset($_POST['add-post'])) {
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- I see everything okay in these codes, because I add the category to the database in the same way when adding a category my function called dd is at the end of the line of code, it's just for checking, it shows results. my create() function seen like this:
function create($table, $data)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- The strange thing is that if I add 1-2 items to the database statically without php code, it is detected and displayed in the blog editing menu, but I can't add a post to the database via the admin interface itself, that's why I wrote here ! :) From testing, I also print the end result of the create function at the end of the control code, which should return an id, but instead of id 1 I get a value of 0 and the post doesn't added to the database after pressing the post button['add-post'] and unfortunately I can't figure out why it is ?! I also attach the pictures of the problem!
The pictures of my problem can be viewed he https://drive.google.com/drive/folders/1WTVNv4LlbJiosWvBZoIRzjiUDkvhMgYk?usp=sharing
Thanks to anyone in advance !!!
Hello, I have a website designed in simple php http://www.fsbizcollect.com/. It has a wordpress blog installed under sub-directory called "business-debt-collection-agency-blog" To query posts from blog on home page, I am using: <? foreach($sql->select("wp_posts", "where post_status = 'publish' order by post_date desc limit 3") as $row){ ?> <div class="bEntry"> <h2><?= $row['post_title'] ?></h2> <h3><?= date('F j, Y', strtotime($row['post_date'])) ?></h3> <p> <?= $row['post_excerpt'] ?> <a href="<?= $row['guid'] ?>">Read More</a></p> </div> <? } ?> It is working fine. I want to put post thumbnails on homepage. Post thumbnail should be automatically resized to width=110px and will be placed in : <div class="blogThumb"> POST THUMBNAIL PHP SCRIPT WILL COME HERE </div> Could anyone provide php script for this? Thank you This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=333014.0 Hi, im looking to pull 3 posts from a specific Wordpress Category. At the minute I can pull 3 latest posts and display them in a flash banner using the code below. Code: [Select] SELECT yah_posts.*, yah_postmeta.* FROM yah_posts LEFT JOIN yah_postmeta ON yah_posts.ID = yah_postmeta.post_id WHERE yah_postmeta.meta_key = 'largeimage' && yah_posts.post_status = 'publish' ORDER BY post_date DESC LIMIT 3 I want to be able to pull 3 latest posts from a specific category instead of just 3 latest posts from every category. I have put together this code below, but it doesn't seem to be working Code: [Select] $query = "SELECT yah_posts.*, yah_postmeta.* FROM yah_posts LEFT JOIN yah_postmeta ON yah_posts.ID = yah_postmeta.post_id AND LEFT JOIN $yah_term_taxonomy ON($yah_term_relationships.term_taxonomy_id = $yah_term_taxonomy.term_taxonomy_id) WHERE yah_postmeta.meta_key = 'largeimage' && yah_posts.post_status = 'publish' AND $yah_term_taxonomy.term_id = '1' AND $yah_term_taxonomy.taxonomy = 'category' ORDER BY post_date DESC LIMIT 3"; This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=348171.0 Currently I can use php snoopy class to auto login in wordpress, but when I try to use the same method to post some articles in wordpress. It does not work. Any one has any ideas? I have tried to use httpwatch to monitor the post data and cookies. It seems I have include everything, but still doesn't work. thanks very much. This really driving me crazy. <?php include "Snoopy.class.php"; $snoopy = new Snoopy; //login part $submit_url = "http://localhost/wordpress/wp-login.php"; $submit_vars["log"] = "baibai"; //username $submit_vars["pwd"] = "123456"; //password $submit_vars["rememberme"] = "forever"; $submit_vars["redirect_to"] = "http://localhost/wordpress/wp-admin/"; $submit_vars["testcookie"] = "1"; $submit_vars["wp_sumbit"] = "submit"; $snoopy->submit($submit_url,$submit_vars); print $snoopy->results; $snoopy->setcookies(); $cookies = $snoopy->cookies; print_r ($cookies); //above part runs perfectly //post $snoopy->fetchform("http://localhost/wordpress/wp-admin/press-this.php"); print $snoopy->results; preg_match('/name=\"_wpnonce\" value=\"([0-9a-z]+)/',$snoopy->results,$matches); print $submit_vars1["_wpnonce"] = $matches[1]; $submit_vars1["autosave"] = ""; $submit_vars1["newtag[post_tag]"] = ""; $submit_vars1["tax_input[post_tag]"] = ""; $submit_vars1["autosave"] = ""; $submit_vars1["title"] = "title"; $submit_vars1["content"] = "content this is what i want post in wordpress"; $submit_vars1["original_post_status"] = "draft"; $submit_vars1["prev_status"] = "draft"; $submit_vars1["post_type"] = "text"; $submit_vars1["publish"] = "发布"; $submit_vars1["_wp_http_referer"] = "/wordpress/wp-admin/press-this.php?u=http%3A%2F%2Flocalhost%2Fwordpress%2Fwp-admin%2Ftools.php&t=%E5%B7%A5%E5%85%B7%20%E2%80%B9%20ekeyvision%20%E2%80%94%20WordPress&s=&v=4"; $submit_url1 = "http://localhost/wordpress/wp-admin/press-this.php?action=post"; $snoopy->submit($submit_url1,$submit_vars1); print $snoopy->results; ?> Also I do not want to use XML-RPC to solve this issue, since xml-rpc are not available is some settings. thanks I had a wordpress site setup for my maintenance company. I am not trying to setup a blog on the site. I have the blogroll showing up on this page: http://handymore.com/blog/ but when you click the individual articles the single post page shows a Error 404 message. Could anyone point me in the right direction as to how to fix this so that the individual post pages are found? Any guidance would be appreciated. Hello, Thanks for reading this. I'm working on a project where the homepage should be a Today's Deal and I'm using the Auto delete posts plugin to move the Today's Deal to the "Previous Deals" Category, after 24 hours. My task is to automatically redirect the homepage to the only post in Today's Deal Category, which will have different permalinks everyday. I'm querring the post with: <?php query_posts("cat=41&showposts=1"); ?> And I tried redirecting to the result with: <?php $url = the_permalink(); header("Location: $url"); ?> just after query_posts... but no success. I tried several other things too, apart from searching the web a lot before posting here. Help! Anyone? Thanks in advance! This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=352987.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=318539.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=356195.0 hi, I'm sruggling to get a drop down list to post the chosen value from an sql database.. could someone please point me in the right direction many thanks! Im wanting to not allow people to post any links in the comments section of a form (spammers) and have created a comma delimited list of essentially of every known domain name extension. To apply the filter I have the following code: Code: [Select] $WordAllowed = true; $BannedWords = explode(",", ReadDB($Options["ban_words"])); if (count($BannedWords)>0) { $checkComment = strtolower($_REQUEST["comment"]); for($i=0;$i<count($BannedWords);$i++){ $banWord = trim($BannedWords[$i]); if (trim($BannedWords[$i])<>'') { if(preg_match("/".$banWord."/i", $checkComment)){ $WordAllowed = false; break; } } } } if($WordAllowed==false) { $SysMessage = $OptionsLang["Banned_word_used"]; } else { Insert into my table I could have sworn this was working last time I was in this code but recently checking it again it is blocking pretty much everything claiming a banned word is used. The only thing I can get to post is 'lol'. Trying funny phrases like: first! or Great information, thanks, this is a test of the comment section, etc....they all get flagged Can anyone with fresh eyes assist? Im weary and frustrated and its been forever since I wrapped my head around this. My banned word list: Code: [Select] www,http,com,org,.aero,.asia,.biz,.com,.coop,.edu,.gov,.info,.int,.jobs,.mil,.mobi,.museum,.name,.net,.org, .pro,.tel,.travel,.xxx,.a,.bitnet,.ac,.ad,.ae,.af,.ag,.ai,.al,.am,.an,.ao,.aq,.ar,.as,.at,.au,.aw,.az,.ba,.bb,.bd,.be,.bf,.bg ,.bh,.bi,.bj,.bm,.bn,.bo,.br,.bs,.bt,.bv,.bw,.by,.bz,.ca,.cc,.cf,.cg,.ch,.ci,.ck,.cl,.cm,.cn,.co,.com,.cr,.cs,.cu,.cv,.cx,.cy,.cz ,.de,.dj,.dk,.dm,.do,.dz,.ec,.edu,.ee,.eg,.eh,.er,.es,.et,.fi,.fj,.fk,.fm,.fo,.fr,.fx,.ga,.gb,.gd,.ge,.gf,.gh,.gi,.gl,.gm,.gn ,.gov,.gp,.gq,.gr,.gs,.gt,.gu,.gw,.gy,.hk,.hm,.hn,.hr,.ht,.hu,.id,.ie,.il,.in,.io,.iq,.ir,.is,.it,.jm,.jo,.jp,.ke,.kg,.kh,.ki,.km ,.kn,.kp,.kr,.kw,.ky,.kz,.la,.lb,.lc,.li,.lk,.lr,.ls,.lt,.lu,.lv,.ly,.ma,.mc,.md,.mg,.mh,.mil,.mk,.ml,.mm,.mn,.mo,.mp,.mq,.mr, .ms,.mt,.mu,.mv,.mw,.mx,.my,.mz,.na,.nc,.ne,.net,.nf,.ng,.ni,.nl,.no,.np,.nr,.nt,.nu,.nz,.om,.org,.pa,.pe,.pf,.pg,.ph, .pk,.pl,.pm,.pn,.pr,.pt,.pw,.py,.qa,.re,.ro,.ru,.rw,.sa,.sb,.sc,.sd,.se,.sg,.sh,.si,.sj,.sk,.sl,.sm,.sn,.so,.sr,.st,.su,.sv, .sy,.sz,.tc,.td,.tf,.tg,.th,.tj,.tk,.tm,.tn,.to,.tp,.tr,.tt,.tv,.tw,.tz,.ua,.ug,.uk,.um,.us,.uy,.uz,.va,.vc,.ve,.vg,.vi,.vn,.vu,.wf, .ws,.ye,.yt,.yu,.za,.zm,.zr,.zw Thanks in advance for any help How can i play with these role in my database table as you can see here //I have a database table CREATE TABLE users ( id int(10) NOT NULL PRIMARY KEY AUTO_INCREMENT, urole varchar(10) ); in the role column, I have 2 roles first role is only used once but the sound one can be assigned to more than one user, now I want to check my table if the first role is already registered, then we can't register user with that role, also the second role can exist two or more times //check role, a variable user role has been defined as $urole = $_POST['urole']; $check = $connect -> prepare('SELECT * FROM users WHERE urole = ?'); $check -> execute([$urole]); $checkfetch = $check -> fetch(); //I'm stacking here, I want to put $checkfetch['urole'] in rowCount() to be counted but I think this is not a correct way of using rowCount() if(($checkfetch['urole'] == 'MainAdmin') && ($checkfetch ->rowCount() == 1)) { echo 'This role can be used by only once!'; } //another role if(($checkfetch['urole'] == 'NormalAdmin') && ($checkfetch ->rowCount() < 4)) { echo 'This role can be used 4 times only!'; }
Hi, I'm new to PHP/MySQL and need some help getting my query to work for my selection list: The selection list is built with: <form action='processformmissing.php' method='POST'> <fieldset> <legend>Choose Department</legend> <select name='depart'> <option value=''></option> <?php while ($row = mysqli_fetch_array($result)) { extract($row); echo "<option value='$department'>$department</option>\n"; } ?> </select> <p><input type='submit' value='Select Department' /></p> </fieldset> </form> The data is then sent to: $depart = $_POST['depart']; $deptlike = "%".$depart."%"; echo "<p>$depart</p>"; echo "<p>$deptlike</p>"; $query = "SELECT * FROM lifecerts INNER JOIN employees ON lifecerts.cid = employees.cid WHERE department LIKE '$deptlike' ORDER BY employees.name"; Hitting the submit button from my selection list form seems to be working fine because when I echo my data ($depart and $deptlike) it is giving me the correct value, but the query doesn't give me any results. However, if my post data comes from a text box instead of a selection list, my query works fine. Any thoughts on what I'm doing wrong??? Many thanks! I'm not totally new to php but I'm no guru either. I'm building an intranet and have three seperate user roles, user - manager - admin. There are some menu items I don't want to allow simple users to see. This will expand later to give them different views of a page as well (some can view/others can edit). As it stands the login validation is holding they're user level in $SESSION. To give you an idea take a look at what I'm trying to do: Code: [Select] function usermenu($usermenu) { if($user_level=0) echo ("<ul id="gooeymenu2" class="solidblockmenu"> <li><a href="main.php">Home</a></li> <li><a href="forms.php">Forms</a></li> <li><a href="/support/index.php" target="_new">Support</a></li> <li><a href="documents.php">Documents</a></li> <li><a href="admin/index.php">Admin</a></li> <li><a href="logout.php">Logout</a></li> </ul> <script> gooeymenu.setup({id:'gooeymenu2', selectitem:1, fx:'swing'}) </script>" "); else($user_level=1,2) echo ("<ul id="gooeymenu2" class="solidblockmenu"> <li><a href="main.php">Home</a></li> <li><a href="forms.php">Forms</a></li> <li><a href="/support/index.php" target="_new">Support</a></li> <li><a href="documents.php">Documents</a></li> <li><a href="new.php">New Adviser</a></li> <li><a href="admin/index.php">Admin</a></li> <li><a href="logout.php">Logout</a></li> </ul> <script> gooeymenu.setup({id:'gooeymenu2', selectitem:1, fx:'swing'}) </script>" "); Any help would be great, thanks in advance. Jason Hi all,
I am working on a project where i need to implement rbac control. I sthere any library available in codeigniter to extend the functionality. I have started working on codeigniter. i want to implement this in codeigniter. Please some on e guide how to achieve that. how to check roles and permssions.
Code what i made so far. Your comments at what should i do differently.
My configs.php
<?php $userQuery = 'SELECT * FROM users WHERE id = :id'; $user = $db->prepare($userQuery); $user->bindParam(':id', $_SESSION['userId'], PDO::PARAM_INT); $user->execute(); $userInfo = $user->fetch(PDO::FETCH_ASSOC); ?>functions.php <?php function loginCheck(){ global $db; if(isset($_SESSION['userId'], $_SESSION['loginString'])){ $query = 'SELECT username FROM users WHERE id = :id'; $user = $db->prepare($query); $user->bindParam(':id', $_SESSION['userId'], PDO::PARAM_INT); $user->execute(); $row = $user->fetch(PDO::FETCH_ASSOC); if($user->rowCount() == 1){ if(hash('sha512', $row['username'].$_SERVER['HTTP_USER_AGENT']) == $_SESSION['loginString']){ return true; }else{ return false; } }else{ return false; } }else{ return false; } } function checkUserRole(){//can be user, admin and moderator global $userInfo; if($userInfo['userRole'] == 'admin' or $userInfo['userRole'] == 'moderator'){ return true; }else{ return false; } } ?>shoutbox.php Can this be done with one query? global $db, $userInfo; $sbQuery = 'SELECT * FROM shoutbox ORDER BY dateCreated DESC LIMIT 30'; $sb = $db->query($sbQuery); $usersQuery = 'SELECT * FROM users WHERE shoutBoxBan = "yes"'; $users= $db->query($usersQuery); $usersRow = $users->fetch(PDO::FETCH_ASSOC); $hiddenAction = ''; while($sbRow = $sb->fetch(PDO::FETCH_ASSOC)){ if(loginCheck() and checkUserRole()){ $hiddenAction = " <a href=\"javascript:;\" onClick=\"deleteMessage('".$sbRow['id']."')\" class=\"shoutBoxDelete\" title=\"Delete\">x</a>"; if($usersRow['username'] == $sbRow['username']){ $hiddenAction .= " <a href=\"javascript:;\" onClick=\"unBan('".$sbRow['username']."')\" class=\"shoutBoxBan\" title=\"Unban\">u</a>"; }else{ if($userInfo['username'] != $sbRow['username']){//admin and moderator cant ban themselves. $hiddenAction .= " <a href=\"javascript:;\" onClick=\"banUser('".$sbRow['username']."')\" class=\"shoutBoxBan\" title=\"Ban\">o</a>"; $hiddenAction .= " <a href=\"javascript:;\" onClick=\"tempBanUser('".$sbRow['username']."')\" class=\"shoutBoxBan\" title=\"Temp Ban\">ø</a>"; } } } ....................................
Hi, I need code that reads from the roles database and then selects which file from these 3 which I want. For example, the user.php file would be loaded if the user has UName = user, Pass = 124, and Roles = User added to the database. But the admin.php and boss.php files would not appear to him.
<?php session_start(); if(!(isset($_SESSION['User']))) { header("Location: index.php"); exit(0); } ?> <!DOCTYPE html> <html> <body> <?php include "config.php"; ?> <!--show for User--> <?php include 'user.php';?> <!--show for Admin--> <?php include 'admin.php';?> <!--show for Boss--> <?php include 'boss.php';?> </body> </html>
|