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

vice07 on "Add custom page to admin menu visible only to admins"

0
0

Hello,

I want to build a custom survey and display his results in the wordpress backend.

I added a new admin menu item like this:

add_action( 'admin_menu', 'register_survey' );

function register_survey(){
    add_menu_page( 'Survey', 'Survey', 'manage_options', '/survey/survey-admin.php', '', '/wp-admin/survey/icon.png', 30 );
}

The menu item named Survey appears in the backend. When i click it goes to /wp-admin/survey/survey-admin.php displaying my php file contents, but the dashboard dissapears with the sidebar menus... This page is also visible to everyone and wordpress function is_admin doesn't work anymore in this page...

What's the correct solution? I just want to display my custom page on wordpress backend and be able to check if the user is admin or not. Do i need to create a plugin for this?

Thanks!


fjpalawan on "Determine wether the shortcode was called in text widget or in content"

0
0

Hi Guys,

I am using a shortcode api and I added a shortcode using add_shortcode.

The shortcode is added to a post and to a text widget. But I want the shortcode to work only when viewing the post content and not in the post list.

Using is_single is my first solution but the text widget shortcode didnt show up also.

Is there a way for me to determine wether the shortcode hook was called in post content or in a text widget?

Thanks
Feljun

Archaic Radio on "Randomize Custom Fields from Posts"

0
0

Hi Ya'll,

I'm having a hard time getting my page to display a random list of custom fields from a specific post. Below is my code.

<?php
$digvaud_id = 1833;
$digvaud_post = get_post($args,$digvaud_id);
?>

<?php $itemnamefeat = get_post_meta ($digvaud_post->ID, 'wpcf-playlist-song-title', false); ?>
<?php $itemmp3feat = get_post_meta ($digvaud_post->ID, 'wpcf-playlist-song-mp3', false); ?>
<h3 class="playlist-title">Playlist</h3>
<ul>
<?php foreach (array_combine($itemnamefeat, $itemmp3feat) as $itemnamefeat => $itemmp3feat){

$playlist_combinedfeat = '<li><a href="' .$itemmp3feat. '">' .$itemnamefeat. '</a></li>';

echo apply_filters('the_content', $playlist_combinedfeat);
} ?>
</ul>

The result is currently a list of custom field values from post #1833. The only issue I'm having is randomizing the list. Thanks for any help.

Daniel858 on "Help me get rid of this footer"

0
0

Hi! I've found two themes that suit my website, but they both have an encoded footer. For the first one, changing it was easy enough. I decrypted footer.php and made an edit in the codes.

However the second theme (which looks a lot nicer than the first!) has a different security. Footer.php is intact but here, the first code lines from functions.php are encrypted. I ran these trough the decrypter and it worked, it just gives me the regular code used by the developer. Here's the output, i think the footer tampering code that i wanna edit is in the last couple of lines:

[ 835 lines of code moderated, that's just way too much. For that many lines of code please use pastebin.com instead. ]

So now you're wondering, if you got all that code, whats to prevent you from editing it. Well, when i try to replace the nonsense encrypted bits with the real codelines that i just posted, my homepage will say:

"Parse error: syntax error, unexpected $end in I:\local wordpress backup\iwpserver\htdocs\wordpress\wp-content\themes\CasinoThemes\OnlineCasinoTemplate935\functions.php on line 1096"

I'm a newbie with wordpress so some help would be rly appreciated! Thnx!

A31 on "Nested Select Menu"

0
0

Hi,
I am really struggling to get a second dropdown / select box to be automatically populated and I hope someone here can help me find my mistake.

Before moving to Wordpress, I have been using the example by W3Schools but now in wordpress, I can't seem to get it working.

My Code is as follows:

<script type="text/javascript">
function showUser(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","Fin_GetAllocation.php?q="+str,true);
xmlhttp.send();
}
</script>
<form>
	<select name="sel_CostCentre" id="sel_CostCentre" onchange="showUser(this.value)">
		<option value=0>Please Select Cost Centre: <?php echo $CostCentreDescriptionOptions; ?>
	</select>
    <select name="Sel" id="txtHint"></select>
</form>

then the code in the file "Fin_GetAllocation.php" is as follows:

<?php
	global $wpdb;

	$q=$_GET["q"];

	$SQL_Query01 = ("SELECT * FROM wp_allocations_tbl WHERE CostCentreDescription = '$q'");
	$SQL_Results01 = $wpdb->get_results($SQL_Query01);

	foreach($SQL_Results01 as $myResult01)
		{
			$AccountDescription = $myResult01->AccountDescription; //Field in DB
			$AccountDescriptionOptions.="<option value='$AccountDescription'>" . $AccountDescription . "</option>";
		}

So my first dropdown / select box works perfectly, but I can't seem to get the second box to populate.

Can you please help?

clickmac on "Adding Drag and Drop for user uploads"

0
0

if their is any such plugin, i don't think it would be for free

hannibal775 on "redirect to a random url stored in an array"

0
0

Hi. I'm trying to run a snippet of php in a page on my site. I am new to php, but I have enough of an understanding of programming languages to do simple things. I have figured out how to execute a php code snippet in a page and have been successful (as in adding the current date and time) but I can't seem to get the following code to work. I am trying to do a random redirect to a group of URLs stored in an array. It works when I test the code outside of Wordpress, but I'm not sure how to get it to work inside a page. Ideally, I'd prefer to have a button execute the snippet, but I would settle for it happening automatically what the page loads. Can anybody give me some guidance on this matter? It would be greatly appreciated. I am building on a local network at the moment, so I do not have a link to the site.

This is what I've got:

<?php $aff_array = array("URL1", "URL2","URL3");
    header("Location: ".$aff_array[rand(0,2)]); exit(); ?>

Thanks in advance!!

kutchbhi on "Allowing anonymous users to post to custom post_type"

0
0

I want anonymous users to be able to submit via a form to a custom post_type that I created i.e whatever gets posted is saved as a post of a custom post_type.

Right now I have a shortcode that outputs a simple form and I am not sure about -
a) what should go into the form's action attribute
b) where exactly do I handle the response ? Do I have to create some sort of hook and then handle it there ? I am so not sure..

Thanks


dakta on "Cunstom Taxonomy Archives with Custom Post Types"

0
0

I have a custom post type with a custom taxonomy. The custom taxonomy is only registered with that custom post type.

I have moved the posts index (the home page) to http://example.com/blog/ by setting the "Posts page" in Settings->Reading and prepending "/blog/" to the "Custom Structure" on Settings->Permalinks. This works well for blog posts, categories, and tags. I get http://example.com/blog/%year%/%monthnum%/%postname%/ permalinks, which I want, and my custom post type gets http://example.com/custom-type/%postname%/.

However, there is a problem: I want to have custom taxonomy archive at http://example.com/custom-type/taxonomy-name/%taxonomy%/ but I can't figure it out. My Custom Taxonomy gets permalinks and a functional archive page at http://example.com/taxonomy-name/%taxonomy%/. But if I change slug in the custom taxonomy rewrite parameters to custom-type/taxonomy-name, I cannot access the taxonomy at either http://example.com/custom-type/taxonomy-name/%taxonomy%/ or http://example.com/taxonomy-name/%taxonomy%/

And yes, I've flushed my permalinks settings.

Is this the proper way to do this?

AJD on "Redirect Wordpress Login and Forgot password running from subdirectory."

0
0

I am trying to redirect the Wordpress login away from the standard page so it doesn't break the appearance of the site. I have read and tried many versions, but none seem to work for me.

I found the following code on another forum, but it is not working on my site. I will be adding the code via a plugin, so the redirection will look and work ok with any theme.

I am running Wordpress in a sub-directory, but without its own domain name, so it is at mysite.com/wp/ - both for site address and WP address.

I wonder if this location is causing the following code not to work.

function redirect_login_page(){

 // Store for checking if this page equals wp-login.php
 $page_viewed = basename($_SERVER['REQUEST_URI']);

 // Where we want them to go
 $login_page  = site_url();

 // Two things happen here, we make sure we are on the login page
 // and we also make sure that the request isn't coming from a form
 // this ensures that our scripts & users can still log in and out.
 if( $page_viewed == "wp-login.php" && $_SERVER['REQUEST_METHOD'] == 'GET') {

  // And away they go...
  wp_redirect($login_page);
  exit();

 }
}

add_action('init','redirect_login_page');

Thanks

freezix on "Adding an option when hoovering a user in user.php"

0
0

Hello,

I think my question is quite simple, but I couldn't find an answer throught the documentation.

I just need to know wich hook I should use to modify the wp-admin/user.php to add an option when I hoover a name.

Thanks

5ngua on "Simple custom login plugin"

0
0

Hi there,

First of all, sorry for my bad WP plugin knowledge. I just want to create a simple custom login following this guide because I do not want to add the code whenever the theme is updated. This is the first time I try to create a WP plugin. I already created a file called plugin.php with it's header. And I do not know what to do next.
Could you tell me what code I have to add to plugin.php to make it work like described in the codex document?

Many thanks,

hombero on "media_handle_sideload() not working, halts execution"

0
0

Hello,

I am attempting to write a PHP script which downloads an off-site image from url, saves it to a permanent directory, and then attach it to a post as a thumbnail. The script successfully saves the temp file, and then saves a permanent file in the wp-content/uploads/... directory, but the call to media_handle_sideload() halts execution.

This is what I have so far:

function wp_sideload_image($post_id, $file, $desc = null)
{
	if ( ! empty($file) ) {
		// Download file to temp location
		$tmp = download_url( $file );
		// Set variables for storage
		// fix file filename for query strings
		preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $file, $matches);
		$file_array['name'] = basename($matches[0]);
		$file_array['tmp_name'] = $tmp;

		// If error storing temporarily, unlink
		if ( is_wp_error( $tmp ) ) {
			@unlink($file_array['tmp_name']);
			$file_array['tmp_name'] ='';
		}

		// do the validation and storage stuff
		if ($debug) { echo 'File array: <br />';
			var_dump($file_array);
			echo 'Post id: <br />';
			echo $post_id;
			echo 'Desc: <br />';
			echo $desc;
		}
// Execution fails on next line
		$id = media_handle_sideload( $file_array, $post_id, $desc );

		// If error storing permanently, unlink
		if ( is_wp_error($id) ) {@unlink($file_array['tmp_name']);}
		add_post_meta($post_id, '_thumbnail_id', $id, true);
	}
}

The parameters being passed are:
$post_id -> an integer representing the post to which to attach
$file -> the url to the remote file
$desc (optional) -> the description of the attachment

I have confirmed that the variables are valid when entering the function, though the script halts when media_handle_sideload() is called.

Any insight and/or help with this issue will be extremely appreciated, thank you!

stephta6 on "Anchor Tags Injected Into Code"

0
0

Suddenly I noticed blank tags in my code in Firebug. They are NOT in the WordPress templates. They are showing up in Firebug only but causing the content to be wrapped as a link that goes nowhere. These mysterious links do not show up when you "View Source."

Also the only pages it seems to be affecting is a new page I created today: http://putterswild.com/test-party-booking/

and the homepage top left content: http://putterswild.com/

Is this a hack?

In Chrome it affects the entire page and it Firefox it only effects the left side content.

I have never seen anything like this.

Ray on "Apollo Theme Header Ad option not working"

0
0

I've got the apollo theme for my wordpress.
There's an option to put a header ad without fumbling with css.
However, when I tried to put my goggle adsense code nothing happens neither for Amazon ads. The only thing that works on this header ad option is if I type a message or imgs through html work.

This is what shows for the header ad option in my theme
style.css
#header-ad { float: right; displat: inline-block; >

This is what it shows on the
header.php

<?php
            // Show header ad as defined in the admin panel
            if( of_get_option('header_ad') !== '' ) {
                echo '<div class="col span_8"><div id="header-ad">'. do_shortcode( of_get_option('header_ad') ).'</div></div>';
            } ?>
    	</div><!-- /header -->

Please help, I want it to be able to work.


mariz_p on "add user notification in bbpress moderation"

0
0

I have modified the bbpress moderation plugin since I'm not getting any response from it's author.
Please see this link: http://pastebin.com/EMmZK1Zt
for my code.

Now, my problem is I cannot make it work. I have checked the structure of wp mail and I know I'm in the right path. It's just why it's still not working.

I hope someone here can help me as I've been struggling on this for months now.

Thanks and have a great day ahead.

Best regards,
Mariz

r1kay on "Problem with constructing the single post lay-out through funtions.php"

0
0

I'm currently working with this wordpress theme and just created this function that adds my ads, share buttons and comment box to my post pages. However, i have some review posts on my site (you know, a rating system with stars or percentages) and this theme inserts this review box below the content of the post. So the review box will apear below the comment box and share buttons that i inserted with this function. I tried to insert the review box code in my function. Here's my function.php code:

function content_injector($content) {
    global $wp_query;
    $postid = $wp_query->post->ID;
    if (is_single((get_post_meta($postid, 'top_ad', true) != 'off' )))  {
        $top_ad = do_shortcode('[td_ad_box spot_name="Ad spot -- topad"]');
        }
    if (is_single((get_post_meta($postid, 'bottom_ad', true) != 'off' ))) {
    $bottom_ad = do_shortcode('[td_ad_box spot_name="Ad spot -- topad"]');
        }
    if (is_single()) {
    $review = //WHAT CODE DO I ADD HERE?
    $custom_share = '<div id="title-deel"><h4 class="block-title"><span>DEEL</span></h4></div>' . do_shortcode('[ssba]');
    $facebook_comments = '<div id="title-reageer"><h4 class="block-title"><span>REAGEER</span></h4></div>' . '<div class="fb-comments" data-href="' . get_permalink() . '" data-colorscheme="light" data-numposts="5" data-mobile="false" data-width="700"></div>';
        }
$content = $top_ad . $content . $review . $bottom_ad . $custom_share . $facebook_comments;
return $content;
}
add_filter('the_content', 'content_injector');

The post pages are constructed with this code located in a file called td_module_1.php (i left out the upper part of the file because it's not relevant):

} else {
            $buffy .= $this->get_content();
        }

        $buffy .= '<footer class="clearfix">';
            $buffy .= $this->get_post_pagination();
            $buffy .= $this->get_review();
            $buffy .= $this->get_the_tags();
            $buffy .= $this->get_source_and_via();
            $buffy .= $this->get_social_sharing();
            $buffy .= $this->get_author_box();
            $buffy .= $this->get_next_prev_posts();
        $buffy .= '</footer>';

    $buffy .= '</article> <!-- /.post -->';

    $buffy .= $this->related_posts();

    return $buffy;
}
}

As you can see the line $buffy .= $this->get_review(); inserts the review box. The question here is, what code do i need to add after $review = to have the function insert the review box? I already tried things like $review = $td_module_1->get_review();

It should be possible to get that get_review function to work in my functions.php, right?

yiags987 on "Individual passwords per user to stop them editing other users posts"

0
0

Hi guys,

I have tried many role permission plugins and none are working as I need. I have a website with about a dozen users - all of which I only want to be able to edit their specific page.

All of the plugins I have tried allow you to categorize a user and allow them to either make page posts or not - nothing about specific pages.

Essentially all I need is that when a user attempts to edit a post (or page) - they are asked for a unique password. If they know the password they can edit - if they do not they can't.

This way - I can control say User A permissions by giving them only the extra password which corresponds to their area. If they try to edit any of User B's posts - they will not know the password and cannot.

Is there a plugin available which covers this? Or a hack?

gnarayan on "Comment counts: Manually add + (some number) to the count"

0
0

Okay got a TOUGH one for you guys:

Have this:

<?php comments_popup_link('0','1','%', ' ', '-'); ?>

But I'm trying to do this

<?php comments_popup_link('0','1','%+5', ' ', '-'); ?>

(obviously this does not work but renders something like 32+5 instead of 37)

I know this CAN be done, just don't know how...

Thank yew!

ebud on "Archive Widget"

0
0

I would like to change the date format that the Archive widget outputs.

Currently it like this
December 2013

and I would like just
Dec 2013

Any hooks or filters? I can seem to find any info on this other then rolling my own.

Viewing all 8245 articles
Browse latest View live




Latest Images