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

desirelabs on "Impossible to delete a user meta"

$
0
0

I'm a beginner with WordPress plugin api, php and ajax.
I'm coding a training plugin for myself to save posts article to read them later, like favourites on web browser, with folders.

I use oop to do so.

I assumed to create a new user meta called 'favoris', wich is an array with the users created folders.

I got something like that for getting favs, creating folders and deleting'em.

/**
 * Get favorites
 */
public function fp_ajax_getFav(){
	$current_user = wp_get_current_user();
	$userid = $current_user->ID;
	$folder = get_user_meta($userid, 'favoris');
	$content =  '<div id="pfolders">';
	$content .= '<h3 class="widget-title">Favoris</h3>';
	$content .= '<form id="pform" action="#" method="POST">';
	$content .= '<input type="text" placeholder="nouveau dossier" class="foldername">';
	$content .= '<input type="submit" class="addfolder" value="+">';
	$content .= '</form>';

	if (!empty($folder)) {
		$content .= '<a href="#" class="clear_all" style="display:inline">Tout supprimer</a>';
		$content .= '<span class="empty" style="display:none"><i>Aucun favoris.</i></span>';
	}
	else{
		$content .= '<a href="#" class="clear_all" style="display:none">Tout supprimer</a>';
		$content .= '<span class="empty" style="display:inline"><i>Aucun favoris.</i></span>';
	}

	$content .= '<ul id="accordion" class="favoris">';

	if (!empty($folder)) {
		$msg = '';
		foreach ($folder as $key) {
			foreach ($key as $k => $value) {
				$content .= '<li class="dossier dossier-' . $k . '"><span><a href="#" class="erase" data-key="' . $k . '"><i class="fa fa-times" style=""></i></a> <a href="#" class="dossier-nom-' . $k . '">' . ucwords($value['titre']) . '</a></span></li>';
			}
		}
	}
	else{
	}
	$content .= '</ul>';
	$content .= '</div>';
	return $content;
}

/**
 * Add folder
 */
public function fp_ajax_addFolder(){
	$current_user = wp_get_current_user();
	$userid = $current_user->ID;
	$meta = get_user_meta($userid, 'favoris');
	if (empty($meta)) {
		if ($_REQUEST['foldername'] !== '') {
			$folder[0]['titre'] = $_REQUEST['foldername'];
			add_user_meta($userid, 'favoris', $folder);
			var_dump($folder);
			echo ucwords($_REQUEST['foldername']);
			die();
		}
	}
	if (!empty($meta)) {
		$folder = $meta[0];
		if ($_REQUEST['foldername'] != '') {
			foreach ($folder as $key => $value) {
				$i = count($folder);
				if ($value['titre'] != $_REQUEST['foldername']) {
					$folder[$i]['titre'] = $_REQUEST['foldername'];
					update_user_meta($userid, 'favoris', $folder);
					var_dump($folder);
					echo ucwords($_REQUEST['foldername']);
					die();
				}
			}
		}
	}
}

/**
 * Remove folder
 */
public function fp_ajax_removeFolder(){
	if ( ( !isset($_POST['folderId']) || empty($_POST['folderId']) ) && ( !isset($_POST['folderName']) || empty($_POST['folderName']) ) ) {
		echo 'Pas de dossier spécifié';
		die();
	}
	else{
		$id = $_POST['folderId'];
		$name = $_POST['folderName'];
		$current_user = wp_get_current_user();
		$userid = $current_user->ID;
		$folder = get_user_meta($userid, 'favoris');
		$folderToErase = $folder[0][$id];
		try {
			delete_user_meta($userid, 'favoris', $folder[0][$id]);
			echo $folderToErase['titre'];
			//print_r($folder[0][$id]['titre']);
		}
		catch (Exception $e) {
			echo 'not ok';
			var_dump($folder);
			return $e->getMessage();
		}
		die();
	}
}

As far as I get or create, everything goes fine. But when I want to remove a folder by key ($id), it doesn't. But when I echo the $folderToErase, the id's right.

Maybe some help ?

Just in case, I also opened a ticket on stackexchange :
http://wordpress.stackexchange.com/questions/136499/how-to-delete-user-meta-by-key


Gunjesh Gaurav on "block fake ip, and rename wp directories"

$
0
0

hi friends,
i am using wordpress latest version, recently i have found to many hacking attempts on my site,and some fake google bots trying to crawl my website, there are many non exiting page error log visited by diffrent fake ip address and from diffrent country.i have blocked these ip address,but problem could nt solved, when i check error log, there are to many from diffrent ip or country, so i cant understand which ip should i block or not? for my site safety i am using sakuri and wordfence with firewall, i have already harden wp content, uploads folder and other.and disabled php file upload in upload directory,i also disabled theme editor and plugin editor to admin area. now problem is someone trying to analyzing my website, backdoors, or trying to find secret information,i know the trick of DDOS, Sql injection,so i need more security for my site, if i rename my wp-content to xxx,wp-include to yyy and plugins to zzz folder then? what configuration should i add in wp-configuration? then i think someone cant find any code easly, or any more ideas for safety?

DuendeB25 on "static image header on some pages"

$
0
0

Hello I wanted to ask you a question about the images in the headers. I put in a situation I have several images in the header which change randomly. In some pages I wanted them to be fixed and will not change. Can you do what I have in mind? Can you give me any recommendation as to if you could? Greetings and thanks.

baalstorm on "Dinamically generate custom post type title from category"

$
0
0

Hello,
I have a custom post type named "event", for which i disabled the title field.
This results in the post to be automatically named "Auto Draft" and the slug "auto-draft-x"

How can i automatically generate the title and the slug according to the post type name and the category set to the post when saving it?

Example:

event-live-1

(where "live" is the category)

There is the Auto Post Title plugin that does the trick for the title, but doesn't seem to affect the slug name.

Any help appreciated, thank you!

discoking86 on "How do you register a plugin function in your wordpress theme?"

$
0
0

I am currently working on a e-commerce site using wordpress and woocommerce and the theme "The Retailer".

The theme does not have "breadcrumbs" links and now I have decided that I want to add them. From my understanding Woocommerce should have support for this.

I will enable the breadcrumbs links on the single-product.php page. The woocommerce documentation says that I should use <?php woo_breadcrumbs(); ?> function to enable them.

But when I add the <?php woo_breadcrumbs(); ?> statement to my single-product.php page I get a fatal error saying that the function is unrecognized.

If I use "brute force" and copy all the original woocommerce breadcrumbs code (found in: woocommerce/templates/global/breadcrumbs.php) to my own function inside my themes functions.php the breadcrumbs are working, although I do not get the delimiters and other things that should come with them...

This is not an elegant solution. Instead there must be some way for me to "register" the woocommerce breadcrumbs function inside my theme so that I can use the standard recommended woocommerce prodcedure. How would I do this?

Thank you for your help! Kind regards, Lukas

gcoulby on "Make more than one database call in wordpress plugin"

$
0
0

I have 2 pieces of code from a simple plugin that work independently from each other but don't work together.

if(isset($_POST['submit'])){

		if(has_presence($_POST['product_name'])){

			insert_row_into_table('CAL_products');
			show_errors();
			if(has_presence($wpdb->last_query)) {
				echo "Update Successful";
			} else {
				echo "Update Failed";
			}
		} else {
			echo "The field 'Product Name' cannot be blank.";
		}
	}

And this one

$results_array = $wpdb->get_results("SELECT * FROM wpCMS_CAL_products ORDER BY id ASC");

	echo build_table_from_results_array($results_array);

The functions are included at the bottom.

The problem I have is that when the page loads there is no $_POST so it skips over the if statement and builds the table. This table builds fine.

When the form is submitted the if statements come back true and the new value is added to the database successfully, but then the table doesn't build until the page is refreshed. If the code to build the table is put at the top above the if statement it builds fine but doesn't include the new value until the page is refreshed.

Is it possible to add a new item to the database table before the results are populated to the HTML table?

function insert_row_into_table($table_name){
	global $wpdb;

	$prefix =  $wpdb->prefix;	//Define the wordpress table prefix
	$table = $prefix . $table_name; //Build the table name
	unset($_POST['submit']);
	echo print_r($_POST);
	$data = $_POST; //collect the data from post

	$wpdb->insert( $table, $data ); //insert data into the table
    }

    function show_errors(){
		echo $wpdb->show_errors();
		echo $wpdb->print_error();
	}

	function has_presence($value) {
		return isset($value) && $value !== "";
	}

function build_table_from_results_array($results_array) {

	$out  = "";
	$out .= "<table class=\"widefat\">";

	$out .= "<thead>";
	foreach($results_array[0] as $key => $element) {
		if($key == "id") {
			$out .= "<th class=\"id-column\">";
			$out .= strtoupper($key);
			$out .= "</th>";
		} else {
			$out .= "<th>";
			$out .= ucwords(str_replace("_", " ", $key));
			$out .= "</th>";
		}
	}
	$out .= "</thead>";
	$out .= "<tbody>";

	$i = 0;
	foreach($results_array as $key => $element){

		if($i % 2 === 0) $extraclass= "alternate";
		$out .= "<tr class=\"$extraclass\">";
		$i++;
		$extraclass="";

		foreach($element as $subkey => $subelement){
			$out .= "<td>$subelement</td>";
		}

		$out .= "<td><a href=\"#\">EDIT</a></td>";
		$out .= "</tr>";
	}

	$out .= "</tbody>";
	$out .= "</table>";

	return $out;
}

marklimmage@gmail.com on "permissions in submenu admin pages"

$
0
0

I have some submenu admin pages generated by code in an array of anonymous functions generated with a loop:

for ($i = 0; $i < count($tables); $i++) {
    $funcs[$i] = function() {
// do stuff..
}

when I add my submenu pages by referencing the elements of my funcs array, I get the permissions error:

for ($i=0;$i<count($tables);$i++) {

add_submenu_page( 'bilby_bo', $tables[$i][form], $tables[$i][form], 'manage_options', 'admin.php?page=bilby_bo_'.$tables[$i][form], $funcs[$i] );}

Can you see what I'm doing wrong?

Howdy_McGee on "Delete Images Attached To Page / Post"

$
0
0

When I delete a page or post I want to delete all images (from the media library) that are attached / associated with said page or post. I've hooked into Delete Posts and tried to query all attached images so I could delete them, but no luck. Anybody have suggestions?

function del_post_media($pid) {
$query = "DELETE FROM wp_postmeta
WHERE ".$pid." IN(
SELECT id
FROM wp_posts
WHERE post_type = 'attachment')";
global $wpdb;
if ($wpdb->get_var($wpdb->prepare($query))) {
return $wpdb->query($wpdb->prepare($query));
}
return true;
}
add_action('delete_post', 'del_post_media');


chrismichaels84 on "Redirect all urls beginning with a keywork (custom post type?)"

$
0
0

I am using WP Multisite with about 10 subdomain installs. I love it. What I need to find is the simplest way to redirect ALL pages that follow a key work to another domain. Similar to URL Mod Rewrite in function.

So,
phantomhearts.dmgstories.com/interactive/cabbot

is redirected to
bf.dmgstories.com/phantom-hearts/cabbot

I will already know that everything is phantom-hearts. So I need to capture the uri following interactive/ and attach it to the url bf.dmgstories.com/phantom-hearts and simply redirect it. The keyword (cabbot) will always be one uri segment.

More examples for clarity
phantomhearts.dmgstories.com/interactive/anadell -> bf.dmgstories.com/phantom-hearts-anadell

I have created several plugins, so I can do the code. I'm just not sure the best way to approach this. Where do I hook into?

Thank you a lot!

3bdelra7man262 on "Add Password to WP registration page"

$
0
0

How to add Password field to WP registration page??

kn1g on "Media uploader - limited user access"

$
0
0

Hi,

i did an extra field for the user edit page, where a user can upload images. Everything works fine but all users have access to all media files. I want to limit the access for the user to only the files he/she uploaded.
Any ideas how to tackle this problem?

thanks and best regards
Nico

TouchTheCow on "featured-image-attribution fix"

$
0
0

Wondering if anyone is using this and has any idea how to fix this little annoyance. I know it's a bit OCD but...

Site: http://www.touchthecow.com

On the featured image attribution the words "Image Credit" show up as part of the link that comes after and It's not supposed to. Only the actual source and license should be linkable.

<?php

/*
  Plugin Name: Featured Image Attribution, by Conversion Insights
  Plugin URI: http://conversioninsights.net/free-software/
  Version: 1.0
  Author: Conversion Insights, Inc.
  Author URI: http://conversioninsights.net/
  Description: Easily attribute Featured Images that require Creative Commons attribution. Just call the <code>featuredImgAttribution()</code> function immediately after the place in your theme where you display the image.
  Text Domain: featured-image-attribution
  Domain Path: /languages
  License: CC0 (Public domain)
 */

add_action( 'admin_init', 'add_attribution_box' );
function add_attribution_box() {
    $screens = array( 'post', 'page' );
    foreach ($screens as $screen) {
        add_meta_box(
            'attribution_box',
            'Featured Image Attribution',
            'show_attribution_box',
            $screen, 'side', 'default'
        );
    }
}

add_action('admin_menu', 'fia_create_menu');
function fia_create_menu() {
    // Enqueue backend assets
    if( is_admin() ) {
        wp_enqueue_script('jquery');
        wp_enqueue_script(
            'angular',
            plugins_url( 'js/angular/angular.min.js' , __FILE__ ),
            array('jquery'),
            '1.0.6',
            false
        );
        /*wp_enqueue_script(
            'fia-backend',
            plugins_url( 'js/fia-backend.js' , __FILE__ ),
            array('jquery', 'angular'),
            1.0,
            false);*/
    }
}

function show_attribution_box( $page ) {
    // Retrieve current settings
    $prefaceText =  get_post_meta( $page->ID, 'preface_text', true );
    $attributionText =  get_post_meta( $page->ID, 'attribution_text', true );
    $attributionHREF =  get_post_meta( $page->ID, 'attribution_href', true );

    $licenseText =  get_post_meta( $page->ID, 'license_text', true );
    $licenseHREF =  get_post_meta( $page->ID, 'license_href', true );
    ?>
    <style>
        #attribution-box input {
            width: 100%;
        }
        #attribution-box h4 {
            margin-bottom: 0;
        }
    </style>
    <script>
        /**
         * The controller for the Featured Image Attribution tool's admin panel
         */
        function FIAAdminController($scope) {
            $scope.prefaceText = "<?php echo $prefaceText; ?>";
            $scope.attributionText = "<?php echo $attributionText; ?>";
            $scope.attributionHREF = "<?php echo $attributionHREF; ?>";
            $scope.licenseText = "<?php echo $licenseText; ?>";
            $scope.licenseHREF = "<?php echo $licenseHREF; ?>";
        }

        var app = angular.module('FIAAdmin', []);
    </script>
    <div id="attribution-box" ng-controller="FIAAdminController" ng-app="FIAAdmin">
        <h4><label for="prefaceText">Prefacing text for attribution:</label></h4>
        <div><input type="text" name="preface_text" value="<?php echo $prefaceText; ?>" placeholder="E.g., Image credit:" id="prefaceText" ng-model="prefaceText"></div>

        <h4><label for="attributionText">Attribution for Featured Image:</label></h4>
        <div><input type="text" name="attribution_text" value="<?php echo $attributionText; ?>" placeholder="E.g., John Doe" id="attributionText" ng-model="attributionText"></div>

        <h4><label for="attributionHREF">URL for attribution:</label></h4>
        <div><input type="url" name="attribution_href" value="<?php echo $attributionHREF; ?>" placeholder="E.g., http://john-doe-photos.com" id="attributionHREF" ng-model="attributionHREF"></div>

        <h4><label for="licenseText">License name:</label></h4>
        <div><input type="text" name="license_text" value="<?php echo $licenseText; ?>" placeholder="E.g., CC-BY-SA 3.0" id="licenseText" ng-model="licenseText"></div>

        <h4><label for="licenseHREF">URL for license:</label></h4>
        <div><input type="url" name="license_href" value="<?php echo $licenseHREF; ?>" placeholder="E.g., http://creativecommons.org/licenses/by-sa/3.0/" id="licenseHREF" ng-model="licenseHREF"></div>

        <h4>Preview:</h4>
        <p class="featured-img-caption">{{prefaceText}} <a href="{{$attributionHREF}}" title="Image attribution" target="_blank">{{attributionText}}</a>. Licensed under <a href="{{licenseHREF}}" title="{{licenseText}}" target="_blank">{{licenseText}}</a>.</p>
    </div>
<?php
}

add_action( 'save_post', 'handle_attribution_data', 10, 2 );
function handle_attribution_data( $pageID, $page ) {
    $keys = array( 'preface_text', 'attribution_text', 'attribution_href', 'license_text', 'license_href' );

    foreach( $keys as $key ) {
        if ( isset( $_POST[$key] ) && $_POST[$key] != '' ) {
            update_post_meta( $pageID, $key, $_POST[$key] );
        } else if( get_post_meta( $page->ID, $key, true ) != '' ) { // post info *used to be* shown
            update_post_meta( $pageID, $key, '' );
        }
    }
}

function featuredImgAttribution() {
    $prefaceText =  get_post_meta( get_the_ID(), 'preface_text', true );
    $attributionText =  get_post_meta( get_the_ID(), 'attribution_text', true );
    $attributionHREF =  get_post_meta( get_the_ID(), 'attribution_href', true );

    $licenseText =  get_post_meta( get_the_ID(), 'license_text', true );
    $licenseHREF =  get_post_meta( get_the_ID(), 'license_href', true );

    $openHREF = "";
    $closeHREF = "";
    if( $attributionHREF && $attributionText ) {
        $openHREF = "<a href=\"$attributionHREF\" title=\"Image attribution\" target=\"_blank\">";
        $closeHREF = "</a>";
    }

    $licenseHTML = "";
    if( $licenseText ) {
        $licenseHTML = " Licensed under ";
        if( $licenseHREF ) {
            $licenseHTML .= "<a href=\"$licenseHREF\" title=\"$licenseText\" target=\"_blank\">$licenseText</a>.";
        } else {
            $licenseHTML .= $licenseText . ".";
        }
    }

    if( $prefaceText || $attributionText ) {
?>
        <!-- Featured Image Attribution -->
        <p class="featured-img-caption"><?php echo $prefaceText, " ", $openHREF, $attributionText, $closeHREF, ". ", $licenseHTML; ?></p>
<?php
    }
}

bdev9 on "querying and displaying post meta data multidementional array"

$
0
0

I am rusty at coding and new to wordpress and PHP, but here is where I am at so far. Any help would be appreciated. I am using a single instance of Wordpress 3.8.1

PROBLEM:

Each of my posts are a store with various store details within the post. I have a plugin called geomywp that saves store hours in post meta data. I would like to display the hours of business when someone views the stores post. I am having trouble figuring out how to query the database, retrieve/parse the data, and display it to the user on the posts page. I was looking at examples here, but I did not make much progress: http://codex.wordpress.org/Function_Reference/get_post_meta

Using the plugin I created some data (company hours) and was able to hunt it down via the php admin.

EXAMPLE DATA
An example piece of data is below. It appears to be a two dimensional array [7x4] with s referring to the number of characters and the ; as the delimiter and i (1 to 7) as the row index. The columns seem to be (days, day of the week, hours, time range)

Table name: wp_postmeta
Table attributes: meta_id   post_id  meta_key  meta_value

The example table attributes are
meta_id = 55
post_id = 29
meta_key = _wppl_days_hours
meta_value =

a:7:{i:0;a:2:{s:4:"days";s:6:"Monday";s:5:"hours";s:7:"9am-5pm";}i:1;a:2:{s:4:"days";s:7:"Tuesday";s:5:"hours";s:7:"6am-8pm";}i:2;a:2:{s:4:"days";s:0:"";s:5:"hours";s:0:"";}i:3;a:2:{s:4:"days";s:0:"";s:5:"hours";s:0:"";}i:4;a:2:{s:4:"days";s:0:"";s:5:"hours";s:0:"";}i:5;a:2:{s:4:"days";s:0:"";s:5:"hours";s:0:"";}i:6;a:2:{s:4:"days";s:0:"";s:5:"hours";s:0:"";}}

PROGRESS SO FAR

$key_1_value = get_post_meta( get_the_ID(), '_wppl_days_hours', true);
// check if the custom field has a value
if( ! empty( $key_1_value ) ) {
  echo $key_1_value;
}
$thepostid = get_the_ID();

The current output does not display anything, so I tested to see if it was pulling the post_id correctly, which it was and providing me with the output of 29 when I visit the individual store post page.

RESULTS I WOULD LIKE
When I arrive at the Store Inc post page I want to see this:

Opened:
Monday 9am-5pm
Tuesday 6am-8pm

What is the correct code I am to use to retrieve and post the hours in a readable format?

Thank you

welcomebrand on "List all posts on a page, split them by year"

$
0
0

I'm guessing it's reasonably simple but I can't find any instruction on how to work this so wondering if anyone could help out.

I've created a custom page template ("Archive List") and in that page I'd like to list every post from my site but split them out by year like this:

2013
|- A post title
|- Another post here

2012
|- Older post here
|- Some more
|- Etc etc

2011
|- Etc etc etc

Anyone able to chuck a snippet of code my way, would be very grateful :)

madsrh123 on "Taxonomy and post types"

$
0
0

I know that there's a ton of threads on this topic, but I can't find any help on this specific issue.

Let say I have a movie review site and want to be able to select a film production company for each movie inside my post-type.
I could do this with taxonomy but then I can't add/edit company logo, description, etc.

I guess I looking for a post-type inside a post-type or ....?

Can any on help me or perhaps point to a tutorial?

//MadsRH


ndh01 on "Automatically reassign posts to a different ID anytime wp_delete_user is called"

$
0
0

Is there a way to always reassign posts to a different ID any time wp_delete_user is called? Are there any hooks that I can use here?

Thank you

ottolo123 on "woocommerce custom invoice date editable in order admin backend"

$
0
0

Im trying to mod woocommerce to adapt it to the italian law. Until now i managed to adapt a lot of things. Im searching a way like the customer note field but aditionally to it i would like to insert a custom date which afterwards we can use to generate the invoice, so the order date should remain the order date and we have a custom manually editable invoice date. Until now i havent found a solution! Could anyone help me?
TThanks max

edow on "Remove text field from comment form"

$
0
0

Hi,

I would like to remove the text field from the comment form. The idea is that users can vote if they like the post or not. The like/unlike option must be done with radio buttons in a custom field (that would be the next problem).

But first: How can I remove the text field? I don't want it hidden, but entirely removed. What is the best practice for this? I can't find a decent solution.

Hopefully anyone can help me with this.

ecat on "wp_create_user doesn't seem to require create_user capability??"

$
0
0

I am building a site which is composed of many chapters (clubs). The requirement is that the chapter president be able to create and manage users for his chapter but not for other chapters. Initially, I thought I would have to go to multisite WP for this, with the club presidents admins for each blog within the multisite. But then I tried wp_create_user and wp_delete user in a plugin for an author user who does not have create_user or delete_user capability (as confirmed with the members plugin). Assuming this works, as it seems to, I can easily do everything in a regular WP install with a custom plugin, which will be much simpler to maintain than the multisite. But since I am building the whole design on this assumption, I want to confirm that I am not missing something that will bite me later, or possibly in another version of WP, or have somehow convinced myself that it is true when it isn't. Has it always been this way?

Logan Knight on "Use javascript as URL in Link Manager"

$
0
0

I've recently built a webpage that allows people to turn textbox table inputs into a random generator bookmarklet, which works great, that's all fine.

I'd really like to have an archive people where people can then submit the bookmarklets they've made as links so that other people can use them.

I've used the bookmarklets in pages and posts without any issues simply by posting the code into the URL field, and when I found the Link Library plugin (which allows people to add links directly to Link Manager) I thought I'd found the perfect solution.

However, any time I try to add a link with javascript as the URL, either through the plugin or directly through Link Manager, it disappears. It doesn't say it's invalid or that it failed, it just refreshes the page without actually completing anything.

So, is there any way to force Link Manager to actually accept JavaScript as a URL?
It also seemed to cut off part of longer bookmarklets that I tested, which makes it seem like there's a length limit for links, but I've been unable to find anything about that or the JavaScript issue.

Viewing all 8245 articles
Browse latest View live




Latest Images