Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop to Master merge for v2.3.1 #49

Merged
merged 17 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![Blogger to WordPress Redirection](https://plugins.svn.wordpress.org/blogger-to-wordpress-redirection/assets/banner-772x250.jpg)

* **Contributors:** [rtcamp](http://profiles.wordpress.org/rtcamp), [rahul286](http://profiles.wordpress.org/rahul286), [nitun.lanjewar](http://profiles.wordpress.org/nitun.lanjewar), [rakshit](http://profiles.wordpress.org/rakshit), [saurabhshukla](http://profiles.wordpress.org/saurabhshukla), [faishal](http://profiles.wordpress.org/faishal), [anantshri](http://profiles.wordpress.org/anantshri), [deepaklalwani](https://profiles.wordpress.org/deepaklalwani/), [vaishu.agola27](https://profiles.wordpress.org/vaishuagola27/), [Nikhil Joshua](https://profiles.wordpress.org/nikhiljoshua/), [Pavan Patil](https://profiles.wordpress.org/pavanpatil1/)
* **Contributors:** [rtcamp](http://profiles.wordpress.org/rtcamp), [rahul286](http://profiles.wordpress.org/rahul286), [nitun.lanjewar](http://profiles.wordpress.org/nitun.lanjewar), [rakshit](http://profiles.wordpress.org/rakshit), [saurabhshukla](http://profiles.wordpress.org/saurabhshukla), [faishal](http://profiles.wordpress.org/faishal), [anantshri](http://profiles.wordpress.org/anantshri), [deepaklalwani](https://profiles.wordpress.org/deepaklalwani/), [vaishu.agola27](https://profiles.wordpress.org/vaishuagola27/), [Nikhil Joshua](https://profiles.wordpress.org/nikhiljoshua/), [Pavan Patil](https://profiles.wordpress.org/pavanpatil1/), [Devansh Chaudhary](https://profiles.wordpress.org/devansh2002/)

* **License:** [GPL v2 or later](http://www.gnu.org/licenses/gpl-2.0.html)

Expand Down Expand Up @@ -47,6 +47,13 @@ Use [support forum](https://wordpress.org/support/plugin/blogger-to-wordpress-re

## Changelog

### 2.3.1

* Compatible with PHP 8.3 compatibility.
* Compatible with WordPress 6.6
* Compatible with WordPress VIP.
* Fix redirection issue when using for multiple blogs.

### 2.3.0

* Blogger to WordPress Redirection 2.3.0 with PHP 8.1 Compatibility.
Expand Down Expand Up @@ -103,6 +110,13 @@ New features added:

## Upgrade Notice

### 2.3.1

* Compatible with PHP 8.3 compatibility.
* Compatible with WordPress 6.6
* Compatible with WordPress VIP.
* Fix redirection issue when using for multiple blogs.

### 2.3.0

* Blogger to WordPress Redirection 2.3.0 with PHP 8.1 Compatibility.
Expand Down
85 changes: 37 additions & 48 deletions b2w-redirection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* Plugin Name: Blogger To WordPress
* Plugin URI: https://bloggertowp.org/tutorials/blogger-to-wordpress-redirection-plugin/
* Description: This plugin is useful for setting up 1-to-1 mapping between Blogger.com blog posts and WordPress blog posts. This works nicely for blogs with old subdomain address (e.g. xyz.blogspot.com) which are moved to new custom domain (e.g. xyz.com)
* Version: 2.3.0
* Version: 2.3.1
* Author: rtCamp
* Author URI: https://rtcamp.com/
* Requires at least: 3.2
* Tested up to: 6.3
* Tested up to: 6.6
* Text Domain: blogger-to-wordpress-redirection
*
* @package Blogger_To_WordPress
Expand All @@ -18,11 +18,13 @@
define( 'RT_B2WR_BLOG_URL', get_bloginfo( 'url' ) );

/**
* Add option to Tools Menu
* Add option to Tools Menu
*
* @return void
*/
function rt_blogger_to_wordpress_add_option() {
function rt_blogger_to_wordpress_add_option(): void {

add_management_page( __( 'Blogger To WordPress Redirection', 'blogger-to-wordpress-redirection' ), __( 'Blogger To WordPress Redirection', 'blogger-to-wordpress-redirection' ), 'administrator', 'rt-blogger-to-wordpress-redirection', 'rt_blogger_to_wordpress_administrative_page' );
add_management_page( __( 'Blogger To WordPress Redirection', 'blogger-to-wordpress-redirection' ), __( 'Blogger To WordPress Redirection', 'blogger-to-wordpress-redirection' ), 'manage_options', 'rt-blogger-to-wordpress-redirection', 'rt_blogger_to_wordpress_administrative_page' );

wp_enqueue_script( 'rt-blogger-to-wordpress-redirection-js', ( RT_B2WR_PLUGIN_URL . 'js/b2w-redirection-ajax.js' ), array( 'jquery', 'postbox' ), filemtime( RT_B2WR_PLUGIN_DIR . 'js/b2w-redirection-ajax.js' ), true );

Expand All @@ -39,52 +41,33 @@ function rt_blogger_to_wordpress_add_option() {
wp_enqueue_style( 'dashboard' );

}

}

add_action( 'admin_menu', 'rt_blogger_to_wordpress_add_option' );

/**
* Administrative Page - Begin
*
* @return void
*/
function rt_blogger_to_wordpress_administrative_page() {

require_once RT_B2WR_PLUGIN_DIR . 'templates/settings.php';

}

/**
* Get Configuration, called via AJAX
*/
function rt_b2wr_get_config() {

function rt_blogger_to_wordpress_administrative_page(): void {
global $wpdb;

if ( ! isset( $_POST['nonce'] )
|| ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'b2w_admin_nonce' )
) {
return;
}

// get all blogger domains, if avaliable.
$sql = "SELECT DISTINCT meta_value FROM {$wpdb->postmeta} where meta_key = 'blogger_blog'";

// unprepared sql ok.
$results = $wpdb->get_results( $sql ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.DirectDatabaseQuery.NoCaching

require_once RT_B2WR_PLUGIN_DIR . 'templates/get-config.php';

die();

require_once RT_B2WR_PLUGIN_DIR . 'templates/settings.php';
}

add_action( 'wp_ajax_rt_b2wr_get_config', 'rt_b2wr_get_config' );


/**
* Redirection Function (!important)
* Redirection Function (!important)
*
* @return void
*/
function rt_blogger_to_wordpress_redirection() {
function rt_blogger_to_wordpress_redirection(): void {

global $wpdb;

Expand Down Expand Up @@ -125,22 +108,21 @@ function rt_blogger_to_wordpress_redirection() {

// wp redirect ok.
wp_redirect( get_permalink( $wpurl[0][0] ) ); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect

exit;
} else {
wp_safe_redirect( home_url(), 301 );
exit;
}
}

wp_safe_redirect( home_url(), 301 );
exit();
}

add_action( 'init', 'rt_blogger_to_wordpress_redirection' );

/**
* Verify Configuration
* Verify Configuration
*
* @return void
*/
function rt_b2wr_verify_config() {
function rt_b2wr_verify_config(): void {

global $wpdb;

Expand All @@ -166,18 +148,24 @@ function rt_b2wr_verify_config() {
$blogger_url = 'https://' . $domain_name . $rand_col2[0]->meta_value;
$local_url = get_permalink( $rand_post_id );

require_once RT_B2WR_PLUGIN_DIR . 'templates/verify-config.php';

echo wp_json_encode(
array(
'blogger_url' => esc_url( $blogger_url ),
'local_url' => esc_url( $local_url ),
)
);

die();

}

add_action( 'wp_ajax_rt_b2wr_verify_config', 'rt_b2wr_verify_config' );

/**
* Get Latest Feeds - Begin
*
* @return void
*/
function rt_get_feeds_from_blogger_to_wp() {
function rt_get_feeds_from_blogger_to_wp(): void {

require_once ABSPATH . WPINC . '/feed.php';

Expand All @@ -189,24 +177,26 @@ function rt_get_feeds_from_blogger_to_wp() {
}

require_once RT_B2WR_PLUGIN_DIR . 'templates/feeds.php';

}

/**
* Update Notice - Begin
*
* @return void
*/
function rt_blogger_to_wordpress_update_notice() {
function rt_blogger_to_wordpress_update_notice(): void {

if ( empty( get_option( 'rtb2wr206' ) ) ) {
require_once RT_B2WR_PLUGIN_DIR . 'template/update-notice.php';
}

}

/**
* Hide Notice block
*
* @return void
*/
function rt_b2wr_hide_notice_block() {
function rt_b2wr_hide_notice_block(): void {

if ( ! isset( $_POST['update_nonce'] )
|| ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['update_nonce'] ) ), 'b2w_update_nonce' )
Expand All @@ -215,7 +205,6 @@ function rt_b2wr_hide_notice_block() {
}

update_option( 'rtb2wr206', 'done' );

}

add_action( 'wp_ajax_rt_b2wr_hide_notice_block', 'rt_b2wr_hide_notice_block' );
48 changes: 17 additions & 31 deletions js/b2w-redirection-ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,12 @@
/**
* Gets configuration and appends to dom.
*
* @param {String} nonce
*
* @returns {void}
*/
function rt_start_config( nonce ){

if ( jQuery( '#get_config' ).html() != '' ) {
jQuery( '#get_config' ).html( '' );
}

jQuery.ajax(
{
url:'admin-ajax.php',
type: 'POST',
data: 'action=rt_b2wr_get_config&nonce=' + nonce,
success: function(result){
jQuery( '#get_config' ).append( result );
}
}
);
function rt_start_config(){
jQuery( '#get_config' ).show();
}

/**
* Generates blogger code
*
Expand All @@ -38,14 +23,15 @@ function rt_start_config( nonce ){
* @returns {void}
*/
function generate_code( domain_name, curr_domain, nonce){

let blogger_code = jQuery( '#blogger-code-textarea' ).val();
blogger_code = blogger_code.replace( /{{curr_domain}}/g, curr_domain );
jQuery( '#blogger-code-textarea' ).val( blogger_code );
jQuery( '#redirection-domain-name-1' ).attr( 'href', domain_name );
jQuery( '#redirection-domain-name-1' ).text( domain_name );
jQuery( '#redirection-domain-name-2' ).text( domain_name );
jQuery( '#check_config' ).attr( 'onClick', 'check_configuration("' + domain_name + '","' + nonce + '")' );
jQuery( '#code_here' ).show();
var response = jQuery( '#code_here' ).html();
response = response.replace( /{{curr_domain}}/g, curr_domain );
response = response.replace( /{{domain_name}}/g, domain_name );
response = response.replace( /{{nonce}}/g, nonce );
jQuery( '#code_here' ).html( response );

jQuery( '#verify_config' ).hide();
}

/**
Expand All @@ -57,18 +43,18 @@ function generate_code( domain_name, curr_domain, nonce){
* @returns {void}
*/
function check_configuration( domain_name, nonce ) {

if ( jQuery( '#verify_config' ).html() != '' ) {
jQuery( '#verify_config' ).html( '' );
}

jQuery.ajax(
{
url:'admin-ajax.php',
type: 'POST',
data: 'action=rt_b2wr_verify_config&dname=' + domain_name + '&config_nonce=' + nonce,
success: function(result) {
jQuery( '#verify_config' ).append( result );
const { blogger_url, local_url } = JSON.parse(result);
jQuery( '#blogger_url' ).attr( 'href', blogger_url );
jQuery( '#local_url' ).attr( 'href', local_url );
jQuery( '#blogger_url' ).text( blogger_url );
jQuery( '#local_url' ).text( local_url );
jQuery( '#verify_config' ).show();
}
}
);
Expand Down
Loading
Loading