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

KW923 on "My Plugin is Printing Code on the Screen"

$
0
0

Hi! Before I go into my issue, I should mention that I am a designer and a newbie when it comes to PHP & WP development. Ok, I am developing a plug-in that should display the AddThis sharing buttons. I enqueued the script, converted HTML and JS to PHP variables, appended buttons to content and script to the footer. Once I activated my plug-in, my entire code printed on the screen in both the admin and on the webpage. Where did I go wrong? Thanks!

AddThis Sharing URL: https://www.addthis.com/get/sharing#.UfRfU2SgmYo

my code:

function add_this_sharing_enqueue_script(){
        wp_enqueue_script(
        'add_this_sharing',
        '//s7.addthis.com/js/300/addthis_widget.js#pubid=xa-51f45f596a3e1f1a',
        array(),
        null,
        true
    );
} 

add_action( 'wp_enqueue_scripts', 'add_this_sharing_enqueue_script' );

function add_this_sharing_buttons( $content ) {
    if ( is_single() ) {

        $button_html = '<div class="addthis_toolbox addthis_floating_style addthis_32x32_style" style="left:50px;top:50px;">';
        $button_html .= '<a class="addthis_button_preferred_1"></a>';
        $button_html .= '<a class="addthis_button_preferred_2"></a>';
        $button_html .= '<a class="addthis_button_preferred_3"></a>';
        $button_html .= '<a class="addthis_button_preferred_4"></a>';
        $button_html .= '<a class="addthis_button_compact"></a>';
        $button_html .= '</div>';

        $content .= $button_html;
    }

    return $content;
}

function add_this_sharing_script( $footer ){

        $js_html = '<script type="text/javascript">';
        $js_html .= 'addthis.layers({';
        $js_html .= '"theme" : "gray",';
        $js_html .= '"share" : {';
        $js_html .= '"position" : "right",';
        $js_html .= '"numPreferredServices" : 3';
        $js_html .= '},';
        $js_html .= '"whatsnext" : {},';
        $js_html .= '"recommended" : {';
        $js_html .= '"title": "Recommended for you:"';
        $js_html .= '}';
        $js_html .= '});';
        $js_html .= '</script>';   

        $footer .= $js_html;
        return $footer;
}

add_filter( "the_content", "add_this_sharing_buttons", 20 );
add_filter( "wp_footer", "add_this_sharing_script", 21 );

mdudu2 on "Custom sql wordpress query with pagination..."

$
0
0

Hello,

I've done a custom sql query for my blog. What the code does is to retrive the latest image from a post that has a gallery. In this way i can display latest ... les't say 12 posts that have a gallery- the code actualy displays the first image that is attached to the post.

Problem is that i cannot create a next prev functionality for this and i really need this

Here is the code:

<?php wp_reset_query();
 global $wpdb;
 $posts = $wpdb->get_results
 ("
 SELECT *
 FROM $wpdb->posts
 WHERE
 post_status = 'publish'
 AND
 ID IN (
            SELECT DISTINCT post_parent
            FROM $wpdb->posts
            WHERE
              post_parent > 0
            AND
              post_type = 'attachment'
            AND
              post_mime_type IN ('image/jpeg', 'image/png')
  )
ORDER BY post_date DESC LIMIT 0, 12
");

foreach($posts as $post) :
setup_postdata($post);
?>

<?php
$images = get_children(array(
  'post_parent' => get_the_id(),
  'post_type' => 'attachment',
  'post_mime_type' => 'image',
  'orderby' => 'menu_order',
  'order' => 'ASC'
));
$ids = array_keys($images);
            ?>

   <div style="height:132px; width:132px; float:left; margin-right:1px; margin-top:1px; overflow:hidden;" ><?php
  echo the_attachment_link($ids[0],false, false, true);
            ?></div>

<?php
endforeach;
wp_reset_query();
?>

Thank you

NMinajInfo on "I been hacked"

$
0
0

I been hacked(nickiminajonline.org) is there any way I can get this fixed?

Lamiskaa on "2 Shortcodes in 1 Lane ?"

$
0
0

Hello, i have a question ...im using a shortcode to put a widget/plugin to my "Main page" (not sidebar but in Index), but the plugin which im using have 300px, so i can place 2 of them in one line, but using the shortcode, twice at one lane, makes it 2 lane /1 plugin

Shortcode

echo do_shortcode('[do_widget "blahblah"]');

Is there any command to make this shortcode works 2x in one line
I mean smthing like (just for an example - the else is no wrking)

echo do_shortcode('[do_widget "blahblah"]'); else do_shortcode('[do_widget "blahblah"]');

mejle12 on "How to make current template show next posts."

greathug2u on "Script tag for jQuery in plugin files"

$
0
0

This might be a silly question since I'm really new at this. Can someone please tell me how to include this script tag inside of my plugin file? I know that I should use enqueue_script to link a js file, but this one is just a piece of code for a jQuery plugin that I want to turn into a customizable WP plugin. Should I insert it as part of $content?

<script type="text/javascript">
addthis.layers({
'theme' : 'gray',
'share' : {
'position' : 'left',
'numPreferredServices' : 5
}
});
</script>

heidekeal on "Nav without blog url"

$
0
0

[ Moderator note: please wrap code or log lines in backticks or use the code button. I've added the backticks to your post. ]

Hello,

I'm looking for a solution. I have a website that's pointed to an anoter domain. The problem is the main nav always links to the not pointed url. So i want to delete the url of the blog in the link;

<a href="/second-page/">

in stead of

</a><a href="http://school.nl/second-page/">

is that possible?

The menu code now

wp_nav_menu(
    	array(
    		'menu' => 'mainNav', /* menu name */
    		'menu_class' => 'nav',
    		'theme_location' => 'mainNav', /* where in the theme it's assigned */
    		'container' => 'false', /* container class */
    		'fallback_cb' => 'bones_main_nav_fallback', /* menu fallback */
    		'depth' => '2', /* suppress lower levels for now */
    		'walker' => new description_walker()
    	)
    );

vafaircloth on "Please Help! 2 lines of spam appear on mobile but not on computer...?"

$
0
0

Hello!

2 lines of spam appear on my website when you view it on mobile (I have an iPhone 4s). However, it doesn't appear on the computer screen. Here is a link to my website >> http://www.cedarandtwig.com <<

Any ideas? Thank you if advance!
V


Chuck on "Woocommerce & Wootique, Remove Sidebar From Product Pages?"

$
0
0

Hello everyone...

Trying this post here. Not sure if this is the best place or not. Just looking for some help.

I'm trying to get a site online for my wife. All is going well so far, but I'm having trouble with the sidebar. I'd like to keep it on the main page only, but remove it from all other pages. Even with very limited content so far, the site is: http://www.aprilsneattreats.com. I've been able to remove the sidebar from the "Cart", "Checkout", and "My Account" pages, but cannot find a way to remove it from the "Shop" or individual product pages, as well as the "Contact" page. At the present time, I've tried the following:

1. Set all pages to the template (full width). This worked for the above mentioned "Cart", "Checkout", and "My Account" pages, but no others.

2. Added the following code to "custom.css". This set the pages to use the full width of the site, but the grey sidebar area still remains.
.woocommerce #main{width:100%}

3. Commented out the line below in "theme-woocommerce.php". This removes sidebar content only.
add_action( 'woo_main_after', 'woocommerce_get_sidebar', 10);

These are the only things I've tried that I've had (some) success with. I've tried other solutions found in the forum, but none seem to work for me, unless I'm doing something wrong.

I would really appreciate any assistance anyone can provide. Thanks.

johncastlegate on "How to remove "Add Media" button in WP 3.5?"

$
0
0

In previous versions of WordPress, I could remove the media upload button with something like:

function z_remove_media_controls($context) {
    return;
}

add_action('media_buttons_context', 'z_remove_media_controls');

However, this does not seem to work in WordPress 3.5. How can I remove or hide the button now?

Nickvdp on "issues with custom post type with custom taxonomy hierarchy"

$
0
0

Hi all,

I am trying to set up my WP install with the custom post type 'dm_tool' and hierarchical custom taxonomy 'tool_type'.

What I am trying to achieve is the following:
domain.com/tools showing the custom post type archive page
domain.com/tools/books showing a books archive page
domain.com/tools/books/title showing the single for a book

I have been searching Google for three days now but I can't find a way to make it work. I have the following in my functions.nl:

$args = array(
			'hierarchical' => true,
			'labels' => $labels,
			'query_var' => true,
			'rewrite' => array('slug' => 'tools', 'hierarchical' => true)
			);

	/* Register the Custom taxonomy */
	register_taxonomy('tool_type',	array('dm_tool'), $args);

	/* Custom Post Type */
    $labels = array(
        'name' => _x('Tools', 'post type general name'),
        'singular_name' => _x('Tool', 'post type singular name')
    );

    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'query_var' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
    	'taxonomies' => array('tool_type'),
        'menu_position' => null,
        'supports' => array('title','editor','thumbnail', 'excerpt'),
        'rewrite' => array(
            'slug' => 'tools/%tool_type%',
            'with_front' => false,

        ),
        'has_archive' => 'tools'
    );

    register_post_type( 'dm_tool' , $args );

domain.com/tools shows archive-dm_tool.php and domain.com/tools/book/title shows single-dm_tool. domain.com/tools/books shows a default page template. Why is this?

Any help/suggestion is greatly appreciated..

Robert Lowe on "Exemplary code for web single sign-on plugin"

$
0
0

I am attempting to create a plugin that causes WordPress to use an external site for authentication using a custom single sign-on protocol.

Essentially, the plugin will need to redirect users to the external site when they need to log in. After authenticating the user, the external site will redirect them back to WordPress, passing a username, along with a message authentication code, which my plugin will need to validate.

I see a number of plugins in the official directory that claim to provide various forms of single sign-on. However, looking at the code for these plugins I see little commonality in the approaches taken.

Can anyone point me to code that they would consider exemplary for implementing web single sign-on in a plugin?

greathug2u on "Settings API"

$
0
0

I have a plugin that's supposed to add some social buttons to a single post page. I use settings API to set some options for the ability to disable and position the buttons left or right, but it doesn't seem to work. Can someone please tell me what I did wrong in my code? I'm kinda new at this so I really have no clue. Thank you.

<?php
/*
	Plugin Name: kvn_addThis
	Plugin URI: https://github.com/greathug2u/addThis
	Version: 1.0
	Description: Adds social buttons to single post page
	Author: Vy Nguyen
	License: GNU General Public License v2 or later
*/

function addthis_enqueue_scripts() {
	if ( is_single() && 0 == get_option( 'addthis_disable_button', 0 ) ) {
		wp_enqueue_script(
			'addthis',
			'//s7.addthis.com/js/300/addthis_widget.js#pubid=xa-51f5484b6f2193d4',
			array(),
			null,
			true
		);
		wp_enqueue_script(
			'addthis_button',
			'//s7.addthis.com/js/300/addthis_widget.js#pubid=xa-51f5532112489668',
			array(),
			null,
			true
		);
	}
}

add_action( 'wp_enqueue_scripts', 'addthis_enqueue_scripts' );

function addthis_scripts() {
	if ( is_single() && 0 == get_option( 'addthis_disable_button', 0 ) ) {
		$script_html = '<script type="text/javascript">';
		$script_html .= 'addthis.layers({';
		$script_html .= '"theme" : "gray",';
		$script_html .= '"share" : {';
		if ( 'right' == get_option( 'addthis_position_choice','right' ) ) {
			$script_html .= '"position" : "right",';
		} else {
			$script_html .= '"position" : "left",';
		}
		$script_html .= '"numPreferredServices" : 5';
		$script_html .= '}';
		$script_html .= '});';
		$script_html .= '</script>';

		echo $script_html;
	}
}

add_action( 'wp_head', 'addthis_scripts' );

function addthis_add_button() {
	if ( is_single() && 0 == get_option( 'addthis_disable_button', 0 ) ) {
		$sharebar_html = '<div class="addthis_toolbox addthis_default_style ">';
		$sharebar_html .= '<a></a>';
		$sharebar_html .= '<a></a>';
		$sharebar_html .= '<a></a>';
		$sharebar_html .= '<a></a>';
		$sharebar_html .= '</div>';

		echo $sharebar_html;
	}
}

add_action( 'wp_head', 'addthis_add_button');

/*---------------------------------SETTINGS---------------------------------*/
function addthis_add_options_page() {
		add_options_page(
			__( 'AddThis Options' ),
			__( 'AddThis Options' ),
			'manage_options',
			'addthis_options_page',
			'addthis_render_options_page'
		);
}

add_action( 'admin_menu', 'addthis_add_options_page' );

function addthis_render_options_page() {
?>
		<div class='wrap'>
			<?php screen_icon(); ?>
			<h2><?php _e( 'AddThis Options' ); ?></h2>
			<form action="options.php" method="post">
				<?php settings_fields( 'addthis_disable_button' ); ?>
				<?php settings_fields( 'addthis_position_choice' ); ?>
				<?php do_settings_sections( 'addthis_options_page' ); ?>
				<p class="submit">
					<input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes' ); ?>">
				</p>
			</form>
		</div>
<?php
}

function addthis_render_main_settings_text() {
	echo "<p>Main settings for the AddThis plugin.</p>";
}

/*----------------------Disable Button----------------------*/
function addthis_add_disable_button_settings() {
	register_setting(
		'addthis_disable_button',
		'addthis_disable_button',
		'absint'
	);
	add_settings_section(
		'addthis_main_settings',
		__( 'AddThis Controls' ),
		'addthis_render_main_settings_text',
		'addthis_options_page'
	);
	add_settings_field(
		'addthis_disable_button_field',
		__( 'Disable Sharing Buttons' ),
		'addthis_render_disable_button_input',
		'addthis_options_page',
		'addthis_main_settings'
	);
}

add_action( 'admin_init', 'addthis_add_disable_button_settings' );

function addthis_render_disable_button_input() {
	$current = get_option( 'addthis_disable_button', 0 );
	echo '<input name="addthis_disable_button"' . checked( $current, 1, false ) . ' type="checkbox" value="1" />';
}

/*----------------------Position Choice----------------------*/
function addthis_add_position_choice_settings() {
	register_setting(
		'addthis_position_choice',
		'addthis_position_choice',
		'absint'
	);
	add_settings_section(
		'addthis_main_settings',
		__( 'AddThis Controls' ),
		'addthis_render_main_settings_text',
		'addthis_options_page'
	);
	add_settings_field(
		'addthis_position_choice_field',
		__( 'Sharing Buttons Positioning' ),
		'addthis_render_position_choice_input',
		'addthis_options_page',
		'addthis_main_settings'
	);
}

add_action( 'admin_init', 'addthis_add_position_choice_settings' );

function addthis_render_position_choice_input() {
	$current = get_option( 'addthis_position_choice', 'right' );
	echo '<input type="radio" name="addthis_postion_choice"' . checked( $current, 'left', false ) . ' value="left">Left';
	echo '<input type="radio" name="addthis_postion_choice" value="right">Right';
}

Robert Lowe on "When does the authenticate filter get called?"

$
0
0

I would like to integrate a WordPress site with an external authentication (single sign-on) service. This service uses a custom protocol so I don't expect to be able to use a standard plugin; rather, I'm looking to write my own plugin.

I have read the documentation on the 'authenticate' filter, but it's not clear to me at what point the filter gets invoked. The fact that it gets passed username and password parameters suggest it is invoked after the WordPress login page gets submitted. I'm hoping this isn't the case however, because the flow I'm looking to implement should not involve displaying the WordPress login page. (Think something like OAuth.)

Can anyone provide illumination?

mejle12 on "Sidebar no longer is recognized by my PHP"

$
0
0

Hello Everyone, I was working on my wordpress site trying to get it compatible on firefox (Still a working progress, but works on chrome). and suddenly my site sidebar are no longer recognized by .php coding. Does anyone have ideas to why this is happening. It worked before.

Thanks.


ribbitfrog on "HTML tags in Category Names (not descriptions)"

$
0
0

I'm trying to get HTML tags to display correctly in my category names in the Categories sidebar widget. I can get the HTML tags to save in the database by using remove_filter( $filter, 'sanitize_text_field'); to my functions.php file. However, it displays the HTML tags along with the category name. So, for example, I have a category called the Cookies Project. So I put in <em>Cookies</em> Project. But instead of reading the 'em' tags, it displays them in the name. Any ideas on how I can make the code recognize that it's HTML tags and not plain text?

whenthathappens on "My site has been hacked"

$
0
0

My site is stupidknews.com. Google has said my site has been compromised. When I go to the mobile version of my site on my iPhone I can see a cialis link right next to the first post but when I try to view the site on my browser the cialis ad is hidden. Please help me, I'm not sure where I should look to delete this hack

brianoz on "Plugin generating virtual pages, issue with the_content not running"

$
0
0

I have a need to be able to generate fake/virtual/dynamic pages based on a url like http://www.mycinema.com/wpcinema/movie/MOVIEID to be able to display movies for cinemas with info on the movie and live session feed information.

After spending many hours researching, there doesn't seem to be much stuff written on how to do virtual pages in WordPress, so I will be writing up my experiences after getting this resolved!

So far, the current plan is to use the two filters - template_redirect to set the template to the current plugin's page.php template, and the_content to insert the content. The idea is to use the theme's template so the pages theme in well with the site.

(I got this approach from this excellent 2012 page from Xavi Esteve).

I have two problems:

  1. What is the best, most bullet proof, way to do this? Am I using the wrong approach? My thinking was that using the current theme's template was likely to provide the best current fit for the style of the website.
  2. TwentyTwelve does not appear to be calling the the_content filter in the context I'm using it. I suspect I'm doing something wrong, but cannot find the problem. This is probably closely related to question 1. TwentyTwelve definitely calls the_content for a normal page, and even an early add_filter() doesn't trigger in my code.

I discovered get_template_part() yesterday and wondered if I should be using that instead of manually looking in the child folder then the parent and running an include (not shown in the code below).

I wouldn't be asking, but I'm at my wit's end having googled extensively, possibly for the wrong search terms.

I've considered custom post types, but there are various complexities around this (including content that may change every few minutes) which means a dynamically generated page works much better.

This is an excerpt from the code I've written to explain the problem further:

add_action('parse_request', array(&$this, 'vm_parse_request'));

function vm_parse_request( &$wp )
{
    global $wp;
    if (empty($wp->query_vars['pagename']))
        return; // page isn't permalink

    $p = $wp->query_vars['pagename'];

    if (! preg_match("#wp-cinema/movie/([^/]+)#", $p, $m))
        return;

    // setup hooks and filters to generate virtual movie page
    add_action('template_redirect', array(&$this, 'vm_template_redir'));
    add_filter('the_content', array(&$this, 'vm_the_content'));
}

function vm_template_redir()
{
    // Reset currrently set 404 flag as this is a plugin-generated page
    global $wp_query;
    $wp_query->is_404 = false;

    $template = 'page.php';

    include(STYLESHEETPATH."/page.php"); // child
    // parent case left out for brevity

    exit;
}

function vm_the_content($content)
{
    return "my new content (actually generated dynamically)";
}

This is going to be an increasingly common thing in WordPress - can anyone offer suggestions or help? Anything is much appreciated.

smplee on "Automatically Create Tags for Post"

$
0
0

I’m trying to create a plugin that will find relevant keywords within a post’s title and content using some kind of search API and automatically inserting them as tags for a post. Is there an existing search API plugin that would be good to use?

Filespit on "Use checkboxes in wp_dropdown_categories"

$
0
0

Hello everyone,

I'm using the wp_dropdown_categories function on my site to let users filter their search with categories. In other words, if they select "fish" in the dropdown and write "pasta" in the search box, the site searches for all posts in the "fish" category. This works perfectly fine, so far so good.

Now to my problem; I want to replace the dropdown with checkboxes, i.e. give the user the option of doing a deeper filtered search. I've been searching far and wide after this and tried out some examples but cannot get it to work the way I want to. The closest I've come is that I can display my categories in checkboxes and select them, but when I do a search it completely ignores the filter and searches through all categories anyway.

Any ideas how I could solve this? Help would be much appreciated!

Viewing all 8245 articles
Browse latest View live




Latest Images