How to generate a WordPress plugin install link - wordpress

I'm created a plugin that replaces a previous plugin I wrote and adds some extra stuff too. I want to create an alert in the settings page of my old plugin with a link to download and install my new plugin and inform them that the old plugin is no longer supported by its developer. Currently, from the plugin page of my admin panel, install links look like this:
http://www.example.com/wp-admin/network/update.php?action=install-plugin&plugin=wptouch&_wpnonce=a8d64aa295
It seems to me there are at least two things too keep in mind when creating the URI:
Check whether or not this is a multi-site setup
Make sure I generate the correct nonce.
Does anybody know how to properly do this? Is there anything else I need to consider when generating this URI?
Thanks in advance for your help.

I've found an answer. In wp-admin/import.php, there's a great example of how this work.
Here is my implementation:
$plugin_name = 'my_plugin_name';
$install_link = 'Install ' . $plugin_name . '';
Then just output that link tag anywhere in your admin pages.
If you want to get fancy and add the thickbox modal window effect, just use the function add_thickbox() and attach it to an action that's called in a typical admin request, such as:
add_action('admin_menu', 'my_plugin_add_thickbox');
function my_plugin_add_thickbox() {
add_thickbox();
}
That should do it!

$action = 'install-plugin';
$slug = 'akismet';
wp_nonce_url(
add_query_arg(
array(
'action' => $action,
'plugin' => $slug
),
admin_url( 'update.php' )
),
$action.'_'.$slug
);
Use this. I found this and I am sure it will work.

Related

Finding hooks Wordpress

I know there are lists of hooks for WordPress like --> http://adambrown.info/p/wp_hooks/hook
But if I want to find hooks for a plugin like WC Vendors there is a much shorter list of hooks on their website.
Are 'do_action' and 'apply filter' functions the only thing we can modify?
If given a class like --> https://github.com/wcvendors/wcvendors/blob/master/classes/admin/class-product-meta.php#L10, is there any way to modify it?
Are we limited to the do_action hooks or is there a way to modify other areas as well? Can we use the WordPress hooks to hook into the WC Vendors plugin as well?
Mostly you should try to accomplish any task with hooks, but some tasks are just not possible without actually modifying the actual code. But we all know its not good to modify core code, as all changes disappear after an update. So instead of modifying a class, you can extend it. You can override the current features and also add new ones. Extending a class is as easy as using a relavant hook in functions.php and then extending it in the same file or requiring it from another file. Here is an official tutorial on how to add a new shipping method to the woocommerce shipping class.
Sometimes you dont even need all the hooks, you just need to find the ones that are running on a specific page. For this you can use the code below to list all the current hooks.
$debug_tags = array();
add_action( 'all', function ( $tag ) {
global $debug_tags;
if ( in_array( $tag, $debug_tags ) ) {
return;
}
echo "<pre>" . $tag . "</pre>";
$debug_tags[] = $tag;
} );
Or you can use this plugin "simply show hooks"which is really helpful while development as it gives you an idea of where each hook is being triggered on the page.

Seo yoast plugin, breadcrumbs

This is question on the seo yoast wordporess plugin.
I have a friend who doesn't know that much about code/wordpress/etc, they have an ecommerce site built using magento and a blog using wordpress which is styled to match the main site and they use yoast seo plugin for seo etc. They have asked me to try an get the breadcrumbs working for them in a different way to what i know, from what i can see they want to add a prefix to the breadcrumbs 'home' which links to main site then renaming the blog from home to blog, for example home(main site) > blog(blog) > post.
Now i did just that in the plugin settings but they said that the schema markup wouldn't be complete and said there’s a filter hook called ‘wpseo_breadcrumb_links’ which gives access to the array of URLs and anchor text used to build the breadcrumbs, now i cant find anything on google that explains this or how to start writing it, i do know that it needs to go in the functions file.
Would it be possible to get some help on this.
Thanks in advance and very much appreciated.
Justin
I'm not sure what Schema.org markup has to do with breadcrumbs! :) Schema is used on post/page level. So, they are either oversmarting themselves or I got you wrong.
I think this sample code may be helpful:
add_filter( 'wpseo_breadcrumb_output', 'custom_wpseo_breadcrumb_output' );
function custom_wpseo_breadcrumb_output( $output ){
if( is_product() ){
$from = '<span typeof="v:Breadcrumb">Products</span> »';
$to = '';
$output = str_replace( $from, $to, $output );
}
return $output;
}
It looks like wpseo_breadcrumb_output gives you access to the entire output instead of just the link portion. Please see this page for more details: http://wpquestions.com/question/showChrono/id/8603

pagination fails when including custom variable in permalinks in wordpress

I'm a wordpress newbie here so please go easy on me.
I am working on a wordpress site and I've run into two problems I just can't seem to find the answer to anywhere. I have permalinks set up on my wordpress site, along with paging, so for example, www.mysite.com/links/page/2 sends you to the second page of links.
I just created a custom template that pulls in two different taxonomies with the same tag name. To do that I created a page called tags that uses my custom template and I have a custom link that goes to it with a structure of: www.mysite.com/tags/?tag=mytag This is ugly but it works for testing purposes.
The problem happens when I go to page two and the link is: www.mysite.com/tags/?tag=mytag/page/2 which doesn't work.
I don't want to mess up my current permalinks, but I want to add a new rule that a) stops the page from breaking, and b) actually looks good. I would like to have the link just be www.mysite.com/tags/mytag/page/2
After a ton of digging I was able to get what I thought was the right code. This is what I've added to my functions.php in my theme directory:
add_action( 'generate_rewrite_rules', 'my_tag_rewrite_rules' );
//add_filter( 'query_vars', 'my_tag_query_vars' );
function my_tag_query_vars( $vars )
{
// $vars[] = 'tag'; // might not need this because 'tag' should already be registered
}
function my_tag_rewrite_rules( $wp_rewrite )
{
$wp_rewrite->rules = array(
'tags/([^/]+)/page/?([0-9]{1,})/?$' => $wp_rewrite->index . 'tags/?tag=' . $wp_rewrite->preg_index( 1 ) . '&paged=' . $wp_rewrite->preg_index( 2 ),
'tags/([^/]+)/?$' => $wp_rewrite->index . 'tags/?tag=' . $wp_rewrite->preg_index( 1 )
) + $wp_rewrite->rules;
}
(I commented out the add_filter part because 'tag' was already a query variable wordpress recognized). From what I read it looked like all I needed to do was go into the wordpress dashboard and go to settings->permalinks and supposedly it would change the .htaccess. It didn't.
My first question, is: is my rewrite rule correct? and secondly, what else do I need to do to get wordpress to update the .htaccess file?
Thanks a ton for any help!

What would cause edit buttons for plugins in wordpress plugins page to disappear?

in the plugins page, under each plugins' name usually there are buttons/links like "Deactivate | Edit | Settings". Recently on one of my sites the "Edit" (and "Settings") button has disappeared. I have just "Deactivate" or "Activate | Delete".
My question is - what could cause this?
I am logged in as an administrator, so I should see the buttons. I suspect that something might have vent wrong with the installation of the last plugin but I am not sure.
Is there some scenario when these buttons get disabled (hidden) or do I have a bug / error?
EDIT:
This is happening on the server. I also have the exact same files (just checked with a comparer) running on my local computer, where plugins have all the buttons. I am now looking in the DB to find differences, but so far have not found anything significant.
Sounds like a file permissions error, make sure the user the web server is running as (typically www-data or similar) has write permissions to the plugin files.
Those "buttons" are called "plugin_action_links" and are/can be set by the plugin´s author.
Some plugin authors choose do not include "settings" .
If you have updated the plugin it might be that the new version does not include that ??
Does the plugin itself work ?
Is it the exact same version as on the other sites ?
As for the "edit" link - it can also be set to not appear or be disabled by third-party plugins that has to do with user-permissions or visibility of links (like adminimize for example)
example how to disable those links for plugin authors :
add_filter( 'plugin_action_links', 'disable_plugin_footlinks', 10, 4 );
function disable_plugin_footlinks( $actions, $plugin_file, $plugin_data, $context ) {
// Remove edit link. if you want to remove selective use if statement
if ( array_key_exists( 'edit', $actions ) )
unset( $actions['edit'] );
// Selectively remove deactivate link for specific plugins with if statement
if ( array_key_exists( 'deactivate', $actions ) && in_array( $plugin_file, array(
'plugin1_specific_name_folder_/plugin1_name.php',
'plugin2_name_folder_/plugin2_name.php'
)))
unset( $actions['deactivate'] );
return $actions;
}

How do I create a new page from my Wordpress plugin

In my wordpress plugin, I want to generate a page on the fly.
I could have the user create the page for me. But I would rather not have them do any steps. Just let them activate it and it works.
So I was wondering is there a way for me to do this, which maintains all the functionality within the plugin.
My initial idea was to add a rewrite rule
add_rewrite_rule('my_page/$', 'wp-content/plugins/my_plugin/page.php', 'top');
Then in my plugin I can have a page.php. Which works well, but I cannot get the header/footer etc.
I am very new to wordpress, so chances are i am missing somethign obvious.
You could create a 404 page code snippet that does wp_insert_post() and then redirects the user to it.
Your theme's 404.php would look like this:
<?php
$post_id = wp_insert_post("post_title" => "my post title", "post_content" => "Lol");
header("location:" . get_permalink( $post_id ) );
die();
?>

Resources