0

I have updated my server PHP from 5.x to 7.x but now my plugin shows error I have two files

1- link_removal_lite.php

    <?php

    /*
    Plugin Name: Link Remover Lite
    Plugin URI:
    Description: Remove or replace any word/phrase or URL quickly and easily throughout your entire site.
    Version: 1.6.3
    Author: Outsourcing Exposed
    Author URI: http://www.outsourcingexposed.com
    */

    /*  Copyright 2010  Outsourcing Exposed
    */
    // The text domain for strings localization
    define( 'LINKREM_TEXT_DOMAIN', 'link-removal-tool-lite' );

    /**
    * Load translate textdomain file.
    */
    function pclaen_load_textdomain() {
        load_plugin_textdomain( LINKREM_TEXT_DOMAIN, false, dirname( __FILE__ ) . '/languages/' );
    }

    add_action( 'plugins_loaded', 'pclaen_load_textdomain' );

    // Hook for adding admin menus
    add_action('admin_menu', 'pclaen_add_pages');

    // action function for above hook
    function pclaen_add_pages() {
        // Add a new top-level menu:
        $pclaen_page = add_menu_page( 'Link Remover Lite', 'Link Remover Lite', 'administrator', 'link-removal-lite', 'pclaen_page', plugins_url( 'link_removal_lite_brush.png' , 'link-removal-tool-lite/link_removal_lite.php' ) );

        wp_register_style( 'pclaen_Stylesheet', plugins_url( 'link_removal_lite_style.css' , 'link-removal-tool-lite/link_removal_lite.php' ) );
        wp_enqueue_style( 'pclaen_Stylesheet' );

    }


    function pclaen_page() {
        include( 'link_removal_lite_page.php' );
    }


    function pclaen_all_posts_check() {
      // do something with the post data
        global $wpdb;

        $sql = "SELECT * FROM $wpdb->posts WHERE post_parent=0";
        $wpdb->query( $sql );
        $posts = $wpdb->last_result;

        $posts = ( array ) $posts;;

        $searchText = $_POST['pclaen_searchText'];

        $urlsdel = 0;
        $postIsChange = 0;

        foreach( $posts as $post ) {

            $stroke = preg_quote( $searchText, "/" );

            if( ( preg_match( '/<a.*?href=[\'"](.*?)' . $stroke . '(.*?)["\'][^>]*?>.*?<\/a>/im',  $post->post_content ) ) ) {
                $post->post_content = preg_replace( '/(<a.*?href=[\'"])(.*?)' . $stroke . '(.*?)(["\'][^>]*?>(.*?)<\/a>)/im', "$5", $post->post_content );
                $postIsChange = 1;
                $urlsdel++;
            }
            if( ( get_post( $post->ID ) != NULL ) AND $postIsChange == 1 ) {

                $wpdb->query( "UPDATE ". $wpdb->posts . " SET post_content = '". mysql_escape_string($post->post_content) . "' WHERE ID = " . $post->ID . "" );

            }

            $postIsChange = 0;

        }
        $answer = "<br /> Deleted URLs: "  . $urlsdel . "<br />";
        return $answer;
    }
?>

2- link_removal_lite_page.php

    <?php

    if ( isset( $_POST['pclaen_action'] ) && $_POST['pclaen_action'] == "pclaen_all_posts" && !empty( $_POST['pclaen_searchText'] ) ) {
        $all_posts_Text = pclaen_all_posts_check();
    }

    $text = '<p>You’ve got the Lite version of this Link Removal Tool plugin. The Pro version is <strong>FREE</strong> and offers <strong>all these benefits</strong>.</p><ol>';
    $text .= '<li>You can add <strong>unlimited  URLs</strong> as you want</li>';
    $text .= '<li>Future check.  Your site will scan and stop any bad link URLs going onto your site ever again</li>';
    $text .= '<li>Wildcard option. Click <a href="http://www.outsourcingexposed.com/155/free-link-removal-tool/" target="_blank" title="Click here">here</a> for details</li>';
    $text .= '<li><strong>REPLACE URL</strong> option (or delete).  Replace with a good URL.</li>';
    $text .= '<li>Centralized URL list option.  Apply the same URL rules to any or all of your sites.</li>';
    //$text .= '</ol><p>So click this button to get the <strong>FREE Pro version</strong></p>';
    $text .= '</ol>';
?>

<div class="wrap">

    <script language="JavaScript">
    <!--
        function pclaen_all_posts() {

            if ( document.pclaen_searchForm.pclaen_searchText.value == "" )
            {
                alert( 'Please write search text!' );
                document.pclaen_searchForm.pclaen_searchText.focus();
                return false;
            } else {
                document.pclaen_searchForm.pclaen_action.value = "pclaen_all_posts";
                document.pclaen_searchForm.submit();
                return true;
            }
        }

    //-->
    </script>

    <h2>Link Remover</h2>
    <br clear="all"/>
    <br clear="all"/>
    <table>
        <tr>
            <td valign="top" width="285">
                <div>URL to un-link. This will remove all hyperlinks on your site pointing to this URL.<br />Add only the root domain, not a sub page and without the <i>http://www. part.</i>
            <br />For example to remove links to <i>http://www.dodgysite.com/this-page/</i> add only <i>dodgysite.com</i></div><br />
                <form action="" method="post" name="pclaen_searchForm">
                    <input type="hidden" name="pclaen_action" value="" />
                    <input type="hidden" name="pclaen_del_ID" value="" />
                    <input type="text" name="pclaen_searchText" size="50" />
                    <br clear="all"/>
                    <br clear="all"/>
                    <input type="button" onclick="pclaen_all_posts();" value="Clear all posts"/>
                    <br clear="all"/>
                    <br clear="all"/>

                    <?php
                        echo isset( $all_posts_Text ) ? $all_posts_Text : '';
                    ?>
                </form>
            </td>
            <td valign="top">
                <a style="margin-left:480px;" href="http://www.outsourcingexposed.com/im-superhero-quiz/" title="www.outsourcingexposed.com" target="_blank"><img src="<?php echo plugins_url( 'ad.gif' , 'link-removal-tool-lite/link_removal_lite.php' ) ?>" border="0" width="300" height="180" alt="AD"></a>
            </td>
        </tr>
    </table>


    <div id="message" class="updated">
        <div class="squeezer">
            <?php _e( $text, LINKREM_TEXT_DOMAIN ) ?>
            <p class="submit">
                <a href="http://www.outsourcingexposed.com/155/free-link-removal-tool/" class="button-primary">
                    <?php _e( 'Download now', LINKREM_TEXT_DOMAIN ) ?>
                </a>
            </p>
        </div>
    </div>

</div>

Now after php upgrade I get this error:

Fatal error: Uncaught Error: Call to undefined function mysql_escape_string() in public_html/wp-content/plugins/link-removal-tool/link_removal_lite.php:71 Stack trace: #0 /public_html/wp-content/plugins/link-removal-tool/link_removal_lite_page.php(4): pclaen_all_posts_check() #1 /public_html/wp-content/plugins/link-removal-tool/link_removal_lite.php(41): include('/w...') #2 /public_html/wp-includes/class-wp-hook.php(286): pclaen_page('') #3 /public_html/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters('', Array) #4 /public_html/wp-includes/plugin.php(453): WP_Hook->do_action(Array) #5 /public_html/wp-admin/admin.php(224): do_action('toplevel_page_l...') #6 {main} thrown in /public_html/wp-content/plugins/link-removal-tool/link_removal_lite.php on line 71

Yahya Hussein
  • 8,767
  • 15
  • 58
  • 114
Moh3n
  • 144
  • 1
  • 10
  • 1
    The `mysql_` API was removed in PHP7. So no `mysql_anything()` calls will work – RiggsFolly Dec 27 '17 at 12:28
  • 1
    Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[this happens](https://media.giphy.com/media/kg9t6wEQKV7u8/giphy.gif)** it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions and prepared statements. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly Dec 27 '17 at 12:28
  • Before upgrading PHP I suggest you read http://php.net/manual/en/migration70.php – RiggsFolly Dec 27 '17 at 12:30
  • @RiggsFolly thanks. would you please correct the code and add it as an answer that i can mark it as the correct answer? – Moh3n Dec 27 '17 at 12:35
  • Not necessary, and I cannot do that now as the question is on hold which stops new answers. Just upvote the Duplicate answer instead – RiggsFolly Dec 27 '17 at 13:06

0 Answers0