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

Howdy_McGee on "Custom MetaBox Data Not Being Added"

$
0
0

I can't figure it out - it won't add anythign to the database even though there is 100% a value being passed into $_POST['_desc'] what am I doing wrong?

/** Add the Meta Box **/
function add_custom_meta_box() {
	global $meta_box;
    add_meta_box(
		'short-desc', // $id
		'Short Description', // $title
		'show_custom_meta_box', // $callback
		'post', // $page
		'side', // $context
		'high'); // $priority
}
add_action('add_meta_boxes', 'add_custom_meta_box');

/** The Callback **/
function show_custom_meta_box() {
	global $post;
	// Use nonce for verification
	echo '<input type="hidden" name="shortdesc_meta_box_nonce" value="'.wp_create_nonce(basename(__FILE__)).'" />';

	// get value of this field if it exists for this post
	$meta = get_post_custom($post->ID);
	echo var_dump($meta);

	// Begin the field table and loop
	echo '<table class="form-table"><tr><td>';

		echo '<strong>Enter A Short Description:</strong>
			<input type="text" name="_desc" id="short-desc" value="'.$meta['_desc'].'" size="30" />';

	echo '</td></tr></table>'; // end table
} 

/** Save the Data **/
function save_custom_meta($post) {
	// verify nonce
	if (!wp_verify_nonce($_POST['shortdesc_meta_box_nonce'], basename(__FILE__)))
		return $post->ID;
	// check autosave
	if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
		return $post->ID;
	// check permissions
	if (!current_user_can('edit_post', $post->ID))
		return $post->ID;

	echo $_POST['_desc'];
//	die();

	if(isset($_POST['_desc']))
		update_post_meta($post->ID, '_desc', strip_tags($_POST['_desc']));
}
add_action('save_post', 'save_custom_meta', 1, 2);

pepe on "New media modal and and add_fields_to_edit with HTML fields"

$
0
0

Is there a new and approved way to add JS snippets to extra edit fields in the new media modal?

I'm trying to fix a plugin that adds JS code in the 'html'-key of a $form_field and this variant is silently dropped by get_compat_media_markup(). So far, I haven't been able to find any documentation on extending the new modal.

chomachomachoma on "Adding Hierarchy Capability to Custom Post Type Removes Thumbnails From Admin"

$
0
0

I have setup in my functions.php a custom post type of 'Portfolio'. I have just added hierarchy capability to it, so I can assign child posts and such.

This works fine, where I am able to assign child/parents, however, by adding the line...

'hierarchical' => true,

...to $args results in the list of posts to be ordered asc by post_title and the thumbnails disappear. Removing this line, or setting its value to false, reverts everything back to the way I would prefer, where it is ordered by publish_date and the thumbnails are present.

Any ideas how can keep hierarchical functionality and have my columns display as I wish? Here is my code...

/*
 * Custom Post Type - Portfolio
*/

if ( ! class_exists( 'Portfolio_Post_Type' ) ) :

class Portfolio_Post_Type {

	var $version = 0.5;

	function __construct() {

		register_activation_hook( __FILE__, array( &$this, 'plugin_activation' ) );

		load_plugin_textdomain( 'portfolioposttype', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );

		add_action( 'init', array( &$this, 'portfolio_init' ) );

		add_theme_support( 'post-thumbnails', array( 'portfolio' ) );

		add_filter( 'manage_edit-portfolio_columns', array( &$this, 'add_thumbnail_column'), 10, 1 );
		add_action( 'manage_posts_custom_column', array( &$this, 'display_thumbnail' ), 10, 1 );

		add_action( 'restrict_manage_posts', array( &$this, 'add_taxonomy_filters' ) );

		add_action( 'right_now_content_table_end', array( &$this, 'add_portfolio_counts' ) );

		add_action( 'admin_head', array( &$this, 'portfolio_icon' ) );
	}

	function plugin_activation() {
		$this->portfolio_init();
		flush_rewrite_rules();
	}

	function portfolio_init() {

		$labels = array(
			'name' => __( 'Portfolio', 'portfolioposttype' ),
			'singular_name' => __( 'Portfolio Item', 'portfolioposttype' ),
			'add_new' => __( 'Add New Item', 'portfolioposttype' ),
			'add_new_item' => __( 'Add New Portfolio Item', 'portfolioposttype' ),
			'edit_item' => __( 'Edit Portfolio Item', 'portfolioposttype' ),
			'new_item' => __( 'Add New Portfolio Item', 'portfolioposttype' ),
			'view_item' => __( 'View Item', 'portfolioposttype' ),
			'search_items' => __( 'Search Portfolio', 'portfolioposttype' ),
			'not_found' => __( 'No portfolio items found', 'portfolioposttype' ),
			'not_found_in_trash' => __( 'No portfolio items found in trash', 'portfolioposttype' )
		);

		$args = array(
			'labels' => $labels,
			'parent_item_colon' => 'PP',
	    	'public' => true,
			'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'comments', 'author', 'custom-fields', 'revisions', 'page-attributes' ),
			'capability_type' => 'page',
			'rewrite' => array("slug" => "portfolio"),
			'menu_position' => 5,
			'hierarchical' => true,
			'has_archive' => true
		);

		$args = apply_filters('portfolioposttype_args', $args);

		register_post_type( 'portfolio', $args );

		$taxonomy_portfolio_tag_labels = array(
			'name' => _x( 'Portfolio Tags', 'portfolioposttype' ),
			'singular_name' => _x( 'Portfolio Tag', 'portfolioposttype' ),
			'search_items' => _x( 'Search Portfolio Tags', 'portfolioposttype' ),
			'popular_items' => _x( 'Popular Portfolio Tags', 'portfolioposttype' ),
			'all_items' => _x( 'All Portfolio Tags', 'portfolioposttype' ),
			'parent_item' => _x( 'Parent Portfolio Tag', 'portfolioposttype' ),
			'parent_item_colon' => _x( 'Parent Portfolio Tag:', 'portfolioposttype' ),
			'edit_item' => _x( 'Edit Portfolio Tag', 'portfolioposttype' ),
			'update_item' => _x( 'Update Portfolio Tag', 'portfolioposttype' ),
			'add_new_item' => _x( 'Add New Portfolio Tag', 'portfolioposttype' ),
			'new_item_name' => _x( 'New Portfolio Tag Name', 'portfolioposttype' ),
			'separate_items_with_commas' => _x( 'Separate portfolio tags with commas', 'portfolioposttype' ),
			'add_or_remove_items' => _x( 'Add or remove portfolio tags', 'portfolioposttype' ),
			'choose_from_most_used' => _x( 'Choose from the most used portfolio tags', 'portfolioposttype' ),
			'menu_name' => _x( 'Portfolio Tags', 'portfolioposttype' )
		);

		$taxonomy_portfolio_tag_args = array(
			'labels' => $taxonomy_portfolio_tag_labels,
			'public' => true,
			'show_in_nav_menus' => true,
			'show_ui' => true,
			'show_tagcloud' => true,
			'hierarchical' => false,
			'rewrite' => array( 'slug' => 'portfolio_tag' ),
			'show_admin_column' => true,
			'query_var' => true
		);

		register_taxonomy( 'portfolio_tag', array( 'portfolio' ), $taxonomy_portfolio_tag_args );

	    $taxonomy_portfolio_category_labels = array(
			'name' => _x( 'Portfolio Categories', 'portfolioposttype' ),
			'singular_name' => _x( 'Portfolio Category', 'portfolioposttype' ),
			'search_items' => _x( 'Search Portfolio Categories', 'portfolioposttype' ),
			'popular_items' => _x( 'Popular Portfolio Categories', 'portfolioposttype' ),
			'all_items' => _x( 'All Portfolio Categories', 'portfolioposttype' ),
			'parent_item' => _x( 'Parent Portfolio Category', 'portfolioposttype' ),
			'parent_item_colon' => _x( 'Parent Portfolio Category:', 'portfolioposttype' ),
			'edit_item' => _x( 'Edit Portfolio Category', 'portfolioposttype' ),
			'update_item' => _x( 'Update Portfolio Category', 'portfolioposttype' ),
			'add_new_item' => _x( 'Add New Portfolio Category', 'portfolioposttype' ),
			'new_item_name' => _x( 'New Portfolio Category Name', 'portfolioposttype' ),
			'separate_items_with_commas' => _x( 'Separate portfolio categories with commas', 'portfolioposttype' ),
			'add_or_remove_items' => _x( 'Add or remove portfolio categories', 'portfolioposttype' ),
			'choose_from_most_used' => _x( 'Choose from the most used portfolio categories', 'portfolioposttype' ),
			'menu_name' => _x( 'Portfolio Categories', 'portfolioposttype' ),
	    );

	    $taxonomy_portfolio_category_args = array(
			'labels' => $taxonomy_portfolio_category_labels,
			'public' => true,
			'show_in_nav_menus' => true,
			'show_ui' => true,
			'show_admin_column' => true,
			'show_tagcloud' => true,
			'hierarchical' => true,
			'rewrite' => array( 'slug' => 'portfolio_category' ),
			'query_var' => true
	    );

	    register_taxonomy( 'portfolio_category', array( 'portfolio' ), $taxonomy_portfolio_category_args );

	}

	function add_thumbnail_column( $columns ) {

		$column_thumbnail = array( 'thumbnail' => __('Thumbnail','portfolioposttype' ) );
		$columns = array_slice( $columns, 0, 2, true ) + $column_thumbnail + array_slice( $columns, 1, NULL, true );
		return $columns;
	}

	function display_thumbnail( $column ) {
		global $post;
		switch ( $column ) {
			case 'thumbnail':
				echo get_the_post_thumbnail( $post->ID, array(35, 35) );
				break;
		}
	}

	function add_taxonomy_filters() {
		global $typenow;

		$taxonomies = array( 'portfolio_category', 'portfolio_tag' );

		if ( $typenow == 'portfolio' ) {

			foreach ( $taxonomies as $tax_slug ) {
				$current_tax_slug = isset( $_GET[$tax_slug] ) ? $_GET[$tax_slug] : false;
				$tax_obj = get_taxonomy( $tax_slug );
				$tax_name = $tax_obj->labels->name;
				$terms = get_terms($tax_slug);
				if ( count( $terms ) > 0) {
					echo "<select name='$tax_slug' id='$tax_slug' class='postform'>";
					echo "<option value=''>$tax_name</option>";
					foreach ( $terms as $term ) {
						echo '<option value=' . $term->slug, $current_tax_slug == $term->slug ? ' selected="selected"' : '','>' . $term->name .' (' . $term->count .')</option>';
					}
					echo "</select>";
				}
			}
		}
	}

	function add_portfolio_counts() {
	        if ( ! post_type_exists( 'portfolio' ) ) {
	             return;
	        }

	        $num_posts = wp_count_posts( 'portfolio' );
	        $num = number_format_i18n( $num_posts->publish );
	        $text = _n( 'Portfolio Item', 'Portfolio Items', intval($num_posts->publish) );
	        if ( current_user_can( 'edit_posts' ) ) {
	            $num = "<a href='edit.php?post_type=portfolio'>$num</a>";
	            $text = "<a href='edit.php?post_type=portfolio'>$text</a>";
	        }
	        echo '<td class="first b b-portfolio">' . $num . '</td>';
	        echo '<td class="t portfolio">' . $text . '</td>';
	        echo '</tr>';

	        if ($num_posts->pending > 0) {
	            $num = number_format_i18n( $num_posts->pending );
	            $text = _n( 'Portfolio Item Pending', 'Portfolio Items Pending', intval($num_posts->pending) );
	            if ( current_user_can( 'edit_posts' ) ) {
	                $num = "<a href='edit.php?post_status=pending&post_type=portfolio'>$num</a>";
	                $text = "<a href='edit.php?post_status=pending&post_type=portfolio'>$text</a>";
	            }
	            echo '<td class="first b b-portfolio">' . $num . '</td>';
	            echo '<td class="t portfolio">' . $text . '</td>';

	            echo '</tr>';
	        }
	}

	function portfolio_icon() { ?>
	    <style type="text/css" media="screen">
	        #menu-posts-portfolio .wp-menu-image {
	            background: url(<?php echo bloginfo('stylesheet_directory'); ?>/assets/img/portfolio-icon.png) no-repeat 6px 6px !important;
	        }
			#menu-posts-portfolio:hover .wp-menu-image, #menu-posts-portfolio.wp-has-current-submenu .wp-menu-image {
	            background-position:6px -16px !important;
	        }
			#icon-edit.icon32-posts-portfolio {background: url(<?php echo bloginfo('stylesheet_directory'); ?>/assets/img/portfolio-32x32.png) no-repeat;}
	    </style>
	<?php }

}

new Portfolio_Post_Type;

endif;

jnwry on "add drop down menu to register post type"

$
0
0

Hi,
I'm trying to figure out how to integrate register post type with my plugin. What I need is that each author have access to post to his/her course. So I need a drop down menu that would select the course he wants to post to. Thanks in advance.

zinc1314 on "Delete post of user with button"

$
0
0

Hi!

Someone know how i can show on front of wordpress, a button for delete entries of logged users?

I have this code, but is only for back (admin)

<?php
function mqw_add_admin_bar_trash_menu() {
  global $wp_admin_bar;
  if ( !is_super_admin() || !is_admin_bar_showing() )
      return;
  $current_object = get_queried_object();
  if ( empty($current_object) )
      return;
  if ( !empty( $current_object->post_type ) &&
     ( $post_type_object = get_post_type_object( $current_object->post_type ) ) &&
     current_user_can( $post_type_object->cap->edit_post, $current_object->ID )
  ) {
    $wp_admin_bar->add_menu(
        array( 'id' => 'borrar',
            'title' => __('Borrar post'),
            'href' => get_delete_post_link($current_object->term_id)
        )
    );
  }
}
add_action( 'admin_bar_menu', 'mqw_add_admin_bar_trash_menu', 35 );
?>

Thanks

primall on "Adding a slider to my homepage"

$
0
0

Trying to add a slider to my homepage of my blog.

Using Soliloquy Lite, unless someone has a better option. Just the first one i came across. Anyways im using the Expound Theme and i have no idea how to make the slider only show up on the homepage.

any help would be awesome :)

greathug2u on "How do I enqueue jQuery in my plugin?"

$
0
0

Hi,

Can somebody please tell me how to properly enqueue jQuery into my plugin code?
I did this:

if (is_admin()) add_action( "wp_enqueue_scripts", "my_jquery_enqueue", 11 );
function my_jquery_enqueue() {
   wp_deregister_script( 'jquery' );
   wp_register_script( 'jquery', "http" . ( $_SERVER['SERVER_PORT'] == 443 ? "s" : "" ) . "://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js", false, null );
   wp_enqueue_script( 'jquery' );
}

And it didn't work. I opened the console and got this message:
GET http://localhost:8888/wordpress/wp-admin/jquery-1.10.2.min.map 404 (Not Found)

everyeurocounts on "Change php date array to javascript array"

$
0
0

I have a php array of dates ($fdates) which outputs as
array (size=1) 0 => string '2013/08/23' (length=10)

I need to change this to a Javascript array in this format

var array = ["2013-09-14","2013-09-15","2013-09-16"]

using json_encode i get ["2013V09V14"]

How do i change the format into the format above (its for beforedate in jquery date picker..

<?php
var_dump( $fdates ); // test query
echo json_encode($fdates);

?>
<script type="text/javascript">
var array = <?php echo json_encode($fdates); ?>;

jQuery(document).ready(function() {
    jQuery('#MyDate').datepicker({
		beforeShowDay: function(date){
        var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
        return [ array.indexOf(string) == -1 ]
    }
    });
});

</script>

caioxavier on "Help with category page"

$
0
0

Hey guys, I'm new to WP and PHP so I can't really rely on my hardcoding skills to get what I want, so I need your help. It should be simple:

I have category pages and child categories in some of them. I want to display in the category page, links to the current parents and child categories, so the user can filter the posts.

Imagine we are broswing Category 1, with has 2 child categories. All I want is to display:

Category Title

[All] - [Child 1] - [Child 2]

[the loop]

Only the content and category title would be displayed if there are no child categories.

I'm aware I could do this by making specific page templates, but I want to keep everything lean and dynamic, so my client can change the categories as he pleases.

Thank you guys in advance!

goloops on "Display the first image in posts from the same category on a page with paginatio"

$
0
0

HI Guys,

I am not a programmer and I want to have this function in my wordpress site very badly. Something similar to this link here: http://www.a-li.com.cn/download/qq_emotion/

I have been searching for the solution for a long time and no result.

I tried the "DISPLAY POST SHORT-CODE" plugin but it doesn't give me a pagination and also have a limit of 300 posts.

Can anyone help me on this? Thank you so MUCH!!!!!!

rommelxcastro on "use wp_editor on category description"

$
0
0

hi, i need to modify the description textarea with the wp_description() i been looking on internet but i can't find a solution
i was thinking maybe remove the default textarea and just a create a new one, but again idk how to remove it

thanks!

chillrobot on "Implicit file upload size limit of 100MB?"

$
0
0

My hosting company, Dreamhost.com, walked me through how to increase the file upload size limit because the methods described here weren't working. Their method involves creating a phprc file:

http://wiki.dreamhost.com/Php.ini#phprc

http://wiki.dreamhost.com/Php.ini#Increasing_the_Filesize_Upload_Limit

Now WP 3.6 shows my upload limit as 360MB (I made it that large because I have hour-long videos). Yet only uploads smaller than 100MB succeed. Is there an implicit processing limit in WP 3.6 on upload size?

hovida on "wp-cron.php - wp_mail not working"

$
0
0

Hey guys,

i wrote a simple Plugin for sending mails over the cronjob.
WP_CRON is disabled and outsourced to crontabs on the server, for example:

* * * * * /usr/bin/php5 -f /homepages/23/d471228603/htdocs/wp-cron.php >> /homepages/23/d471228603/htdocs/cron.log

Here is the source: http://pastebin.com/tA4JgEBC

Description:
For testing, i use the direct-link to wp-cron on my Browser (for example: http://domain.com/wp-cron.php)

When i use the wp_mail function first time, i become an PHP Error:

Fatal error: Cannot redeclare class phpmailerException in /homepages/23/d471228603/htdocs/wp-includes/class-phpmailer.php on line 2825

After reloading the page will be blank/white. The printing of display_name and email of the users will be not printed.

Can anyone tell me why this does not work?

I would like to use WordPress-own functions and needs wp_mail here.

theleafszone on "integrate blueimp ajax chat with wordpress"

$
0
0

Has anybody integrated the blueimp ajax chat with wordpress (login to wordpress, automtically logged into chat). Seems like it should be fairly straight forward but not sure where to start

greathug2u on "Save user input data from settings api"

$
0
0

I'm writing a plugin that's using the settings api. Can someone please tell me how I could save the data that users enter into the settings fields and use that in a function after users hit the "Save Changes" button on the settings page? I'm just really stuck right now. Thank you so much.


rohantendolkar on "Help Needed with Menu based on tag and catagory Intesection"

$
0
0

My website have categories on which i have modified so that i can put menu and images on header. i want to provide with menu (of tags) which will refine result for that category and tag. menu( based on tags) will not be used anywhere else
references used before
1. tdo tag fixes
thank you

jzmwebdevelopment on "Homepage Block using Woocommerce"

$
0
0

I am trying to work out a way to be able to get Woocommerce products displaying like http://d.pr/i/fFjs would it be best to use a custom post type?

I really need the image a title and a short description for the homepage - will be changed regularly.

KW923 on "Security Question: SQL Injections"

$
0
0

Hi,

I have heard about the importance of properly sanitizing or preparing SQL Queries while developing plugins. I'm just not sure if I understand how to do it. I've created my query which takes the page titles and flushes them from the database. The plugin is supposed to allow the user to create new page titles in a custom form by using wp_insert_post.

How do I sanitize/validate the page title input that will be sent to the database?

global $wpdb;
	$args['menu_order'] = $wpdb->get_var("SELECT MAX(menu_order)+1 AS menu_order FROM {$wpdb->posts} WHERE post_type='page'");
	$wpdb->flush();

Hube2 on "Show a specific page instead of 404"

$
0
0

This may be an odd question, but here goes.

Lets say that I have a page that has a URL that is:

http://www.mysite.com/logical/url/sturcture/

but we want to keep that url from an older version of the site because this URL ranks well in google and we don't want to take the hit from 301 redirecting the old url to the new url.

The URL might be:
http://www.mysite.com/comlpetely/illogical/url/structure/page/

So, when the old page url is requested we don't want to show a 404, instead we want to show the content from the page where it has been moved to.

Possible? How?

rafaht on "Problems with tags display"

$
0
0

Hi,
I've modified a theme to my like. I created a CSS class to the post tags and searching, I found this: http://codex.wordpress.org/Function_Reference/get_tags. I've adapted this:

<?php
					$tags = get_the_tags();
					foreach ($tags as $tag){
						$tag_link = get_tag_link($tag->term_id);
						$html .= "<a href=\"{$tag_link}\" title=\"{$tag->name} Tag\" class=\"tags\">";
						$html .= "{$tag->name}</a>";
					}
				?>

On the first post, the tags is correct. But on the second post or more (I display two posts per page), the tags of first post is repeated with the tags of second posts.
How can I fix this?
Thanks so much!

Viewing all 8245 articles
Browse latest View live




Latest Images