advanced-301-and-302-redirect
Last commit date
images
2 years ago
include
2 years ago
index.php
2 years ago
notices.php
2 years ago
readme.txt
2 days ago
index.php
117 lines
| 1 | <?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly ?> |
| 2 | <?php |
| 3 | /* |
| 4 | Plugin Name: YYDevelopment - Advanced 301 and 302 Redirect |
| 5 | Plugin URI: https://www.yydevelopment.com/yydevelopment-wordpress-plugins/ |
| 6 | Description: Simple plugin that will allow to redirect pages as 301 and 302 redirects in wordpress |
| 7 | Version: 1.6.7 |
| 8 | Author: YYDevelopment |
| 9 | Author URI: https://www.yydevelopment.com/ |
| 10 | */ |
| 11 | |
| 12 | include('include/settings.php'); |
| 13 | require_once('include/functions.php'); |
| 14 | |
| 15 | $yydev_redirect_data_plugin_version = '1.5.0'; // plugin version |
| 16 | $yydev_redirect_data_slug_name = 'yydev_advanced_301_redirect_version'; // the name we save on the wp_options database |
| 17 | |
| 18 | // ================================================ |
| 19 | // Creating Database when the plugin is activated |
| 20 | // ================================================ |
| 21 | |
| 22 | function yydev_redirect_create_redirection_database() { |
| 23 | require_once('include/install.php'); |
| 24 | } |
| 25 | |
| 26 | register_activation_hook(__FILE__, 'yydev_redirect_create_redirection_database'); |
| 27 | |
| 28 | // ================================================ |
| 29 | // update the database on plugin update |
| 30 | // ================================================ |
| 31 | |
| 32 | // loading the plugin version from the database |
| 33 | $db_plugin_version = get_option($yydev_redirect_data_slug_name); |
| 34 | |
| 35 | // checking if the plugin version exists on the dabase |
| 36 | // and checking if the database version equal to the plugin version $yydev_redirect_data_plugin_version |
| 37 | if( empty($db_plugin_version) || ($yydev_redirect_data_plugin_version != $db_plugin_version) ) { |
| 38 | |
| 39 | // update the plugin database if it's required |
| 40 | $yydev_redirect_database_update = 1; |
| 41 | require_once('include/install.php'); |
| 42 | |
| 43 | // update the plugin version in the database |
| 44 | update_option($yydev_redirect_data_slug_name, $yydev_redirect_data_plugin_version); |
| 45 | |
| 46 | } // if( empty($db_plugin_version) || ($yydev_redirect_data_plugin_version != $db_plugin_version) ) { |
| 47 | |
| 48 | // add_action('plugins_loaded', 'my_awesome_plugin_check_version'); |
| 49 | |
| 50 | |
| 51 | // ================================================ |
| 52 | // Adding menu tag inside wordpress admin panel |
| 53 | // ================================================ |
| 54 | |
| 55 | function yydev_redirect_wordpress_redirect_page() { |
| 56 | |
| 57 | include('include/settings.php'); |
| 58 | |
| 59 | include('include/style.php'); |
| 60 | include('include/script.php'); |
| 61 | |
| 62 | // Including the main page and the secondary page |
| 63 | if( isset($_GET['view']) && ($_GET['view'] === 'secondary') && isset($_GET['id']) ) { |
| 64 | include('include/secondary-page.php'); |
| 65 | } else { |
| 66 | include('include/main-page.php'); |
| 67 | } |
| 68 | |
| 69 | } |
| 70 | |
| 71 | function yydev_redirect_plugin_menu() { |
| 72 | include('include/settings.php'); |
| 73 | add_options_page('301/302 Redirection', '301/302 Redirection', 'manage_options', 'yydev-redirection', 'yydev_redirect_wordpress_redirect_page'); |
| 74 | } |
| 75 | |
| 76 | add_action('admin_menu', 'yydev_redirect_plugin_menu'); |
| 77 | |
| 78 | // ================================================ |
| 79 | // Add settings page to the plugin menu info |
| 80 | // ================================================ |
| 81 | |
| 82 | function yydev_redirect_add_settings_link( $actions, $plugin_file ) { |
| 83 | static $plugin; |
| 84 | |
| 85 | if (!isset($plugin)) { $plugin = plugin_basename(__FILE__); } |
| 86 | |
| 87 | if ($plugin == $plugin_file) { |
| 88 | |
| 89 | $admin_page_url = esc_url( menu_page_url( 'yydev-redirection', false ) ); |
| 90 | $settings = array('settings' => '<a href="' . $admin_page_url . '">Settings</a>'); |
| 91 | $donate = array('donate' => '<a target="_blank" href="https://www.yydevelopment.com/coffee-break/?plugin=advanced-301-and-302-redirect">Donate</a>'); |
| 92 | |
| 93 | $actions = array_merge($settings, $donate, $actions); |
| 94 | |
| 95 | } // if ($plugin == $plugin_file) { |
| 96 | |
| 97 | return $actions; |
| 98 | } //function yydev_redirect_add_settings_link( $actions, $plugin_file ) { |
| 99 | |
| 100 | add_filter( 'plugin_action_links', 'yydev_redirect_add_settings_link', 10, 5 ); |
| 101 | |
| 102 | // ================================================ |
| 103 | // Include the redirect functions only if the theme |
| 104 | // is loaded and not on the admin panel area |
| 105 | // ================================================ |
| 106 | |
| 107 | if ( ! is_admin() ) { |
| 108 | require_once('include/redirect-page.php'); |
| 109 | } // if ( ! is_admin() ) { |
| 110 | |
| 111 | // ================================================ |
| 112 | // including admin notices flie |
| 113 | // ================================================ |
| 114 | |
| 115 | if( is_admin() ) { |
| 116 | include_once('notices.php'); |
| 117 | } // if( is_admin() ) { |