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

ChinchillaSanchez on "Replace Password Protect with QR code?"

$
0
0

I'm trying to develop a plugin that creates a bitcoin paywall. I want to create a checkbox similar to the Password Protect Visibility option. Instead a password form appearing, I want a QR code linking to my bitcoin wallet. What would the best way to implement this be?


eclipsedmind on "Need help integrating adsense to post thumbnail"

$
0
0

Hello people,

I'm new here and even more new to the world of coding, so i'm sorry if i sound dull. I will try to be as specific as my (lack of) knowledge allows.
I'm running a wp blog with a decent number of visitors, but a percentage of ad clicks is very low.
I was able to get my hands on the code that integrates adsense code to a featured image (post thumbnail) in the post. As i lack knowledge in coding i would very much appreciate your help. I know that the code must be placed into Single Post (single.php), but when I do that the article content duplicates itself in a way that the new re-coded post content just continues after original text. I'm missing something, but don't know what. I suppose I should add some more codes to tell the theme to overwrite settings in single.php but to keep all other settings.

The post thumbnail in article should look like this one.

Thanks in advance,
ecl

josefe03 on "show menu plugin to Suscriptor Role"

$
0
0

i create a plugin, This has a menu inside setting options where a page appears, as I show this page to subscribers.

focus97 on "Extend Wordpress (4.x) session and nonce"

$
0
0

Disclaimer - I posted this on StackExchange but also want to post here, as I'd love some insight.

We've got a small web application that allows users to log in (via WordPress) and remain logged in for a max 15 min session for security purposes. Because most sessions will last longer, I have a small ajax call that's made on each click of the html document itself.

The ajax call itself fires to the /admin-ajax.php file, and it hits a function (in functions.php). Below is that function:


function extend_my_session_yo(){
$user_id = get_current_user_id();
wp_set_auth_cookie($user_id, false, true);

$new_logout = wp_logout_url();

if ( is_user_logged_in() ) {
echo 'session extended 15 mins ' . $new_logout;
}
// if a user is *not* logged in, Wordpress just outputs a "0".
die();
}

The wp_set_auth_cookie() does the hard work. It correctly allows for (on each click) an extended 15 mins session. The problem is if someone tries to logout. The current logout link is echo'd via wp_logout_url(), but that logout url has a nonce from the moment it's created by WordPress.

So in the function above, I'm generating a new logout url (and from the WP core code it seems that this is generated by getting the session token from the new cookie), but each click of the new logout url gives the Wordpress Failure Notice page indicating a nonce mismatch. I've even gone so far to copy code from pluggable.php (for wp_verify_nonce()) for checking the hash_equals() function for $expected vs $nonce and they're equal. Yet I still get nonce errors.

Does anyone know how to set a new auth/logged_in cookie while also setting a new nonce to avoid these errors?

Alain on "checkbox issue with wordpress update_post_meta()"

$
0
0

Hi,

usually it is a PHP issue but in my case i read on internet several posts about the way how to do it and it seems my code is correct, so i do not understand where is the problem.

I'm creating a plugin that should modify posts appearance.
For that i have a meta box where i have a checkbox and i want to store in DB the status of that check box (checked or not).
For that i use the following code:

/*
 * Function to render the meta box added by the plugin in post
 */
function rgt_metabox_callback( $post ) {

    // Add an nonce field so we can check for it later.
    wp_nonce_field( 'rgt_meta_box', 'rgt_meta_box_nonce' );

    /*
     * Use get_post_meta() to retrieve an existing value
     * from the database and use the value for the form.
     */
    $rgt_post_images_slider = get_post_meta( $post->ID, '_rgt_post_images_slider', true );
    $rgt_post_images_slider_usage = get_post_meta( $post->ID, '_rgt_post_images_slider_usage', true );

    echo '<label for="rgt_post_thumbnail_slider">';
    if($rgt_post_images_slider_usage == "true"){
        echo '<input type="checkbox" id="rgt_image_list_usage" name="rgt_image_list_usage" checked="checked" value="true" />';
    }
    else{
        echo '<input type="checkbox" id="rgt_image_list_usage" name="rgt_image_list_usage" value="true" />';
    }

    _e( 'Use images slider instead of Featured image.', 'rgt-post-thumbnail-slider-plugin' );
    echo '</label> ';

and later:

function rgt_save_meta_box_data( $post_id )
{

    /*
     * We need to verify this came from our screen and with proper authorization,
     * because the save_post action can be triggered at other times.
     */

    // Check if our nonce is set.
    if (!isset($_POST['rgt_meta_box_nonce'])) {
        return;
    }

    // Verify that the nonce is valid.
    if (!wp_verify_nonce($_POST['rgt_meta_box_nonce'], 'rgt_meta_box')) {
        return;
    }

    // If this is an autosave, our form has not been submitted, so we don't want to do anything.
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }

    // Check the user's permissions.
    if (isset($_POST['post_type']) && 'page' == $_POST['post_type']) {

        if (!current_user_can('edit_page', $post_id)) {
            return;
        }

    } else {

        if (!current_user_can('edit_post', $post_id)) {
            return;
        }
    }

    /* OK, it's safe for us to save the data now. */

    // Make sure that it is set.
    if (!isset($_POST['rgt_image_list'])) {
        return;
    }

    if (!isset($_POST['rgt_image_list_usage'])) {
        return;
    }

    // Sanitize user input.
    $my_data = sanitize_text_field($_POST['rgt_image_list']);

    $img_slider_usage = "";
    error_log("value of checkbox (in SAVE): ".$_POST["rgt_image_list_usage"]);

    if (isset($_POST["rgt_image_list_usage"])) {
        $img_slider_usage = $_POST['rgt_image_list_usage'];
    }

    // Update the meta field in the database.
    update_post_meta( $post_id, '_rgt_post_images_slider', $my_data );
    update_post_meta( $post_id, '_rgt_post_images_slider_usage', $img_slider_usage );
}
add_action( 'save_post', 'rgt_save_meta_box_data' );

However when checkbox is not checked, it does not clear value in DB.
So where is my mistake ?
thx

reportkanpur on "how i get back my admin panel"

$
0
0

i purchase and mainten my web site from a vender .and when i ask for my admin panale for changes .they dids not give me support.how get it back p[lz tell me .i want to download Facebook and twitter auto post plugin plz help me.
http://www.worldkhabarexpress.com

icetek on "html entity problems with xmlrpc python."

$
0
0

If I try to send HTML through post.content via python Wordpress xmlrpc it scrambles up and renders & html entity characters breaking HTML entirely. What could cause this and how do I fix it?

kmoksha on "How to have two sites with same content, diff themes running from one database"

$
0
0

I would like to have 2 sites with identical content and different themes running from same database.

On adding a post, it should be updated on both the sites should have updated that post although with a different link.

I read older articles on this - https://wordpress.org/support/topic/two-sites-two-themes-one-database-same-content

According to the thread, it is mentioned that I have to do this -

In the second sites directory do the following:

In the wp-settings.php file change the options database value to something like this:

// Table names
$wpdb->posts = $table_prefix . 'posts';
$wpdb->users = $table_prefix . 'users';
$wpdb->categories = $table_prefix . 'categories';
$wpdb->post2cat = $table_prefix . 'post2cat';
$wpdb->comments = $table_prefix . 'comments';
$wpdb->links = $table_prefix . 'links';
$wpdb->linkcategories = $table_prefix . 'linkcategories';
$wpdb->options = 'YOURNEWPREFIX_options';
$wpdb->postmeta = $table_prefix . 'postmeta';
$wpdb->usermeta = $table_prefix . 'usermeta';

$wpdb->prefix = $table_prefix;

See how I've removed $table_prefix . in the options line?
Instead of YOURNEWPREFIX put something like 'site2' or whatever you want.

But I did not find this code in the wp-settings.php file

Please advise and help


hanspralon on "Result limited to 10 items"

$
0
0

We have a website that developed by third party vendor some times ago. Now we find out there is one features (Post Category) that could only show 10 lines in our website, while at back office (admin panel), the items are more than 10. I need to show all items. Where do i start to fix this? tia.

JRM47R1X on "Advanced WP_Query Problem, any help appreciated!"

$
0
0

Hey guys,

I'm trying to come up with a way of querying a CPT by a specific author but also if a meta_key has a specific value.

For example, my CPT has an author ID attached to it as well as a 'recipient' custom field. What i need is all posts of this type by this author as well as all posts of this type where 'recipient' = this author.

(Hope I've explained that well enough!)

I'm usually pretty OK with SQL but just having a random brain fart moment and can't figure this one out. Like I said, any help is much appreciated!

dvpl on "allow wordpress shortcode in wp_kses()"

$
0
0

Hi,
I have used wp_kses() function on the_content() as :

echo wp_kses(get_the_content(), $allowed_html );

According to need allowed tags are working fine except wordpress shortcode ex : [shortcode].

shortcodes are printing as it is written in backend content area. I need them to work as usual.

I need your valuable help.
Thanks.

gislef on "JQuery conflict"

$
0
0

Hello,

In functions file I inserted the css and js Bootstrap:

<?php
function add_theme_scripts(){
wp_enqueue_style('bootstrap-css', get_template_directory_uri() . '/css/bootstrap.css');
        wp_enqueue_style('bootstrap-min-css', get_template_directory_uri() . '/css/bootstrap.min.css');
        wp_enqueue_style('bootstrap-theme-css', get_template_directory_uri() . '/css/bootstrap-theme.css');
        wp_enqueue_style('bootstrap-theme-min-css', get_template_directory_uri() .  '/css/bootstrap-theme.min.css');

wp_enqueue_script('bootstrap-js', get_template_directory_uri() . '/js/bootstrap.js', array('jquery'), '1.0', false);

	wp_enqueue_script('bootstrap-js', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery'), '1.0', false);

	wp_enqueue_script('jquery-js', get_template_directory_uri() . '/js/jquery.js', array('jquery'), '1.0', false);
}

add_action( 'wp_enqueue_scripts', 'add_theme_scripts' );
?>

I know that by default loads the wp-includes / js / jquery / jquery.js, but the point is that the modal and toggle the botstrap were not working so I had to call the function above the jquery that within the theme folder (which is the same version of that in wp / includes):

wp_enqueue_script('jquery-js', get_template_directory_uri() . '/js/jquery.js', array('jquery'), '1.0', false);

In all scripts put false, so do not load in the footer but in the header, script bootstrap in the footer does not work properly.

Ok bootstrap, all scripts running but has a menu plugin (not using bootstrap) that with the code below loads the jquery located in wp-include:

wp_enqueue_script( 'jquery' );

if I shot function file the snippet below:

wp_enqueue_script('jquery-js', get_template_directory_uri() . '/js/jquery.js', array('jquery'), '1.0', false);

the bootstrap scripts do not work correctly but the plugin works perfectly. If I leave, everything related to bootstrap works but not the menu.

the menu plugin uses the standard wordpress jquery, the jquery of bootstrap uses the same version of standard wordpress jquery

How can I fix?

Sergejack on "Why is my plugin's version not up to date?"

$
0
0

this plugin: https://wordpress.org/plugins/this-page-needs-files/

Has a version 1.0.1, when you download the zip file, it's named according to 1.0.1, and inside the readme.txt the stable tag is 1.0.1. Yet the download button show "1.0.0" and the "wordpress version/plugin version" dropdown also shows 1.0.0 as the current one?

What can I have done wrong?

vamonos on "How to hide custom field if it stays empty ?"

$
0
0

Hi everybody,

I have different custom fields on listings and in single-page views, which can be filled through the backend.
Now I'm trying to hide all empty custom fields or rather where nothing has been entered because these fields are not needed in different cases.
Everything is working nice, but to hide the fields seems to be a bit tricky.
This is for example what I've tried at last:

<li>
<div class="customcontainer">Rental-Car:</div>
<?php $Rentalcar = trim( get_post_meta($post->ID, "rentalcars", true) );
if( !empty( $Rentalcar ) ) :
?>
<?php echo $Rentalcar ?>
<?php
else :
  // Output the info you want if source isn't set
endif;?>
</div>
</li>

I've tried now different code-combinations..but I don't get it to work.
Can please someone help?

Thanks in anticipaton,
vamonos

TavrinWins on "[Plugin programming] Adapting the 'Posts' menu"

$
0
0

Hi,

I'm creating a WordPress plugin.
I want the plugin to have a 'Products' menu in the WordPress back-end (admin) section where you can view/add/edit/delete products.
The pages to manage these products should be nearly the same was those of the standard WordPress 'Posts' (where you can manage your posts).

Here comes my question:
Can I just copy the existing php files that make up the 'Posts' menu and modify them? Or is this bad practice?
Or would it be better to just start from scratch?

Thanks!


DanielAGW on "Using PHP closures in class-based plugin"

$
0
0

Hello,
I was recently updating my plugin when I realized that I don't know how to use PHP closures properly within filters/hooks in a class-based plugin.

Basically this is what I wanted to do:

add_action('admin_bar_menu', function(){
	add_filter('get_avatar', 'some_function');
}, 0);

So we have two typical WP hooks, one inside another - we're using anonymous function with admin_bar_menu action and we're filtering get_avatar with the output of function named some_function.

That's easy and it would have worked... if only my plugin wasn't an object. And because I realised I don't know how to use anonymous functions with WP hooks in class-based plugins, I ended up doing this:

class Some_plugin {

	public function __construct(){
		add_action('admin_bar_menu', array($this, 'some_unnecessary_function'), 0);
	}

	public function some_unnecessary_function(){
		add_filter('get_avatar', array($this, 'some_function'), 10);
	}

	public function some_function(){
		//do something
	}

}

$some_plugin = new Some_plugin();

This solution works, of course, but I am not very happy with the way it is written. Declaring another method just to make it work, instead of using perfectly-suited closures which were born to serve exactly this purpose, made me look for the solution, but I just couldn't find anything. I know how to use closures with WP hooks, I know how to write object-oriented plugins, but I don't know how to use closures with WP hooks in an object-oriented plugin. Any ideas?

Thank you for your time.

Cheers,
Daniel

fastbysuzuki on "Table in 2012 theme"

$
0
0

Hi
I want to put a table in a page without using a theme, I am trying to learn some code my attempt has resulted in the table working however the table border and column division lines do not show on the published page. The row lines show but very feint could someone point out what is wrong please?
Site is under construction and maintenance is on.
The code I have used is below.

<table style="text-align: center; height: 152px;” border=”1″ cellspacing=”0″ cellpadding=”0″ width=”390″>

<tbody>

<tr style=”background-color: #e9e9e9; font-weight:bolder;”><td>Title 1 </td>
<td>Title 2</td>
<td>Title 3</td>
<td>Title 4</td>
</tr>

<tr>
<td>Detail One</td>
<td>Detail Two</td>
<td>Detail Three</td>
<td>Detail Four</td>

</tr>

<tr>
<td>Detail One A</td>
<td>Detail Two A</td>
<td>Detail Three A</td>
<td>Detail Four A</td>

</tr>

</tbody>

</table>

Brayll on "Add New "Display Name As" Option - Combination of Username and First/Last Name"

$
0
0

Hello fellow Wordpress coders,

How's it going? I've been a Wordpress developer for the past 3 years or so, but have been developing HTML & CSS and a bit of PHP for the past decade. I'm currently working on an esports (electronic sports) publication theme based off of Wordpress and I've (for the first time) encountered something I'm stumped on.

So basically - in the esports industry, you're name is display as First Name "Nickname" Last Name. For example, mine (as a writer) is Jacob "Brayll" Wolf. What I'm wondering is, how would I change (assuming it's user.php in wp-includes) to compensate for an option in the "Display Name As" field for First Name "Nickname" Last Name.

I'd like this to be available to all users on my site, as they're freelancers and they can have that formatting for their work.

Any clue on how to do this?

paulaespindola on "My website is gone and I don't know what to do"

$
0
0

So this is what happened: My website is gone.
This is the second time it happens this week and I don't know what kind of thing I am doing wrong.
First time I was putting the code of Google Analytics on it and suddenly it dissapeared.
Never knew what happened and I had to do all the web again.
Now I cannot do that! I can't restart my website everytime it's gone!
I wanted to erase the message from bluehost that says "coming soon". I read some advices in forums telling that I needed to delete the file comingsoon.php from my ftp.
I was freakily scared of doing it because due to what already happened about four days ago... I was fearing that my website was gone again.
And that is exactly what happened.
I don't know what to do!! Please help me!

(I use bluehost)

Nic727 on "Appoinment+ add a 3rd service without paying?"

$
0
0

Hi,

I'm a student and one of my client (yes we have a client) want an appointment option for the website, so I found appointment+ which is what I was looking for (because other one look ugly in screenshots), but it only allow 2 services providers (employees) in the free version. I need 3!!!

The premium plugin price is $19 per month, but I don't want to pay this much for one employee. Do you know if it's possible to enter in the file to allow 3 services providers. I really want to support them creating this plugin, but 19/months for one person and I don't have a job to pay that every month... You understand right?

Thank you

Viewing all 8245 articles
Browse latest View live




Latest Images