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

paulsimonrough on "Use wordpress widget option (instance) outside the class"

$
0
0

I'm trying to use an instance or option from the widget backend settings outside the class but can't seem to get it to work.

I've omitted some of the code to simplify what I mean:

<?php

##trying to use variable here!
echo $instance['variableiwant'];

   class my_class extends WP_Widget {

        ## get variable from the backend form settings of widget
        function form($instance) {
           $title = ! empty( $instance['variableiwant'] ) ? $instance['title'] : __( 'variableiwant' );
        }

        ##update save of widget
        function update($new_instance, $old_instance) {
            $instance = $old_instance;
            $instance['variableiwant'] = strip_tags($new_instance[ 'variableiwant']);
            return $instance;
        }

        function widget($args, $instance) {
        }

I can use the variable perfectly fine inside the class and its functions but is there special API I need to use to pull the variable outside the class as the code:

echo $instance['variableiwant'];

Just returns 0 or zero


Mackelius on "One submission per user"

$
0
0

Hi,

This has been asked before but I haven't found a solution.

Is there any way to restrict submissions to one per user? Preferably it would be a check against a hidden field with the email in it.

The form I'm using is currently only a submit button and a hidden field.

Another solution would be if I could apply a filter or something which is filling in the email automatically for the user since I can restrict unique values if the user has filled in a text field.

Sincerely Maximiliam

andy277 on "Activate plugins by a theme's functions.php"

$
0
0

Is it possible to activate plugins per theme?

I have a multisite, and I know it is possible to activate plugins per site. But I need plugins to be enabled for specific themes.

Someone asked a similar question - if it is possible to activate plugins by other plugins: http://wordpress.stackexchange.com/questions/4041/how-to-activate-plugins-via-code

This was an accepted answer:

//Activate a plugin programmatically - Akismet example

    function run_activate_plugin( $plugin ) {
    $current = get_option( 'active_plugins' );
    $plugin = plugin_basename( trim( $plugin ) );

    if ( !in_array( $plugin, $current ) ) {
        $current[] = $plugin;
        sort( $current );
        do_action( 'activate_plugin', trim( $plugin ) );
        update_option( 'active_plugins', $current );
        do_action( 'activate_' . trim( $plugin ) );
        do_action( 'activated_plugin', trim( $plugin) );
    }

    return null;
}
run_activate_plugin( 'akismet/akismet.php' );

However someone commented about this not being very safe and I'm also not sure if this would be a good idea to add to a theme's functions.php file.

I added this above code to a themes functions.php to activate some plugins and so far this is working without any problems. Would I run into problems with this, or is there some better code to use? There is also this function activate_plugin() not sure if that function is a better way to activate plugins.

I am not very good with code, any help appreciated.

knoppys on "update_post_meta() and wp_mail() when adding a new psot"

$
0
0

Hi All

I have a custom post type ('booking')that uses around 20 custom fields to populate the post content. Once this content is added, various calculations are made, various other fields are automatically populated and everything ends up as a 'booking'.

So heres the problem, when the post is published, Im hooking into 'updated_post_meta' to send an email using wp_mail() containing all the posts content and meta.

However, the mail is being sent before the meta fields are being added to the database? I need a way to add the data, save it and then send the mail.

Thanks

nicky112 on "Automatically decorate a specific text with a different font"

$
0
0

Hello,

every time I use the name of my blog in a post I want it to be decorated with another font. Is there any way to do this automatically? I guess some replacements on the original text has to be done. Maybe a filter?

PS: I am not sure if I picked the right forum - Sorry if not ;)

Best

nicky

MatiasLN on "Add Woocommerce order notes field to cart.php & single-product.php"

$
0
0

Is it possible to add the Woocommerce order notes field before the checkout form page? I would like to add it to the cart.php page and single-product.php if that's possible. It would be great if the content entered would be displayed in the checkout form so that the customer can update it if necessary.

theadvoor on "Replicating Menu Functionality"

$
0
0

The concept is the following: I need a new post type which will organise another post type into a hierarchical structure ( as well as store additional information which is why I cant just use the menu system ).

What I'm trying to do its replicate how the Wordpress menu functionality works, and then extend on it. The two sections I need to replicate is the accordion on the left hand side which allows you to view and search different post types (will need to be restricted to only one post type), and the drag and drop menu functionality to modify the order and hierarchy on the right.

I've already created the new post type. The next step is to get the search box to display on the new custom post type; I've located the following code which I believe outputs the search box:

<form id="nav-menu-meta" class="nav-menu-meta" method="post" enctype="multipart/form-data">
			<input type="hidden" name="menu" id="nav-menu-meta-object-id" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
			<input type="hidden" name="action" value="add-menu-item" />
			<?php wp_nonce_field( 'add-menu_item', 'menu-settings-column-nonce' ); ?>
			<?php do_accordion_sections( 'nav-menus', 'side', null ); ?>
		</form>

However this does not show up. Changing the 'nav-menus' several different settings did not work at all. The function's documentation is not really that helpful : https://codex.wordpress.org/Function_Reference/do_accordion_sections

Any help getting this (and then the menu functionality) to work would be appreciated!

foolix on "Creating a language Link / dissection of a Link"

$
0
0

Hi everybody,

I am using WPGlobus, a translation-plugin to save two versions of a web site, one in German, one in English.

The plugin by default gives me language switchers and language links, however I would like to create links by myself (with php code) that allow to switch the language.

This should be a fairly easy task for most of you.

On this page:

http://example.com/page-one

I would like to display two links:

http://example.com/de/page-one
http://example.com/en/page-one

and on this page:
http://example.com/category/post-one

I would like to get these two links:
http://example.com/de/category/post-one
http://example.com/en/category/post-one

so I would like to insert the /en and /de paths into my hyperlinks.

How can it be done??

Thank you for your support.
F.


amandathewebdev on "Rewrite rules for my custom post types"

$
0
0

Hi all,

I'm stuck and really could use some help! After a lot of research and feedback on several forums, I found a way to remove the slug of my custom post type from my URL. I am using a plugin to add my custom taxonomies into my permalinks. So my permalinks are now right: /%county%/%postname%/ where %county% is a custom taxonomy.

Now to stop getting a 404 I need a redirect rule and I am so close it is painful! But I can't figure it out even after reading the codex on wp_rewrite. Here is my full code that gets the slug out, registers the custom taxonomy to all other taxonomies (which I'm not sure I need), and stop the 404: http://hastebin.com/ceruxiqehu.coffee. But the 404 is the part I am not getting, this part below:

add_filter('generate_rewrite_rules', 'my_rewrite', 9);
 function my_rewrite($wp_rewrite)
 {
    $wp_rewrite->rules = array_merge(array(
        '^([^-]*)-county-([^/]*)/([^/]*)/?$' => 'index.php?custom_taxonomy_slug=county?post_type=county-job'
    ), $wp_rewrite->rules);
}

//No longer use links with /county-job/ as prefix
add_filter('post_type_link', 'my_post_link', 1, 3);
function my_post_link($post_link, $id = 0) {
  $post = get_post($id);
  if(is_object($post) && $post->post_type == 'job') {
      return str_replace('county-job/', '', $post_link);
  }
  return $post_link;
}

I think it's that line: '^([^-]*)-county-([^/]*)/([^/]*)/?$' => 'index.php?custom_taxonomy_slug=county?post_type=county-job'

I have been messing with it for over an hour! I can't find anything online about rewriting a custom post type slug and custom post type taxonomy to go to the post! Right now this redirects to BOTH posts. So I know it's doing something, and I know it's close, but no dice!

Any help would be super appreciated, I'm about to bash my head into a wall!

bschigel on "using web inspector"

$
0
0

I know how to use the web inspector but sometimes when I inspect an element I don't know where to locate what I'm inspecting, it's not part of the style.css file, it'll say
div.dd-select - style attribute and underneath it there's stuff to edit but I can't find where those attributes are located to make adjustments

RaresMan on "Using /wc-auth/v1/authorize endpoint returns error"

$
0
0

Hi there,

I have a VM running WordPress 4.3 w/ WooCommerce 2.4.4, REST api is enabled, I can make requests if I manually create API keys in the admin area. However, I am trying to use the new authorize endpoint.

The only documentation I have been able to find for using the /wc-auth/v1/authorize endpoint is here: https://woocommerce.wordpress.com/2015/08/07/api-settings-and-the-api-authentication-endpoint-in-2-4/

My wordpress VM is on https://devel.wordpress.net and my own app is running on https://devel.api.thriveapp.net:8443

I followed the instructions as provided, and I get the prompt asking to grant access to my app, but on the next screen I get redirected to the following url:

https://devel.wordpress.net/wc-auth/v1/access_granted?app_name=Thrive&user_id=5&return_url=https%3A%2F%2Fdevel.api.thriveapp.net%3A8443%2Fwoocommerce%2Fauthorization%2F&callback_url=https%3A%2F%2Fdevel.api.thriveapp.net%3A8443%2Fwoocommerce%2Fauthorization%2F&scope=read&wc_auth_nonce=76e9c39ce0

And the page says: Error: A valid URL was not provided.

I'm not sure what the problem is, any help would be greatly appreciated.

Thanks,
-Rares

oneruffryder on "Custom post multiple uploader"

$
0
0

I have these two codes http://pastebin.com/78djwMtp

The first part is an array to create a box inside custom posts area

and the below part is to upload an image inside that box

thing is, it uploads in the first box ok, but on the second it uploads also on the first.

I tried changing the below part but I'm not an expert and it could be that the issue is also with the id's (top part as they use the same upload, considering there's java included.

I v also tried to echo below part once more and then just change image1 to image2 but no luck.

Can someone tell me how to work this out?

gnewmann on "Change Link for: "Edit Profile" on Top- Bar"

$
0
0

Hi there,

i searched a lot on this topic, but I didn't find a solution that works for me, probably you guys and girls can help me.

I installed the "Ultimate Member" Plugin, to have an option to edit user profiles in a good look.
I don't like the "Edit User- Dashboard" from Wordpress, because it's not integrated into my page, and on the other side, in my opinion, it looks awful :)
The Side "Ultimate Member" created looks fine to me, but I got the problem that I want to link this better looking "user- edit"- Site to the Button "Edit Profile" on the Top- Bar of Wordpress.

I read about following hook, to do this:

add_filter( 'edit_profile_url', 'modify_profile_url_wpse_94075', 10, 3 );

/**
 * http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/link-template.php#L2284
 *
 * @param string $scheme The scheme to use.
 * Default is 'admin'. 'http' or 'https' can be passed to force those schemes.
*/
function modify_profile_url_wpse_94075( $url, $user_id, $scheme )
{
    // Makes the link to http://example.com/custom-profile
    $url = site_url( '/custom-profile' );
    return $url;
}

I'm new to wordpress, so I don't know where to put this hook. And on the other side it seems static to me, because of the static variables used for the function: add_filter (But at all I'm new to wordpress and php).

Can somebody please explain me, how to change the link in a clean way? I would like to use the hook, or to change the url in the source (but this doesn't seems to be a clean solution).

Thank you in advance.

GNewmann

infotexsupport on "Change post-type rewrite"

$
0
0

in the gdlr_portfolio plugin they define a custom post type something like the below:

register_post_type( 'portfolio',
...
'rewrite'            => array( 'slug' => 'portfolio'  )
...
)

Is it possible to effectively add 'with_front' => false, to that without hacking the original plugin and causing updating issues.
I've tried redefining the register_post_type and it doesn't seem to work.

Any pointers appreciated.

midlot on "Changing the position of widgets in a sidebar"

$
0
0

nicky112 on "Add the_excerpt to the_content"

$
0
0

Hello,

I want to display the the_excerpt above the content for all posts. Here's what I came up with:

add_filter( 'the_content', 'ab0187_the_content' );
function ab0187_the_content( $content ) {
  $content = "<div class=\"excerpt\">" . the_excerpt() . "</div>" . $content;
  return $content;
}

The excerpt is added to it but unfortunately the div gets added below the_excerpt. Why is that happening?

wambamboo on "permalinks causing issues with php includes"

$
0
0

Hello

I'm building my site on a subdomain.

I am using a php include to reference a html file which is in the root folder, like this:

<?php include ABSPATH.'myfile.html';?>

I've also tried this:

<?php include 'myfile.html';?>

If I am using default permalinks, it works great

If I choose any of the other permalinks settings, it only works on whichever page I have set to be the static front page. All other pages just leave a space where the included file should be.

Can anyone please help me?

Cheers x

iteneranter on "Cleaning "Unsafe" WordPress URLs with a Virtual Host"

$
0
0

Hello, everyone!

This post is in reference to this article from 2013. In it, the author identified the following characters that should be encoded in URLs for security reasons: “{”, “}”, “|”, “\”, “^”, “~”, “[”, “]”, and “`”. Also in the article, the author indicated that an earlier version of WordPress (3.5) used at least some of these characters (such as square brackets) by default.

I am looking to automatically remove specific unsafe characters from user-submitted URLs by using specific rewrite protocols associated with a virtual host. (I already know how to do this.) However, I want to make sure that I am eliminating only those "unsafe" characters that are NOT essential to WordPress operations.

Put another way, which of the "unsafe" characters listed above are safe to eliminate from URL requests associated with my website?

dmlWS on "Custom Dashboard Widget to Show Download Links from CPT"

$
0
0

I have a custom post type ('hrbenefitsupload'). The cpt has a file upload field ('upload_paperwork').

I'm trying to display links for logged in users to download the files from a custom dashboard widget.

For example...
User adds new 'hrbenefitsupload' called 'Paid Time Off'. They attach a pdf (paid-time-off.pdf) that explains 'Paid Time Off'.

In my custom dashboard widget, I want to display the name of the new benefit...
Paid Time Off
... and have it link to the PDF (someurl.com/paid-time-off.pdf).

At one point, I was able to list the files, but I can't figure out how to link to the pdf.

Here is the last code I tried:

// CUSTOM DOWNLOADS DASHBOARD WIDGET
add_action('wp_dashboard_setup', 'dml_cpt_downloads_widget');

function dml_cpt_downloads_widget() {
global $wp_meta_boxes;

wp_add_dashboard_widget('custom_help_widget', 'Human Resources Forms', 'dml_cpt_download');
}

function dml_cpt_download() {
echo '<p>Click form name to download.</p>';

$query = query_posts( array( 'post_type' => 'hrbenefitsupload'));

while ( $query->have_posts() ) : $query->the_post();

$download_link = get_post_meta( get_the_ID(), 'upload_paperwork', true );
echo $download_link[ 'guid' ];

}

Thanks for your help.

justravis on "First Image From Post & BFI Thumbs?"

$
0
0

Featured image shows up fine in blog listings, but gray image is shown instead of first image from post - http://monkeyzbusiness.com/

Thoughts?

Functions.php

function get_first_img() {
	#echo "get first image";
  global $post, $posts;
  $first_img = '';
  ob_start();
  ob_end_clean();
  $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  $first_img = $matches [1] [0];

/*
  if(empty($first_img)){ //Defines a default image
    $first_img = "/images/default.jpg";
  }
*/
	#echo $first_img;
  return $first_img;
}

get_first_img() is grabbing the correct image url. I echoed it to make sure.

loop.php

<?php
	#if featured image is not set, use first image in the post.
	#if(get_first_img() ){ echo '.'; }
	if ( has_post_thumbnail() || get_first_img() )// check if the post has a Post Thumbnail assigned to it.
	{
		#echo "has_post_thumbnail() | get_first_img()";
		echo '<div class="blog_img  ">';
		echo '<a href="'.get_permalink().'">';
		if( (get_post_meta( $post->ID, 'kaya_image_streatch', true )) == "0")
		{
			$params = array('width' => '1100', 'height' => '450', 'crop' => true);
		}
		else
		{
			$params = array('width' => '', 'height' => '', 'crop' => true);
		}

		if(!$img_url=wp_get_attachment_url( get_post_thumbnail_id() ))
		{
			$img_url=get_first_img();
		}

		#Test
		#echo $img_url;

		echo kaya_imageresize($img_url,$params,'');
		echo '</a>'; ?>
        	</div>
      <?php }   ?>

Thoughts?

Thanks!

Viewing all 8245 articles
Browse latest View live




Latest Images