Enable WP-postratings - wordpress

I've created my own wordpress theme and installed WP-Postratings plugin, but it doesn't work. I add only
<?php if(function_exists('the_ratings')) { the_ratings(); } ?>
It show rating image, but i can't rate anything.
Should I add something to the functions, maybe the reason is ajax, should I add some function?

I'm using the same plugin on my theme
Rating Buttons
if(function_exists('the_ratings')) { the_ratings(); }
Rating Avarage
if(function_exists('the_ratings')) { echo ''.expand_ratings_template('<span class="rating-images">%RATINGS_IMAGES%</span>', get_the_ID()); }
If it doesnt work you may have any javascript conflict , try to disable all plugins and try it again.You must be sure that admin-ajax.php is not blocked by server or anything else.

You should add something to the functions. That code is enough.
It usually happened because the plugin is crashed with another plugin. Disable another plugins one by one until you can rate. Then change the plugin that make the issue with the similar one.

Related

How to stop W3 Total Cache from globally replacing URLs in Wordpress

I'm trying to create a custom wp_head implementation in a Wordpress theme to work alongside the original method.
I've setup my code like this in functions.php:
function wp_head_r()
{
echo '<script src="http://sample-url.com/js/file.js"></script>';
}
Then in header.php, I have this:
wp_head(); //original
wp_head_r();
The problem I have is that the Wordpress install I'm working with has W3 Total Cache installed. So what is happening is that any file that has sample-url.com that references a JavaScript or CSS file is being replaced to sample-url-cdn.com before it is output to the page.
This was happening with enqueued scripts and stylesheets, and I was thinking that setting up a custom wp_head method would prevent this, but that doesn't seem to be the case.
Is it possible to create some kind of filter to prevent W3 Total Cache from globally replacing all the urls?
I managed to figure this out. The trick is to use a filter with a high priority, effectively overriding [I think] the one that W3 Total Cache is leveraging.
Here's the code [for functions.php]:
function my_filter_w3tc_cdn_url( $new_url, $url, $is_engine_mirror )
{
if(preg_match('/\/(my_special_dir_pattern)/i', $new_url))
{
$new_url = $url;
}
return $new_url;
};
add_filter( 'w3tc_cdn_url', 'my_filter_w3tc_cdn_url', 100, 3 );
I used preg_match to target all urls that fit a specific pattern, and then exclude them from being updated to the CDN url. Also, notice that I used a priority of 100, which seems high enough and worked in my specific use case.
Hope it helps.

Hide Wordpress dashboard?

I'm new to wordpress and a bit confused with something. I'm trying to build a classified marketplace type of website for myself. I am NOT building this for a "client". I will probably be using a hack of several different plugins as my coding skills are not up to par. Eventually I will hopefully have lots of users who will be composed of buyers & sellers.
My question pertains to the WP dashboard. When buyers/sellers sign up for my site, will they be able to see the backend WP dashboard? I would prefer that they NOT be able to access a backend dashboard at all let alone a WP branded one. Is this possible? If so any clue as to how this might be accomplished?
thank you Brian
Normal users do not actually see the 'backend' WP dashboard. What they are seeing is a 'profile' type page meant for the original functionality of wordpres; being a blog.
If you do not want users to go to this page when they log-in, you can use a couple of hooks. Here is some code that redirects to the front page after logging-in and logging-out. This goes in your functions.php file.
add_action('login_form', 'ang_redirect_to_front_page');
add_action('wp_logout', 'go_home');
function ang_redirect_to_front_page() {
global $redirect_to;
if (!isset($_GET['redirect_to'])) {
$redirect_to = get_option('siteurl');
}
}
function go_home(){
wp_redirect( home_url() );
exit();
}
And, if your theme is still displaying the menu at the top of the screen that allows the users to go to this 'profile' area, you can go into your footer.php file and remove this:
<?php wp_footer();?>
However, if you do this, then you will not see it as the admin either.
WordPress is might not be the thing to use for that kind of website, even with a bunch of plugins. Read up on other content management systems just incase.
This link might answer your question:
http://buddypress.org/support/topic/how-to-prevent-non-admins-from-accessing-wp-admin-dashboard/
You can also add this to your theme's function.php file:
// DISABLE ADMIN BAR FOR ALL USERS
show_admin_bar( false );
If you are not too used to wordpress, use WOOCOMMERCE plugin. Its completely free and well documented

How to customize Wordpress Theme before going live

Yesterday I installed a new theme on Wordpress on my self-hosted website. I am aware of the feature that allows you to preview a theme and have used it to select a new Theme that I want to install.
Problem
I do not want to interrupt normal operations of my website, but this new theme requires a lot of customization before it is ready to go. How do I do this?
My Crappy Solution
Is the only way to go about it to run a virtual server on my desktop? This seems tedious, not to mention all the errors I usually get when switching to the "real" server when doing this.
A better way?
I've been searching on SO as well as the WordPress Forum for an answer as to how to do this, but have come up short. I would have thought this is a common question. Maybe I'm using the wrong search terms [themes, customization, before installing]???
Any help is greatly appreciated! Thanks!
Ok, since your question is a pretty good one and probably not a few people are going through the same process when they decide to update their site, I decided to give a try to the get_stylesheet and get_template filter hooks. It turns out that with a very small plugin, you can easily enforce a specific theme(well in this case any logged-in visitor, but you can change this to use any logic you want) according to a specific rule/s.
Here's the code that you need to put in a file in your plugins directory:
<?php
/*
Plugin Name: Switch Theme
Description: Switches the theme for logged-in visitors, while keeping the current theme for everyone else. !!!NOTE!!! Please back-up your database prior using this plugin - I can't guarantee that it will work with any theme, nor that it won't break your site's set-up - USE AT YOUR OWN RISK(I did a quick test and it seemed to be fine, but haven't done extensive testing).
You don't need to switch to the desired theme before that - you want to keep active the theme that you will display to your visitors - the one that you will see will be used programatically.
Before activating the plugin, change the line that says `private $admin_theme = '';` to `private $admin_theme = 'theme-directory-name';` where "theme-directory-name" is obviously the name of the directory in which the desired theme resides in.
*/
class MyThemeSwitcher {
private $admin_theme = '';
function MyThemeSwitcher() {
add_filter( 'stylesheet', array( &$this, 'get_stylesheet' ) );
add_filter( 'template', array( &$this, 'get_template' ) );
}
function get_stylesheet($stylesheet = '') {
if ( is_user_logged_in() && $this->admin_theme ) {
return $this->admin_theme;
}
return $stylesheet;
}
function get_template( $template ) {
if ( is_user_logged_in() && $this->admin_theme ) {
return $this->admin_theme;
}
return $template;
}
}
$theme_switcher = new MyThemeSwitcher();
So - first of all BACKUP YOUR DATABASE! I tested locally with Twenty Eleven being the default theme and a basic framework theme as my custom theme - the theme options and navigation menus were saved properly.
Then all you need to do is to update the file(change the line that says private $admin_theme = ''; to private $admin_theme = 'theme-slug'; where theme-slug is the name of the directory in which the theme you want to use is).
Also - you won't be able to change the Front page and Posts page options, without this affecting the live site, nor will you be able to change the any shared components that both themes use(Site name, Front Page, Posts page, Posts Per Page, etc options, content and so on).
So if you have no clue whether this solution is for you - well, it depends.
If both themes are not relatively complex, then most-likely you should be able to use this hack. If they are though maybe you should do a second installation of your website as others suggested - I think that a second installation in either a sub-domain or a sub-directory would be the best option for you(simply because moving a multisite database is more complex than moving a normal WP database).
I'd setup local apache server with a wordpress installed to customize and test a new theme. When you finished customizing it then you can upload the theme to your live site and activate it. If there are settings that you need to set in the dashboard then you probably will have to adjust them again. That's one way to test/customize a theme before putting it live.
You could create a network (make WordPress multisite with define('WP_ALLOW_MULTISITE', true);, see : http://codex.wordpress.org/Create_A_Network) and then create one sub-site, then turn it "off" with a Maintenance plugin so it is not accessible to users not logged in as admin, export your posts & data from main blog, import them in sub-blog with WordPress default importer, then apply your new theme to this sub-blog and work on it. When everything satisfies you, apply the theme to the main site and deactivate subsite.

switch wordpress theme base on URL

I have a wordpress website that host several themes inside it.
Now I want to switch the themes for visitor base on the URL that they enter.
for example :
my WP website is at http://www.myblog.com/wp/
but if user enter :
http://www.myblog.com/wp?theme=twentyten -> using twentyten theme
and if user enter :
http://www.myblog.com/wp?theme=mycustomtheme ->using mycustometheme
then
is there any plugins available out there? I've been searching for days but no one seam to work for me.
Any suggestion is very appreciated!
Thanks
I haven't done it, and looking for a minute I don't see a plugin that does that for you. I think your best bet is to make a plugin that would change the theme variable based on the base URL. It's about as simple of a plugin as you can make, so it would be a good one to cut your teeth on if you have any programming ability whatsoever.
This might help:
http://codex.wordpress.org/Theme_Switching
There are 2 plugins noted in that url: http://wordpress.org/extend/plugins/theme-preview/
Theme preview which is what you want.
http://wordpress.org/extend/plugins/theme-switcher/
Theme switcher which do that too and create a sidebar widget so user can change the template.
I've found this good tutorial about base theme swithing on URL.
First, you have to catch the parameter in the URL:
function sjc_add_query_vars($vars)
{
return array('template') + $vars;
}
add_filter('query_vars', 'sjc_add_query_vars');
And then you serve the template:
function sjc_template($template)
{
global $wp;
if ($wp->query_vars['template']=='basic')
{
return dirname( __FILE__ ) . '/single-basic.php';
}
else
{
return $template;
}
}
add_filter('single_template', 'sjc_template');
Please note that the code above check if $wp->query_vars['template']=='basic' and not simply return the template specified in the URL, because it could be a security issue.
for who is still interested you have a WordPress functions that switches the theme
switch_theme( $stylesheet )
see https://codex.wordpress.org/Function_Reference/switch_theme
Just be care to call it in the right time, I would write it in a mu-plugin for use it.

Extending Contact Form 7 Wordpress plugin by using hooks

I would like to create a plugin that uses the contact form 7 hook, wpcf7_admin_after_mail. I want to use the plugin to interface with a CRM system. What I have thus far is the following:
//plugin header here
function add_to_CRM( $cf7 )
{
if (isset($cf7->posted_data["your-message"]))
{
full_contact($cf7);
} else {
quick_quote($cf7);
}
return $cf7;
}
add_action('wpcf7_admin_after_mail', 'add_to_CRM');
//other functions here
I can't seem to get this working. I can't even get the hook to work and do something like mail me. Anybody have any idea what I'm doing wrong here. Since I have limited Wordpress experience I might me missing the boat completely with what I'm trying to do here. I've Googled for answers to no end.
EDIT: I ended up adding this to the theme's functions.php file and it works perfectly. Thing is, I want to get it working as a plugin. Any help will be appreciated.
Try delaying the add_action() call, something like;
add_action('init', create_function('',
'add_action("wpcf7_admin_after_mail", "add_to_CRM");'));
This actually registers your CF7 hook once WordPress is ready (which is nearer the time functions.php gets loaded in).

Resources