Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all 8245 articles
Browse latest View live

adriannei on "Change WP_Die error to view in dashboard"

$
0
0

I added a code in my functions.php to require the maximum words in order to publish for my authors. I have an article directory where people guest blog.

The only issues is that the Error message shown when you try to post something under X amount of words appears in another window saying:

"Error: Your post is below the minimum word count."

How can I get this error to show up right above the post title after they publish it?

function minWord($content){
	global $post;
        $num = 100; //set this to the minimum number of words
	$content = $post->post_content;
	if (str_word_count($content) <  $num)
	    wp_die( __('Error: your post is below the minimum word count.') );
}
add_action('publish_post', 'minWord');

Flabadab on "WP User Profile Overhaul"

$
0
0

I'm not sure that this is the right place to post this, but I couldn't find anywhere else that made sense.

I've searched for ways to make the user profile page more customizable and the truth is that there is very little that can be done using the current filters and hooks available.

So, to add more functionality to the user profile page, I came up with a (somewhat graceful) solution that mimics the new media editor page:

https://github.com/Flabadab/WordPress/blob/master/wp-admin/user-edit.php

By implementing the add_meta_box function on the user/profile edit page, all sections are completely customizable. I've also added 2 new action hooks that allow new fields to be added to the Name and Contact sections, without re-creating the entire meta box.

maxious on "Get taxonomy terms from list of posts specified by another terms"

$
0
0

I want to make post filter "by custom taxonomies" that acts this way:

  • two lists of taxonomy terms (A and B) with checkboxes
  • user selects term(s) from first list (taxonomy A)
  • second list (taxonomy B) refreshes automatically: it show's only terms, existing in posts, where selected terms from taxonomy A exist

Actually it means taxonomy list B depends on taxonomy A selected terms through posts. I have no idea how to get list B. Only brute-forse one: getting all posts filtered by A with regular WP_Query and walking throug it getting terms B from every post and checking for possible duplicates.

Please help me to find the right way.

k83 on "Change sidebar navigation in Silesia theme to open as default?"

$
0
0

Hi!
I'm using the Silesia theme and it is cool!

I really want to tweak the jQuery code to allow the navigation to be open as default so you can close it if you want to.

I'm alright at modifying themes, but not so much when it comes to scripts at all...

Here's the script:

jQuery(document).ready(function(){
  var flagClosed = true;

  jQuery("#control").click(function(e){

    if(flagClosed){ // closed
      jQuery('#main-nav').animate({marginLeft: 0}, 300, function() {
        jQuery('#control').html('-');
      });
      if(!(navigator.userAgent.indexOf('iPad') != -1)){
				jQuery('#main-wrapper').animate({marginLeft: 200}, 300);
			}
      flagClosed = false;
		} else {
      jQuery('#main-nav').animate({marginLeft: -200}, 200, function() {
        jQuery('#control').html('+');
      });
      if(!(navigator.userAgent.indexOf('iPad') != -1)){
				jQuery('#main-wrapper').animate({marginLeft: 0}, 200);
			}
      flagClosed = true;
		}
		e.preventDefault();
  });
});

I can't provide a link to the site i'm working on because of privacy issues, but you can preview it if you follow the link in the beginning of my post.

Thank you.

toyNN on "Filter to modify the_permalink not working WP3.6"

$
0
0

Looking for suggestions on how to fix a filter that's part of a custom plugin. The filter modifies the_permalink and with changes in WP3.6 it no longer works. WP3.6 core now wraps the_permalink() in the esc_url() function.

From /wp-includes/link-template.php:

function the_permalink() {
     echo esc_url( apply_filters( 'the_permalink', get_permalink() ) );
}

The filter I have, maybe is a bit of a messy hack but did work up in prior WP versions, that appends " target="_blank" to the the_permalink based on a var set in the custom plugin,

function append_link($the_permalink){
      global $win_target;
      if ($win_target != NULL){
           $the_permalink = $the_permalink . "\" target=\"" .$win_target;
      }
      return $the_permalink;
  }

The esc_url() function is stripping out the double quote and space which ends up with just "target=_blank" tacked onto the end of the url.

Thoughts on how I might repair this filter short of editing the core files or page templates.

Thanks!

madphill on "Query posts with attachments by category"

$
0
0

I'm attempting to pull media from posts by category and the media is showing up, it's just not by category. It's currently ALL media regardless of whether or not it's attached to a post. I'm having trouble figuring out what to do.

<div class="row-fluid">
<?php
global $post;
$args = array(
'post_category' => 'trees',
'post_type' => 'attachment',
'numberposts' => 8,
'orderby' => 'random',
'post_status' => null,
'post_parent' => null, // any parent
);
$attachments = get_posts($args);
foreach ($attachments as $post) : setup_postdata($post); ?>
<div class="span3">

MissGwenny on "Publicize :: Show my website logo"

$
0
0

Hi,

I use publicize from JetPack to publish my post on Facebook.

I don't understand why but the image is always the logo of my website. I want that it is the picture in my post.

How can I hack this? (I'm good in coding, I can modify some files if needed).

Example: http://commeunchapeau.com/les-chapeaux/

Thanks for your help

kcoo on "WooCommerce add to cart button style"

$
0
0

I'm pretty new to WordPress so please bear with me.

I have a client that wants to use a specific theme that is not supported by woocommerce.

I have used the integration tutorial to some success, but the add to cart button and quantity selector buttons don't look right.


for reference.

Am I missing something simple?


rekkette on "Input text from admin page has weird formatting issues"

$
0
0

I added some theme options by way of my "functions.php" file. What it does is allow users to upload a photo and write paragraph text which will then be used in the theme. These options are on the dashboard sidebar under the "Appearance" menu item.

I got the photo working great... and even the text works really awesome EXCEPT it's replacing every ' and " with /.

Here is from function.php:

/*** Options ***/

function options_admin_menu() {
	// here's where we add our theme options page link to the dashboard sidebar
	add_theme_page("Profile Theme Options", "Theme Options", 'edit_themes', basename(__FILE__), 'options_page');
}
add_action('admin_menu', 'options_admin_menu');

function options_page() {
    if ( $_POST['update_options'] == 'true' ) { options_update(); }  //check options update
	?>
    <div class="wrap">
        <div id="icon-options-general" class="icon32"><br /></div>
		<h2>Profile Theme Options</h2>

        <form method="post" action="">
			<input type="hidden" name="update_options" value="true" />

            <table class="form-table">
                <tr valign="top">
                    <th scope="row"><label for="profile_url"><?php _e('Custom profile pic URL:'); ?></label></th>
                    <td><input type="text" name="profile_url" id="profile_url" size="50" value="<?php echo get_option('profile_url'); ?>"/><br/><span
                            class="description"> <a href="<?php bloginfo("url"); ?>/wp-admin/media-new.php" target="_blank">Upload your profile pic</a> (max 150px x 150px) using WordPress Media Library and insert its URL here </span><br/><br/><img src="<?php echo (get_option('profile_url')) ? get_option('profile_url') : get_bloginfo('template_url') . '/images/profile.png' ?>"
                     alt=""/></td>
                </tr>
                <tr valign="top">
                    <th scope="row"><label for="sd"><?php _e('Profile Bio:'); ?></label></th>
                    <td><textarea name="sd" id="sd" cols="48" rows="18"><?php echo get_option('sd'); ?></textarea></td>
                </tr>
            </table>

            <p><input type="submit" value="Save Changes" class="button button-primary" /></p>
        </form>
    </div>
<?php
}

// Update options

function options_update() {
	update_option('logo_url', $_POST['logo_url']);
	update_option('sd', $_POST['sd']);
}

Here is what I have in the theme template:

<div class="profile">
                    <a href="<?php bloginfo('home'); ?>"><img src="<?php echo (get_option('profile_url')) ? get_option('profile_url') : get_bloginfo('template_url') . '/images/profile.png' ?>" alt="<?php bloginfo('name'); ?>"/></a>
                </div>

<div class="question">
    <span>+Bio</span>
</div>
<div class="answer" style="display: none"><?php echo (get_option('sd')) ? get_option('sd') : get_bloginfo('template_url') ?></div>

Here is the address of the site:
http://rachelforshee.net

clhereistian on "wordpress custom post type pagination and pre_get_posts"

$
0
0

Hi,

Thanks for looking at my post.

I created a plugin that creates a custom post type. The custom post type has an archive page with pagination. That all works fine. The archive page also has two html select elements that sort the posts, and that also works correctly. The problem is that when I use the pagination links to move to a new page, the posts return to the default sort (by date).

I am doing nothing fancy in the archive file:

<form method="post" id="sortForm">
    <label for="sort">Sort by: </label>
    <select name="sort" onchange='this.form.submit()'>
        <option value="title"<?php if (isset($_POST['sort']) && $_POST['sort'] == "title") echo " selected"; ?>>Title</option>
         <option value="author"<?php if (isset($_POST['sort']) && $_POST['sort'] == "author") echo " selected"; ?>>Author</option>
     </select>

    <select name="dir" onchange='this.form.submit()'>
        <option value="asc"<?php if (isset($_POST['dir']) && $_POST['dir'] == "asc") echo " selected"; ?>>Ascending</option>
        <option value="desc"<?php if (isset($_POST['dir']) && $_POST['dir'] == "desc") echo " selected"; ?>>Descending</option>
    </select>
 </form>

<?php if (have_posts ()) { ?>
<?php while (have_posts ()) { (the_post()); ?>

// normal loop display stuff

 <?php kriesi_pagination(); ?>

To actually do the sort from those select elements, I hooked into pre_get_posts:

function sort_posts( $query ) {
    if ( !is_admin() && $query->is_main_query() && is_post_type_archive('cchs_library')) {

        if (isset($_POST['sort'])) {
            $dir = isset($_POST['dir']) && $_POST['dir'] == "asc" ? "asc" : "desc";

            $query->set('order', $dir);

            if ($_POST['sort'] == 'title') {
                $query->set('orderby', 'title');
            } else if($_POST['sort'] == 'author' ) {
                $query->set('orderby', 'meta_value');
                $query->set('meta_key', 'library_author');
            }
        }
    }
}
add_action( 'pre_get_posts', 'sort_posts' );

The pagination function isn't mine, it came with the theme, but here it is:

function kriesi_pagination($pages = '', $range = 2)
{
     $showitems = ($range * 2)+1;

     global $paged;
     if(empty($paged)) $paged = 1;

     if($pages == '')
     {
         global $wp_query;
         $pages = $wp_query->max_num_pages;
         if(!$pages)
         {
             $pages = 1;
         }
     }

     if(1 != $pages)
     {
         echo "<ul class='pagination clearfix'>";
         if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<li><a class='button-small grey rounded3' href='".get_pagenum_link(1)."'>«</a></li>";
         if($paged > 1 && $showitems < $pages) echo "<li><a class='button-small rounded3 grey' href='".get_pagenum_link($paged - 1)."'>‹</a></li>";

         for ($i=1; $i <= $pages; $i++)
         {
             if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
             {
                 echo ($paged == $i)? "<li><span class='button-small-theme rounded3 current'>".$i."</span></li>":"<li><a class='button-small grey rounded3 inactive' href='".get_pagenum_link($i)."' >".$i."</a></li>";
             }
         }

         if ($paged < $pages && $showitems < $pages) echo "<li><a class='button-small grey rounded3' href='".get_pagenum_link($paged + 1)."'>›</a></li>";
         if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<li><a class='button-small grey rounded3' href='".get_pagenum_link($pages)."'>»</a></li>";
         echo "</ul>\n";
     }
}

Once again, my question is why isn't the sorting preserved when I use the paginator to go to a new page? If I print out the query object, orderby is not set after I paginate.

The live code is a little more cluttered, but if you want to see the page it is here:

http://www.centrehistory.org/cchs_library/

bertism on "need to rewrite subdirectory url when post is clicke"

$
0
0

Hello All,

I installed my wordpress blog into a subdirectory so the home page url looks like this:
http://example.com/worpress-blog/

When a post is clicked, the URL looks like this:
http://example.com/worpress-blog/post-title

This is what I am having trouble with:

I need to rewrite the url structure (be it with rules in the htaccess file or otherwise) so the home page remains the same (http://example.com/worpress-blog/), but when a post is clicked, it looks like this:
http://example.com/content/post-title

Any help is much appreciated!

monkeypunch3 on "Can XMLRPC be used with with WordPress login authentication?"

$
0
0

The user logs in to the site and is authenticated. Now I would like to asynchronously interact with WP to do things such as get a list of posts, get a list of categories, add a new post and so on. With XML RPC there is an API I am familiar with. But I do not want to send the user's login credentials on each call especially because they have already authenticated. Is there a way to use the XML-RPC without sending the login credentials on each call? Can the login be blank after the user is authenticated? Am I doing this right?

The reason I am doing it this way is that the application is asynchronous. I am loading it once after the user logs in and from then on out there are no page loads only AJAX calls. So I need to get information to and from WordPress while still in the browser.

mrvelle on "Is it safe to change post to page in db?"

$
0
0

Maybe over the edge to call this hacking :) But...

I created a bunch of posts, that I would now like to make into pages. I want to do the following:

UPDATE wp_posts SET post_type='page' WHERE post_type='post';

Is that safe? I am afraid of messing something up! Maybe this will require updates to other tables too, to maintain integrity?

Sincerely! :)

sparkss on "User Profiles Made Easy: Trying to order members by first or last name."

$
0
0

Hello, I am using the plugin User Profiles Made Easy and you are able to view all registered members. Right now the possible values for ordering that work are ID, login, nicename, email, url, registered, display_name, or post_count. I am trying to get it to be able to order by first or last name.

I know it has to do with this part of the code

// Setting up order data
        if (in_array($this->profile_order_field, array('nicename', 'email', 'url', 'registered')))
            $orderby = 'users.user_' . $this->profile_order_field;
        elseif (in_array($this->profile_order_field, array('user_nicename', 'user_email', 'user_url', 'user_registered')))
            $orderby = 'users.' . $this->profile_order_field;
        elseif ('name' == $this->profile_order_field || 'display_name' == $this->profile_order_field)
            $orderby = 'users.display_name';

  elseif ('firstname' == $this->profile_order_field || 'user_firstname' == $this->profile_order_field)
            $orderby = 'users.user_firstname';

        elseif ('ID' == $this->profile_order_field || 'id' == $this->profile_order_field)
            $orderby = 'users.ID';
        else
            $orderby = 'users.user_login';

And this part

c=b.addMenu({title:"Multiple Profiles / Member List"});
									a.addImmediate(c,"Group of Specific Users", '[upme group=user_id1,user_id2,user_id3,etc]');
									a.addImmediate(c,"All Users", '[upme group=all users_per_page=10]');
									a.addImmediate(c,"All Users in Compact View", '[upme group=all view=compact users_per_page=10]');
									a.addImmediate(c,"All Users in Compact View, Half Width", '[upme group=all view=compact width=2 users_per_page=10]');
									a.addImmediate(c,"Users Based on User Role", '[upme group=all role=subscriber users_per_page=10]');
									a.addImmediate(c,"Administrator Users Only", '[upme group=all role=administrator users_per_page=10]');
									a.addImmediate(c,"All Users Ordered by Display Name", '[upme group=all order=asc orderby=display_name users_per_page=10]');
									a.addImmediate(c,"All Users Ordered by Post Count", '[upme group=all order=desc orderby=post_count users_per_page=10]');
									a.addImmediate(c,"All Users Ordered by Registration Date", '[upme group=all order=desc orderby=registered users_per_page=10]');
                                                                a.addImmediate(c,"All Users Ordered by First Name", '[upme group=all order=desc orderby=first_name users_per_page=10]');
									a.addImmediate(c,"All Users showing User ID", '[upme group=all show_id=true users_per_page=10]');
									a.addImmediate(c,"Search Profiles", '[upme_search operator=OR]');
									a.addImmediate(c,"Search with Custom Field Filters", '[upme_search filters=meta1,meta2,meta3]');

This is the shortcode I'm using on the page

[upme_search autodetect=off filters=graduate] [upme group=all view=compact width=2 order=asc orderby=first_name users_per_page=8]

As you can see I have already messed with the code trying to add first name as an option to order as well. I have tried all kinds of combinations so far, but have had no luck. Any help in resolving this would be much appreciated. Thank you.

Demetrius Pop on "CSS for plugin"

$
0
0

I have this simple plugin that creates a copyright in the footer section.
`function add_copyright() {
$copyright_message = "Copyright ". date(Y) . bloginfo('name') . ", All Rights Reserved";
echo '<div id="plugin-copyright">' . $copyright_message . '</div>';
}
add_action("wp_footer",add_copyright);`

My question is:
How do I add the CSS so that the div can be positioned?


cbonwp on "$_SESSION access on logout"

$
0
0

Function wp_logout documentation says
"Log the current user out, by destroying the current user session."

but the $_SESSION variables seem to be already destroyed. Is there somewhere in the logout process where I can still access them?

djeyewater on "Retrieving the post content from a save_post action"

$
0
0

According to the codex

The data for the post is stored in $_POST, $_GET or the global $post_data, depending on how the post was edited. For example, quick edits use $_GET.

So, how are you meant to handle this in your function? Do they all use the same format for storing the data, i.e. an associative array? Do they all need stripslashes_deep applying?

When I tried doing a quick edit, it used POST, not GET as the codex suggests.

Also, it's probably covered in the codex somewhere, but I'm not sure to where to find it - what's the difference between post_content and content?

Thanks

Dave

fyreus on "Show specific user data in widget"

$
0
0

Hello!

I am wondering if it's possible to add information stored in the Bio section (or a custom section with a comment box) and show it inside a sidebar via adv. iframe. The idea is to find out if it's possible and hire someone who's able to pull this off if this is safe AND possible.

nick_nielsen on "Converting a page template to a plugin"

$
0
0

Context :
I have decided to stop using the NextGen gallery plugin - basically because the code has bloated from 1Mb to 9Mb with features I don't want (as it was when Alex Rabe maintained it, I only used the basic image management). It was rather forced upon me as when I tried to follow the instructions to wind back to the pre-version 2, it broke the site and I lost all the image information.
So I have decided to use Wordpress' media management (which was inexistant when I started using NextGen). I've found a plugin to deal with the thumbnail cropping (because what's on offer is useless) and now I'm working on creating a way of presenting the images.
I've looked at various "portfolio" plugins, but none of them actually offer a solution for what I need - they are oriented towards graphics people or photographers and I'm looking for a way of presenting my work as a visual artist.

Bearing in mind Justin Tadlock's advice to put personal "permanent" customisations into a plugin rather than changing functions.php every time you change or modiy your theme, I'm trying to do this with my galleries.

My solution at the moment is a custom page template, but it would be better if the gallery could be called with a shortcode

Problem:
I use the content on the page to give an introduction to the works that are being shown and this needs to be integrated into the gallery structure -
schematically the existing custom template looks like this :

< Query to get the attached images >
< Do things >
< the_content() --intro to work >
< do the rest >

This works. But trying to get to the shortcode solution has defeated me. I need to stop the_content() from printing as is usual, and I need it's output as a variable.

I've found that I can get something using $post->post_content but it starts, inevitably with "[workgallery]..." my shortcode, which I don't know how to get rid of and equally inevitably, the_content() outputs below as well.

I trawled the net, and found that I could put the_content() into an output buffer, which would give me it's output as a variable but as the content of the page contains my shortcode, it sets up an infinite loop and the page goes into meltdown.

I've looked at add_filter(the_content, $myvariable) but all the examples I've found have been for adding bits to a post, rather than manipulating the output as described above.

Advice and possible solutions would be much appreciated.

nyzeta on "Multisite (site_id) multiblog (blog_id) adaption"

$
0
0

Hi there.
This is a bit of a strugle for me. I've been diving into Wordpress multisite code for a while now and I've got the whole thing running by adding database entries manually (trough sql queries).

I got a multiple domain, multiple subpage setup. I got a wordpress network up and running. I got http://example1.com and http://example2.com pointing to the same storage on my web server. I started up http://example1.com first, adding a subdomain setup. Then I went into the SQL-server and checked the mu_site (mu is my prefix) table. One entry here so I added another one.
INSERT INTO mu_site (id,domain,path) VALUES (2,'example2.com','/')
Now the table shows two lines.

The next part of the hack is the mu_sitemeta table. On a fresh install there are a bare minimum of information here. So I duplicated the whole thing.
INSERT INTO mu_sitemeta (site_id,meta_key,meta_value) SELECT 2,meta_key,meta_value FROM mu_sitemeta where site_id = 1

Now to make things easy, I went into example1.com and added a fresh subdomain trough GUI. Then I entered mu_blogs and found two lines of data. One for example1.com and one for sub.example1.com. I replaced the two fields site_id and domain. blog_id being the primary key in the table and a nice reference I did as following.

UPDATE mu_blogs set site_id = 2, domain = 'example2.com' WHERE blog_id = 2

Wolah.. both example1.com and example2.com got its full webpage trough one setup. It really works flawless, but I would like to add some functionality to the network admin.

- Hitting the admin toolbar "my sites" shows a list of all sites and blogs (no filtering). This is OK.
- Since there is two site_id's one get two network-admin pages. This can be a bit disturbing. They are choosen by first entering example1.com and then the network admin sub menu. If you then hit example2.com and goto the same menu, you will get a different admin. Logical enough, but as I said, a bit messy.
- If you go to the page /wp-admin/network/sites.php the whole query is site_id dependent. And there is where my hack come in handy. A file called /wp-admin/includes/class-wp-ms-sites-list-table.php contain a class extention and here is where the query defines/filters out other site_id's. So I added a little hack here on line 50 and 66. Commenting out the site_id parts. I would love to have this done by a parameter in the future. Any ideas here is most welcome.
- I've added some extra fields with the filter wpmu_blogs_columns and the action manage_sites_custom_column. Now with the help of the site_id and a minimum command I'm able to pick out the main blog_id for each site. This helps me list the total amount of blogs and sites in my big multisite, multiblog network. Hope it helps somebody :)

Viewing all 8245 articles
Browse latest View live




Latest Images