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

txxxax on "user_has_cap filter allows edit but will not allow save"

$
0
0

Problem

I'm working on a website where we need to be able to put a username in the custom field of a custom post type, and allow the user specified to make changes to that post and only that post. I thought user_has_cap would be the filter hook to use but weirdly it doesn't seem to be allowing a user to update the post.

The user can see the edit screen for the post and only that post which implies my filter is working correctly, but clicking update gives the error You are not allowed to edit posts as this user. which contradicts this.

The post type has capability_type => post so I feel that shouldn't be the issue.

Code

function event_cap_filter($all, $cap, $args) {
        // if not requesting edit post then return caps
        if('edit_post' != $args[0]) return $all;
        // if user can already edit others posts then return caps
        if($all['edit_others_posts']) return $all;

        // if user is the post author then return caps
        $post = get_post($args[2]);
        if($args[1] == $post->post_author) return $all;

        // query to find user in custom field
        // and therefore if they are allowed to edit this post

        if($can_edit) {
            foreach($cap as $c) {
                $all[$c] = true;
            }
        }

        return $all;
    }
    add_filter('user_has_cap', 'event_cap_filter', 10, 3);

Question

If my user can edit the post where he is specified in the custom field I check for, why can he not save his changes? Am I overlooking something?


LebCit on "JavaScript loading but not working !"

$
0
0

Hello everyone,

After three days, war coding, to make a js file run, i have only this great place to ask, hoping that i'll find someone with good experience in js into WP to tell me what's wrong and how should i proceed to make it work.

First things first, i'm trying to implement a menu in a personal parent theme (i've tried to implement it for testing in underscores and in Twenty Thirteen).

1- After seting up the markup of my menu in a separate php file in the root of the theme folder (e.g. nav-top.php)

<ul id="gn-menu" class="gn-menu-main">
    <li class="gn-trigger">
        <a class="gn-icon gn-icon-menu"><span>Menu</span></a>
        <nav class="gn-menu-wrapper">
			<div class="gn-scroller">
				<ul class="gn-menu">
					<li class="gn-search-item">
						<input placeholder="Search" type="search" class="gn-search">
						<a class="gn-icon gn-icon-search"><span><?php get_search_form(); ?></span></a>
					</li>
					<li>
						<a class="gn-icon gn-icon-download">Downloads</a>
						<ul class="gn-submenu">
							<li><a class="gn-icon gn-icon-illustrator">Vector Illustrations</a></li>
							<li><a class="gn-icon gn-icon-photoshop">Photoshop files</a></li>
						</ul>
					</li>
				</ul>
			</div><!-- /gn-scroller -->
        </nav>
    </li>
    <li><a href="http://tympanus.net/codrops">Codrops</a></li>
    <li><!-- ... --></li>
    <!-- ... -->
</ul>

I left the markup like this for testing. Working fine under an html file !

2- I tried just to wp_enqueue_script the two necessary files for the menu and wp_enqueue_style in fuctions.php, without registering in a function !
Then i used <?php get_template_part('nav', 'top'); ?> at the top of the header.php before the title of the site.
The css worked just fine, i could see the menu bar, but the js files where not working since the sidebar panel of the menu was not opening.

3- I tried to register and enqueue the scripts and the style in a function in functions.php, but i had the same result as before, the css was here and the js files where not working.

4- I tried to integrate the navigation directly in header.php after
a- just enqueue the scripts and the style
b- register and enqueue the scripts and the style in a function
BUT, the result was always the same css working, js not working.

In the title i type "JavaScript loading..." i can tell because i saw the code source of my page and they where here like the style.

Oh, just for more info, when i enqueue or register/enqueue the js files, i've tried to put them in the footer than in the header (true, false), than i tried to call jquery in the array( array('jquery') ),
nothing seems to work !

Finally, why three days for an hour of testing ?
Hell, because i've tried a lot of menu and the result was the same for all of them : css working, js loading but not working !
And i made a lot lot lot of reading :)

So, the problem is in my experience with js in WP, it's my fault :)
I hope that someone will help me to finally pass this step and go further in js into WP.

Thanks a lot in advance for your help :)

Pete on "Display a specific level of a category tree"

$
0
0

I'm trying to find a way to display a specific category level of a post.

For example. I have a post with a hierarchical category tree structure like below...

Parent cat
Child cat A
Child cat B
Child cat C

I'm looking for a nifty piece code I can use within the loop that will allow me to display any of the category levels, not all the levels.

Clear as mud? :)

Thanks heaps - Pete

crdipu on "How to add custom status to quick edit"

$
0
0

Hi All,
I have added some custom post status to WordPress, I can able display in New and Edit interfaces of POST. I would like to display those to quick edit too. Also I need to apply some condition to display custom status, I will explain with example.

Example : I have created status below
1)status-1
2)status-2

"status-1" appear in the drop-down box only if current post status is 'pending'.

"status-2" appear in the drop-down box only if current post status is 'status-1'.

Thanks in advance.

Andy Mercer on "Call Media Editor Gallery Page Directly"

$
0
0

I'm calling the WP 3.5 media uploader from a metabox, and have gotten it working to select single or multiple images. What I'd really like to do is call it to the Gallery's page instead though, so that I can then click through to the sorting page, and be able to sort the images.

My current code is this:

jQuery('#fg_select').on('click', function(event){

		event.preventDefault();

		// If the media frame already exists, reopen it.
		if ( file_frame ) {
			file_frame.open();
			return;
		}

		// Create the media frame.
		file_frame = wp.media.frame = wp.media({
			title: "Select Images For Gallery",
			button: {text: "Select",},
			library : { type : 'image'},
			multiple: true // Set to true to allow multiple files to be selected
		});

		file_frame.on('open', function() {
			var selection = file_frame.state().get('selection');
			ids = jQuery('#fg_metadata').val().split(',');
			ids.forEach(function(id) {
				attachment = wp.media.attachment(id);
				attachment.fetch();
				selection.add( attachment ? [ attachment ] : [] );
			});
		});

		file_frame.on('ready', function() {
			// Here we can add a custom class to our media modal.
			// .media-modal doesn't exists before the frame is
			// completly initialised.
			$( '.media-modal' ).addClass( 'no-sidebar' );
		});

		// When an image is selected, run a callback.
		file_frame.on('select', function() {
			var imageIDArray = [];
			var imageHTML = '';
			var metadataString = '';
			images = file_frame.state().get('selection');
			images.each(function(image) {
				imageIDArray.push(image.attributes.id);
				imageHTML += '
<li><button></button><img id="'+image.attributes.id+'" src="'+image.attributes.url+'"></li>
';
			});
			metadataString = imageIDArray.join(",");
			if(metadataString){
				jQuery("#fg_metadata").val(metadataString);
				jQuery("#featuredgallerydiv ul").html(imageHTML);
				jQuery('#fg_select').text('Edit Selection');
				jQuery('#fg_removeall').addClass('visible');
			}
		});

		// Finally, open the modal
		file_frame.open();

	});

[Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

Any ideas?

BRG Web on "WP_Query Taxonomy Parameters"

$
0
0

I am trying to query a custom post type but it is not working.

I am using Elegant Theme's Nexus with All in One Event Calendar.

The theme has a featured slider in the home page that gets the recent posts from a regular post category and displays it as slides. I want it to get the recent events from AIO Event Calendar, that are saved as a specific post type and display as slides.

The original code for the featured slider in the homepage is:

<?php
	$i = 1;

	$featured_args = array(
		'posts_per_page' => is_category() ? 2 : 4,
		'cat'            => (int) get_catId( ( is_category() ? get_query_var( 'cat' ) : et_get_option( 'nexus_feat_posts_cat' ) ) ),
	);

	if ( is_category() ) {
		$sticky_posts = get_option( 'sticky_posts' );

		if ( is_array( $sticky_posts ) ) {
			$featured_args['post__in'] = $sticky_posts;
		} else {
			$featured_args['orderby'] = 'rand';
		}
	}

	$featured_query = new WP_Query( apply_filters( 'et_featured_post_args', $featured_args ) );
?>

I changed the $featured_args like this:

<?php
	$i = 1;

	$featured_args = array(
		'posts_per_page' => is_category() ? 2 : 4,
		/*'cat'            => (int) get_catId( ( is_category() ? get_query_var( 'cat' ) : et_get_option( 'nexus_feat_posts_cat' ) ) ),*/
		'post_type' => 'AI1EC_POST_TYPE'
	);

	if ( is_category() ) {
		$sticky_posts = get_option( 'sticky_posts' );

		if ( is_array( $sticky_posts ) ) {
			$featured_args['post__in'] = $sticky_posts;
		} else {
			$featured_args['orderby'] = 'rand';
		}
	}

	$featured_query = new WP_Query($featured_args ) );
?>

But nothing is showing in the slider anymore.

What am I doing wrong?

The nexus theme: http://www.elegantthemes.com/demo/?theme=Nexus
All in One Event Calendar: http://wordpress.org/plugins/all-in-one-event-calendar/

The site that I am trying to do this: http://brgweb.com.br/ibmundial

Thanks!

knoppys on "Plugin Code does nto list all my posts."

$
0
0

Good morning

I created my own plugin. Just something for listing all sub categories including posts and permalinks of a given parent category.

Problem is it only seems to be outputting 5 posts per categpry.

I dont think theres anything in the code that limits the output to 5 posts, can someone just put my mind at rest for me and tell me im right.

public function widget( $args, $instance ) {
		if( $c = get_category(@$instance['category_id']) ){

			foreach(get_categories(array(
				"child_of"	=> $c->cat_ID

			)) as $childCat){

				echo '<div class="container">';
				echo('<h2 class="widgettitle">'.$childCat->name.'</h2>');
				echo '<ul>';

				foreach( get_posts('cat='.$childCat->term_id) as $p) {
					echo('
						<li>
							<a href="'.get_permalink($p->ID).'">'.$p->post_title.'</a>
						</li>
					');
				}
				echo '</ul>';
				echo "</div>";

			}
		}

	}

maxarch3 on "Change image size large in p attachment display settings"

$
0
0

is it posible to change in my post add media
in image attachment details

size:
Medium - 300 x 200
large - 1024 x 682

i will like to have something in between
like 700 x ?

do you know where i can adjust that


hektorjg on "Help with comment form popup. Close after comment"

$
0
0

Hi all!
I need help to solve this headache.
I have a site where you comment in a Wall where everybody comments, but you can comment wherever. So my solution to do it is a pop-up window with javascript that shows a comment form.

When you comment then you are redirected to the wall-comment#n
My idea is to close it, because you can do it with window.close() but I have searched for hours and Im stuck.

I need to know where I have to put the function to close just after the comment is done.
Also I tought about a redirect to an url that autoclose after x secs the window but I dont know how to do it also.

Thanks in advance

MatiasLN on "jQuery menu"

$
0
0

Hi!

I want to create a menu system based on this: http://boston.html.themeforest.createit.pl/index-slogan.html#MainHeader

The idea is to have the menu fixed at the bottom and on the top on the other pages with the transition from home to any of the other menu items. I do not want the other menu items in the menu to have the same scrolling effect though. They should remain static when going from item to item and the menu should scroll to the bottom when returning to the home page.

I figured jQuery would be the best option to do this, but I have no idea how to achieve this solution. Does anyone have any pointers?

[Moderator Note: Please ensure that you are embedding links correctly in your posts.]

rec19 on "Move admin menu names"

$
0
0

Hello

I have plugins installed that show up as a parent menu on the left admin menu that I would like to put in the Settings tab.

Can anyone give me an example, for instance, how you would move the comments tab in the settings tab so it says:
General
Writing
Reading
Discussion
Media
Permalinks
Comments

Maybe I can work out how to move things about from that example.

dveat on "Custom columns shown in post overview"

$
0
0

Hi all,

I have an issue that I can't seem to resolve. A friend is running a WordPress site in combination with Shopperpress as a shop. He had that developped a couple of years ago, but isn't satisfied with the result, so I am trying to fix things for him.

Anyway, the shop now works well, however there are thousands of products (posts) in the shop and edditting can be a pain. Therefore we'd like to add extra columns to the overview. The data for those columns are in the MySQL table wp_posts, just like most other columndata such as posttitle. The previous developer succeeded there partially. However:

1. I'd like to add more columns (also in the same table as wp_posts) e.g. SKU

2. When I click filter, all extra columns get lost and I get the standard overview. I would like to add the custom columns there as well.

I've searched a long time, but I simply can't find the files to edit. I assume there is some file generating both tables / columns and I guess there is some class / function fetching the results from the query. But I am lost.

Could anyone direct me to the files to get started?

Thanks in advance.

Linesh Jose on "How remove description and slug fields from taxonomy"

lemonthirst on "displaying the number of active visitors on a single post"

$
0
0

Hi, i've searched/tested most of the plugins available in the repository for a plugin that can count how many users are online on a single post.

I want to display the number of active users reading that post(just that url not the whole site)
Ex. Hello World (2 active visitors)
Hello World 2 (5 active visitors)
and so on based on the number of visitors

Is there a plugin like this?

Jpetracca on "Trouble with my loop: how to get next posts and previous posts working"

$
0
0

I'm having trouble getting the loop to show next and previous posts on a page.php.
The loop is supposed to show 10 posts (I set it down to 2 to try it out..) and then the next/previous posts link on the bottom... leading to the older posts if there are more than 10, etc...

site/page: tobylavigne.com/guidnace

<div class="col-md-8">
                     <?php
  $my_query = new WP_Query( array( 'numberposts' => 5,) );
  if( $my_query->have_posts() ):
     while( $my_query->have_posts() ):
        $my_query->the_post(); ?>

            <div id="fademobile" class="col-md-5" style="margin-top:30px"><div><?php if ( has_post_thumbnail()) : ?>
   <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
   <?php the_post_thumbnail( array(999999, 250)); ?>
   </a>
 <?php endif; ?></div></div>
            <div id="onlymobile" class="col-md-5" style="margin-top:30px"><div><?php if ( has_post_thumbnail()) : ?>
   <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
   <?php the_post_thumbnail( array(220, 9999999)); ?>
   </a>
 <?php endif; ?></div></div>
            <div class="col-md-7 block1 blogcontent">
            <div class="col-md-3 col-md-offset-2">
                    <div class="blogposttitle"><h3 class="text-center" style="margin-top:1px; color:#fff; font-size:1.3em; padding-top:2px"><?php the_time('F'); ?></h3><h4 class="text-center" style=" color:#fff; font-size:1em"><?php the_time('j, Y'); ?></h4>
                        </div>
                    </div>
                    <div><br><br><br>
                        <a href="<?php the_permalink(); ?>"><h4 class="text-center"><? the_title(); ?></h4></a>
                        <p><?php the_excerpt(); ?></p>

                    <div class="fb-share-button" data-href="<?php the_permalink(); ?>" data-type="button" style="top:-5px"></div>
                        <a href="http://twitter.com/share" class="twitter-share-button" data-url="<?php echo get_permalink(); ?>" data-count="none" data-text="Check out <?php the_title(); ?>" data-via="TobyLaVigne" >Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
                        <script src="//platform.linkedin.com/in.js" type="text/javascript"  >
 lang: en_US
</script>
<script type="IN/Share" data-url="<?php the_permalink(); ?>"></script>

                    </div>

                </div>
                <?php endwhile; ?>
                <div class="navigation"><p><?php posts_nav_link(); ?></p></div>

                    <?php else : ?>
                    <h4>The Stuff You're Looking For Is Not Here!</h4>
                  <?php endif; ?>
</div>

Please Help - I'm up for anything that works!


whiteorange39 on "Custom Taxonomy and Category Problems"

$
0
0

Hello!

Bit green around the edges in php, but I've been currently tasked with fixing my companies old website design (not coded by me) and its been a nightmare.

I have one problem that is particularly tough for me to tackle and that is creating a product page using categories and a custom taxonomy. This was all previously set up but currently looks a bit odd as it displays every product in every category without listing it according to the category hierarchy set up in the front end.

For example:

The page displays as such-

Wardrobes
-Item A
-Item B
-Item C
- etc.

Modern
-Item A
-Item B
-Item C
- etc.

Classic
-Item A
-Item B
-Item C
- etc.

I'd like it list as such:

Wardrobes
-Modern
--Item A
--Item B
--Item C
-- etc.
-Classic
--Item A
--Item B
--Item C
-- etc.

This is how it is set up through the categories in the front end, but I cant quite understand how I'm calling this up wrong in my php.

This is what I have:

<div id="primary" class="site-content">
		<div id="content" role="main">
			<?php $terms = get_terms('productcat');

			    $count = count($terms);
				if ($count > 0) {
			     foreach ( $terms as $term) {?>
				<div class="products-grid">

				<h3><?php echo $term->name; ?></h3>
					<div class="wrap">
			        <?php $loop = new WP_Query(array('productcat' => $term->slug, 'posts_per_page' => 999) );
							$counter = 999;
			            while ( $loop->have_posts() ) :?>

			 			<?php $loop->the_post(); ?>
			            <div class="product">

Any pointers would really help. Thanks.

crdipu on "post_row_actions filter is not working while update post using quick edit"

$
0
0

Hi All,
I have created two links using post_row_actions, it was displaying fine when page loads. But the links will get disappear after update post using quick-edit. Is it a bug from WordPress or did I miss something. My code will look like given below.

add_filter('post_row_actions', 'add_new_link', 10, 2);

public function add_new_link($actions, $page_object)
{
    $actions['new_action'] = '<a href="'.admin_url().'post.php?id='.$page_object->ID.'&action=new-action">New Action</a>';
}

deg29 on "Post Loop widget issue"

$
0
0

I am using the Vantage theme and until today had the Post Loop widget on my front page in the "grid" format and filtering one category only (news). I'm not sure if this is related or not but today I edited all my posts using post builder and then I noticed that the category filter/query was no longer working and all the posts were showing up in the loop, one of the posts was listed twice. When I changed the Post Loop to display in "carousel" format the filter works fine, if I change it back to the "grid" it stops filtering again. My plugins are all up to date. Any idea why this is happening?

tnoguchi on "Display Groups of Custom Posts by their Custom Taxonomy Term"

$
0
0

Hi,

I'm trying to output a portfolio page composed of sections of CPT post thumbnails organized by their custom taxonomy term slugs.

While it's easy for me to output the terms associated with the custom taxonomy, I'm not sure how one nests a custom query to retrieve the posts associated with each term in the foreach loop.

I've included the code that I've worked on; but this is a bit beyond my PHP skill level.

//retrieves an array of the terms as slugs
$terms = get_terms('tn_cstm_work_taxonomy', 'fields=names');

// This returns all posts in the custom taxonomy, rather than posts for each term
    $projectsArgs = array(
            'tax_query' => array(array(
                    'taxonomy' => 'tn_cstm_work_taxonomy',
                    'field' => 'slug',
                    'terms' => $terms
            ))
          );

        foreach ( $terms as $term ) {        ?>
      <div class="row">
//Populates the the section and titles with the slug; needed for navigation
        <section id="<?php echo $term; ?>" class="large-12 columns" data-magellan-destination='<?php echo $term; ?>'>
           <h3><?php echo $term; ?></h3>
           <ul class="large-block-grid-4 small-block-grid-2">

            <?php
            $projects = new WP_Query($slug); while ($projects->have_posts()) : $projects->the_post(); ?>

              <li>
                  <?php
                        //outputs thumbnails for gallery
                         if(function_exists('tn_cstm_work_thumb')) {
                          tn_cstm_work_thumb();
                    ?>
              </li>

            <?php endwhile; wp_reset_postdata(); ?>

          </ul>
        </section>
      </div><!-- .row -->     

<?php } ?>

This is obviously incorrect, the custom query will just pull all of the posts associated with any term in the custom taxonomy. Is there a way to output just the posts associated with each term?

Any hints, or help would be appreciated.

Thanks!

damiroquai on "Is this corect syntax for adding java script to plugin?"

$
0
0

I wanna create plugin wich will place google analytics code or any other js code in footer.
Can I do it like this?

<?php
   /*
    Plugin Name: myplugin
    Plugin URI:
    */

function myganalytics() {
?>
<script>
// my google analytics script
</script>
<?php
}
   add_action('wp_footer', 'myganalytics');
?>
Viewing all 8245 articles
Browse latest View live




Latest Images