Paid Membership Pro if statement in Wordpress theme - wordpress

I'm using the www.paidmembershipspro.com plugin on my wordpress site and I want to do an if statement in my wordpress theme...
if (has membership) {
// echo
} else {
}
I've gone through the docs and I cannot find a solution.

According to their docs (you need to sign up to view them) you can use pmpro_hasMembershipLevel to check for level ID or name, so for example:
if(pmpro_hasMembershipLevel('12')) {
...
if(pmpro_hasMembershipLevel('Gold')) {
...
You can even check for an array of levels:
if(pmpro_hasMembershipLevel(array(12,14,'Gold')))

Related

WordPress Multisite - Different admin theme on different site

I want to set different color on the dashboard of each site (in my multisite). For example the first site is based on the user's preference, but the second one always use Midnight theme.
Is there a way to set this in functions.php?
Thanks
Just found it on other's question. Put this on functions.php.
add_filter('get_user_option_admin_color', 'change_admin_color');
function change_admin_color($result) {
if(get_current_blog_id() === 2) {
return 'midnight';
}
else {
return $result;
}
}

Modify User Roles in WordPress?

I have been working on a client's WordPress Website and last day my client want to hide navigation menu and pages from author/contributor categories.
I have searched and tried some of the plugin but didn't get the exact thing. Please let me know what should i use to hide some pages from user and from navigation.
Only Admin can see all the pages and other members should see only 1 section that is allowed to visible for them.
Thank You
use this plugin to manage All roll:
http://wordpress.org/plugins/user-role-editor/
Here is the Complete function for removing each Menu and submenu from wp-admin for another user:
function remove_menus() {
global $menu, $submenu;
$restricted = array(__('Dashboard'), __('Profile'), __('Users'), __('Tools'), __('Comments'), __('Settings'), __('Plugins')); //Here you can also define the name like Pages
end($menu);
while (prev($menu)) {
$value = explode(' ', $menu[key($menu)][0]);
if (in_array($value[0] != NULL ? $value[0] : "", $restricted)) {
unset($menu[key($menu)]);
}
}
unset($menu[5]); // this is just for example
unset($submenu['edit.php'][16]); // this is just for example
}
Now You have to put a conditon for other user i.e:
$thisusername = $current_user->user_login; // this is to get the current user login
if (($thisusername == "user123")) {
add_action('admin_menu', 'remove_menus');
}
Note: You can find many plugins but all of them are not in depth like this code.Well you can try this plugin to manage your user's roles.Capability Manager Plugin

modify url permalink wordpress

I use wordpress and I have the following question,
I use the URL:
- www.mysite.com/page
- www.mysite.com/cat/page
- www.mysite.com/custompostype/post
The value of permalinks is %category%/%postname%, everything works fine except now I have to use two languages ​​and I want to configure as follows:
www.mysite.com/EN/page
www.mysite.com/ES/cat/page
www.mysite.com/BR/custompostype/post
I want to change the structure of wordpress urls where the first rule is the language and to take it as variable value. Similar to /%lang%/%category%/%postname%/
i used the wp_rewrite and have had no success, any idea?
for now I just found a solution to my problem, which I handled sessions
<?php function init_sessions() {
if (!session_id()) {
session_start();
} } add_action('init', 'init_sessions'); ?> <?php function detecta_idioma() { if($_SESSION["IDIOMA"]["actual"]=="") {
$_SESSION["IDIOMA"]["actual"]="ES";
$_SESSION["IDIOMA"]["abreviatura"]="";
$_SESSION["IDIOMA"]["nombre"]="Español";
$_SESSION["IDIOMA"]["tag"]="ES"; } if($_GET["action"]=="idioma" &&
$_GET["lang"]) { unset($_SESSION["IDIOMA"]);
switch($_GET["lang"]) { case "EN":
$_SESSION["IDIOMA"]["actual"]="EN";
$_SESSION["IDIOMA"]["abreviatura"]="_en";
$_SESSION["IDIOMA"]["nombre"]="Ingles";
$_SESSION["IDIOMA"]["tag"]="EN"; break; case "ES": default:
$_SESSION["IDIOMA"]["actual"]="ES";
$_SESSION["IDIOMA"]["abreviatura"]="";
$_SESSION["IDIOMA"]["nombre"]="Español";
$_SESSION["IDIOMA"]["tag"]="ES"; break;
} } $IDIOMA=array("actual"=>$_SESSION["IDIOMA"]["actual"],"ab"=>$_SESSION["IDIOMA"]["abreviatura"],"nombre"=>$_SESSION["IDIOMA"]["nombre"],"tag"=>$_SESSION["IDIOMA"]["tag"]);
global $wp_rewrite;
$wp_rewrite->set_permalink_structure($_SESSION["IDIOMA"]["tag"].'/%category%/%postname%');
return $IDIOMA; } add_action('init', 'detecta_idioma'); ?>
works well on the route entries, eg www.misitio.com/en/post-demo, t not working with pages or categories or taxonomies, eg: www.misite.com/es/category/, www.site.com/es/page/subpage or www.site.com/br/taxonomy <----- Dont work, shows error 404 page
I can not use the plugin qTranslate and CMS plugin multulengual either they do not work well with the use of plugins Advanced custom fields and custom post types UI.
Thanks

How can I customize a specific node in Drupal 6 WHEN a custom template has already been applied to the node's content type?

[For Drupal 6] Let's say I've created a content type called "my_content_type". I can override the default template for that entire content-type by creating "page-node-my_content_type.tpl.php". But, what would be the best way to then further customize a single node of that content type (e.g., node 5555)?
I tried the following, but none worked:
page-node-5555.tpl.php
page-node-my_content_theme-5555.tpl.php
node-5555.tpl.php
None of these work. They all continue to use my original content-type template.
Drupal's page templates work on a suggestion system. Based on the current URL, an array of possible template files is created. It loops through the array (in reverse order) looking for template files that exists. The first one it finds, it will use.
drupal's theme system provides a hook for you to modify the template suggestions.. open up your template.php and find
function phptemplate_preprocess_page(&$vars) {
the $vars variable is what contains the suggestions, specifically $vars['template_files']
By default the only page suggestions that are available are
page.tpl.php
page-node.tpl.php
page-node-[node_id].tpl.php
As far as im aware, page-node-[node_type].tpl.php does not work by default, so its likely you have already modified the preprocess_page template to added in this functionality.
However if you want to add more specific templates you could do something like this...
function phptemplate_preprocess_page(&$variables) {
if ($variables['node']->type != "") {
$variables['template_files'][] = "page-node-" . $variables['node']->type;
$variables['template_files'][] = "page-node-" . $variables['node']->type . "-" . $variables['node']->nid;
}
}
this will allow the following hierarchy of template suggestions
page.tpl.php
page-node.tpl.php
page-node-[node_id].tpl.php
page-node-[node_type].tpl.php
page-node-[node_type]-[node_id].tpl.php
In Drupal 7 just copy the page.tpl.php template and rename it as
page--node--[node:id].tpl.php
Clear cache and start tweaking..
function phptemplate_preprocess_page(&$variables) {
if ($variables['node']->type != "") {
$variables['template_files'][] = "page-node-" . $variables['node']->type;
$variables['template_files'][] = "page-node-" . $variables['node']->type . "-" . $variables['node']->nid;
}
}
This code should not work because hook_preprocess_page() does not get passed any node information. hook_preprocess_node() does. So you can easily create a custom node.tpl, but you cannot easily create a custom page.tpl for a specific node. Not that I've been able to figure out anyway :)
Later...
In default Drupal, page-node-NID.tpl.php will work with no special coding. On a site of mine, it wasn't working, however, and I used the following code to make it work:
/**
* Implementation of hook_preprocess_page().
*/
function MYMODULE_preprocess_page(&$variables) {
// Allow per-node theming of page.tpl
if (arg(0) == 'node' && is_numeric(arg(1))) {
$variables['template_files'][] = "page-node-" . arg(1);
}
}

Wordpress Plug-ins: How-to add custom URL Handles

I'm trying to write a Wordpress Plug-in but can't seem to figure out how you would modify how a URL gets handled, so for example: any requests made for:
<url>/?myplugin=<pageID>
will get handled by a function in my plug-in. I'm sure this is a very simple to do, but I'm pretty new to working with Wordpress and couldn't find it in the documentation.
In order to handle just a specific URL use the code below:
add_action('parse_request', 'my_custom_url_handler');
function my_custom_url_handler() {
if(isset($_GET['myplugin']) && $_SERVER["REQUEST_URI"] == '/custom_url') {
echo "<h1>TEST</h1>";
exit();
}
}
add_action('parse_request', 'my_custom_url_handler');
function my_custom_url_handler() {
if( isset($_GET['myplugin']) ) {
// do something
exit();
}
}
That should set you on the right direction. parse_request happens before WordPress runs any of the complicated WordPress queries used to get the posts for the current URL.

Resources