Forum Replies Created

Viewing 1 replies (of 1 total)
  • Forum: Plugins
    In reply to: Plugin for URL shortener
    Thread Starter john888999

    (@john888999)

    I did it with this code

    <?php
    
    /*
    
    Plugin Name: Shorted.ga Easy Link plugin
    
    Plugin URI: https://shorted.ga/
    
    Description: Just simple, if you use this plugins, your Shorted.ga EASY LINK will be added automatically, for all the external links of your website posts or pages.
    
    Version: 1.0
    
    Author: John
    
    Author URI: https://shorted.ga/
    
    License: GPL2
    
    */
    
    add_filter( 'the_content', 'cn_nf_url_parse2');
    
    function cn_nf_url_parse2( $content ) {
    
    	$tip = get_option( 'shortedga-tip' );
    
    	$id = get_option( 'shortedga-id' );
    
    	$content = str_replace('href="', 'href="https://shorted.ga/'.$id.'/'.$tip.'/', $content);
    
    	return $content;
    
    }
    
    add_action( 'admin_menu', 'register_shortedga_menu_page' );
    
    function register_shortedga_menu_page(){
    
        add_menu_page( 'Shorted Menu', 'Shorted Menu', 'manage_options', 'shorted-easy-link-plugin/shorted-easy-link-plugin.php', 'shortedga_menu_page', '', 6 );
    
    }
    
    function shortedga_menu_page(){
    
     ?><h1>Shorted.ga Menu Options</h1>
    
     <form method="post" action="options.php">
    
       <?php settings_fields( 'shortedga-id' ); ?>
    
        <?php do_settings_sections( 'shortedga-id' ); ?>
    
        <table class="form-table">
    
          <tr valign="top">
    
          <th scope="row">Shorted.ga Menu Options</th>
    
         </tr>  <tr valign="top"> <td>Please add your Shorted.ga ID<br /><input type="text" name="shortedga-id" value="<?php echo get_option( 'shortedga-id' ); ?>"/></td>
    
    	    </tr>
        </table>
    
        <?php submit_button(); ?></form>
    
    <form method="post" action="options.php">
    
    	<?php settings_fields( 'shortedga-tip' ); ?>
    
        <?php do_settings_sections( 'shortedga-tip' ); ?>
    
        <table class="form-table">
    
    <tr valign="top">
    
    <td>Please write correct type of links "0" for Family Safe and "1" for Adult links<br /><input type="text" name="shortedga-tip" value="<?php echo get_option( 'shortedga-tip' ); ?>"/></td>
    
          </tr>
    
        </table>
    
        <?php submit_button(); ?></form>
    
    <?php
    }
    
    function register_mysettings() { // whitelist options
     	 register_setting( 'shortedga-id', 'shortedga-id' );
    	 register_setting( 'shortedga-tip', 'shortedga-tip' );
    }
    add_action( 'admin_init', 'register_mysettings' );

    `
    This works perfect for me and for every version of wordpress. How can I post it to Plugin page???

Viewing 1 replies (of 1 total)