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

Xavier Serrano on "Plugin wp-admin rename and constants"

$
0
0

HI i was just wondering certain things about developing a plugin for myself the right wordpress way. In terms of wordpress constants and renaming the wp-admin. how would be the best way to create a plugin that defines certain wordpress constants such as wp-debug, wp_cache, SITECOOKIEPATH, ADMIN_COOKIE_PATH. Ive seen plugins such as W# total cache that write onto the wp-config in order to define WP_CACHE constant. Ive also seen some security plugins that in turn change the template of the login page in order to change the wp-admin. Is it ok and secure for me to recreate the functionality of w3 total cache in order to add and change wp constants on the wp-config?


Guido on "Get widget instance with wp_options"

$
0
0

Hi again,

I have a widget with wp_options name: my_widget.

Within my widget file I can retrieve a value like this:

if ( !empty( $instance['title'] ) ) {
	echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title'];
}

But how do I retrieve this value outside the widget file?

I've read something about get_option, but don't understand how to get a single value from my my_widget option, such as: $instance['title']

Thanks in advance!!

Guido

driftmagazine on "Where do I gather various information on only one page?"

$
0
0

Hi!
I have made my own theme and use quite many Custom post type. I also use page and post.
I would now like to gather all the info one place. What is the best and easiest way to get to?
I also use a lot Advanced Custom Field, so it may well be easy to use. I have tried this as a basis?

Page
I name the topic and make a template where I collect multiple sidebars?
I can not get it to work.
http://driftmagazine.se/driftsm/

Custom post type / taxonomy categori arkiv
http://driftmagazine.se/blog/kalendercategory/drift-sm/

Category of post

http://driftmagazine.se/blog/category/event/drift-sm/

Mariah_A_C on "wp_handle_upload () setting $overrides correctly"

$
0
0

Yes I have searched and yes I have found lots of answers, but I am not sure I have found the correct answer.

I have a form with an image upload. I am using wp_handler_upload() to upload the image to my uploads file. The code works fine as long as 'test_form' => false is in the $overrides array. So here is my question everything I have found online says to set this this way, but in the codex it says

$overrides
(array) (optional) An associative array to override default behaviors. When called while handling a form, 'action' must be set to match the 'action' parameter in the form or the upload will be rejected. When there is no form being handled, use 'test_form' => false to bypass this test, and set 'action' to something other than the default ("wp_handle_upload") to bypass security checks requiring the file in question to be a user-uploaded file.

Default: false

The source file says

// All tests are on by default. Most can be turned off by `$overrides[{test_name}] = false;
$test_form = isset( $overrides['test_form'] ) ? $overrides['test_form'] : true;
$test_size = isset( $overrides['test_size'] ) ? $overrides['test_size'] : true;`

// If you override this, you must provide $ext and $type!!
` $test_type = isset( $overrides['test_type'] ) ? $overrides['test_type'] : true;
$mimes = isset( $overrides['mimes'] ) ? $overrides['mimes'] : false;`

// A correct form post will pass this test.
` if ( $test_form && ( ! isset( $_POST['action'] ) || ( $_POST['action'] != $action ) ) ) {
return call_user_func( $upload_error_handler, $file, __( 'Invalid form submission.' ) );
}`

So my questions are first how do I set action to my forms action parameter? I tried 'action'=>'' which didn't work.

Second is setting 'test_form' => false just an easy fix that is bypassing a security measure? or is it really supposed to be set that way? The only example in codex uses it and every example I have found online uses it, but it says a form should be able to pass the test. I am so confused.

Here is my current code:

if ( ! function_exists( 'wp_handle_upload' ) ) {
				require_once( ABSPATH . 'wp-admin/includes/file.php' );
			}

			$uploadedfile = $_FILES['fileToUpload'];

			$upload_overrides = array( 'test_form' => false, 'mimes' => array('jpg' => 'image/jpeg', 'png' => 'image/png') );

			$movefile = wp_handle_upload( $uploadedfile, $upload_overrides );

			if ( $movefile && !isset( $movefile['error'] ) ) {
				echo "File is valid, and was successfully uploaded.\n";
				//var_dump( $movefile);
				$image=$movefile[url];

			} else {
				/**
				 * Error generated by _wp_handle_upload()
				 * @see _wp_handle_upload() in wp-admin/includes/file.php
				 */
				echo $movefile['error'];
			}

and the form

<form method="post" action="<?php echo htmlspecialchars('');?>" enctype="multipart/form-data">
   <input type="file" name="fileToUpload" id="fileToUpload"><br>
   <input type="submit" name="submit" value="Save">
</form>

andy.newby on "Getting stuff out of the main script-loader.php"

$
0
0

Hi,

I'm trying to optimize my site, and as such want to put some stuff into a core file, and other stuff get rid of. For example, the jquery-migrate one I want to get rid of.

In wp-includes/script-loader.php, we have stuff like:

// jQuery
	$scripts->add( 'jquery', false, array( 'jquery-core', 'jquery-migrate' ), '1.11.3' );
	$scripts->add( 'jquery-core', '/wp-includes/js/jquery/jquery.js', array(), '1.11.3' );
	$scripts->add( 'jquery-migrate', "/wp-includes/js/jquery/jquery-migrate$suffix.js", array(), '1.2.1' );

I want to get rid of those, and change it for the 2.2.2 version (without migrate). I this may cause issues with some plugins, but I'm willing to take that chance.

Then, we have stuff like:

$styles->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.css', array( 'dashicons' ) );

I want to take that CSS out (as I know its not going to change), and plop that into my main CSS file. However, I don't seem to be able to do this in the themes functions.php script - any suggestions as to how it can be done?

Thanks!

Andy

tmask2 on "Remove first/last name from edit-account page"

$
0
0

I need to remove the first and last name from the my-account/edit-account/ section. I found old code but none of it is working for some reason. Ive tried:

add_filter( 'woocommerce_save_account_details_required_fields', 'wc_remove_required_last_name' );

function wc_remove_required_last_name( $fields ) {
	unset( $fields['account_last_name'] );

	return $fields;
}

But nothing happens. Any insight is appreciated

sherafff on "[Plugin: EasyDigitalDownloads] Category as slug"

thisnluv on "Adding custom post types into latest post grid plugin"

$
0
0

I have a masonary styled grid on my blog and I am wanting to create a custom post type for my instagram posts, and shop feed items.

For example:

<script type="text/html" id="post-item-template"><div class="item post" data-type="post">
	<div class="post-item {text_color}">
	<a class="btn overlay-btn" href="{url}">
		<figure class="image post-image">
			<img src="{image_url}">
		</figure>
		<header class="header">
			<span class="label">{category}</span>
			<h3 class="title post-title">{title}</h3>
			<span class="read-more-btn tertiary-btn">read more</span>
		</header>
	</a>
</div></div></script>

<script type="text/html" id="instagram-item-template"><div class="item instagram {size}" data-type="instagram">
	<div class="instagram-item ">
	<a class="btn" href="{url}" target="_blank">
		<figure class="image instagram-image">
			<img src="{image_url}">
		</figure>
		<div class="instagram-meta meta">
			<div class="instagram-logo">
				<i class="icon-instagram icon"></i>
				<span class="name">@thehautepursuit</span>
			</div>
			<div class="instagram-stats stats">
				<span class="likes">{likes}</span>
				<span class="comments">{comments}</span>
			</div>
		</div>
	</a>
</div></div></script>

<script type="text/html" id="product-item-template"><div class="item product {size}" data-type="product">
	<div class="product-item {size}">
	<a class="btn overlay-btn" href="{url}">
		<figure class="image product-image">
			<img src="{image_url}">
		</figure>
		<header class="header">
			<span class="label">THPSHOP</span>
			<h4 class="title product-title">{title}</h4>
			<span class="price">{price}</span>
			<span class="buy-btn tertiary-btn">buy now</span>
		</header>
	</a>
</div></div></script>

<script type="text/html" id="custom-item-template"><div class="item custom {size}" data-type="custom">
	<div class="custom-item {text_color}">
	<a class="btn overlay-btn" href="{url}">
		<figure class="image custom-image">
			<img src="{image_url}">
		</figure>
		<header class="header">
			<span class="label"></span>
			<h3 class="title custom-title">{title}</h3>
			<span class="read-more-btn tertiary-btn">read more</span>
		</header>
	</a>
</div></div></script>

This is an exmaple from a live site that I am wanting to emulate...

How is this done? Any reference material or advice would be great...


blueclochard on "WP 4.4: remove json-api and X-Pingback from HTTP Headers"

$
0
0

Starting with 4.4 WordPress adds a new HTTP Header. It looks like this:

Link: "<http://www.example.com/wp-json/>; rel="https://api.w.org/""

Does anyone know how to remove it? I know the REST API can be disabled, but I still would like to remove the HTTP Header as well.

Also starting with 4.4 old methods to remove the X-Pingback HTTP Header no longer work. This is the header I am talking about:

X-Pingback: "http://www.example.com/xmlrpc.php"

I would be very happy if anyone could tell me how to remove both of these headers.

Guido on "Uninstall.php: remove custom taxonomy and term"

$
0
0

Hi,

I have this in my uninstall.php in order to delete my custom taxonomy called 'event_cat' and all terms:

// If uninstall is not called from WordPress, exit
if ( !defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit();

// Delete terms
$terms = get_terms( 'event_cat', array(
	'fields' => 'ids',
	'hide_empty' => false
) );
foreach ( $terms as $value ) {
	wp_delete_term( $value, 'event_cat' );
}

global $wpdb;

// Delete taxonomy
$table = $wpdb->prefix . "event_cat";
$wpdb->query( "DROP TABLE IF EXISTS $table" );

But after de-installing plugin custom taxonomy and terms are still listed in database.

Am I missing something?

Guido

KatrineDS on "Woocommerce Checkout Add-ons filter"

$
0
0

Hi guys,

I'm trying to make a filter to remove a Woocommerce Checkout Add On, so it doesn't show for logged in users. It's a field that requires customers to buy a membership before checking out - but obviously they don't have to, when they return to buy more and already have an account and a membership.

I've tried this, but it's not working.

add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
if( is_user_logged_in() ){
unset($fields['wc_checkout_add_ons_2_field']);
$fields['wc_checkout_add_ons_2_field'] = array();
}
return $fields;
}

Could someone please help point me in the right direction?

Link to site: http://www.enjoi.dk/checkout

Thanks in advance :)

pixar1942 on "Automatically minify the size or dimension of image attach during the upload"

Dotan Cohen on "Tool for quickly connecting to MySQL from any WP directory."

$
0
0

Hi all, as I'm working on plugins and exploring the WP core, I find that I often need to connect to MySQL to check something. I wrote a tool that searches for the wp-config.php file from any WP directory and returns the connection string.

$ pwd
/var/www/wordpress/public_html/wp-content/themes

$ wpdb
mysql -u"AzureDiamond" -p"hunter2" -h"localhost" some_db

$

It can optionally connect directly or produce a mysqldump string complete with suggested time-based filename:

$ wpdb -c
Welcome to the MySQL monitor.  Commands end with ; or \g.
mysql> SELECT COUNT(*) FROM wp_posts;
+----------+
| COUNT(*) |
+----------+
|      351 |
+----------+
1 row in set (0.01 sec)

mysql> EXIT;

$ wpdb -d
mysqldump -u"AzureDiamond" -p"hunter2" -h"localhost" some_db --skip-opt > some_db_2016-02-10_1602.sql

$

You can get the tool from my Github repo:

https://github.com/dotancohen/wpdb

If you guys need any more features, or find a bug, please let me know and I'll be happy to add it. Enjoy!

ledocool on "Restrict posting by taxonomies"

$
0
0

I have a custom post type with custom taxonomy. Is there a way to set restrictions on post creation for certain taxonomy term? What I look for is capability-based solution so I can hook up Groups (or any other) plugin for membership management.

I know groups allows read restrictions on content, but what I also need is posting restriction.

pete_398 on "Is this an exploit ?"


Guido on "Echo checkbox input field"

$
0
0

Hi,

Rookie question, but I'm having trouble echoing a checkbox field in php syntax:

<input name="my_field" type="checkbox" id="my_field" value="yes" <?php checked('yes', $value ); ?> />

Obviously this doesn't work:

echo ' <input name="my_field" type="checkbox" id="my_field" value="yes" <?php checked('yes', $value ); ?> /> ';

Who can help me out.. or maybe I just need some sleep.. ;-)

Guido

TrisectDevelopment on "Login to WP from PHP"

$
0
0

I'm working with custom pages in WP and I have beeb making a few pages.
In the database I have created a new table for profiles.

I have made a custom PHP page where you can create a new profile. At the same time it creates a new WP user.

I have also made a custom PHP page where you can login to the system (new table).

Here in this file I want to also let the user login to WP, but here I have failed so far.

Heres the code I have tried:

$creds = array(
        'user_login'    => 'username',
        'user_password' => 'password',
        'rememember'    => true
    );
    $user = wp_signon( $creds, true )

When I then go to /wp-admin page is okay, but I have an forum page that only WP users can se and this page I'm not allowed to visit.

If I login to WP with the same credential the normal way (wp-login) I can see the forum fine.

So my question is simply:

How do I login to a WP site in PHP code?
After login I want to go the the main page of the site.

stuartbennett2012 on "Add To Calendar Using URL Params"

$
0
0

I have a form on my wordpress site. When I submit that form it takes you to a thank you page.

On that thank you page I use a wordpress plugin called URL Params to display a confirmation of the booking info.

But i want to insert an add to calendar button that uses the params in the url to the thank you page to set the following

event name
event location
event date
event start time
event end time (start time + a fixed event length to calculate end time)

how can i acheive this easily within wordpress?

waubau on "Get all post types, taxonomies and terms"

$
0
0

Hi,
For a plugin I need to get all the registered custom post types, its taxonomies and their terms.
As I currently see the solution I need two nested loops:

Get all the post types using get_post_types(). Then loop foreach post_type with get_object_taxonomies() to get all associated taxonomies and then loop foreach taxonomy with get_terms().

As a result I will get 3 nested arrays of post_types -> taxonomies ->terms.

The solution looks feasible but a bit complicated. Is there any way just to get some kind of post_type object with all these taxonomy and terms data in one go?

lauryn77 on "show list of tag by category with custom permalinks"

$
0
0

Hi!!
I've seen that using permalink /category/nameofcat/?tag=/nameoftag
I get what I want: a list of post in a specific category with that tag.

Now: how can I get a tag list related to the category with this permalink structure?
I already changed tag base with ?tag= but I can't get to append it to the category structure already existing: how can I do? Thanks!

Viewing all 8245 articles
Browse latest View live




Latest Images