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

YOEBO on "Missing Argument Warning"

$
0
0

Hi, I have the following code in my functions.php to show a lightbox on the Simple Paypal Shopping Cart Plugin

function make_wpspsc_thumbs_lightbox_previews( $thumbnail, $atts ) {

	// Code Credit: http://stackoverflow.com/questions/19323324/how-to-get-image-src-attribute-value-from-php-string

	$doc = new DOMDocument();

	// Let's make sure we don't execute this code on the wrong elements & blow up the site
	if ( ! is_object( $doc ) ) {
		return $thumbnail;
	}

	libxml_use_internal_errors(true);
	$doc->loadHTML( $thumbnail );
	$xpath = new DOMXPath($doc);
	$imgs = $xpath->query("//img");
	for ($i=0; $i < $imgs->length; $i++) {
    		$img = $imgs->item($i);
    		$src = $img->getAttribute("src");
	}
	// Now let's use the image src we just got & rel="lightbox" because that's what Responsive Lightbox from dFactory uses
	$new_thumbnail = '<a href="'.$src.'" rel="lightbox">'.$thumbnail.'</a>';

	return $new_thumbnail;
}
add_filter( 'wspsc_product_box_thumbnail_code', 'make_wpspsc_thumbs_lightbox_previews' );

When I add something the the cart I get the warning:

Warning: Missing argument 2 for make_wpspsc_thumbs_lightbox_previews()

On line 16 which is this:

function make_wpspsc_thumbs_lightbox_previews( $thumbnail, $atts ) {

Can anyone see what is causing the problem please?


wp_torturer on "A new creating-content-form"

$
0
0

Hi everyone!
I'm not good at English, it'll be difficult to explain what i'm trying to do... I need users of my site to add new materials through a form looks like the one in administrative panel. Adding materials in admin-page doesn't look stylistically appropriate. Could you give me a hint?

chickspirit on "WooCommerce Product Image to External Link in New Window"

$
0
0

I have an external link product and would like the featured image on the single product page to link to the external page in a new window.

Out of the box the image, when clicked, opens in a lightbox.

The section of code I have to adjust is in the product-image.php

<div class="images">

	<?php
		if ( has_post_thumbnail() ) {

			$image_title 	= esc_attr( get_the_title( get_post_thumbnail_id() ) );
			$image_caption 	= get_post( get_post_thumbnail_id() )->post_excerpt;
			$image_link  	= wp_get_attachment_url( get_post_thumbnail_id() );
			$image       	= get_the_post_thumbnail( $post->ID, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ), array(
				'title'	=> $image_title,
				'alt'	=> $image_title
				) );

Specifically I need to change this line:
$image_link = wp_get_attachment_url( get_post_thumbnail_id() );

I changed it to this:
$image_link = esc_url( $product->get_product_url() );
which accomplished the image opening the external link when clicked. However it's opening in the same window and I'd like it to open in a new window.

I tried this:
$image_link = esc_url( $product->get_product_url(), array('target' => '_blank', 'rel' => 'new_window') );
But now it just kind of refreshes the page and takes me nowhere.

Suggestions? Thank you!
Page I'm trying this on.

D C on "SQL script for publishing"

$
0
0

So I am running into some issues here with auto publishing. I am mimic the process that accure once the Publish button is pressed with an SQL script.

A bit of backstory:
I have a site that it is feed posts from feedly. By default these posts are put into draft mode. Using the following script, I have figured out a way to change the post from draft to publish.
UPDATE DB_Name.wp_posts SET post_status = replace(post_status, 'draft', 'publish'), post_name=id where post_status = 'draft';

This works great and does switch from draft to publish and does assign a slug. However, when a post comes from feedly, it does not create a featured image. To do this, I have installed a plugin (Quick Featured Images Pro). The plugin basically scans the post and uses the first image it sees as the featured image.

Here is the catch. The plugin only works if you the feedly post is set to draft first and then you manually login and click publish. Thus, my script only makes the chagnes in the database, but does not fully do what I need.

So my question would be, does anyone know how to script (php or sql) the process of pushing the publish botton? Or better yet, how to run the plugin script after my script above is run?

Thanks in advance.

mjd1953 on "How to modify rss template but leave core feed-rss2.php alone"

$
0
0

I want to make a modification to the core feed-rss2.php file (basically, have it feed the author's first and last name rather than the username), but also want to follow the maxim of never-ever-change-core-files. How do I make sure feeds will be generated by the modified file? Or is there a way?

judahnator on "Assigning Terms to Post"

$
0
0

I am writing a system for a friend that automatically generates posts.

This system will add tags and categories to the post, but I am running into a problem I have never seen before:
I can only assign a tag to a post, IF the tag does not already exist on the remote site.

For example, I have a bit of code that looks like this:

wp_set_post_tags(42,array("meaning","life"));

This will work, but ONLY if neither the "meaning" or "life" tags had already been created.

For those who want the EXACT details of my setup, I doing everything via the WP REST API, with THIS extension (waiting for the API to fully support categories+tags), and THIS chunk of code (slightly modified to be a stand-alone script)

kenbowen on "Problem using wp_new_comment"

$
0
0

I’m trying to add a simple custom comment management facility to a WordPress site. The comment form is managed by javascript and works fine, including calling into my PHP file as needed. I’m trying to utilize wp_insert_comment. Based on the Example code there, I believe I’m assembling the right $commentdata array as argument. Here’s my code, including some simple logging to verify the data:

<?php
/*
include '../../../wp-includes/comment.php';
include ‘<MY PATH>/wp-includes/comment.php';
*/

$db = new mysqli($hostname,$username,$password,$database);
if ($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}

/* Open Log file */
$filename=“<MY PATH>/wp-content/themes/blocks2/dbi/testf.log";
$fd = fopen($filename, "a");
$str = "++++--------new_post---------++++";
fwrite($fd, $str . "\n");

$cid = 0;
$pid = $_POST['pid'];
$ulogin = $_POST['ulogin'];
$uid = $_POST['uid'];
$cmttxt = $_POST['txt'];

$str = $ulogin . ' ' . $cmttxt;
fwrite($fd, $str . "\n");

$commentdata = array(
'comment_post_ID' => $pid,
'comment_author' => $ulogin,
'comment_author_email' => 'someone@example.com', //fixed value - can be dynamic
'comment_author_url' => 'http://example.com', //fixed value - can be dynamic
'comment_content' => $cmttxt,
'comment_type' => '', //empty for regular comments, 'pingback' for pingbacks, 'trackback' for trackbacks
'comment_parent' => 0, //0 if not a reply to another comment; if it's a reply, parent comment ID here
'user_id' => $uid
);

$str=">>>comment_post_ID=" . $commentdata["comment_post_ID"] . " comment_author=" . $commentdata["comment_author"] . " comment_author_email=" . $commentdata["comment_author_email"] . " comment_author_url=" . $commentdata["comment_author_url"] . " comment_content=" . $commentdata["comment_content"] . " comment_type=" . $commentdata["comment_type"] . "| comment_parent=" . $commentdata["comment_parent"] . " user_id=" . $commentdata["user_id"];
fwrite($fd, $str . "\n");

/* Insert new comment and get the comment ID */
$comment_id = wp_new_comment( $commentdata );

$str = "AFTER wp_new_comment-comment_id= " . $comment_id;
fwrite($fd, $str . "\n");
fclose($fd);

For a comment with text = “Silly-Comment”, here is what is logged:

ken Silly-Comment
>>>comment_post_ID=17 comment_author=ken comment_author_email=someone@example.com comment_author_url=http://example.com comment_content=Silly-Comment comment_type=| comment_parent=0 user_id=3

The final log entry "AFTER wp_new_comment-comment_id= " . $comment_id; is missing.
It’s occurred to me that I might need to explicitly include wp-includes/comment.php, which contains wp_new_comment. I’ve attempted the two versions of the includes shown commented-out at the top of the code, but neither seems to have any effect.

Can anyone supply some guidance please?
Thanks in advance,
Ken Bowen

Xtremefaith on "Force homepage login while hiding wp-login.php"

$
0
0

After hours of attempts, and countless articles dating back over a decade I nearly have this working 100%. Essentially as the title mentions I have a homepage (much like facebook), with a buddypress registration form and menu login.

The login form is using the wp-login.php to $POST vars (until 4.5 is released it appears this how this is to be done since). I do not want access to the site unless logged in, and I preferably don't want wp-login.php ever seen. Here are the following precautions I have in place so far:

# Force Redirect on WP default login page
add_action('init', array( $this, 'prevent_wp_login') );
function prevent_wp_login() {
    global $pagenow;

    # Check if a $_GET['action'] is set, and if so, load it into $action variable
    echo $action = (isset($_GET['action'])) ? $_GET['action'] : '';
    if( $pagenow == 'wp-login.php' && ( ! $action || ( $action && ! in_array($action, array('login', 'logout', 'lostpassword', 'rp'))))) {
        wp_redirect( get_home_url() );
        exit();
    }
}

add_action('template_redirect', array( $this, 'check_if_logged_in') );
function check_if_logged_in(){
    if(!is_front_page() && !is_user_logged_in()) auth_redirect();
}

# Redirect members to their profile page
add_filter( 'bp_login_redirect', array( $this, 'redirect_to_profile'), 11, 3 );
public function redirect_to_profile( $redirect_to, $redirect_url_specified, $user ){
    if( empty( $redirect_to ) )
        $redirect_to = admin_url();

    # if the user is not have contributor capabilities, redirect to his/her profile
    if( isset( $user->ID) && ! user_can( $user->ID, 'edit_posts' ) )
        return bp_core_get_user_domain( $user->ID );
    else
        return $redirect_to;
}

With those snippets everything works as expected except when the user fails to login, then it goes to the wp-login.php and notifies them of a bad password. How can I notify them on my login form without being redirected to the wp-login.php screen?


elnicknamio on "compare date between in meta_query"

$
0
0

Hi,
on my page, the user chooses a event date. This date should be between the start and end date of a event.
How can i bring this query to work?

add_action('pre_get_posts', 'alter_query');

function alter_query($query) {

	if (is_search() && $query->query_vars['post_type'] == 'event') {

		if (!empty($_GET['selected_date'])) {

			$arr_selected_date = explode('-', $_GET['selected_date']);
			$selected_date = mktime(0, 0, 0, $arr_selected_date[1], $arr_selected_date[2], $arr_selected_date[0]) * 1000;

			$query->set(
				'meta_query',
				array(
					'relation' => 'AND',
					array(
						'key' => '_event-date-from',
						'value' => $selected_date,
						'compare' => '<='
						),
					array(
						'key' => '_event-date-to',
						'value' => $selected_date,
						'compare' => '>='
						)
					)
				);

		}

	}

}

Zwerg-im-Bikini on "Using theme templates for the login page"

$
0
0

I have a question regarding the login page and hope you can help me :).

Usually there seems to be no template for the login page in the theme folder, but I want to redesign it. I want it to look exactly like my regular pages (with the menu bar and header, footer and menu bar). So I installed the plugin "custom login" which looked promising. But it only allows me to add HTML after the login form.

Is there an easy way to make the login page use the regular "page" template of the theme? If not - where should I add the code of the menu bar and header to make it look this way?

Hamlet_PL on "My first shorecode"

$
0
0

Welcome,
I try add my own shortcod to function.php in Hueman theme. Function doesn't show any error but I no see any <a href="...">. Below i paste my code. Where I make a error?

// ShowPrivateFile
function ShowPrivateFile() {
	ob_start();
	$output='';
	if ( is_page( 'login' ) ) {
		$output = 'Pliki dostępne tylko po zalogowaniu:'.
                '<a href="aaa.pl">abcd</a></br>'.
		'<a href="aaa.pl">Faktura Klamki.JPG</a></br>'.
		'<a href="aaa.pl">Faktura Wkladki Klucze.JPG</a></br>';
	}
	return $output;
}
add_shortcode("pokaz_prywatne_pliki", "ShowPrivateFile");

regards

nnitramm on "Sharing user database permission"

$
0
0

Hi, I have recently setup my second WordPress installation to use user database of my first wp installation. I have setup everything correctly and everything works, one problem is just that when I try to login to my second website with my admin account, I am getting this error: You do not have sufficient permissions to access this page. I know I should have replaced this line:

$this->cap_key = $wpdb->prefix . 'capabilities';

in my second wordpress installation's
wp-includes/capabilities.php
with

if (defined ('CUSTOM_CAPABILITIES_PREFIX')) {
	$this->cap_key = CUSTOM_CAPABILITIES_PREFIX . 'capabilities';
	}
	else {	$this->cap_key = $wpdb->prefix . 'capabilities';
	}

but there is no such line in capabilities.php in the new wordpress version. Any ideas what might help? I only found several old tutorials.

davtwo on "Widget variant issue"

$
0
0

Sorry in advance if this not the right sub-forum.

I have a widget provided by a plugin that I have overridden. I want to add it to two widget areas, but I want it to behave differently depending on which area it is in. (In my case display images on the sidebar, not display them in the footer). I'm hoping there is a quick way to determine which area is running the widget? Or maybe a way to pass that state variable?

I'd rather not clone the whole widget.

Thanks!

Zachdoug on "Laying a widget over another widget."

$
0
0

How can i lay a widget over another widget?

Is it possible?

Basically I have a large image on my home screen that I want to lay a single line of a contact form over.

HammerSix on "Hover Effects"

$
0
0

I want to underline or otherwise highlight specific words that refer to a specific picture. When a reader hovers over those words, I want for the associated picture (not in the same place as the words) to expand by about 15-20%. For example, the content might read, "As shown right, I painted the interior black." Therefore on "hoverin" when a reader hovers over "right" the associated picture grows, and on "hoverout" returns to original size.

Is there a way to create hover effects in which the hover location and the effect location are separated?

I am totally new to this, but hopefully just savvy enough to decipher what I expect might be very complex answers. Thanks for any suggestions and hand-holding available.


D C on "Script or wp-cron to change status from draft to publish"

$
0
0

Hey all,

I am looking for a script that will run on a hourly basis that will switch all posts in draft status to publish status. I know how to do this with a sql script to update the database, but that does not fully act like clicking the "Publish" button would do. So many of the script/hooks/etc are not fully run and thus any plugin that ties into those hooks are not run.

Anyone have an idea on how to do this?

Thanks in advance!

FireSamurai on "Switch/Case Doesn't recognize shortcode parameters. Why?"

$
0
0

Hi,

I'm wondering why a switch/case scenario I've written will not recognize the parameters in a shortcode function.

Here is a compact version of it:

<?php
add_shortcode( 'the_shortcode' , 'the_shortcode_function' );
function the_shortcode_function( $atts, $content=null ) {
	extract( shortcode_atts( array(
		'term'	=> '',
		'url'	=> 'http://originalurl.com'
	), $atts ) );

	$output = '<a href="'.$url.'">Link text</a>';

	switch( $term ) {
		case 'foo':
			$url = 'http://foourl.com';
			return $output;
			break;
		case 'bar':
			$url = 'http://barurl.com';
			return $output;
			break;
		default:
			return $output;
	}

}
?>

To my untrained eye, I would think that case 'foo': would return
<a href="http://foourl.com">Link text</a>

And case 'bar': would return
<a href="http://barurl.com">Link text</a>

However, both foo and bar return the default URL string
<a href="http://originalurl.com">Link text</a>

Could somebody explain to me what is happening to prevent my desired output? Much thanks!

ZaddKeefer on "Custom Post Type for TV Shows, Seasons, Episodes"

$
0
0

I am trying to create a hierarchical post type as Series which flows like this: Parent ( Tv Show Name, eg X-Files ), Child ( Season 1 ), Grand-child ( Episode 1 - Pilot ) So on
(Tv Show)post-parent->(Tv Show Season)category-child->(Tv Show Episode)posts-grand-child?

- Series: Name,Title,Description (Parent post)
-- Season 1 (child category?)
--- Episode 1 (grand child post)
-- Season 2 (child category?)
--- Episode 1 (grand child post)

But have no idea how custom post types works with this NOR how to make post type as "child" and "grand-child" or even parent? I want help with a template to display it

Some similarity to this code.. But have no clue how to setup a custom post as parent:
http://pastebin.com/m78DESL8

tobbger on "Make [audio]-player play next song"

$
0
0

I have a music blog where every post contains a link to a mp3 with an [audio]-tag surrounding them. Therefore, every post only consists of an audio player. I would like the next post/song to play when the previous post/song has ended, like if every post in the blog feed is a song in a playlist.

Is it possible to make this playlist-like connection between separate audio-tags?

alexrdc on "Automatically Change User Role After x Days"

$
0
0

I'm currently using the User Role Editor plugin along with a function that upgrades a user's role when they purchase a specific product from the site's WooCommerce shop. The function to upgrade the user role is:

add_action( 'woocommerce_order_status_completed', 'upgrade_user_role' );

function upgrade_user_role( $order_id ) {

	$order = new WC_Order( $order_id );
	$items = $order->get_items();

	foreach ( $items as $item ) {
	    $product_name = $item['name'];
	    $product_id = $item['product_id'];
	    $product_variation_id = $item['variation_id'];
	}

	if ( $order->user_id > 0 && $product_id == '3156' ) {
		update_user_meta( $order->user_id, 'paying_customer', 1 );
		$user = new WP_User( $order->user_id );

		// Remove role
		$user->remove_role( 'subscriber' );

		// Add role
		$user->add_role( 'magazine-subscriber' );
	}
}

I would like to modify or add to this function so that after so many days the user role that was added (in this case magazine-subscriber) is removed and the only way to get it back is to buy the product again. I would like to avoid having to install any paid plugins if possible, but would consider it if necessary.

If anyone has any advice on how to achieve this I would really appreciate it!

Viewing all 8245 articles
Browse latest View live




Latest Images