How to Create a Wordpress Plugin in 10 Minutes Flat - How to Create a Wordpress Plugin in 10 Minutes Flat

How to Create a WordPress Plugin in 10 Minutes Flat

Today, We want to share with you How to Create a WordPress Plugin in 10 Minutes Flat.In this post we will show you how to create plugin in WordPress step by step, hear for how to create plugin in wordpress step by step with example we will give you demo and example for implement.In this post, we will learn about Create a Custom WordPress Plugin From Scratch with an example.

How to Create a WordPress Plugin in 10 Minutes Flat

There are the Following The simple About How to Make a Word-press Plugin in 10 Minutes Flat Full Information With Example and source code.

As I will cover this Post with live Working example to develop how to create plugin in wordpress with example, so the create wordpress plugin from scratch for this example is following below.

Step 1: Structure of the WordPress Plugin

|-new-tab-redirect-plus
|--new-tab-redirect-plus.php
|--readme.txt

Step 2: Coding WordPress Plugin

new-tab-redirect-plus.php

<?php
/**
 * New Tab Redirect Plus Plugin is the Open Redirect Comment Links in New Tab/Window.
 * Open WordPress Comment Links in New Tab/Window (add target=”_blank”).
 *
 * @package Pakainfo New Tab Redirect Plus Plugin
 * @author Pakainfo
 * @license GPLv2
 * @link https://pakainfo.com/jobs/technology/programming/wordpress/
 * @copyright 2019 Pakainfo, LLC. All rights reserved.
 *
 *            @wordpress-plugin
 *            Plugin Name: New Tab Redirect Plus
 *            Plugin URI: https://pakainfo.com/jobs/technology/programming/wordpress/
 *            Description: New Tab Redirect Plus Plugin is the Open Redirect Comment Links in New Tab/Window.
 *            Version: 1.0
 *            Author: Jaydeep Gondaliya
 *            Author URI: https://pakainfo.com/
 *            Text Domain: pakainfo-new-tab-redirect-plus
 *            Contributors: Pakainfo
 *            License: GPLv2
 *            License URI: http://www.gnu.org/licenses/gpl-2.0.txt
 */


defined('ABSPATH') or die('access denied');
if (!defined('BASE_URL')){
  define('BASE_URL', get_bloginfo('url'));
}

Class ntprwp {
	Public $dir;
	function __construct(){
		$this->dir = dirname(__FILE__);
	}


	function ntrp_comment_links_in_new_window($text) 
	{
		$url = stripslashes_deep ( esc_attr ( get_option ( 'ntrp-website-full-url' ) ) );
		$check_plugin_enable = stripslashes_deep ( esc_attr ( get_option ( 'ntrp-open-comment-links-in-new-window' ) ) );
		$check_othor = stripslashes_deep ( esc_attr ( get_option ( 'ntrp-othar-comment-links-in-new-window' ) ) );

		if(!empty($check_plugin_enable)){
				return str_replace('<a', '<a target="_blank"', $text);
		}
		else if(!empty($check_othor) && !empty($url))
		{
							//$a = new SimpleXMLElement($text);
				$s = explode('href="',$text);
				$t = explode('">',$s[1]);

				$text =  '<a href ='.$url.' rel="nofollow" target="_blank">'.$t[1].'</a>';
				return str_replace('<a', '<a target="_blank"', $text);
		}
		else {
				return str_replace('<a', '<a', $text);
		}
	}

	/**
	 * Setting Page Options
	 * - add setting page
	 * - save setting page
	 *
	 * @since 1.0
	 */
	function ntrp_plugin_page() {
		?>
	<div class="wrap">
		<form method="post" action="options.php">
	            <?php
		settings_fields ( "ntpr_plugin_config" );
		do_settings_sections ( "ntrp-plugin" );
		?>
	     </form>
	</div>
	 
	<?php
	}
	 
	/**
	 * Init setting section, Init setting field and register settings page
	 *
	 * @since 1.0
	 */
	function ntpr_plugin_settings() {
		add_settings_section ( "ntpr_plugin_config", "", null, "ntrp-plugin" );
		add_settings_field ( "ntrp-website-full-url", "", array($this,"ntpr_plugin_options"), "ntrp-plugin", "ntpr_plugin_config" , "ntrp-open-comment-links-in-new-window", "ntrp-othar-comment-links-in-new-window");
		register_setting ( "ntpr_plugin_config", "ntrp-website-full-url" );
		register_setting ( "ntpr_plugin_config", "ntrp-open-comment-links-in-new-window" );
		register_setting ( "ntpr_plugin_config", "ntrp-othar-comment-links-in-new-window" );
	}
	/**
	 * Add simple textfield value to setting page
	 *
	 * @since 1.0
	 */

	function ntpr_plugin_options() {
		?>
		<style type="text/css">
			.form-table { width: 0px; }
		</style>
	<div class="postbox" style="padding: 30px;">

	<div class="wrap" id="profile-page">
		    <center>
   
	<h1 class="wp-heading-inline">
			New Tab Redirect Plus By <a
				href="https://pakainfo.com/" target="_blank">Pakainfo</a>
	</h1>
	<p>Custom WordPress Comment Links in New Tab</p>
	 
	<hr/>
	<table>
	<tr>
			<th scope="row">Open Link in a New Tab</th>
			<td><label for="ntrp-open-comment-links-in-new-window"><input type="checkbox" class="franquiaCheckbox" name="ntrp-open-comment-links-in-new-window" value="1" <?php 
			checked(1, get_option('ntrp-open-comment-links-in-new-window')); ?> /> Enable the WP Open Comment Links in New Window</label>
				<br/>
				<mark>Open WordPress Comment Links in New Tab/Window (add target=”_blank”)</mark>
			</td>
		</tr>
		<tr> <td colspan="2" align="center"><h3>OR</h3></td></tr>

	<tr>
			<th scope="row">Open Link in a New Tab</th>
			<td><label for="ntrp-othar-comment-links-in-new-window"><input type="checkbox" class="franquiaCheckbox" name="ntrp-othar-comment-links-in-new-window" value="1" <?php 
			checked(1, get_option('ntrp-othar-comment-links-in-new-window')); ?> /> Enable/change a custom link's destination with a redirect</label>
			</td>
		</tr>

	<tr>
		<th><label for="first_name">Website URL</label></th>
		<td><input type="url" size="50" placeholder="Enter redirect Comments URL"  name="ntrp-website-full-url"
			value="<?php
		echo stripslashes_deep ( esc_attr ( get_option ( 'ntrp-website-full-url' ) ) );
		?>"/>
	</td>
	</tr>

	</table>
	<?php 
	submit_button ();
	?>
	</div>

<p style="text-align:right;">© 2017 - <?php echo date("Y"); ?> <a href="https://pakainfo.com/" target="_blank">www.pakainfo.com</a><p>



	</div>
	<?php
	}
	 
	/**
	 * Append saved textfield value to each post
	 *
	 * @since 1.0
	 */
	
	function ntrp_com_content($content) {
		return $content . stripslashes_deep ( esc_attr ( get_option ( 'ntrp-website-full-url' ) ) );
	}

	 function admin_js() { ?>
	    <script type="text/javascript">

	        jQuery(document).ready( function () { 
	           jQuery('.franquiaCheckbox').click(function() {
				     jQuery('input[type="checkbox"]').not(this).prop('checked', false);    
				});
	        });

	    </script>
	<?php }

	function ntpr_add_menu() {
		add_submenu_page ( "options-general.php", "New Tab Redirect Plus", "New Tab Redirect Plus", "manage_options", "ntrp-plugin", array($this,"ntrp_plugin_page") );
	}



	function ntpr_activation_redirect( $plugin ) {
	    if( $plugin == plugin_basename( __FILE__ ) ) {
	        exit( wp_redirect( admin_url( 'options-general.php?page=ntrp-plugin' ) ) );
	    }
	}

	function ntpr_api_init() {
	  if (phpversion() < 5) {
	    add_action('admin_notices', array($this,'ntpr_php_version_warning'));
	    return;
	  }
	  add_action ( "admin_menu", array($this,'ntpr_add_menu') );
	}

	function ntpr_php_version_warning() {
	  echo "<div id=\"ntpr-warning\" class=\"updated fade\"><p>Sorry, New Tab Redirect Plus requires PHP version 5.0 or greater.</p></div>";
	}

	function ntpr_register(){
		add_filter('comment_text', array($this,'ntrp_comment_links_in_new_window'));
		add_action ( "admin_init", array($this,'ntpr_plugin_settings') );
		add_filter ( 'the_content',array($this,'ntrp_com_content') );
		add_action('admin_head', array($this,'admin_js'));

		// Add initialization and activation hooks
		add_action('init', array($this,'ntpr_api_init'));
	}

	function ntpr_activate(){
		add_action( 'activated_plugin', array($this,'ntpr_activation_redirect') );
		flush_rewrite_rules();
	}

	function ntpr_deactivate(){
		flush_rewrite_rules();
	}

}

if(class_exists('ntprwp')){
	$ntpr = new ntprwp();
	$ntpr->ntpr_register();
}


//activation
register_activation_hook(__FILE__,array($ntpr,'ntpr_activate'));

// desactivation
register_deactivation_hook(__FILE__,array($ntpr,'ntpr_deactivate'));

//desinsallation
function ntpr_plugin_activate(){
    register_uninstall_hook( __FILE__, 'ntpr_uninstall' );
}
register_activation_hook( __FILE__, 'ntpr_plugin_activate');
 
// And here goes the uninstallation function:
function ntpr_uninstall(){
    delete_option('ntrp-website-full-url');
    delete_option('ntrp-open-comment-links-in-new-window');
    delete_option('ntrp-othar-comment-links-in-new-window');
}

Step 3: Create a WordPress Readme TXT File

readme.txt

=== New Tab Redirect Plus ===
Plugin Name: New Tab Redirect Plus
Contributors: pakainfo
Donate link: https://pakainfo.com/donate
License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: comment, author, links, new tab, new window, comment author links, open in new window, open in new tab, comments new tab, wordpress comment links, open, comments, author url, target blank, blank, external-links, target new
Requires at least: 4.0
Tested up to: 5.1
Stable tag: 1.0

Stop any fake data sending visitors away - By default, Open WordPress Comment Links in New Tab/Window (add target=”_blank”) tab or window with: New Tab Redirect Plus.

== Description ==
New Tab Redirect Plus will allow you to have your comment visitors links open in a new tab or window. In other words, instead of leaving your site completely when clicked, they will open in a new tab.

This plugin opens all the web links added in the footer comments URL, in a new tab or window which helps to decrease the bounce rate and increase user engagement on your wordpress blog.

Opens all the Web site links (URLs) added in the comments and author URL, in a new tab or window.

This will increase the likelihood that visitors will continue browsing your website.

Simple, fast, and effective!

= Some of the features include: =
*Open comment links in a new tab or the same tab
*change a custom link's destination with a redirect
*Open WordPress Comment Links in New Tab/Window (add target=”_blank”)
*Replace URL INTO Your Custom web URL
*Works with http:// and https:// links
*Simple, fast, and effective!

== Installation ==

= From within WordPress =
1. Visit 'Plugins > Add New > Search plugins'
1. Search for 'New Tab Redirect Plus' and click to install
1. Activate New Tab Redirect Plus from your Plugins page.
1. Go to Settings > New Tab Redirect Plus.

You can also download the zip file from this page and upload it from the Plugins >> Add New > Upload page.

= Manually =
1. Upload the `new-tab-redirect-plus` folder to the `/wp-content/plugins/` directory
1. Activate the New Tab Redirect Plus plugin through the 'Plugins' menu in WordPress
1. Configure the plugin by going to the WordPress `Settings` menu, then to `New Tab Redirect Plus` that appears in your admin menu

== Frequently Asked Questions ==

= What does this plugin do? =

This plugin opens all the links added in the comments and author URL, in a new tab or window which helps to decrease the bounce rate and increase user engagement on your blog.


= Are there any limitations? =

No - Any specific requirements for this(New Tab Redirect Plus) plugin

= Is that it? =

Pretty much, yeah.


== Screenshots ==

1. WordPress Admin Dashboard New Tab Redirect Plus in Settings Page
2. Enable the wordpress Open Comment Links in New Window  - target _blank set
3. Enable/change a custom link's destination with a redirect


== ChangeLog ==

= 1.0.0, August 21, 2019 =

* First Initial Release

== Upgrade Notice ==

* Just click Update Now from the Plugins or Updates screen and let WordPress do it for you automatically. Nothing else needs done.

New Tab Redirect Plus 1 - How to Create a Wordpress Plugin in 10 Minutes Flat
New Tab Redirect Plus 1

New Tab Redirect Plus 2 - How to Create a Wordpress Plugin in 10 Minutes Flat
New Tab Redirect Plus 2

New Tab Redirect Plus 3 - How to Create a Wordpress Plugin in 10 Minutes Flat
New Tab Redirect Plus 3

Web Programming Tutorials Example with Demo

Read :

  javascript String to Get Hours and Minutes

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about How to Create a WordPress Plugin in 10 Minutes Flat.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Reply

avatar
  Subscribe  
Notify of