question
stringlengths 0
34.8k
| answer
stringlengths 0
28.3k
| title
stringlengths 7
150
| forum_tag
stringclasses 12
values |
---|---|---|---|
I just installed Automatic Wordpress Backup on a fresh install of wordpress, with no other plugins installed, nothing else has changed from the default install. The plugin is saying zip is not found, I verified with my host that it is, and updated the path for it in automatic-wordpress-backup.php. I also have debug turned on, and am about to have to turn it off due to the number of warnings and notices displayed. It appears to be mostly Notices about deprecated arguments and Warning: Cannot modify header information. It also causes me to just get a blank page after updating info, for example I just changed the permalinks, after I hit save it takes me to a blank page, it made & saved the changes, but I can't tell my client that it's just going to work that way. Is this normal? Any suggestions?
|
The plugin's description in repository says following: Important caveat: this plugin currently has to be run on a linux server. Also, the wp-content/uploads folder has to be server-writable or it won't be able to create the zips for backup. ...which makes me think that developer was not too interested in making plugin use proper WP APIs to work robustly across different hosting server configurations. If this plugin alone generates enough debug output to break things I'd seriously consider looking for alternative.
|
Automatic Wordpress Backup Plugin works, but says it's not
|
wordpress
|
I'm trying to schedule a pseudo cron job to send an email after a set amount of time utilizing a WordPress plugin. So far, I've been able to make this code run when I hard code the email address and message into the 'email_about_coupon' function; however, when I try to send the arguments to the function, the email is never sent. By using the Cron GUI plugin (http://wordpress.org/extend/plugins/cron-view/installation/), I'm able to see that the cron job is registered even with the arguments. I believe that I'm doing something incorrectly that does not allow the arguments to be used properly within the function at the time that it is run. Here's what I have: <code> function schedule_email_cron($post_id) { // Get the UNIX 30 days from now time $thirty_days = time() + 60; // (30 * 24 * 60 * 60) $post = get_post($post_id); $email = get_the_author_meta('user_email', $post->post_author); $args = array('email' => $email, 'title' => $post->post_title); wp_schedule_single_event($thirty_days, 'email_about_coupon_action', $args); } add_action('save_post', 'schedule_email_cron', 1, 1); add_action('email_about_coupon_action', 'email_about_coupon', 1, 1); function email_about_coupon($args) { // Email text $text = "<html><body><p>Your coupon titled, ".$args['title']." is expiring soon. Please visit <a href=\"\">".get_bloginfo('siteurl')."/registered/</a> ".get_bloginfo('siteurl')."/registered/ to renew your coupon.</p></body></html>"; // Email headers $headers = array( 'From: '.get_bloginfo('name').' <'.get_bloginfo('admin_email').'>', "Content-Type: text/html" ); $h = implode("\r\n",$headers) . "\r\n"; // Send email wp_mail($args['email'], 'Renew Your Coupon Now!', $text, $h); } </code> As always, thanks so much for your help!
|
I think you have mismatch in how you pass arguments and how you expect it to work. You pass array of arguments to schedule and expect your hooked function to receive identical array of arguments. This is not the case. Cron events are processed by <code> do_action_ref_array() </code> , which in turn passes arguments via <code> call_user_func_array() </code> . So your hooked function does not receive array of arguments, it receives multiple arguments - one for each element in your array. So you need to either wrap array of arguments in array one more time or modify your function to process multiple arguments. Note that for letter you will also need to modify your <code> add_action() </code> call so that required number of arguments is passed instead of just one.
|
Using wp_schedule_single_event with arguments to send email
|
wordpress
|
I have a template that pulls three posts query_posts() loop. Two of the posts and are truncated to 10 words like I have it set in a filter. The third decided to ignore the filter and is spitting out 33 words. I can't see a difference between the posts. Does anybody know why this would happen? <code> while (have_posts()) : the_post(); $img = get_post_meta($post->ID, 'Featured Thumbnail', true); ?> <div style="width:237px; float:left; margin-right:20px;" <?php post_class(); ?> id="post-<?php the_ID(); ?>"> <div class="entry"> <img style="margin-bottom:10px;" src="<?php echo $img; ?>"/><br /> <div style="margin-bottom:5px;"> <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title('<h3>', '</h3>'); ?></a></div> <?php the_excerpt(); ?> </div> </div> <?php endwhile; ?> </code>
|
Does that post have an excerpt manually entered? the filter only works on excerpts when they're pulled from the post content.
|
Using the_excerpt() some posts are truncated and some are not
|
wordpress
|
I tried to install a premium theme called Superb. I'm new to WordPress and I'm having a bit of a problem. I think that it has to do with permission settings, but I'm not sure. This is my situation: I'm on a Mac running MAMP Pro. I've setup WP on my local machine. When I open my site in a browser, I see the default WordPress page. So far, so good. I unbundled the Superb zip file and put the directory in wp-content --> themes. I went to WP's dashboard Appearance--> Themes, but Superb was not visible. There was no picture of the theme and no nothing to activate. So I changed the Superb directory's permissions to Me: Read & write, Everyone: Read only. Now, the Superb theme is visible. I activated the theme. When I opened the browser, I got these error messages at the top of the page and then the default page styled with the Superb theme: <code> Warning: include(recaptchalib.php) [function.include]: failed to open stream: Permission denied in /Users/myname/Sites/mysite/wp-content/themes/Superb/uContact/contact.php on line 136 Warning: include() [function.include]: Failed opening ‘recaptchalib.php’ for inclusion (include_path=’.:/Applications/MAMP/bin/php5.2/lib/php’) in /Users/myname/Sites/mysite/wp-content/themes/Superb/uContact/contact.php on line 136 </code> Now, I can't even login into wp-admin and there are lots of warnings as above. I think that I'm doing something wrong with the permissions. Maybe I made some other idiotic mistake. If someone can give me detailed instructions on how to solve this problem on a Mac, I would be psyched. Thank you! -Laxmidi
|
Laxmidi: You wouldn't FTP to your local installation of WordPress, which is under some directory that you have assigned with MAMP. Wherever that directory lives, you must unpack your theme.zip folder on your desktop, then move the theme into /wordpress/wp-content/themes Once you add move your downloaded theme directory into WordPress, you should see the Theme under Dashboard -> Appearance -> Themes, after which you will activate it, then navigate to the local URL and see your WP install working. All files should be 644 and all folders 755. Tony Zeoli
|
Problem Installing a Premium Theme-- File Permission Issue on a Mac, Local Machine?
|
wordpress
|
I know this is very avant-garde, but bear with me. I've read that one is able to query a page by the page/post name or slug. I'm trying to do this because I need information from a page with a similar title/slug and will not have the ability to get the page id (unless there's a way to convert a title to an ID). I've tried multiple variations without success. This seems like the most reasonable way of handling this, but it's simply not working. <code> <?php $args = array( 'pagename' => 'CM-145', 'post_type' => 'page', 'posts_per_page' => 1, 'numberposts' => 1 ); ?> <div> <?php query_posts( $args ); get_template_part( 'loop' ); wp_reset_query(); ?> </div> </code> The Loop <code> <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?> <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <?php if ( is_front_page() ) { ?> <h2 class="entry-title"><?php the_title(); ?></h2> <?php } else { ?> <h1 class="entry-title"><?php the_title(); ?></h1> <?php } ?> <div class="entry-content"> <?php the_content(); ?> <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?> <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="edit-link">', '</span>' ); ?> </div><!-- .entry-content --> </div><!-- #post-## --> <?php comments_template( '', true ); ?> <?php endwhile; // end of the loop. ?> </code> I've also tried <code> 'name' => 'CM-145' </code> , I'm not sure if this is the correct or reasonable way to perform this action. Ultimately I simply need to pull the page's thumb and excerpt so if you have a better Idea don't hesitate to let me know. Thanks in advance.
|
Hi @Zach Shallbetter: If I understand your question, then you are looking to solve your problem using theming functions when you really need to use more of WordPress' API. The following code can be copied to a <code> test.php </code> file and run using <code> http://yoursite.com/test.php </code> for you to see how it works (assuming you replace <code> http://yoursite.com </code> with your own website's domain, of course!) Then read the comments to see where to place the code for use in your site: <code> <?php // The function should go into your theme's functions.php file function get_excerpt( $post_id ) { $post = get_post( $post_id ); $excerpt = $post->post_excerpt; return ( post_password_required($post) ? false : apply_filters( 'get_the_excerpt', $excerpt ) ); } include('../wp-load.php'); // This code goes where you need to get and display the excerpt and thumbnail $post = get_page_by_path('CM-145'); $excerpt = get_excerpt($post->ID); $thumbnail = get_the_post_thumbnail($post->ID); ?> <div style="width:300px"> <span style="float:right;"><?php echo $thumbnail; ?></span> <?php echo $excerpt ?> </div> </code> Also, I'm a bit concerned you may be experiencing a bit of the "hammer-and-nail" syndrome; i.e. when you have a problem and you only have a hammer you treat the problem like a nail when maybe what you need is to find a screwdriver? Specifically I'm concerned that you are using a Page for something that should either simply be an Option, or maybe at least a Custom Post Type? Can you explain your use-case more in-depth, and why you have chosen to use a Page?
|
Get post by page name or slug
|
wordpress
|
Hey guys, I've added a TinyMCE to some textareas that are displayed in a custom meta box. All of the formatting works perfectly fine, except that the editor will not save <code> <p> </code> or <code> <br/> </code> tags. It doesn't preserve the line breaks. The TinyMCE is setup like this: <code> wp_tiny_mce(true, array('editor_selector' => $field['class'] ) ); '<textarea name="', $field['id'], '" class="', $field['class'], '" id="', $field['id'], '" cols="60" rows="8" style="width:97%">', $meta ? esc_html($meta) : $field['std'], '</textarea>'; </code> And that all works perfectly fine. All the formatting buttons work fine, except for the <code> <P> </code> and <code> <BR> </code> tags. I'm not sure if the editor is stripping them out before or after the post meta is saved. Ideas?
|
I recently got this working. You should search and replace <code> metaname </code> with your meta box name. The key to maintaining formatting was using <code> wpautop(); </code> when saving the data. <code> add_action( 'add_meta_boxes', 'add_metaname_box'); add_action( 'save_post', 'metaname_save'); function add_metaname_box() { add_meta_box( 'metaname_id', __( 'metaname text', 'metaname_textdomain'), 'metaname_custom_box', 'page' ); } function metaname_custom_box() { global $post; wp_nonce_field( plugin_basename( __FILE__ ), 'metaname_noncename' ); $data = get_post_meta($post->ID, 'metaname_custom_box', true); echo <<<EOT <script type="text/javascript"> jQuery(document).ready(function() { jQuery("#metaname_custom_box").addClass("mceEditor"); if ( typeof( tinyMCE ) == "object" && typeof( tinyMCE.execCommand ) == "function" ) { tinyMCE.execCommand("mceAddControl", false, "metaname_custom_box"); } }); </script> <textarea id="metaname_custom_box" name="metaname_custom_box">$data</textarea> EOT; } function metaname_save($post_id) { global $post; // Verify if ( !wp_verify_nonce( $_POST['metaname_noncename'], plugin_basename(__FILE__) )) { return $post_id; } if ( 'page' == $_POST['post_type'] ) { if ( !current_user_can( 'edit_page', $post_id )) return $post_id; } else { if ( !current_user_can( 'edit_post', $post_id )) return $post_id; } $key = 'metaname_custom_box'; $data = wpautop($_POST[$key]); // New, Update, and Delete if(get_post_meta($post_id, $key) == "") add_post_meta($post_id, $key, $data, true); elseif($data != get_post_meta($post_id, $key, true)) update_post_meta($post_id, $key, $data); elseif($data == "") delete_post_meta($post_id, $key, get_post_meta($post_id, $key, true)); } </code>
|
Extra TinyMCE editor strips and tags?
|
wordpress
|
I want to start giving back to the community, but writing a plugin from scratch is currently slightly beyond my skill level and creativity level (meaning, I don't know what kind of problem I can solve with a plugin! every time I think of something, I find a plugin or 6 that have already been written!). However, I have recently identified a very simple plugin that looks to be abandoned since WP 2.8, and I think I can modify it to be 3.1 compatible. I've asked, and it seems that the best way to update this plugin may be to simply fork it. So now my question: how do I do that? I'm new to SVN, so I'm totally uncertain as to where to go, how to start, etc etc. Can anyone guide me? :)
|
there are several guides in the Codex that can help, Set up your plugin for submission Submit your plugin Keep it up to date I also think it's a great idea to "fix" older useful plugins :) Steps : http://wordpress.org/extend/plugins/about/ Submit : http://wordpress.org/extend/plugins/add/ How to Use Subversion : http://wordpress.org/extend/plugins/about/svn/ Promotion and additional info : http://codex.wordpress.org/Plugin_Submission_and_Promotion Using subversion depends on your OS, for windows I recommend tortoise SVN http://tortoisesvn.tigris.org/ For Mac check out "Versions", http://versionsapp.com/ or you can use the command line. Also a lot of IDE's now have subversion support built right in.
|
How to fork a plugin?
|
wordpress
|
I'd love to be able to hide meta boxes using screen options, instead of removing them or restricting them to user roles, the goal is to just "uncheck" the meta box for the user. I see how this would be tricky since any code that would make a DB change for a user wouldn't be allowed to run every time they hit the page because it would just reset. But smarter people than I code the core, so maybe there's a way. And if there is, I'm dying to know. Any ideas?
|
You are referring to the metaboxes on the admin post screen right? For that you don't need a plugin, just drop the following into your functions.php file. <code> // add_action('user_register', 'set_user_metaboxes'); add_action('admin_init', 'set_user_metaboxes'); function set_user_metaboxes($user_id=NULL) { // These are the metakeys we will need to update $meta_key['order'] = 'meta-box-order_post'; $meta_key['hidden'] = 'metaboxhidden_post'; // So this can be used without hooking into user_register if ( ! $user_id) $user_id = get_current_user_id(); // Set the default order if it has not been set yet if ( ! get_user_meta( $user_id, $meta_key['order'], true) ) { $meta_value = array( 'side' => 'submitdiv,formatdiv,categorydiv,postimagediv', 'normal' => 'postexcerpt,tagsdiv-post_tag,postcustom,commentstatusdiv,commentsdiv,trackbacksdiv,slugdiv,authordiv,revisionsdiv', 'advanced' => '', ); update_user_meta( $user_id, $meta_key['order'], $meta_value ); } // Set the default hiddens if it has not been set yet if ( ! get_user_meta( $user_id, $meta_key['hidden'], true) ) { $meta_value = array('postcustom','trackbacksdiv','commentstatusdiv','commentsdiv','slugdiv','authordiv','revisionsdiv'); update_user_meta( $user_id, $meta_key['hidden'], $meta_value ); } } </code> Basically what is happening is that for the currently logged in user, you are changing some saved meta_values in the wp_usermeta table. There are two ways to use this function, you can either hook into 'user_register' or you can hook into 'admin_init'. The advantage of using 'user_register' is that this function will only fire when a new user is registered (thus lower overhead). However it will not work for users that already exist. If you want it to work for users that already exist, then hook into 'admin_init'. The disadvantage of course is that now this function fires every time a user goes to the admin page.
|
How to set default screen options?
|
wordpress
|
I'm trying to create two queries. In the first query, I will, for example, display 6 posts, in a given order. In the second query, I want to display the same 6 posts, but "offset" the first 3 and then have those same 3 appear at the end. For example, Query #1 would return: 1 2 3 4 5 6 Then, Query #2 would return: 4 5 6 1 2 3 Any ideas on how I might pull this off??
|
No need to have two queries, you can just reuse the same post data by resetting the current post position and running the loop again: <code> $wp_query->current_post = 2; </code> you'd have to do this twice to achieve what you're asking, and stop it the second time at the third post.
|
WP_Query - Adding "offset" posts to the end of the loop
|
wordpress
|
Will adding code similar to what I've pasted below to the functions.php theme file slow down a Wordpress site or effect CPU? (Thank You) <code> function remove_menu_items() { global $menu; $restricted = array(__('Links'), __('Comments'), __('Media'), __('Plugins'), __('Tools'), __('Users')); end ($menu); while (prev($menu)){ $value = explode(' ',$menu[key($menu)][0]); if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){ unset($menu[key($menu)]);} } } </code>
|
Nope or Not really or Not noticeably.
|
Functions file mods and CPU
|
wordpress
|
I'd like to know how I can rewrite a search URL that also contains an extra query var into a pretty permalink using <code> wp_redirect </code> and the <code> template_redirect </code> hook. I have taken the code from the Nice Search plugin which works fine to change <code> http://example.com?s=africa </code> into <code> http://example.com/search/africa </code> : <code> add_action( 'template_redirect', 'my_rewrite' ) ); function my_rewrite() { if ( is_search() and false === strpos( $_SERVER['REQUEST_URI'], '/search/' ) ) { wp_redirect( get_bloginfo( 'home' ) . '/search/' . str_replace( ' ', '+', str_replace( '%20', '+', get_query_var( 's' ) ) ) ); exit(); } } </code> But I am using a select dropdown in combination with the Relevanssi plugin to allow visitors to narrow down the search to a particular post type. This adds a <code> post_type </code> query var, e.g. <code> http://example.com?s=africa&post_type=features </code> . I would like this to have a URL something like <code> http://example.com/search/africa/section/features </code> . The Nice Search code causes the post_type query var to be lost. So I tried the following code: <code> function my_rewrite() { if ( is_search() and false === strpos( $_SERVER['REQUEST_URI'], '/search/' ) ) { if ( isset( $_GET['post_type'] ) and '' !== $_GET['post_type'] ) { wp_redirect( get_bloginfo( 'home' ) . '/search/' . str_replace( ' ', '+', str_replace( '%20', '+', get_query_var( 's' ) ) ) . '/section/' . str_replace( ' ', '+', str_replace( '%20', '+', get_query_var( 'post_type' ) ) ) ); } else { wp_redirect( get_bloginfo( 'home' ) . '/search/' . str_replace( ' ', '+', str_replace( '%20', '+', get_query_var( 's' ) ) ) ); } exit(); } } </code> but WordPress now thinks the search term is <code> africa/section/features </code> . Is there a way I can keep the search term and the query var all in a nice permalink? Thanks Simon
|
To modify the search rewrite rules you can hook into the <code> search_rewrite_rules </code> filter. You can either add the extra rewrite rules that match post types yourself, or you can change the default "search rewrite structure" to also include the post type and then re-generate the rules (there are four rules: one standard, one with paging and two for feeds). Because <code> WP_Rewrite::generate_rewrite_rules() </code> generates rules at every "directory level" , you will get rules for <code> /search/[keyword]/section/[post_type]/ </code> , <code> /search/[keyword]/section/ </code> and <code> /search/[keyword]/ </code> . You don't need the middle rule, but it won't hurt to keep it in. <code> add_filter( 'search_rewrite_rules', 'wpse15418_search_rewrite_rules' ); function wpse15418_search_rewrite_rules( $search_rewrite_rules ) { global $wp_rewrite; $wp_rewrite->add_rewrite_tag( '%post_type%', '([^/]+)', 'post_type=' ); $search_structure = $wp_rewrite->get_search_permastruct(); return $wp_rewrite->generate_rewrite_rules( $search_structure . '/section/%post_type%', EP_SEARCH ); } </code> To check the rules, use stackexchange-url ("my Rewrite analyzer plugin").
|
Pretty permalinks for search results with extra query var
|
wordpress
|
fellow coders! I an having a hard time JOIN(ing) tables. I have a a lot of users on my site and many of them have the same last names. I am trying to get their emails by their last name. WP stores emails in the users table and user names in the usermeta and I have been trying to use JOIN to get what I want, but I don't understand how it works and I am about to give up for the day. This is what i have after 4.5 hours. <code> $usersemails = $wpdb->get_results("SELECT users.user_email, usermeta.meta_value FROM $wpdb->users LEFT JOIN $wpdb->usermeta ON $wpdb->users.ID = $wpdb->usermeta.user_id WHERE user_status = '0' AND meta_value = 'Smith'"); </code> Any help is appreciated, so can you please help? Thanks.
|
Hi @Holidaymaine : Not sure where you are doing wrong, but try the following instead which is a self contained <code> test.php </code> file you can drop into the root of your website and load in your browser with <code> http://yoursite.com/test.php </code> (assuming you replace <code> yoursite.com </code> with your site's domain! Also, note how I adding in a <code> WHERE {$wpdb->usermeta}.meta_key = 'last_name' </code> to ensure you did not get records you were not expecting): <code> <?php /* Filename: test.php */ include('wp-load.php'); $sql =<<<SQL SELECT {$wpdb->users}.user_email, {$wpdb->usermeta}.meta_value FROM {$wpdb->users} LEFT JOIN {$wpdb->usermeta} ON {$wpdb->users}.ID = {$wpdb->usermeta}.user_id WHERE 1=1 AND {$wpdb->users}.user_status = '0' AND {$wpdb->usermeta}.meta_key = 'last_name' AND {$wpdb->usermeta}.meta_value = 'Smith' SQL; $usersemails = $wpdb->get_results($sql); header('Content-type:text/plain'); print_r($usersemails); </code>
|
LEFT JOIN, INNER OUTER JOIN, LEFT OUTER JOIN is driving me crazy. Please help?
|
wordpress
|
<code> sanitize_title_with_dashes </code> (see code below for reference) is the function Wordpress uses to format "pretty" urls. However, contrary to the function's comment header, it allows much more than alphanumeric characters, underscore (_) and dash (-). It also allows signs like °, etc. How would I go about really allowing only alphanumeric characters and dashes? <code> /** * Sanitizes title, replacing whitespace with dashes. * * Limits the output to alphanumeric characters, underscore (_) and dash (-). * Whitespace becomes a dash. * * @since 1.2.0 * * @param string $title The title to be sanitized. * @return string The sanitized title. */ function sanitize_title_with_dashes($title) { $title = strip_tags($title); // Preserve escaped octets. $title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title); // Remove percent signs that are not part of an octet. $title = str_replace('%', '', $title); // Restore octets. $title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title); $title = remove_accents($title); if (seems_utf8($title)) { if (function_exists('mb_strtolower')) { $title = mb_strtolower($title, 'UTF-8'); } $title = utf8_uri_encode($title, 200); } $title = strtolower($title); $title = preg_replace('/&.+?;/', '', $title); // kill entities $title = str_replace('.', '-', $title); $title = preg_replace('/[^%a-z0-9 _-]/', '', $title); $title = preg_replace('/\s+/', '-', $title); $title = preg_replace('|-+|', '-', $title); $title = trim($title, '-'); return $title; } </code>
|
Consider this function as a rough placeholder. It has more flaws than you might imagine … :) There are many plugins to improve the conversion for different languages and needs. You may take a look at my plugin Germanix to see how this could be done.
|
Is sanitize_title_with_dashes formatting function too liberal (in terms of accepted characters)?
|
wordpress
|
I have a Custom template with a custom query. I want to use additional information about the current taxonomy > description and name (and use it in the HEAD, desc, keywords, etc...) <code> <?php $productvariable = $_GET['product']; $term = get_term_by('slug', $productvariable, 'mytaxonomy'); $mytitle = $term->name; $mydesc = $term->description; ?> </code> How do i make the variable safe from url to get_term_by ($value)? And what if there is no match is it possible to use ELSE? Is it possible to use the values inside HEAD (header.php)? Is there a security issue when using a GET variable from url with get_term_by?
|
you can look at line 874 in /wp-includes/taxonomy.php for the function itself. the value has <code> stripslashes </code> applied and then it's used in a prepared statement, so I'd say it's safe. but there's nothing stopping you from checking the value yourself first if you know what parameters it will always fall within, like <code> ctype_alnum </code> or something. then check if(empty($term)), to see if anything matched and print something else if not.
|
get_term_by with a variable
|
wordpress
|
I added a Merchant to the Wordpress E-commerce plugin. I want on the submit, after doing my curl() call, to clear the cart How do I do that? ( link to plugin page )
|
according to their docs: <code> $wpsc_cart->empty_cart(); </code>
|
Clear Cart with Wordpress E-commerce plugin
|
wordpress
|
I was thinking of removing/hiding admin-bar from my wordpress (3.1.1) installation. I visited following link: http://codex.wordpress.org/Plugin_API/Filter_Reference/show_admin_bar I was surprised to see only a single line to remove/hide admin-bar <code> add_filter( 'show_admin_bar', '__return_false' ); </code> My question is what is __return_false means? why __ and _?
|
WordPress contains built in functions for quickly returning values. They are intended to be used as a quick built in function that returns a common value to a filter hook such as true, false, or an empty array. <code> __return_false </code> — Returns the Boolean value of false. <code> __return_true </code> — Returns the Boolean value of true. <code> __return_empty_array </code> — Returns an empty PHP array. <code> __return_zero </code> — Returns the integer 0. <code> __return_null </code> — Returns NULL
|
what is __return_false in filters
|
wordpress
|
I'm currently wanting to have it so that writers on my site have to have an admin approve their content before it's published, but still be allowed to do other tasks such as uploading images, adding tags, etc, and the wordpress static permission levels are either too restrictive, or let writers publish themselves. I know on drupal there is an easy way to edit permissions for account types, but I was wondering if there is a way to do the same level of functionality with wordpress at all.
|
heres a brilliant resource for the info you required. wp roles and capabilities
|
Create custom permissions for user type
|
wordpress
|
I have an Expand/ Collapse plugin which, via a shortcode, can expand/ collapse content. My expandable content is a shortcode of a gallery. See here: http://shop.dearearth.net/collections INTERMITTENTLY, the gallery shows up in at least the first to be expanded section, but never in the second... * these are the plugins: *dagondesign.com/articles/expanding-text-plugin-for-wordpress and wordpress.org/extend/plugins/galleria-galleria Any help on this would really be appreciated, of course! :)
|
Even after listening to the podcast this morning where Joel and Jeff talk about how "Fix my Code" questions are too localized to stackexchange-url ("benefit the community") and serve no purpose to anyone but the op, I'm going to try and answer this in a way that will be useful and beneficial to other weary WordPressors who scour the interwebs in search of a quick fix for their plugin and theme woes and leave this as a useful artifact that will hopefully be found one day and still be relevant. WordPress Troubleshooting 101 When troubleshooting any error or broken functionality the first thing is to try and determine what caused it to break or stop working. Did it ever work? If yes, you have to find out what changed that broke it. Did I add a new plugin? Did I change a setting that caused it to stop working? Were any updates recently released that might of bonked things Am I using the latest version?? 7. Do I really need 15 or 30 different plugins to make my website work??? If it is a jQuery problem like the one mentioned by the op in the above question, you should first check if there are any conflicts or if the javascript is not loading in the right order. jQuery plugins require that jQuery is actually loaded before the will work. How do you check for conflicts? I like to use the WebKit Inspector built into the Chrome Browser Developer Tools . If your a Firefox guy then you can use the handy reliable FireBug extension Safari comes with it's built in Webkit Inspector Don't admit it to anyone but if you use Internet Explorer you can even enable Microsofts browser developer tools You just right click and choose "Inspect Element" from the menu to get started. (By the way it's also VERY handy for debugging CSS problems). On the website linked and mentioned by the op here is what I found inspecting the DOM. When the inspector comes up it shows 2 Uncaught Fatal Errors from the galleria-1.2.2.2.min file. Copy and past your error message into Google One of the first results is from the actual Gallaria.js documentation This should be your fix but I always like to dig a little deeper to see if there are any other issues. The theme and plugins running on the site linked to in the question are loading jQuery 5 times. Not the same jQuery but different versions. You have 1.2.6, 1.3.1, 1.4.2, the Google CDN version and even some versions where the license and version # were stripped out (I assume for faster loading...) Not to mention you are combing all theses regular jQuery plugins with a whole slew of jQuery UI plugins. Here is the listing of all the scripts that were loaded when my browser visited the linked to site in the question. The problem, is that the browser loads jQuery then it loads an earlier version that wipes out the version before it. Then it loads a plugin that starts to work then another version of jQuery loads and wipes out anything that was already loaded. (Most users will just click the back button and not spend money with slow loading sites) If any of your jQuery plugins use newer techniques that weren't available in jQuery 1.2.6 they will break, and when jQuery breaks, it prohibits any other jQuery from working after the break. So whats my next step? How do I get it working? Most of the jQuery is being loaded from your themes library directory (is this a Theme Forest Theme or another commercial theme? If so get a refund). Check your functions.php file and header.php (I'm sure none of this is loaded with wp_enqueue_script so be on the lookout for inline <code> <style type...> </code> tags and also lookout for <code> wp_derigister_script </code> Remove every reference to jQuery and add this to your functions.php to load the WordPress version. If your theme uses any other custom scripts register them and enqueue them like so. <code> add_action ('get_header', 'myprefix_load_jquery'); function myprefix_load_jquery() { wp_enqueue_script('jquery'); wp_register_script('custom_script', get_bloginfo('template_directory') . '/js/custom_script.js', array('name_of_script_dependencies'), '1.0' ); wp_enqueue_script('custom_script'); } </code> Now we need to apply the fix we found searching google so add this to the end of a js file or you can use this function to output it in your footer. <code> add_action('wp_footer', 'myprefix_fix_galleria'); function myprefix_fix_galleria() { echo 'jQuery(document).ready(function($) { $("#gallery").galleria({ width: 800, height: 500 }); });'; } </code> Hopefully this answer will be useful to anyone who is searching for a quick answer to fix their problem and learns how to troubleshoot and figure out why things happen they way they do. If this fixes your problem please be so kind to come back and mark it as accepted so that when others find your question they will know that the answer given actually worked.
|
Nested Gallery Shortcode INTERMITTENTLY working
|
wordpress
|
I added descriptions to my menus using this post, stackexchange-url ("Menu items description?"). However I need to be able to use html tags and WordPress is stripping them out. Can anyone help?
|
You can remove the filter by adding this to your functions.php file: <code> remove_filter('nav_menu_description', 'strip_tags'); </code>
|
Allow html tags in WordPress Custom Menus Description Field
|
wordpress
|
How do I do that? Any custom post type I register shows up as a meta box on the menu page...
|
It's really simple, when registering the Custom Post Type use: <code> register_post_type( 'post_type_name', array ( ... 'show_in_nav_menus' => FALSE ... ) ); </code>
|
Prevent custom post type from showing up in custom menus
|
wordpress
|
I'm using the mingle plugin and the mingle-forum plugin. I want to show a certain part on my site only if those two plugins are active. How can I solve this? <code> <?php if ( is_plugin_active('mingle-forum') ) { ?> <div id="login"><?php include (TEMPLATEPATH . '/inc/userlogin.php' ); ?></div> <?php } ?> </code> This throws a php error. Call to undefined function is_plugin_active Any idea what I'm doing wrong? update: <code> <?php if ( plugin_active('plugin-directory/mingle-forum/wpf-main.php') ) { ?> <div id="login"><?php include (TEMPLATEPATH . '/inc/userlogin.php' ); ?></div> <?php } ?> </code>
|
This function exists in wp-admin/includes/plugin.php so I'm assuming it doesn't get included by the theme. You can either <code> require </code> it, or just create your own version of it - see here: http://wordpress.org/support/topic/is_plugin_active
|
if plugin is active? check wheter plugin is enabled or not?
|
wordpress
|
I've got a custom post type (CPT) called <code> event </code> . Every event has got an associated <code> meta_key </code> called <code> event_date </code> . I want to make sure that events with empty <code> event_date </code> won't appear in my list of all events and in the prev/next event navigation when viewing a single event. I also want to order events by the <code> event_date </code> meta_key. I managed to exclude events with empty <code> event_date </code> and order them correctly in the overall list of events by hooking into <code> pre_get_posts </code> hook. Is it possible to hook into <code> prev_post_link </code> and <code> next_post_link </code> functions to specify <code> meta_key </code> select condition and <code> meta_key </code> order condition without the plugin? Is there a hook for it? [P.S. note]: I also tried using Ambrosite Next/Previous Post Link Plus plugin. I figured out how to order events by meta_key. However, the events with empty <code> event_date </code> meta_value are still appearing in the prev/next navigation when viewing a single event. It doesn't seem to be possible to hook into WP before the plugin, because I think it constructs its own SQL. I could use <code> ex_posts </code> with the list of all the event ids to exclude, but that would mean extra query to the db. Many thanks, Dasha
|
I ended up using the Ambrosite Next/Previous Post Link Plus plugin . As to an empty <code> event_date </code> meta key - I have added some code to prevent a post from being saved if meta key value isn't correct. Have a look at this posts: stackexchange-url ("Modifying Wordpress post status on Publish") stackexchange-url ("don't publish custom post type post if a meta data field isn't valid")
|
specify meta_key / meta_value condition for prev_post_link and next_post_link
|
wordpress
|
Note: This is more of a tutorial/wiki than a real question and should be a reference for later Questions. If you got something to add, please feel free to add an answer. Working answers get upvoted. :) Szenario You want to modify the output of some wp core function and instead of modifying the core directly (which is always bad), you have found a call like this: <code> $filterable_var = apply_filters( 'name_of_filter', $filterable_var ); </code> . The filter function allows you to modify eg. <code> $filterable_var </code> and therefore the output of the wp function. The Problem You don't know what exactly the function wants as input. The Taks Check what you can modify. Possibly Related Q: [Fell free to add your own Questions here.] stackexchange-url ("How-to inspect global variables?")
|
Example Nav menu walker - allows adding eg. css classes to (all) menu items. <code> // copyied from /wp-core/wp-includes/nav-menu-template.php > line 76 (wp 3.1.1) - start_el() function $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) ); </code> Now let's check the $var: <code> function wpse15319_check_nav_menu_classes( $classes ) { // You can take any of the $vars from the core function above: $classes, $item, $args echo '<pre>'; // nice list: print_r( $classes ); // or check of what type the $var is var_dump( $classes ); echo '</pre>'; return $classes; } add_filter( 'nav_menu_css_class', 'wpse15319_check_nav_menu_classes', 10 ); </code> Modify - Applied example <code> function wpse15319_add_nav_menu_classes( $classes ) { $classes[] = ''; $classes[] .= 'my added css classes'; return $classes; } add_filter( 'nav_menu_css_class', 'wpse15319_add_nav_menu_classes', 10 ); </code>
|
How-to inspect filter-able $vars?
|
wordpress
|
Does a method exist that can return a simple array of the pages in the site that are published? I only want the name and the slug returned, not the full content or other default values. I've tried WP_query(), get_posts(), get_pages() and query_posts() but they all return the post/page content. I'm only looking to get the post name and slug returned. If there's no lighter method, I can use one of these. Just want to make sure. Any help, much appreciated.
|
Like a commented the only way to do it is with a custom sql query so: <code> global $wpdb; $mypages = $wpdb->get_results( "SELECT post_title, post_name FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish' AND parent = '0'"); if (count($mypages) > 0){ foreach ($mypages as $page){ //do you stuff //$page['post_title'] for title //$page['post_name'] for slug } } </code>
|
How to exclude content (and other returned values) from WP_query()?
|
wordpress
|
I'm trying to learn HOW to learn about WordPress by following its source code etc. I'm really stumped at the_excerpt(). Documentation states that the_excerpt uses get_the_excerpt(), and will return either the (manual) excerpt, or will use the first 55 characters of the_content. I'm interested in the logic that looks first for the manual excerpt and then decides whether it needs to go in and extract a substring from the post content. But I can't find it. In post-template.php, we see the_excerpt() and get_the_excerpt() defined. the_excerpt() does nothing more than echo out get_the_excerpt(): <code> 249 function the_excerpt() { 250 echo apply_filters('the_excerpt', get_the_excerpt()); 251 } </code> get_the_excerpt() seems to do nothing more than grab the post_excerpt column from the wp_post table: <code> 261 function get_the_excerpt( $deprecated = '' ) { 262 if ( !empty( $deprecated ) ) 263 _deprecated_argument( __FUNCTION__, '2.3' ); 264 265 global $post; 266 $output = $post->post_excerpt; 267 if ( post_password_required($post) ) { 268 $output = __('There is no excerpt because this is a protected post.'); 269 return $output; 270 } 271 272 return apply_filters('get_the_excerpt', $output); 273 } </code> I don't see where the logic to grab $post-> post_content resides. Is it in the filters? I can't see those filters defined anywhere, but this may be because I just don't know where to look. A cursory glance at Adam Brown's source code search site doesn't seem to be turning up any definitions either. Can someone help me pick up the thread and figure this out? Remember, I'm more interested in how to figure it out than I am in the actual answer. I appreciate everyone's input. Tom
|
From what I understand in the default-filters.php file a filter is applied to the 'get_the_filter' filter. The callback is for a method called 'wp_trim_execrpt'. This is found in formatting.php. From there you can see the logic. Hope that helps.
|
Where is the logic that defines the excerpt?
|
wordpress
|
I need to extend the cookies of a subdomain.domain.com to all of the domain.com's subdomains (.domain.com in cookie terms). I am trying to minimize the impact of this transition. It seems that flipping the switch with <code> define('COOKIE_DOMAIN', '.domain.com'); </code> in wp-config leaves the user in a state of limbo -- their cookie is good enough to validate, so it won't move to the new domain scope. Any ideas on how I can transition cookies from .subdomain.domain.com to .domain.com with minimal impact on users? Here's the code I've been failing and flailing with. It attempts to validate the old cookies when a bad hash is detected (from changing <code> AUTH_KEY </code> in wp-config.php) and then tries to re-validate and send them back to where they came from: <code> function do_report_bad_hash( $cookie_elements ) { if( isset( $_COOKIE['wordpress_logged_in_'] ) ) { $user_id = wp_validate_auth_cookie( urldecode( $_COOKIE['wordpress_logged_in_']), 'logged_in' ); setcookie( 'wordpress_logged_in_', '', 0, '/', '.subdomain.domain.com', false, true ); unset( $_COOKIE['wordpress_logged_in_'] ); setcookie( 'wordpress_', '', 0, '/', '.subdomain.domain.com', false, true ); unset( $_COOKIE['wordpress_'] ); if ( $user_id !== false ) { wp_set_auth_cookie($user_id); $redirect = ( strpos($_SERVER['REQUEST_URI'], '/options.php') && wp_get_referer() ) ? wp_get_referer() : $proto . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; header("Location: $redirect"); } } } add_action('auth_cookie_bad_hash', 'do_report_bad_hash', 11, 1 ); </code>
|
stackexchange-url ("This answer") may help. To quote: The basic code you need here is this in the wp-config file: <code> define('LOGGED_IN_COOKIE', 'login_cookie_name'); define('AUTH_COOKIE','auth_cookie_name'); define('COOKIE_DOMAIN', '.example.com'); define('COOKIEHASH', 'random_hash_here'); </code> Put that in the config across multiple sites, set the keys and salts to be the same, and you'll have login cookies that work across the domain and subdomains.
|
How to transition cookies from .subdomain.domain.com to .domain.com with minimal impact on users?
|
wordpress
|
Im using the following code to get an array of children taxonomies and write them out with links in an unordered list. <code> <?php $termID = 10; $taxonomyName = "products"; $termchildren = get_term_children( $termID, $taxonomyName ); echo '<ul>'; foreach ($termchildren as $child) { $term = get_term_by( 'id', $child, $taxonomyName ); echo '<li><a href="' . get_term_link( $term->name, $taxonomyName ) . '">' . $term->name . '</a></li>'; } echo '</ul>'; ?> </code> What I'm trying to achieve is to get the actual term (category) id so I can replace it on $termID and don't have to hardcode the id of the term. Any help would be kindly appreciated! Thanks!
|
Here is a function I use to list subterms: <code> /** * Lists all subentries of a taxonomy. * * @return void */ function ttt_get_subterms( $args = array () ) { if ( ! isset ( get_queried_object()->taxonomy ) ) { return; } $options = array ( 'child_of' => get_queried_object_id() , 'echo' => 0 , 'taxonomy' => get_queried_object()->taxonomy , 'title_li' => FALSE , 'use_desc_for_title' => FALSE ); $settings = array_merge( $options, $args ); $subtermlist = wp_list_categories( $settings ); // Without results WP creates a dummy item. It doesn't contain links. ! empty ( $subtermlist ) and FALSE !== strpos( $subtermlist, '<a ' ) and print "<ul class=subterms>$subtermlist</ul>"; } </code> Use it like <code> wp_list_categories() </code> . Avoid <code> get_term_by() </code> . It is very expensive and not necessary.
|
Get current term's ID
|
wordpress
|
i am trying to learn and create some deeper things with Wordpress. My goal is to create a code/script/plugin that will allow me to post from the frontend. I have seen many plugins, like templatic classifieds theme that submit, handle and edit posts from the frontend but are very complex with useless code for my purpose. I would like to have a clearer view on how to get the ID, how to set a title, content and custom fields of course. Once I go through this, I want to study it according to user_meta. Thank you for your examples, codes, ideas, links!
|
To post from the front-end you can use wp_insert_post() function. So its simply a matter of a form and processing it the form: <code> <!-- New Post Form --> <div id="postbox"> <form id="new_post" name="new_post" method="post" action=""> <p><label for="title">Title</label><br /> <input type="text" id="title" value="" tabindex="1" size="20" name="title" /> </p> <p><label for="description">Description</label><br /> <textarea id="description" tabindex="3" name="description" cols="50" rows="6"></textarea> </p> <p><?php wp_dropdown_categories( 'show_option_none=Category&tab_index=4&taxonomy=category' ); ?></p> <p><label for="post_tags">Tags</label> <input type="text" value="" tabindex="5" size="16" name="post_tags" id="post_tags" /></p> <p align="right"><input type="submit" value="Publish" tabindex="6" id="submit" name="submit" /></p> <input type="hidden" name="action" value="new_post" /> <?php wp_nonce_field( 'new-post' ); ?> </form> </div> <!--// New Post Form --> </code> the processing: <code> if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == "new_game_post") { // Do some minor form validation to make sure there is content if (isset ($_POST['title'])) { $title = $_POST['title']; } else { echo 'Please enter a game title'; } if (isset ($_POST['description'])) { $description = $_POST['description']; } else { echo 'Please enter the content'; } $tags = $_POST['post_tags']; // Add the content of the form to $post as an array $new_post = array( 'post_title' => $title, 'post_content' => $description, 'tags_input' => array($tags), 'post_status' => 'publish', // Choose: publish, preview, future, draft, etc. 'post_type' => $_POST['post_type'] // Use a custom post type if you want to ); //save the new post and return its ID $pid = wp_insert_post($new_post); } </code> Bonus Once you have the post id ($pid in the above example) then you can easily set terms and custom fields: <code> //insert taxonomies like categories tags or custom wp_set_post_terms($pid,(array)($_POST['cat']),'category',true); //insert custom fields update_post_meta($pid,'meta_key_name',$_POST['meta_value']); </code> hope this helps.
|
I am trying to create a simple frontend form for posting
|
wordpress
|
I'm currently working on importing an MovableType blog into WordPress. The blog has several thousand posts, and each post has an image associated with it. The export file contains references to each image as follows (and as expected): <code> <img src="http://domain/path/to/image"> </code> I've got all the images, and have rewritten all the links in the export file to use the new (local) location. However, the WordPress import process doesn't actually create attachments for the post, which I need. So - what's the best way of doing this - right now I'm thinking about iterating through the set of posts, parsing out any image urls, and creating new posts: post_parent = the actual post post_type = attachment Questions Is <code> post_guid </code> the image location reference? Or is the path to the image stored somewhere else? Where is featured image set? Is this the best way of doing this? [I've tried using the cache-image plugin, but it borks on the number of posts / images]
|
Answers: Is post_guid the image location reference? Or is the path to the image stored somewhere else? $post-> guid is the record in a post which holds the URL for your attachment. Where is featured image set? featured image is saved as post meta so use <code> update_post_meta() </code> once you have the attachment id: <code> update_post_meta( $post->ID, '_thumbnail_id', $attachment_id ); </code> Is this the best way of doing this? Its a lot of work for several thousand posts and any way you choose will cause you some "pain" but it seems like a reasonable way of accomplishing this.
|
Programatically creating image attachments from local URLs and setting featured image
|
wordpress
|
I have a custom post type that I'm just using just to keep data in but I sometimes share it with others, and I don't want any confusion when the "view" link appears in the admin column. Is there a way of removing that?
|
<code> add_filter( 'post_row_actions', 'remove_row_actions', 10, 1 ); function remove_row_actions( $actions ) { if( get_post_type() === 'my_cpt' ) unset( $actions['view'] ); return $actions; } </code> Should see you through :) The $actions array consists of the following: <code> $actions['edit'] $actions['inline hide-if-no-js'] $actions['trash'] $actions['view'] </code> For future reference.
|
Remove the "View" Link in Post Admin
|
wordpress
|
Im working on a little plugin that when activated creates a theme page and then a function sets this page to published this is the code i have for published: <code> // function that creates the new ads page on plugin install // function mjj_create_page () { // Create new page object $ads_page = get_option('mjj_smart_ads_page'); $ads_new_page = array( 'post_title' => 'Smart Ads', 'post_content' => '', 'post_status' => 'publish', 'post_type' => 'page' ); // Insert the page into the database $ads_page = wp_insert_post( $ads_new_page ); update_option('mjj_smart_ads_page', $ads_page); // now lets give this new page a groovy template $ads_page_data = get_page_by_title('Smart Ads'); $ads_page_id = $ads_page_data->ID; update_post_meta($ads_page_id, '_wp_page_template','tpl-smart-ads.php'); } </code> dont know if its semanticaly wp perfect but it seems to work ok and does what i need, however now im trying to set a function that will on plugin deactivate set this created page to draft status so it doesnt show in the menu, but it just doesbt seem to want to play, heres what im working with: <code> // function that drafts smart ads page on plugin deactivate // function mjj_unpublish_page () { $old_ads_page = get_option('mjj_old_smart_ads_page'); $ads_old_page = array( 'post_title' => 'Smart Ads', 'post_content' => '', 'post_status' => 'draft', 'post_type' => 'page' ); // Insert the page into the database $old_ads_page = wp_update_post( $ads_old_page ); update_option('mjj_old_smart_ads_page', $old_ads_page); } </code> and below are my hooks <code> // create the page to get the info for selling ads and posting ads register_activation_hook($file, array(&$this, 'mjj_create_page')); //while in this block i will also add the deactivate function to unpublish the created page register_deactivation_hook($file, array(&$this, 'mjj_unpublish_page')); </code> as you can see im thinking that setting to draft will include the use of wp_update_post, but it dont seem to be working right when deactivating, im ending up with one Smart Ads page published and one in draft
|
I'm posting this as another solution for you and its based on the page id <code> /* $post_id - The ID of the post you'd like to change. $status - The post status publish|pending|draft|private|static|object|attachment|inherit|future|trash. */ function change_post_status($post_id,$status){ $current_post = get_post( $post_id, 'ARRAY_A' ); $current_post['post_status'] = $status; return wp_update_post($current_post); } </code> So once you have this function you can use it with the page id of the page you created: <code> $ads_page = get_option('mjj_smart_ads_page'); $old_ads_page = change_post_status($ads_page,'draft'); update_option('mjj_old_smart_ads_page', $old_ads_page); </code>
|
Set page to draft on plugin deactivation
|
wordpress
|
I have a simple meta box that updates the post custom fields (using <code> update_post_meta() </code> ). How can I send a error or warning message to the next page after the user publishes/updates the post and doesn't fill one of the meta box fields (or fills them with invalid data) ?
|
You can do this by hand, but WP natively does it like this for settings errors: <code> add_settings_error() </code> to create message. Then <code> set_transient('settings_errors', get_settings_errors(), 30); </code> <code> settings_errors() </code> in <code> admin_notices </code> hook to display (will need to hook for non-settings screens).
|
Passing error/warning messages from a meta box to "admin_notices"
|
wordpress
|
I'm using the code below to create custom menu items on the fly. Its working great, except all menus are created as "Custom". In the code below, setting the menu-item-type to 'page' appears to have no effect. <code> foreach($thePages as $page){ wp_update_nav_menu_item($menu->term_id, 0, array( 'menu-item-title' => $page->post_title, 'menu-item-type' => 'page', 'menu-item-status' => 'publish') ); } </code> wp-includes/nav-menu.php shows that the value is hard coded to "Custom". However, if I manually add a page to the menu, using the WP Menus manager, it lists it as "Page", not "Custom". What can I do to set the menu type to "Page"?
|
There's a filter: <code> function wpse15368_update_menu_item_type( $args ) { return $args['menu-item-type'] = 'page'; } add_action( 'wp_update_nav_menu_item', 'wpse15368_update_menu_item_type' ); </code>
|
Custom Nav Menu items default to 'menu-item-type' => 'custom'. How to make a "page" menu item?
|
wordpress
|
I have a wordpress multisite installtion with 5 sites within, the multisite is called Lifestyle Homes Cars Architecture Holidays Communities I am trying to get the blog name, for each blog when viewing in my theme, every function I use returns 'Lifestyle'. I have tried; <code> get_bloginfo('name'); get_bloginfo(); global $current_site; var_dump(get_current_site_name($current_site)); get_current_blog(); </code> none of the strings or objects returned contain the blog name, they all contain the site name "Lifestyle" can anyone offer any advice...
|
This is what you need: <code> global $blog_id; $current_blog_details = get_blog_details( array( 'blog_id' => $blog_id ) ); echo $current_blog_details->blogname; </code> Have a nice multisite! :)
|
How to get blog name, when using Wordpress Multisite
|
wordpress
|
After a new user registration, WP sends out an email with the login / password, and a link to the login page. Is there a way to change this defaut email template? I'd also like to change the subject and sender. Edit : For anyone interested, here is a plugin solution.
|
the new user email is sent using <code> wp_new_user_notification() </code> function which is pluggable meaning that you can overwrite it: <code> // Redefine user notification function if ( !function_exists('wp_new_user_notification') ) { function wp_new_user_notification( $user_id, $plaintext_pass = '' ) { $user = new WP_User($user_id); $user_login = stripslashes($user->user_login); $user_email = stripslashes($user->user_email); $message = sprintf(__('New user registration on your blog %s:'), get_option('blogname')) . "\r\n\r\n"; $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n"; $message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n"; @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), get_option('blogname')), $message); if ( empty($plaintext_pass) ) return; $message = __('Hi there,') . "\r\n\r\n"; $message .= sprintf(__("Welcome to %s! Here's how to log in:"), get_option('blogname')) . "\r\n\r\n"; $message .= wp_login_url() . "\r\n"; $message .= sprintf(__('Username: %s'), $user_login) . "\r\n"; $message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n\r\n"; $message .= sprintf(__('If you have any problems, please contact me at %s.'), get_option('admin_email')) . "\r\n\r\n"; $message .= __('Adios!'); wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_option('blogname')), $message); } } </code>
|
How to change the default registration email ? (plugin and/or non-plugin)
|
wordpress
|
Does Wordpress MU not allow domain mapping to subdirectories, such as example.com/blog? Wordpress.com doesn't allow this. I couldn't find an option to do this in WordPress MU Domain Mapping plugin.
|
Domain mapping works for both subdomains and subfolders (AKA subdirectories). It used to not be available for subfolder installs via the WordPress MU Domain Mapping plugin, but that's no longer the case for a long time. With that being said, it's for a self-hosted blog (WordPress.org install) and not for WordPress.com.
|
How to do Domain Mapping to Subdirectories?
|
wordpress
|
I've just set up a new multisite installation. Everything works as I'd except that images don't show up on any of the sub-sites. Any idea why the images don't show up? I'm running Wordpress 3.1.1 on IIS6 in a shared Windows server (hosted by Arvixe.com). The secondary sites are in sub-directories rather than sub-domains. The images for the main site work, as does the header image, but the images in sub-sites don't appear. I know that the images are uploading properly as they appear in the blogs.dir folder on the server. They also show up if I navigate them like this: http://www.example.com/test/wp-content/blogs.dir/5/files/2011/04/LazyDog.jpg However, they don't work when I navigate to them like this: http://www.kramii.com/test/files/2011/04/LazyDog.jpg When I try this second version in IE I get the broken image icon, whereas in Firefox I get just the filename at the top of the screen. Interestingly, when I show the page info in Firefox it shows type as "image/jpeg", which suggests to me (and I might be wrong) that the server has found the image and is attempting to send it to the browser. My web.config looks like this: In my settings for the site I've got: Site url = http://kramii.com/test/ Home = http://kramii.com/test/ Upload path = http://kramii.com/wp-content/blogs.dir/5/files Upload URL path = http://kramii.com/wp-content/blogs.dir/5/files Fileupload URL = http://kramii.com/wp-content/blogs.dir/5/files I've disabled all plugins. One final note: someone on another site had a similar problem and someone else replied "Is your webhost using a caching mechanism or proxying your webtraffic?". Quite honestly I don't really understand what this means. How would I know? What can I do if they are? Thanks.
|
Finally, I've got it! Sniffing the HTTP resonses indicated that a few extra bytes were being inserted between the headers and body of the http response, resulting in bad image data. Further investigation revealed that these characters represent a Unicode Byte Order Mark (BOM). These, in turn, were caused by a Windows editor that saved wp-config.php with a UTF-8 encoding that includes the BOM. Re-saving the wp-config file using a editor (Notepad++) that can strip the BOM resolved the problem. The only additional requirement was to flush the browser cache to clear the bad response. I hope this helps someone else who has a similar problem. It has taken me literally hours to fins the answer, but I've learned a lot on the way.
|
Images don't show up
|
wordpress
|
Does anyone know of a theme that completely removes all uses and aspects of the frontend. So the sole use of the site will be in the admin section. to use as a portal for something like a school or internal government uses.
|
There are three things (if i understood your needs correctly): Adjust the admin menu items @MikeSchinkel Gist The Backpress project ...or simply <code> wp_redirect(); </code> on login and offer only a login screen in your index.php template .
|
wordpress theme backend admin only
|
wordpress
|
I am trying to get scripts via <code> wp_enqueue_script(); </code> . I have tried this in header but WordPress is not importing any script. I am using like this <code> wp_enqueue_script('jquery'); </code> http://codex.wordpress.org/Function_Reference/wp_enqueue_script Is any other step needed for importing script via WordPress?
|
In simple case you need to enqueue script before header scripts are printed, which happens in <code> wp_head </code> hook. Basic approach would be this in <code> functions.php </code> of your theme: <code> add_action('wp_enqueue_scripts', 'my_enqueue_scripts'); function my_enqueue_scripts() { wp_enqueue_script('jquery'); } </code>
|
How wp_enqueue_script works?
|
wordpress
|
I'm trying to figure out a permalink structure for my pages (not posts) in Wordpress. Right now, I can add a "Category Base" for posts... so, something like www.mysite.com/categorybase/post1/ or www.mysite.com/categorybase/post2/ But, if I wanted to do something similar for pages, how would I do that? For example, www.mysite.com/pagebase/page1/ or www.mysite.com/pagebase/page2/ Anyone tried this before?
|
For the example you're using (ie www.mysite.com/pagebase/page1) you can: create a page called pagebase create a page called page1 and make pagebase the parent page - the url for this page will be www.mysite.com/pagepage/page1 This does mean that www.mysite.com/pagebase also exists as a browsable page, but I generally use that as a section description and section index page.
|
Default Permalink Structure for Pages
|
wordpress
|
I'm seeking advice on the best way to construct a PDF repository. Basically, there will be an uploader in the administrator section and in the front end. The user should be allowed to add tags to the files. So I guess I need: Front-end uploader Backend-uploader Custom-post type? Security to check the PDF files and not just upload anything. What else am I missing?
|
Right now, the support for tagging media is pretty disappointing. You can add tags or categories to the attachment post type, but you'll find the UI is unacceptably bad (it's a text box where you enter terms separated by commas). There's a plugin Media Tags that is decent though, so you might look into that. GravityForms is nice for front-end uploading, but make sure you're thinking through security if you have a front-end upload system. Alternatively, you might be able to create a special role that only has access to upload and manage their own media items. You can write your own custom role or use something like Members or User Role Editor to do that. Once you've setup all that, it's just a matter of building out some nice taxonomy and attachment archive pages.
|
How to build a PDF repository in WordPress
|
wordpress
|
I am pretty new to web design, so this is a perplexing problem to me. I am creating a floating social media share button to the left of my content that scrolls with the blog content. Here is the code I am using: <code> <div id="floating-menu-blog" style="opacity:0.3;filter:alpha(opacity=30)" onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100" onmouseout="this.style.opacity=0.3;this.filters.alpha.opacity=30"> <div class="float-title"> <iframe src="http://platform.twitter.com/widgets/tweet_button.html?url=<?php echo rawurlencode(get_permalink()) ?>&amp;text=<?php echo rawurlencode(strip_tags(get_the_title())) ?>&amp;count=vertical" style="width:55px; height:62px;" frameborder="0" scrolling="no"></iframe> </div> <div class="float-title"> <script type="text/javascript">var fbShare = { url: <?php the_permalink() ?>, size: 'large', badge_text: 'fff', badge_color: '3b5998', google_analytics: 'true' }</script> <script type="text/javascript" src="http://widgets.fbshare.me/files/fbshare.js"> </script> </code> And here is what is in my css file: <code> /*float social media buttons*/ #floating-menu-blog {background-color:#fff;border:1px solid #ccc;position: fixed; left: 50%; top: 342px; margin-left:-554px; z-index:100;} #floating-menu .float-title{padding:1px 3px;} #floating-menu .float-title a{color:#000;text-decoration:none} </code> However, on the site, the css is not being applied at all. I cleared all caches and disabled w3total cache to make sure that wasn't the issue. I have no clue what the issue is as it was working a week ago and I really haven't changed anything in relation to this code. Please let me know if I can provide more info. Thanks!
|
A plugin conflicted witt eh last 30 lines or so of my css file. No idea what exactly it did to cause this, but disabled the plugin and everything is solved.
|
CSS not being applied
|
wordpress
|
About 60% of plugins that I install don't show up in my plugins section. When I install them it says they're installed, and when I click "activate plugin" it says theres no valid header for the plugin. Navigating to the main plugin section in the dashboard the plugin doesn't show up at all, so I can't activate it from the main plugin page either. What's wrong here. I'm not using the multi-site wordpress, just a standard wordpress installation with buddypress on top. Thanks Tom
|
Download the plugin as a zip, extract and manually upload the folder that immediately parents all the .php files (i.e not a folder that has another folder as its child) into you plugin folder. Sometimes dev's can zip things within an extra folder, which confuses wordpress.
|
Plugins not showing in dashboard-> plugins section
|
wordpress
|
When a user selects a specific category from a drop-down a list of multiple post types is displayed. I'd like to display the data in groups with the post-type title above in a heading. I'm unsure how to segment into post-type groups. I spent a bit of time looking but didn't find exactly what I need. I also tried to add <code> <?php $post_type = get_post_type( $post->ID ); echo $post_type; ?> </code> but it's simply repeating (obviously). calling the loop <code> <div id="content" role="main" style="float:right; width:765px;"> <?php $category_description = category_description(); if ( ! empty( $category_description ) ) echo '<div class="archive-meta">' . $category_description . '</div>'; get_template_part( 'loop', 'support' ); ?> </div> </code> The Loop <code> <?php else : ?> <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <h2 class="entry-title" style="margin-bottom:3px;"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2> <span>type = <?php $post_type = get_post_type( $post->ID ); echo $post_type; ?> <?php echo get_post_meta($post->ID, "document-type", true); ?> <?php echo get_post_meta($post->ID, "software-type", true); ?></span> <?php if ( is_archive() || is_search() ) : // Only display excerpts for archives and search. ?> <?php the_excerpt(); ?> <span class="%1$s">Compatible with:</span><br /> <?php if ( count( get_the_category() ) ) : ?> <?php printf( __( '%2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-cat-links', get_the_category_list( ', ' ) ); ?> <?php endif; ?> <?php else : ?> <?php endif; ?> <div class="entry-utility"> <?php $tags_list = get_the_tag_list( '', ', ' ); if ( $tags_list ): ?> <span class="tag-links"> <?php printf( __( '<span class="%1$s">Tagged</span> %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-tag-links', $tags_list ); ?> </span> <?php endif; ?> </div> </div> </code>
|
Yep, I don't think this is something you can easily do natively. Two ways that I see: Use <code> posts_orderby </code> to modify SQL request and order posts by post type, then just need to check so headings don't repeat. Instead of looping through posts in order returned, take array of those and sort by post type before looping for output.
|
Grouping post-types in loop
|
wordpress
|
I have seen a number of solutions of how to manually attach links to the new WP admin bar, but I need to make this much easier for my site admins. It occurred to me that the easiest solution would be to create a custom navigation menu, and then have that menu 'attached' to the admin bar. This way the site admin could very easily add new links to the admin bar by simply adding pages to the custom menu. The primary idea being to place a dropdown menu displaying the menu pages directly on the right side of the admin bar.
|
It turns out to be very easy! No need for a special walker, <code> wp_get_nav_menu_items() </code> returns everything you need. This example adds an single root menu item and then the menu, you can do this differently if you want. It maps all extra menu features I could find in the code, I don't know whether you can set them all in the menu UI. <code> add_action( 'admin_bar_menu', 'wpse15186_admin_bar_menu' ); function wpse15186_admin_bar_menu( &$wp_admin_bar ) { $menu = wp_get_nav_menu_object( 'WPSE 15186 test menu' ); $menu_items = wp_get_nav_menu_items( $menu->term_id ); $wp_admin_bar->add_menu( array( 'id' => 'wpse15186-menu-0', 'title' => 'WPSE 15186 menu', ) ); foreach ( $menu_items as $menu_item ) { $wp_admin_bar->add_menu( array( 'id' => 'wpse15186-menu-' . $menu_item->ID, 'parent' => 'wpse15186-menu-' . $menu_item->menu_item_parent, 'title' => $menu_item->title, 'href' => $menu_item->url, 'meta' => array( 'title' => $menu_item->attr_title, 'target' => $menu_item->target, 'class' => implode( ' ', $menu_item->classes ), ), ) ); } } </code>
|
Attaching a navigation menu to the admin bar?
|
wordpress
|
Is there a ready plugin or solution for implementing Featured Image function to Categories and Links? At Pages and Posts I use the feature image as a background image, using the full size original image, and I'd like to achieve the same, meaning I'd like to have featured full size image for categories. With Links, I'd like to attach an upload image to them, probably with auto-resize ability with different size to the default media size. Are there solutions already done to achieve these? Thanks, cadeyrn
|
Finally, I managed to use two plugins: Link Image Gallery and Category Meta plugin although I had to tweak one of them. They both use the media gallery to select picture, but if both very active, Link Image Gallery disabled the return function of Category Meta plugin, so I added a check in Link Image Gallery's main function: "if (strsrt($_SERVER['PHP_SELF'],'links.php'))", and now they both work.
|
Featured image for links and categories
|
wordpress
|
I have this query that shows the categories that a user had posted in. For example if I have 3 cats, name NEWS, MEDIA, PUBLICATIONS and the author had only posted in the first two, it will show NEWS MEDIA Is there any better code than this or an improvement because my db is really huge and it gives me throttling? Thank you. <code> <?php $author = get_query_var('author'); $categories = $wpdb->get_results(" SELECT DISTINCT(terms.term_id) as ID, terms.name FROM $wpdb->posts as posts LEFT JOIN $wpdb->term_relationships as relationships ON posts.ID = relationships.object_ID LEFT JOIN $wpdb->term_taxonomy as tax ON relationships.term_taxonomy_id = tax.term_taxonomy_id LEFT JOIN $wpdb->terms as terms ON tax.term_id = terms.term_id WHERE posts.post_author = '{$post->post_author}' "); ?> <ul> <?php foreach($categories as $category) : ?> <?php if ( ($category->ID == '3') || ($category->ID == '4') || ($category->ID == '5')) { ?> <li> <a href="<?php echo get_category_link( $category->ID ); ?>/?author_name=<?php echo $curuser->user_login; ?>" title="<?php echo $category->name ?>"> <?php echo $category->name; ?> </a> </li> <?php } ?> <?php endforeach; ?> </ul> </code>
|
Your SQL isn't limiting the term matching to categories only. You're also getting back tags and any other taxonomy. So the data coming back may be more than expected. Taxonomy is a key in the term_taxonomy table, so it should be fast to eliminate the ones you don't need. <code> SELECT DISTINCT(terms.term_id) as ID, terms.name FROM $wpdb->posts as posts LEFT JOIN $wpdb->term_relationships as relationships ON posts.ID = relationships.object_ID LEFT JOIN $wpdb->term_taxonomy as tax ON (relationships.term_taxonomy_id = tax.term_taxonomy_id AND tax.taxonomy = "category") LEFT JOIN $wpdb->terms as terms ON tax.term_id = terms.term_id WHERE posts.post_author = {$post->post_author} </code> Might help. Your DISTINCT also probably causes usage of a temp table for sorting and such. You might try using a GROUP BY instead, like this: <code> SELECT terms.term_id AS ID, terms.name FROM $wpdb->posts AS posts LEFT JOIN $wpdb->term_relationships AS relationships ON posts.ID = relationships.object_ID LEFT JOIN $wpdb->term_taxonomy AS tax ON ( relationships.term_taxonomy_id = tax.term_taxonomy_id AND tax.taxonomy = "category" ) LEFT JOIN $wpdb->terms AS terms ON tax.term_id = terms.term_id WHERE posts.post_author = {$post->post_author} AND terms.term_id IS NOT NULL GROUP BY terms.term_id </code> Might give better results. Set 'em both up, run 'em through phpMyAdmin and have it do an EXPLAIN on them, see which is giving better results. Also, post_author is an int. You don't need quotes around it.
|
Is there any better/faster code than this ? It shows the categories that an author had ever posted in
|
wordpress
|
So the reason why I am don't want to include <code> get_header() </code> or <code> get_footer() </code> tags is because this page will be loaded as an iframe using the thickbox modal plugin and its content will be a form and I don't want the aforementioned tags to render all the menus and banner images and menus as well as the footer content because it will make for lots of scrolling on this page. However, current I'm running something like this: <code> add_action('template_redirect', 'my_plugin_add_js'); </code> However, when I take out the <code> get_header() </code> and <code> get_footer </code> () tags then the JavaScript doesn't load even though the javascripts inside the ' <code> my_plugin_add_js </code> ' are being added within the body HTML tags at the end and not inside the head tags, like so: <code> wp_register_script("validate_form", plugins_url('js/my_plugin_validate_form.js', __FILE__), array('jquery', 'validation'), '1.0', true); </code> So I gather that the 'template_redirect' action hook is not the right one to use.
|
Completely skipping <code> wp_head </code> and <code> wp_footer </code> doesn't seem like a good idea, many core components and plugins depend on these hooks. Instead, you could create a light header and footer, and load them via an extra argument to <code> get_header() </code> and <code> get_footer() </code> . <code> get_header( 'light' ) </code> will load <code> header-light.php </code> instead of the regular header file. Create one without the visual header of the other pages, but leave the <code> wp_head </code> action intact.
|
What action hook can I use to add a JavaScript to a page post using a theme template that is not including get_header() nor get_footer()?
|
wordpress
|
I have a custom post type ("News"), and a custum user role ("Friends"). How can I get the last "News" written by "Friends" ?
|
I would try the following (not tested) <code> <?php $friends = get_users( array( 'role' => 'friends' ) ); $friend_ids = array(); foreach( $friends as $friend ) $friend_ids[] = $friend->ID; $news = new WP_Query( array( 'author' => implode( ',', $friend_ids ), 'post_type' => 'news', 'paged' => get_query_var('paged') ) ); ?> </code> Note: 'friends' is the role ID, not the nice name. Then use the loop as normal : <code> <?php if ( $news->have_posts() ) : while ( $news->have_posts() ) : $news->the_post(); ?> ... <?php endwhile; endif; ?> <?php wp_reset_postdata(); ?> </code> Hopefully that will work :)
|
How can I get the last posts by user role?
|
wordpress
|
Question is simple. Can i get the title and main url of the site from where the posts are loading? Actually i want to linked to the main site. The url can be found by wordpress function esc_url(); function but what about site title? The page is here: http://citystir.com/author/designdons/ Thanks!
|
<code> $feed = fetch_feed($feedurl); $channel = $feed->channel; $blog_title = $channel["title"]; </code> Note - I haven't tested this, am relying on my (faulty) memory.
|
Showing RSS feed via fetch_feed. How to show the site title of the feed?
|
wordpress
|
I have migrated my blog from blogspot to WordPress. Then I have noticed many of the posts contain duplicate custom fields. Like blogger_author, blogger_permalink, blogger_blog are duplicated upto 5 times. How can I remove the duplicate Custom Fields?
|
You can delete directly from the database, using an SQL statement like: <code> delete from wp_postmeta where meta_id in ( select * from ( select meta_id from wp_postmeta a where a.meta_key = 'blogger_blog' and meta_id not in ( select min(meta_id) from wp_postmeta b where b.post_id = a.post_id and b.meta_key = 'blogger_blog' ) ) as x ); </code> Don't forget to change name of the meta_key on both places if you want to delete duplicates for another custom field. or you can use a php script for this. Example: <code> <?php define('WP_USE_THEMES', false); require('wp-blog-header.php'); define( 'WP_DEBUG_DISPLAY', true ); ini_set( 'display_errors', true ); $allposts = get_posts('numberposts=-1&post_type=post&post_status=any'); $keys = array('blogger_blog', 'blogger_author', 'blogger_permalink'); foreach ( $keys as $key ) { foreach( $allposts as $postinfo) { // Fetch array of custom field values $postmeta = get_post_meta($postinfo->ID, $key); if (!empty($postmeta) ) { // Delete the custom field for this post (all occurrences) delete_post_meta($postinfo->ID, $key); // Insert one and only one custom field update_post_meta($postinfo->ID, $key, $postmeta[0]); } } } ?> </code>
|
How to remove duplicate Custom Fields?
|
wordpress
|
It is possible to restrict the upload process to choose only one file. Now a person can select various files from pc, Im trying to find a way to restrict this feature just to one file. Thanks in advance.
|
WordPress contains 2 media up-loaders. The Flash uploader allows the selection of multiple files while the browser uploader only allows 1 file at a time. To disable the Flash uploader add the following filter to functions.php <code> add_filter('flash_uploader', create_function('$flash', 'return false;')); </code> EDIT After further investigation it's probably not a great idea to use create_function. A beter way to remove the filter would be: <code> function disable_flash_uplaoder() { return $flash = false; } add_filter( 'flash_uploader', 'disable_flash_uploader', 7 ); </code>
|
Media upload - choose only one file
|
wordpress
|
I'm getting ready to submit a theme to the .Org repo and wanted to make sure that everything is in ordnung. One of the biggest holes left in my design is the comments template. I've taken a look at comments.php in a few themes, Twenty Ten chief among them and have come away more confused than when I started. It seems as though (based upon tutorials from Otto, WP Engineer, etc.) the comments template has been simplified, yet when I look at the source to most themes' comments.php, they are still as convoluted as in the Christian-Montoya-derived days of old. So help me out -- what's the best way to set up a comments template that will capture the state-of-the art functionality as of WP 3.0/3.1 and yet maintain code simplicity?
|
You really don’t need much. A headline with id=comments <code> <h2 id="comments"><?php comments_number(); ?></h2> </code> This will be the target for <code> comments_link() </code> in the article loop. Links for paginated comments. Usually, I put these links into a function and call the function above and below the comments list: <code> class TTT_Template { function comment_pager() { if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) { ?> <div class="comment-navigation"> <div class="nav-previous"> <?php previous_comments_link( 'Ältere Kommentare' ); ?> </div> <div class="nav-next"> <?php next_comments_link( 'Neuere Kommentare' ); ?> </div> </div> <?php } } } </code> wp_list_comments() You may use a custom callback function, but you don’t have to. For a theme on wp.org I’d use gravatars in the callback. And I wouldn’t namespace it with <code> my_ </code> . ;) <code> <ol class="commentlist"> <?php wp_list_comments( array ( 'type' => 'comment' , 'style' => 'ul' , 'callback' => 'my_comment_callback' ) ); ?></ol> </code> As you can see, the <code> type </code> parameter allows you to separate normal comments from pings. See the codex for more information. If you build two separate lists, check <code> get_option( 'default_ping_status' ); </code> to avoid an empty list. comment_form(); You may use the default settings or add your own filters. I use a custom class to move the textarea to top and rearrange some minor other things. <code> if ( comments_open( get_the_ID() ) ) { locate_template( array ( '/php/class.TTT_Comment_Form.php' ), TRUE, TRUE ); $ttt_comment_class = new TTT_Comment_Form(); comment_form(); } </code> And that’s all. Complete code <code> <?php if ( ! defined('ABSPATH') ) { die ('Nö.'); } if ( have_comments() ) { ?><h2 id="comments"><?php comments_number(); ?></h2> <?php TTT_Template::comment_pager(); ?> <ol class="commentlist"> <?php wp_list_comments( array ( 'type' => 'comment' , 'style' => 'ul' , 'callback' => 'my_comment_callback' ) ); ?></ol> <?php TTT_Template::comment_pager(); } if ( comments_open( get_the_ID() ) ) { locate_template( array ( '/php/class.TTT_Comment_Form.php' ), TRUE, TRUE ); $ttt_comment_class = new TTT_Comment_Form(); comment_form(); } </code>
|
What are the current recommended best-practices for comments.php?
|
wordpress
|
Is there a native function to check if a theme a template file. For instance, if a theme is not using the 'home.php' file, then execute some code...
|
So I would add to the Answer the following: <code> function foo_function() { $located = locate_template( 'home.php' ); if ( !empty( $located ) ) { // 'home.php' found in Theme, do something } } add_action('init', 'foo_function'); // remember to change both of the parameters above, first one for where you want the // action to happen and the second one the name of the function declared </code> As @Chip Bennett, said it will check both <code> TEMPLATEPATH </code> and <code> STYLESHEETPATH </code> , but I would append the code to a hook instead of just putting it in the <code> functions.php </code> file. But's up to you.
|
How do you check if a WordPress template file exist?
|
wordpress
|
I'm using site_url() for my href for anchors. I want to control what when I send the user to a secure page or non secure page. I thought I could do that with site_url('/foo', 'http') and site_url('/bar', 'https') but the scheme is not changing. If I'm on a secure page and site_url('/foo', 'http') is set, the clicked page is still secure instead of non-secure.
|
What is original link? <code> var_dump( get_option('siteurl') ); </code> If I am interpreting code right then for <code> http </code> protocol argument action is to not change the link. So if you have set up URL to be secure by default then function doesn't override that.
|
site_url is not honoring scheme
|
wordpress
|
I want to move all my content, posts and pics from Tumblr to Wordpress ..! What would be the best way to do this???
|
Try the Tumblr Importer. :) http://wordpress.org/extend/plugins/tumblr-importer/ Let me know if you have any problems with it, we're actively trying to improve it.
|
Moving a blog from Tumblr to Wordpress
|
wordpress
|
I want to know all the classes and functions(individual .php files) in a wordpress installation that handle serialization and unserialization.
|
WordPress uses <code> maybe_serialize() </code> and <code> maybe_unserialize() </code> . Both of them use PHP's native <code> serialize() </code> and <code> unserialize() </code> functions. See: http://phpxref.ftwr.co.uk/wordpress/wp-includes/functions.php.source.html#l1028 http://phpxref.ftwr.co.uk/wordpress/wp-includes/functions.php.source.html#l222 Both of those functions make use of the function <code> is_serialized() </code> , which checks if the variable is serialized yet. See: http://phpxref.ftwr.co.uk/wordpress/wp-includes/functions.php.source.html#l222
|
Classes and functions involved in serialization and unserialization
|
wordpress
|
I'm having trouble reading RSS feeds created by WP3 on the same domain. When I do a print_r($rss); at the part of my plugin where it does the RSS parsing, I get the following output: <code> WP_Error Object ( [errors] => Array ( [simplepie-error] => Array ( [0] => WP HTTP Error: couldn't connect to host ) ) [error_data] => Array ( ) ) </code> The RSS feed address being supplied validates and everything, btw. It seems to me the issue has something to do with the webserver being unable to grab its own RSS feeds. This is all very confusing. There's a blog post that seems to identify the issue at: http://www.ajaykumarsingh.com/wordpress/rss-error-wp-http-error-couldnt-resolve-host.html ...Alas, it does not contain any solutions. Any ideas for a workaround would be much appreciated.
|
Anyone with a similar issue: First off, try the following after connecting to your webhost via SSH: <code> ping <yourwebsite> </code> If you get a "cannot connect to host" issue, there's a firewall or NAT problem blocking traffic for RSS. Contact your server admin.
|
WP HTTP Error: couldn't connect to host for RSS feeds on same domain
|
wordpress
|
I have a third party events plugin that uses custom tables in the database. I have created a theme file (event.php) that pulls the data in based on a slug that is ideally given in the URL. I want to create a custom URL rewrite rule for this template, so a URL like this: /event/my-slug Will call the event.php file, grabbing the specific event they have requested (the slug). The class I am including in the functions.php to accomplish this is: <code> <?php $EventpageCode = new Eventpage(); register_activation_hook( __file__, array($EventpageCode, 'activate') ); add_filter('rewrite_rules_array', array($EventpageCode, 'create_rewrite_rules')); add_filter('query_vars',array($EventpageCode, 'add_query_vars')); add_filter('admin_init', array($EventpageCode, 'flush_rewrite_rules')); add_action('template_include', array($EventpageCode, 'template_redirect_intercept')); class Eventpage { function activate() { global $wp_rewrite; $this->flush_rewrite_rules(); } function create_rewrite_rules($rules) { global $wp_rewrite; $newRule = array('event/(.+)' => 'index.php?pagename=event&eventid='.$wp_rewrite->preg_index(1)); $newRules = $newRule + $rules; return $newRules; } function add_query_vars($qvars) { $qvars[] = 'eventid'; return $qvars; } function flush_rewrite_rules() { global $wp_rewrite; $wp_rewrite->flush_rules(); } function template_redirect_intercept($template) { global $wp_query; if ($wp_query->get('eventid')) { $template = locate_template( array( 'event.php' ) ); } return $template; } function pushoutput($message) { $this->output($message); } function output( $output ) { header( 'Cache-Control: no-cache, must-revalidate' ); header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' ); echo json_encode( $output ); } } ?> </code> This works great for displaying the content, except that the page throws a 404 error (but still displays the content). Any suggestions on how to avoid having the 404 error returned?
|
Just remove pagename=event& and reset your rewrite rules... <code> $newRule = array('event/(.+)' => 'index.php?eventid='.$wp_rewrite->preg_index(1)); </code> *template_include* is a filter NOT an action! <code> add_filter('template_include', array($EventpageCode, 'template_redirect_intercept')); </code> You can use *wp_title* function or filter to modify your page title.
|
Adding Theme File for Non-Wordpress Content
|
wordpress
|
I am going to have two WordPress websites running off the same database, so that they both have the same products set (each post is a product) but they have different homepages, about us pages, etc. thanks to the themes of each site. (Note: NOT using MU). But there is once concern: <code> <title> </code> and <code> <meta> </code> tags on the site. I want the mini-site to have completely separate tags, as it has a different identity. So I will use custom fields in the posts to set the tags for each domain but herein lies the problem: I already have an SEO plugin installed and loads of custom tags, so how do I disable that plugin for the new site only ? I assume that if I just omit the files for that plugin on one of the installs then WordPress will detect that it is not there, and disable it in the DB, so it will disable for both sites. Does anyone know the answer?
|
Hm... In more pure sense of the question I suppose you could filter <code> active_plugins </code> option on retrieval via <code> option_active_plugins </code> filter and throw plugin out for one of the sites. But I won't try to predict what this can cause to active/inactive state in your situation. :) I think more practical solution would be to figure out functions and hooks that SEO plugin uses and unhook them. Hopefully plugin you use is coded decently enough for that to be possible without much trouble. One more idea - dump plugin in <code> mu-plugins </code> for one of the sites so it is forcefully active for it.
|
More than one WordPress site using the same database - how to disable plugin for one site?
|
wordpress
|
First things firs.... up until now (before I experimented with some plugins - many) my blog was behaving properly.... 1. I write the post 2. Import the media from my computer 3. Insert the media into my post 4. When I click on media link ... it fires up the pdf file (for example) Now when I do everything same from 1 to 3 and when I try to open up the pdf file, my blog leads me from post url (/?p=1491 in the url) first to attachemtn URL (/?attachment_id=1927) which is WRONG. On that page there is a link to the pdf file. How can I bypas this extra step and go directly to pdf? |help|please|
|
In the Add Media window, click the "File URL" button, not "Post URL" before inserting it into the post.
|
Links to my uploads went crazy
|
wordpress
|
I'm using - this tutorial - to add simple meta boxes to a custom post type. But the textarea meta boxes are spitting out content all as one big paragraph, with no <code> <p> </code> formatting applied. What code would add the - wpautop filter - to the meta box textarea? Thanks for any help.
|
Add a function that grabs your meta data, applies wpautop and echoes it out, or otherwise run it through when you output it in your template. <code> $my_meta = get_post_meta($post->ID,'_my_meta',TRUE); echo $my_meta['name']; echo wpautop( $my_meta['description'], 1 ); </code>
|
Add filter 'wpautop' to meta box textarea
|
wordpress
|
I'm trying to prevent people from adding terms to some, but not all of my taxonomies. There are four taxonomies in a certain post type. I need to prevent people from adding to two of those. I used jQuery to prevent people from adding them on the taxonomy page, but I'm having trouble with the new post/edit post page. I can't just hide the box, because I need them to be able to search and select from existing items. I don't know if jQuery will do the trick, because I'd like that input box to still be available for searching for existing terms. So, does anyone know if this is possible?
|
For these situations build your own metabox for the tax terms and use radio or select. My fork of Jared Atchison's Custom Meta Box class supports custom taxonomy metaboxes. After you get the metabox directory uploaded use this to create your meta box. <code> $prefix = 'xxx_'; //Add your own unique prefix. $meta_boxes = array(); $meta_boxes[] = array( 'id' => 'test_metabox', 'title' => 'Test Metabox', 'pages' => array('page'), // post type 'context' => 'normal', 'priority' => 'high', 'show_names' => true, // Show field names on the left 'fields' => array( array( 'name' => 'Test Taxonomy Radio', 'desc' => 'Description Goes Here', 'id' => $prefix.'text_taxonomy_radio', 'taxonomy' => '', //Enter Taxonomy Slug 'type' => 'taxonomy-radio', ), ); require_once('metabox/init.php'); </code>
|
Prevent users from adding taxonomy terms
|
wordpress
|
Hi to all I'm running a Wordpress MS installation and I would like to move a couple of heavy "sub" blogs on a different DB, will it encrease my performances? Actually I'm on a dedicated server with quadcore 2.5 Ghz, 6GB ram and a few nice stuff like Lightspeed eaccelerator and so on. I'm a "self made webmaster" so I need an easy to follow guide that can teach me how to split safely my DB and improve my performance. Thank you very much for this! (just read: stackexchange-url ("Split WP install between 2 databases?") is this the only solution available or there is an easier one?)
|
WPMUdev has a Multi-DB plugin but you won't see any performance gains from splitting your database up unless you have a very high volume of sites with thousands of tables. From the plugin instructions: Step 1: Decide how many databases you want (16, 256, 4096) So, how do you know that this plugin is necessary for your install? Well, there are several factors to consider beyond the scope of this walkthrough, but as a basic guideline: 1-5,000 blogs/sites you should be fine with your WordPress default database 5,000 - 50,000 blogs/sites - go with 16 databases 50,000 - 100,000 blogs/sites - use 256 databases 100,000+ blogs/sites - use 4096 databases
|
Split a database will improve performance?
|
wordpress
|
I have been playing around with media queries quite a bit lately and I love the concept. It is so easy to display images or change div floats depending upon what the users screen max-width is. I'm trying to find a way of displaying a custom sidebar on my template Only if the users screen size is large enough to permit it. i.e. max-width is > 900px. So far every solution I have found simply uses css to hide/show a div via the media query. example: <code> @media screen and (max-width: 880px) { #secondary-nav { display: none; } </code> The 'problem' with this approach is that I am still sending the data to devices that can't see it due to my hiding it. Creates unnecessary bloat for mobile users. What I am looking for is the best approach to loading the sidebar only if it fits my 'rules'. Also, it needs to readjust itself if the viewer changes the browser window size, like when snapped to side in win7. I did find one concept of using javascript to check the screen width, and save that to a cookie: http://www.yiibu.com/resources/scripts/default.js I'm guessing at that point, there would be a way of checking the cookie 'width' data and then serving up the sidebar or not. The only problem with that is what happens if cookies are not enabled? also, what happens when screen size changes, does that mean the cookie is being set/unset over and over again? Anyhow, I am really open to ideas on this one, as this is virgin territory for me. The primary idea here is to serve up device appropriate wp templates without sending data to the users device that is hidden for smaller screens. After all, mobile data is kind of expensive, so I want to do all I can to help my users out.
|
On my website I load the recent comments per AJAX for window sizes above 480px: <code> if ( 480 < jQuery(window).width() ) { jQuery(document).ready( function() { jQuery.get('http://toscho.de/?rc', function(data) { jQuery(data).insertBefore('#inner'); } ); } ); jQuery('#posts').after('<div class=clear>&#160;</div>'); } </code> This code is quite old and not very elegant. But it may give you a hint for the right direction …
|
Best approach for loading a sidebar Only if the screen max-width is > 900px?
|
wordpress
|
I have a gallery attached to a page. On that page, I'm running the following query: <code> $events_gallery = new WP_Query( // Start a new query for our videos array( 'post_parent' => $post->ID, // Get data from the current post 'post_type' => 'attachment', // Only bring back attachments 'post_mime_type' => 'image', // Only bring back attachments that are images 'posts_per_page' => '3', // Show us the first three results 'status' => 'inherit', // Inherit the status of the parent post 'orderby' => 'rand', // Order the attachments randomly ) ); </code> I've experimented quite a few ways and, for some reason, I can't get attachments to return. Am I missing something obvious here? Update* Thanks to Wok for pointing me in the right direction. It turns out I was using "status" instead of "post_status". The codex had used "status" as the example in its in-context explanation of the "attachment" post type. I updated the codex to reference "post_status" instead. The correct code is as follows: <code> $events_gallery = new WP_Query( // Start a new query for our videos array( 'post_parent' => $post->ID, // Get data from the current post 'post_type' => 'attachment', // Only bring back attachments 'post_mime_type' => 'image', // Only bring back attachments that are images 'posts_per_page' => '3', // Show us the first result 'post_status' => 'inherit', // Attachments default to "inherit", rather than published. Use "inherit" or "all". 'orderby' => 'rand', // Order the attachments randomly ) ); </code>
|
These are the query parameters i use...works for me when i loop through the results <code> array( 'post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type'=> 'attachment', 'post_mime_type' => 'image/jpeg,image/gif,image/jpg,image/png' ); </code>
|
Broken? WP_Query and "attachment" as a post type
|
wordpress
|
I have massive number of files in my uploads folder. Is there a way of identifying those which are not linked to any post? Note: some of those files are manually copied to uploads folder not via "media library"
|
The easiest way would probably be: 1) perform a WordPress XML export ( Dashboard -> Tools -> Export ) 2) import into a clean WordPress install ( Dashboard -> Tools -> Import ) At this point, everything in the <code> /uploads </code> directory of the clean install is attached. You can now: 3) backup/delete your original <code> /uploads </code> directory 4) copy over the <code> /uploads </code> directory from the clean install
|
Garbage in uploads folder
|
wordpress
|
I have serious trouble displaying code blocks in my theme. I want to display something like: <code> <something> <something-else> Content </something-else> </something> </code> And it works fine everywhere, but doing that inside code tag: <code> <code> <something> <something-else> Content </something-else> </something> </code> </code> Displays code block looking like: <code> <something> <something-else> Content </something-else> </something> </code> And setting code's CSS to: <code> white-space: pre-wrap; </code> Produces confusing: <code> <something> </br> <something-else> </br> Content </br> </something-else> </br> </something> </code> Almost perfect, but where these come from? Additionally I'm disabling WP AutoP and it works, but not within code tags: functions.php <code> remove_filter ('the_content', 'wpautop'); add_filter( 'the_content', 'wpautop' , 12); </code> Any ideas?
|
You either need to add such code via the HTML editor (and not switch back to the Visual editor), or else you will need to pass a custom configuration to the Visual editor. I have similar needs, and here's what I use (in <code> functions.php </code> ): <code> // http://tinymce.moxiecode.com/wiki.php/Configuration function cbnet_tinymce_config( $init ) { // Change code cleanup/content filtering config // Don't remove line breaks $init['remove_linebreaks'] = false; // Convert newline characters to BR tags //$init['convert_newlines_to_brs'] = true; // Preserve tab/space whitespace $init['preformatted'] = true; // Add to list of formats to remove with Remove Format button $init['removeformat_selector'] = 'b,strong,em,i,span,ins,del,h1,h2,h3,h4,h5,h6,pre'; // Do not remove redundant BR tags $init['remove_redundant_brs'] = false; // Add to list of valid HTML elements (so they don't get stripped) // IFRAME $valid_iframe = 'iframe[id|class|title|style|align|frameborder|height|longdesc|marginheight|marginwidth|name|scrolling|src|width]'; // PRE $valid_pre = 'pre[id|name|class|style]'; // DIV $valid_div = 'div[align<center?justify?left?right|class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title]'; // Concatenate $cbnet_valid_elements = $valid_iframe . ',' . $valid_pre . ',' . $valid_div; // Add to extended_valid_elements if it alreay exists if ( isset( $init['extended_valid_elements'] ) ) { $init['extended_valid_elements'] .= ',' . $cbnet_valid_elements; } else { $init['extended_valid_elements'] = $cbnet_valid_elements; } // Pass $init back to WordPress return $init; } add_filter('tiny_mce_before_init', 'cbnet_tinymce_config'); </code> Specifically, you'll want to set <code> remove_linebreaks </code> to <code> false </code> , set <code> preformatted </code> to <code> true </code> , and probably add the <code> <pre> </code> tag to the whitelist.
|
Formatting <code> ?
|
wordpress
|
Does anyone have a function I can place in my <code> functions.php </code> that will remove this? I want to avoid altering the core files. It currently says "Both comments and trackbacks are currently closed."
|
for thematic, it's inside the 'content-extensions.php' just do a search with ctrl-f and just leave the field empty
|
function to remove 'comments and trackbacks are closed'
|
wordpress
|
I'm interested in the theory of a user being able to register/upload a gravatar directly in their user account within a hosted WP system. Is this feasible?
|
If you are looking to connect your sites sign-up with Gravatar then you simply can't, since Gravatar don't have a sing-up api you can use. But if you are just looking to let your users upload there own photos the either Simple Local Avatars Plugin that Chip suggested or one I've used a lot before is User Photo will do the job just fine. But the better part of User Photo plugin is that it has an overwrite function <code> get_avatar </code> which will get the user photo if exists or the gravatar if not.
|
Upload gravatar in WP profile?
|
wordpress
|
I have a custom post type that doesn't use the default title bar to define the post's title. Instead it is a series of taxonomies: artist, album and year. Right now my xml feed is displaying <code> <title>Auto Draft</title> </code> for each post type. What filter can I use to have these three taxonomies be the post type's title tag in the feed?
|
You can use <code> wp_insert_post_data </code> filter hook which is called by the wp_insert_post function prior to inserting into or updating the database. for example this will take the first term of each taxonomy and set them as the title: <code> function custom_post_type_title_filter( $data , $postarr ) { //check for your post type if ($postarr['post_type'] == 'your type name'){ if (isset($_post['newtag'])){ $artist = $album = $year = ''; foreach($_post['newtag'] as $tax => $terms){ if ($tax == "artist"){ $artist = $terms[0]; continue; } if ($tax == "album"){ $album = $terms[0]; continue; } if ($tax == "year"){ $year = $terms[0]; continue; } } $data['post_title'] = $artist.' '.$album .' '. $year; } } return $data; } add_filter( 'wp_insert_post_data' , 'custom_post_type_title_filter' , '99' ); </code> this assumes that your custom taxonomies are none hierarchical (like tags) and you will have to change to there right name as well as the custom post type name. Hope this helps.
|
How to make custom post type feed title = taxonomies?
|
wordpress
|
Looking at the code in feed-rss2.php and feeds-rss2-comments.php, after the header preamble, we have a Loop - eg in feeds-rss2-comments.php: <code> if ( have_comments() ) : while ( have_comments() ) : the_comment(); $comment_post = get_post($comment->comment_post_ID); get_post_custom($comment_post->ID); </code> Where is the wp_comment_query object being created for this loop? What I'm doing (following my question yesterday), is creating 2 new RSS feeds - one showing posts that have been trashed, the other showing comments that have been trashed. It's easy enough to add a new query_posts / get_comments call, but is there a more efficient way of doing it?
|
These files are not loaded directly, but similar to regular template files, only after the <code> WP </code> class is initialized. This class does the main query, which already can include the comments if the correct query variables are set. The execution flow is a follows, starting in the main <code> index.php </code> : <code> require('./wp-blog-header.php'); require_once( dirname(__FILE__) . '/wp-load.php' ); // Initialization of settings, plugins, theme wp(); WP::main(); WP::init(); WP::parse_request(); // Parse `/feed/` and `/comments/feed/` and set the query variables WP::send_headers(); WP::query_posts(); WP::build_query_string(); WP_Query::query(); WP_Query::init(); WP_Query::get_posts(); // This does the actual query // `pre_get_posts` is the action you'll probably want to use WP::handle_404(); WP::register_globals(); require_once( ABSPATH . WPINC . '/template-loader.php' ); if ( is_feed() ) { do_feed(); // This calls the `do_feed_[feedtype]` action, e.g. rss2 do_feed_rss2( $for_comments ); if ( $for_comments ) load_template( ABSPATH . WPINC . '/feed-rss2-comments.php' ); else load_template( ABSPATH . WPINC . '/feed-rss2.php' ); } </code>
|
How / where is the wp_query object created for RSS feeds?
|
wordpress
|
I created some posts using a custom post type, then I decided to delete this custom post type but of course the old posts remained orphan inside the database. How can I remove these orphan posts and all related attachment (post meta, etc.) safely from DB?
|
<code> DELETE a,b,c FROM wp_posts a LEFT JOIN wp_term_relationships b ON (a.ID=b.object_id) LEFT JOIN wp_postmeta c ON (a.ID=c.post_id) WHERE a.post_type='customposttype' </code>
|
How does one delete orphan custom post type?
|
wordpress
|
I need an easy way to create a set of users who cannot interact with the other users, all they can do is administrate a group (they can upload documents to the group-documents plugin and maybe change the name and description and avatar). Apart from that they're not allowed to have a profile, they're not allowed to interact with other users, post to groups or anything. All they can do is log in and administrate their group. Any ideas? I'd greatly prefer to create this in plugin format, and don't really want to edit any core files. Thanks for any help. Tom
|
If you want them to be able to choose the type You'll need to write your own registration logic After that check via get_user_meta() to see if they have a certain permission if they can do xyz and allow accordingly. I've done custom user types before for a plugin i wrote. There's no build in roles in BP AFAIK but a lot can be done via actions and filters, does require some coding skills though. Let me know if you need more help
|
Buddypress - New user type with no profile and can't interact but can be admin of a group
|
wordpress
|
I really like the way Vanilla Forums is integrating with WordPress however I am wondering if it is possible to take it one step further? What i'd like to be able to do is to replace WordPress comments with a Vanilla Forum thread. That way, the conversation can continue and work more in the fashion of a forum thread, as opposed to a point in time comment. Can this be done?
|
Vanilla recently released an update to their WordPress plugin that enables the comments to be replaced with a Vanilla thread discussion. See here: http://vanillaforums.com/blog/news/introducing-vanilla-comments/
|
Vanilla Forums as a replacement for WordPress comments?
|
wordpress
|
Consolidating several blogs into a single multisite instance - we have 2 sets of blogs - active and archived. What's the best way of adding <code> /archive/ </code> to the URLs of the archived blogs? So, as an example: An active blog would be accessed via <code> www.domain.com/blogname </code> An archived blog would be accessed via <code> www.domain.com/archived/blogname </code> I've taken a look at a couple of domain mapping plugins (including the WPMU Dev) one, but I don't think they do what I need.
|
In order to do partition your blogs like this you're going to need to write a custom plugin similar to the WordPress MU Domain Mapping plugin. Here's how your plugin needs to work. Create a <code> sunrise.php </code> file for your plugin, and properly <code> define('SUNRISE',true); </code> in your wp-config.php file. Create a table which maps the tuples {blog_slug, blog_id, is_archived} In <code> sunrise.php </code> perform the following logic: <code> $access_url = $_SERVER[ 'REQUEST_URI' ]; $on_archive = false; $slug = ""; $parts = explode('/',$access_url); for($i = 0; $i < count($parts); ++$i) { if(strpos($parts[i],"yourdomain.com") !== false) { if($parts[i + 1] == "archived") { $on_archive = true; $slug = $parts[i+2]; // TODO: Index checking } else $slug = $parts[i + 1]; break; } } $blog_id = $wpdb->get_var("SELECT blog_id FROM YOURTABLE WHERE blog_name=$slug ..."); if($blog_id && $on_archive) { $current_blog = $wpdb->get_row("SELECT * FROM {$wpdb->blogs} WHERE blog_id = '$blog_id' LIMIT 1"); $current_blog->path = '/archived'; $site_id = $current_blog->site_id; $current_site = $wpdb->get_row( "SELECT * from {$wpdb->site} WHERE id = '{$current_blog->site_id}' LIMIT 0,1" ); $current_site->blog_id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} WHERE domain='{$current_site->domain}' AND path='{$current_site->path}'" ); } else { // Things went wrong, redirect to the home page, or something } </code> Finally, populate the fields of your table so that it knows which blogs are "archived". In production you'd probably want to add some array safety checks, as well as checking that if "blog_a" is archived, then visiting yourdomain.com/blog_a redirects to yourdomain.com/archived/blog_a. All of these things can be handled in the sunrise file.
|
Multisite - sub-subfolders for certain blogs
|
wordpress
|
Should a breadcrumbs navigation have links set to rel="nofollow"?
|
I think it depends what your goal is and what the breadcrumbs represent. I would say that for most wordpress sites nofollow on breadcrumbs is probably a nonissue. Let's start with nofollow. Nofollow says you don't want a search engine to pass on page rank to this link. So if you had comment links and people can post their personal website you would probably use nofollow. This makes spamming your website link pointless because the links aren't being followed anyways. Nofollow is also important because page rank flows evenly between links on the page. So if you have three links that are really important to you and then a hundred comments with random websites in them, you don't want page rank getting split 103 ways. Now your question. If the breadcrumb items are important for search engines then have them followed. If you don't care about your breadcrumbs getting indexed then nofollow them. If it were me I would probably have my root node followed, the front page of my blog, and I would not have child nodes followed because those are just categories.
|
breadcrumbs & rel="nofollow"
|
wordpress
|
My plugin code is below. In the myPlugin_cleanup() function, I'm creating some categories and assigning term id 1 as the parent. Due to the known bug with creating categories via script (the category_children array does not get created and results in a fatal error when pages containing category listings are accessed), I've placed the clean_term_cache() call directly below the function that creates my categories. However, its not working. The category_children option is not getting created. Interestingly, if I create a plugin whose sole function is to execute the clean_term_cache('','category') call, it fixes the problem and creates the category_children option with the correct values. I'm just not sure why its not working in the same plugin that creates the categories. What might I be missing? <code> function myPlugin_activate(){ if ( get_option( 'myPlugin_activated' ) !== "1"){ //comment out any function you don't want to run myPlugin_copy('themes'); myPlugin_copy('plugins'); myPlugin_images(); myPlugin_options(); myPlugin_settings(); myPlugin_widgets(); myPlugin_links(); myPlugin_posts(); myPlugin_pages(); myPlugin_custom_menus(); myPlugin_cleanup(); clean_term_cache('','category'); //does not work here update_option('myPlugin_activated', "1"); } } function myPlugin_cleanup(){ //include dependencies require_once(ABSPATH.'/wp-admin/includes/taxonomy.php'); if(!get_cat_ID('nofollow')){wp_create_category('nofollow',1);} if(!get_cat_ID('noindex')){wp_create_category('noindex',1);} clean_term_cache('','category'); //Does not appear to work here either. } register_activation_hook(__FILE__, 'myPlugin_activate'); ?> </code>
|
After creating about 40 test WP installs today on localhost, here's what I can report: It appears that the correct function call to rebuild the category_children options is: <code> _get_term_hierarchy('category') </code> Previously, I was trying to call: <code> clean_term_cache('','category') </code> And I was calling it just after my categories were created in my plugin code. However, I could never get this function to do anything when called from the same plugin that I'm using to create the categories. Interestingly, I could place the function in a stand-alone plugin and run it (after my category creation plugin) and it would rebuild the category_parents options array perfectly. The reason it can't be called in the same script that creates the categories appears to be related to a peculiar behavior of clean_term_cache() which is best stated by "foofy" in a comment in the bug track ticket : This is only a problem if you make multiple term changes in the same PHP request/script lifetime. clean_term_cache() tracks each taxonomy it cleans in a static variable and won't clean it a second time. If several term changes are made in the same request, the {$taxonomy}_children option is left with the hierarchy as it was after the first change. I hope this helps someone!
|
Calling clean_term_cache() fails when called in the same plugin that creates terms, succeeds when called separately?
|
wordpress
|
I have a structured Custom Menu: parent 1 children1_1 children1_2 parent 2 children2_1 children2_2 parent 3 parent 4 children4_1 etc. I want the following: on every page, the parent level items will be shown as main menu. If a parent level item is active, I want to show the child menu items as a separate list somewhere else in the page. Is there an "easy" way to achieve this, or do I have to list the menu every time and select the current one with PHP and have headache for this for days? :) Thanks, cadeyrn
|
This plugin do exactly what you want! http://wordpress.org/extend/plugins/rv-submenus/
|
List WordPress Custom Menu's active parent level's children as separate menu
|
wordpress
|
Can one plugin activate another plugin via script? I know its possible to stackexchange-url ("deactivate known plugins via script"), but can't find any examples of how to activate them.
|
Take a look at <code> function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ); </code> in wp-admin/includes/plugin.php
|
Can one plugin activate another plugin via script?
|
wordpress
|
I have a site where pages will often move from draft to published and then to legacy. I would like to create another status type similar to draft or published titled "legacy". Wherein the page exists but is indicated as no longer active on the site. Is anyone aware of a Plugin or way to hack this feature?
|
take a look at Edit Flow plugin which offers a suite of functionality to redefine your editorial workflow within WordPress. Features include Custom Statuses
|
Additional page and post status types
|
wordpress
|
Im trying to display user login instead of user full name below each post avatar. Im using the following hook: <code> function my_member_username_link() { global $post; if (isset($post->post_author)) { $user_info = get_userdata($post->post_author); return '<a href="/' . $user_info->user_login . '/" title="' . $user_info->user_login . '">' . $user_info->user_login . '</a>'; } } add_filter('bp_core_get_userlink','my_member_username_link'); </code> This works on each avatar close to each post, but acts weird in the right sidebar where my session is displayed. Any help is welcome. Thanks in advance.
|
The reason it's not working in the sidebar is likely because the sidebar content is outside the Loop, and <code> $post </code> data, and thus, <code> $post->post_author </code> , are only available inside the Loop. You could try setting a variable equal to <code> $post->post_author </code> while still inside the Loop, and then passing that variable to <code> get_userdata() </code> in your function call outside the Loop.
|
BuddyPress - User Login instead of Full Name
|
wordpress
|
If I want to apply a style to only an item in a menu that has a submenu, how can I select that with CSS?
|
You could use jQuery, if you're open to a jQuery solution? <code> <script type="text/javascript"> jQuery(document).ready( function($) { $('#your_menu_id li').has('ul').addClass('has_children'); }); </script> </code> Slight modification of what i posted stackexchange-url ("here") basically. Any menu item with a submenu will then have a <code> has_children </code> class you can target in the stylesheet.. <code> #your_menu_id li.has_children { /* your styling */ } #your_menu_id li.has_children ul { /* your styling */ } #your_menu_id li.has_children ul li { /* your styling */ } </code> Hope that helps..
|
Custom CSS class or ID on menu items that have a Submenu
|
wordpress
|
I need to create a feed (RSS or Atom) of posts and comments that have been deleted (ie moved to Trash). What's the best way of doing this? Right now I'm thinking about creating 2 pages templates containing a SQL / $wpdb query that returns posts and comments with trashed status (and then creating new pages eg deletedposts / deletedcomments) Any better ways? Main reason for doing it this way is easy routing - ie the URLs are created for me. How would I handle the routing if I put this in a plugin and don't create pages?
|
Well if you want a feed it would be logical to create a feed, rather than emulate it with page. <code> add_feed() </code> ( source ) and your queries+output in callback.
|
RSS feed for deleted posts and comments
|
wordpress
|
I'm using Get Posts plugin to list posts with post type "project". I want to filter the list by two custom fields: year (ex. 2006) and state (ex. Completed). I added <code> meta_query </code> to the plugin's <code> get_post </code> args and tried the shortcode: <code> [get_posts post_type="project" meta_query="array(array('key' => 'state', 'value' => 'Completed'),array('key' => 'year','value' => '2006'))" suppress_filters="false"] </code> This is not working, though I can get both "state" and "year" to work by their own using <code> meta_key </code> and <code> meta_value </code> . Can someone put me in the right direction?
|
Besides the plugin not being updated, this will not work because the meta_query arg is evaluated as a string: <code> array(3) { ["post_type"] => string(7) "project" ["meta_query"] => string(96) "array(array('key' => 'state', 'value' => 'Completed'),array('key' => 'year','value' => '2006'))" ["suppress_filters"] => string(5) "false" } </code> I suggest you make a custom page template , where you would directly call get_posts() with the meta_query you want. You will have to copy the code that handles the actual listing of the posts.
|
Get Posts shortcode plugin and meta_query?
|
wordpress
|
Whats the difference between <code> current_page_item </code> and <code> current-menu-item </code> when using Custom Menus <code> .current_page_item{} // Class for Current Page .current-cat{} // Class for Current Category .current-menu-item{} // Class for any other current Menu Item .menu-item-type-taxonomy{} // Class for a Category .menu-item-type-post_type{} // Class for Pages .menu-item-type-custom{} // Class for any custom item that you added .menu-item-home{} // Class for the Home Link </code>
|
current_menu_item is the active element in the menu, independent from the type (page, archives, post, etc.) of the current menu element, while current_page_item only available, if the current item is a page and is current. For more details: http://codex.wordpress.org/Dynamic_Menu_Highlighting
|
Whats the difference between current_page_item and current-menu-item
|
wordpress
|
I added a custom button to the TinyMCE editor, and I want to open WP's Thickbox when I click on it. How can I make it so that the <code> tb_show() </code> function loads the content I want with ajax? <code> // the ajax add_action('wp_ajax_getTheContent', 'getTheContent'); function getTheContent(){ echo 'weqwtegeqgr'; // <- this should be displayed in the TB die(); } </code> Here's some of the editor plugin code I'm using: <code> init : function(ed, url) { ed.addButton('do_stuff', { title : 'Do Stuff', image : url + '/icon.gif', onclick : function() { OpenMyThickbox('do_stuff'); } }); ... </code> So the <code> OpenMyThickbox </code> javascript function should do what I want: <code> function OpenMyThickbox(tag){ tb_show(tag, '...'); // <- how to load content trough ajax here ? } </code>
|
The second parameter for <code> tb_show </code> is the URL, so you'll want to use something like.. <code> <?php $ajax_url = add_query_arg( array( 'action' => 'getTheContent', 'query_var1' => 'value1', 'query_var2' => 'value2' ), admin_url( 'admin-ajax.php' ) ); ?> tb_show(tag, <?php echo $ajax_url; ?> ); </code> I'd guess you need to pass the action and any additional query vars manually(as per above), else your request is simply for <code> admin-ajax.php </code> , when what you are looking for is something along the lines of ... <code> admin-ajax.php?action=getTheContent&someothervar=someothervalue </code> , hence the <code> add_query_arg </code> usage above.. For clarification: The following call to <code> add_query_arg </code> ... <code> add_query_arg( array( 'action' => 'getTheContent', 'query_var1' => 'value1', 'query_var2' => 'value2' ), admin_url( 'admin-ajax.php' ) ); </code> Is equivalent to and will produce ... <code> http://example.com/wp-admin/admin-ajax.php?action=getTheContent&query_var1=value1&query_var2=value2 </code> However! Having now explained myself i've come to realise we don't want the absolute URL and thus don't need the call to <code> admin_url </code> in there. The code should instead be. <code> <?php $ajax_url = add_query_arg( array( 'action' => 'getTheContent', 'query_var1' => 'value1', 'query_var2' => 'value2' ), 'admin-ajax.php' ); ?> tb_show(tag, <?php echo $ajax_url; ?>); </code> So the resulting URL looks something like this.. <code> admin-ajax.php?action=getTheContent&query_var1=valu1&query_var2=value2 </code> Functions referenced in the above code samples: Add Query Arg http://codex.wordpress.org/Function_Reference/add_query_arg Admin URL http://codex.wordpress.org/Function_Reference/admin_url
|
Open a Thickbox with content trough AJAX
|
wordpress
|
I'm working on a plugin, which converts a site into a feedback sort of portal. I made a new object page, 'Feedbacks', which displays all the feedbacks is a tabular format, and I'm using <code> register_column_headers($array_of_column_headers) </code> to make my table. I wanted to know if it is possible to add my own page row actions to this table, i mean under every feedback in the list, actions like 'approve', 'delete', 'blacklist' etc. I read the code and a couple of tickets, and found out its done this way: for posts, its <code> post_row_actions </code> , for comments its <code> comment_row_actions </code> , for media its <code> media_row_actions </code> and so on. Is there a filter that allows me to do, <code> my-page-slug_row_actions </code> ?
|
When using custom post type you use the <code> post_row_actions </code> filter hook and check the post type to modify it only: <code> add_filter('post_row_actions','my_action_row', 10, 2); function my_action_row($actions, $post){ //check for your post type if ($post->post_type =="feedbacks"){ /*do you stuff here you can unset to remove actions and to add actions ex: $actions['in_google'] = '<a href="http://www.google.com/?q='.get_permalink($post->ID).'">check if indexed</a>'; */ } return $actions; } </code> Quick update: thanks to somatic if you custom post type is "hierarchical" then you action hook is: <code> page_row_actions </code> .
|
Row actions for custom post types?
|
wordpress
|
How do I show 10 posts on the first page of the archive, and 20 on others (> 1)? My custom post type name is "apartments". Cheers!
|
You can change the <code> posts_per_page </code> variable depending on the page you are on, so make it 10 on the first page and 20 on the other pages. However, you will have to offset </code> query variable too , otherwise you will skip posts 11-20 on the second page, because this page thinks they are already displayed on the first page. <code> add_action( 'pre_get_posts', 'wpse15087_pre_get_posts' ); function wpse15087_pre_get_posts( &$wp_query ) { if ( $wp_query->is_post_type_archive( 'apartments' ) ) { if ( ! $wp_query->is_paged() ) { $wp_query->set( 'posts_per_page', 10 ); } else { $wp_query->set( 'posts_per_page', 20 ); $wp_query->set( 'offset', ( ( $wp_query->get( 'paged' ) - 2 ) * 20 ) + 10 ); } } } </code>
|
Number of posts in the archive
|
wordpress
|
Is it possible to use the "Insert/edit link" dialog box outside of TinyMCE? For example, if I wanted to add that dialog box to a generic button within a plugin settings form, is it possible to include just the portion of the TinyMCE that is required to make it work?
|
this was asked before, but sadly the "Insert/edit link" (with interlinking) was developed as a tinymce plugin so using it outside of tinymce is not really possible unless your write the whole thing from scratch.
|
Utilize TinyMCE hyperlink chooser outside of TinyMCE
|
wordpress
|
My site requires the use of https for all img src HTML. This is the WordPress function I'm using to display images: <code> <img src="'.get_bloginfo("template_url").'/images/thumb-default.gif" /> </code> This outputs an http img src - how can I convert that to https?
|
WordPress checks the return value of <code> is_ssl() </code> before creating URLs using <code> get_bloginfo() </code> . If the function returns true, it creates https URLs. If it returns false, it creates http URLs. From the WordPress source ... <code> function is_ssl() { if ( isset($_SERVER['HTTPS']) ) { if ( 'on' == strtolower($_SERVER['HTTPS']) ) return true; if ( '1' == $_SERVER['HTTPS'] ) return true; } elseif ( isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] ) ) { return true; } return false; } </code> So ... if the request was made over https or if the request came in over port 443, then <code> get_bloginfo() </code> will return an <code> https:// </code> URL. In reality, if you're forcing https anyway, you should force all requests to port 80 (http) over to port 443 (https) ... but that's a server configuration issue, not a WordPress issue. Alternatively, you could hook into a filter and replace http with https ... Just use: <code> function replace_http( $original ) { // use preg_replace() to replace http:// with https:// $output = preg_replace( "^http:", "https:", $original ); return $output; } add_filter( 'template_url', 'replace_http' ); </code>
|
Use https for img src
|
wordpress
|
I've isolated the source of a fatal error that's been occurring when a brand new site is previewed just after installing and activating the plugin I'm working on. The problem appears to be that the "category_children" item in the options table is not being created. Interestingly, it appears that two actions trigger WP to create the category_children option. They are: (1) Activating a theme that contains code to create categories and (2) Simply accessing the category manager. If I do either of those, after activating the plugin, the category_children option is being created (presumably due to checks in the theme activation or the edit-tags.php load) and the error goes away. Here's the code I'm using in my plugin to create the categories (executes on plugin activation only): <code> if(!get_cat_ID('nofollow')){wp_create_category('nofollow',1);} if(!get_cat_ID('noindex')){wp_create_category('noindex',1);} </code> What am I missing? Do I need to explicitly call a method to have WordPress generate the category_children options array for these items? UPDATE: Thanks to scribu's help below on the reason for this bug, I've found that the PARTIAL fix for this bug is to place this line just after my wp_create_category() calls are complete: <code> clean_term_cache('','category'); </code> However, this does not work when called in the same plugin that creates the categories. I had to place it in a standalone plugin that's activated separately from the plugin that creates my categories.
|
This is a known (and nasty) bug in the taxonomy hierarchy caching code: http://core.trac.wordpress.org/ticket/14485 Basically, you have to force a refresh by deleting the option.
|
Missing "category_children" option when dynamically creating categories via a plugin
|
wordpress
|
My issue is prety much what the title indicates. Whenever I publish a new post, everything works fine - the post is listed in my WP dashboard and all looks good. However, if I try to 'view post' to view it live on my website, I've searched for this issue throughout the net, and all point into editing the .htaccess file. However, this issue is more likely related to a theme I've developed (why? because several buyers have reported this issue, so I need to find a fix for the theme itself). That said, editing or manipulating the root .htaccess file is not really an option as the issue is originated in my theme. Best, Chris
|
I just ran into something similar to this. It had to do with refreshing permalinks. If you go to Settings -> Permalink and just click save see if it fixes your problem. It did for me. In the end I added the following to my functions.php file which updated the permalinks for me. I was using custom post types. Maybe you have a plugin that is doing the same. <code> add_action('admin_init', 'flush_rewrite_rules'); </code>
|
404 error after publishing a post
|
wordpress
|
I have a page "Portfolio", it contains a loop that outputs the list of portfolio (Custom Post Type, is this the problem? ) items using <code> page-portfolio.php </code> . Problem is somehow WordPress used the <code> archive.php </code> to render my portfolio page, why is that?
|
An archive of a custom post type is displayed using <code> archive-[posttype].php </code> or <code> archive.php </code> if the first does not exist (see the Template Hierarchy for the full details). <code> page-[posttype].php </code> is only used if you create a "dummy" page to show a custom post type archive (before WordPress 3.1). So in your case you should rename <code> page-portfolio.php </code> to <code> archive-portfolio.php </code> , and don't include a header to indicate a page template name.
|
Why is archive.php used for my page
|
wordpress
|
What i'm trying to achieve is bringing a loop from one WP site into another WP Site. I used this method to get the loop into an external php file (which all works fine, the results show) <code> <?php define('WP_USE_THEMES', false); require('path_on_server/wp-blog-header.php'); query_posts('showposts=5'); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <li> <a href="<?php the_permalink() ?>"><?php the_title(); ?>" /></a> </li> <?php endwhile; endif; ?> </code> I then try and include the file in my sidebar using a simple php include call but the results don't show.... I imagine this is because of some sort of confliction between my WP & the other sites WP. Any help on achieving this? Thanks
|
If you want to grab info right off the page you should use one of these options if you don't want a plugin, the content can be returned and parsed as xml, rss, json or just html/text. This is the proper way to do this. WordPress HTTP API: http://codex.wordpress.org/HTTP_API or <code> fetch_feed() </code> ( for rss only). ps. On side note I usually use simplexml instead of the built in rss wp stuff as it has way more functionality along with the HTTP API. Also an alternative, though more troublesome way is to connect to the other database.
|
Loop from another WP site onto mine
|
wordpress
|
I am trying to reload the fresh posts using jQuery. As far as I know, I can't reload the contents of a div inside the page so I reload a file into that div. The problem is that my loaded file gives me a Fatal error: Call to undefined function wp_query() How can I implement functions to a newly created file inside the theme directory to work properly? This is my jQuery <code> <script language="JavaScript"> $(function() { var SANAjax = function(){ } setInterval(SANAjax, 15000 ); }); </script> </code> And this is what i have in <code> reloadhomeposts.php </code> (I have deleted the content though) <code> <?php $recent = new WP_Query("cat=3,4,5&showposts=10"); while($recent->have_posts()) : $recent->the_post();?> . . . <?php endwhile; ?> </code>
|
The reason for this error is that your loading the file without loading in the WordPress system and so wp_query() doesnt exist. Quick fix is to: <code> include("../../../wp-load.php"); </code> <-- guessing at the location of the wordpress file. at the top of the php file.
|
Can't access WordPress functions in file called via Ajax?
|
wordpress
|
I'm trying to create a custom RSS feed template for a site my company manages, and I've encountered a very confusing bug I'd like some input on. First off, as background context, after a lot of Googling, this is the method I've chosen to create the RSS template. (If there's a better approach, I'm all ears): Copy /wp-includes/feed-rss2.php into my theme folder Specify that file as a page template, and modify as desired From the Wordpress backend, create a new page that uses the above template From there, you get an XML feed that's formatted for RSS. That process seems to work fine, even if it's a bit kludgy. Now, here's the issue I'm having. The XML outputted looks something like this: <code> <?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" > <channel> <title>New Grocery Coupons & Online Coupons Added Daily</title> <atom:link href="http://couponkim.dev/weekly-deals-rss/" rel="self" type="application/rss+xml" /> <link>http://couponkim.dev</link> <description>Coupon Kim has online coupons, printable coupons, and coupon code section for Moms like me trying to save money!</description> <lastBuildDate>Mon, 18 Apr 2011 14:51:44 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.1</generator> <item> <title>coupon-code</title> <link>http://couponkim.dev/soap-com-coupons/coupon-code-159/</link> <comments>http://couponkim.dev/soap-com-coupons/coupon-code-159/#comments</comments> <pubDate>Mon, 18 Apr 2011 13:46:18 +0000</pubDate> ... </code> (I've truncated the output for the sake of relevancy.) When I try to view the above in a Google Chrome, I get the following error message: <code> error on line 12 at column 30: xmlParseEntityRef: no name </code> My assumption here is that the ampersand is causing problems, though honestly, that's still a guess at this point. OK. So this is where it starts to get weird. I went into the PHP template, and embeded that title inside of a CDATA tag. Strangely, I didn't see that change reflected in the output when I refreshed the page. Trying something simpler, I just killed all of the PHP in the template inside of the title tags, and replaced it with static text like "This is a Test." When I refreshed the page, I still didn't see any change in the output. At that point, I suspected that some cache somewhere must be working against me. I disabled the W3 Total Cache plugin, cleared my browser's cache (I'm using Chrome), and restarted Apache for the hell of it. I reloaded the page again, but saw no change. Now, as an experiment, I changed the <code> <title></title> </code> tags to read <code> <test></test> </code> and reloaded. This time, I did see the change. So at this point, I thought, OK, cool, I'm finally breaking through the cache. I changed the line back to: <code> <title>This is a Test</title> </code> , but saw outputted <code> <title>New Grocery Coupons & Online Coupons Added Daily</title> </code> . So that's where I am. I've got literally no clue what the problem could be at this point. Here's one more weird thing to know, though. When I changed the <code> <title> </code> tags to <code> <test> </code> , and did see the change made on line 12, the next title tags (at channel-> item-> title at line 22) changed to read <code> <title>New Grocery Coupons & Online Coupons Added Daily</title> </code> - ie, the troublesome output from line 12! My best guess is that there is some Wordpress filter that I don't know about that's operating on this output, but I'm really stumped at this point. Any light you guys could shed on this problem would be very much appreciated! Thanks in advance.
|
First off, as background context, after a lot of Googling, this is the method I've chosen to create the RSS template. (If there's a better approach, I'm all ears): Second time this comes up today. :) You should use <code> add_feed() </code> ( source ) rather emulate this stuff with page. As for issue you describe I am not sure. If caching is involved I'd try to test stuff on separate local test installation.
|
Bizarre issue with custom RSS template
|
wordpress
|
I have a plugin filter that isn't working for me: <code> add_filter( 'gform_notification_email_3', 'route_notification', 10, 2 ); function route_notification($email_to, $entry) { global $post; $email_to = get_the_author_email(); return $email_to; } </code> I think the $email_to variable isn't being set properly, but how do I echo this variable out to check it?
|
Like usual. :) Works most of the time unless it ends up in some place that is not echoed to the screen by browser. <code> echo $email_to; </code> And for debug it is more informational to use <code> var_dump() </code> . Personally I usually use this to quickly add/remove dump to filter: <code> add_filter('filter','dump_filter',10,2); // or how much it passes, etc function dump_filter($input) { var_dump(func_get_args()); return $input; } </code>
|
What's the best way to echo out a filter variable?
|
wordpress
|
I've bee experimenting with a site I'm working on. My client wants the header with its nav and logo intact, so visitors always have the ability to access the navbar while scrolling to read the page content. I have added <code> fixed </code> to my wrapper <code> div </code> and that keeps the background static, but in this design the background is also part of the header. My page is http://axiomwest.com/client-services/ How can I achieve a fixed header area and allow scrolling only in the main content area?
|
Alright, what you'll need to do here is separate the header into it's own wrapper. What I did to get this to work is to close the #wrapper div right after you close the #header div and start a new div with the same class hfeed and a new ID other than wrapper. Should look like this: <code> <div class="hfeed" id="wrapper"> <div id="header"> <div id="logo">... (stuff in here) </div><!-- #header --> </div> <div class="hfeed" id="wrapper-lower"> <div id="main"> <div id="container">... (so on, so forth) </code> Now if you apply position:fixed to the #wrapper element, you'll get the desired effect. You will still need to change the way your graphics work to really sell the effect. I might suggest using a .png where everything under the red line of the swoosh is transparent. The file size will be much bigger, but if this is the only large image you are using, you'll be fine. Almost forgot! You'll also need to apply a top padding to #wrapper-lower in order to push it down past the fixed element. The padding-top of #wrapper-lower should be the same as the total height of #header.
|
How to create a fixed header and scrolling content area
|
wordpress
|
I find that if I use <code> class widget_name extends WP_Widget { function __construct() { ... } } </code> instead of <code> class widget_name extends WP_Widget { function widget_name() { ... } } </code> I get an error like <code> Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 523800 bytes) in /var/www/vhosts/klifmedia.net/httpdocs/jm/km/wp-content/themes/km/functions.php on line 77 </code>
|
Because <code> widget_name::__construct() </code> calls <code> WP_Widget::WP_Widget() </code> , which in turn calls <code> widget_name::__construct() </code> etc. A simple solution would be to make <code> widget_name::__construct() </code> call <code> WP_Widget::__construct() </code> directly. Also see http://core.trac.wordpress.org/ticket/16768#comment:9
|
Why will using __construct instead of widget_class_name when creating widget trigger out of memory error
|
wordpress
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.