Tuesday 31 January 2023

Save One field data in option table.

 add_action('admin_menu','admin_menu_adding');

add_action('admin_init','admin_reg_settings');


function admin_menu_adding(){

    add_menu_page('Phone Number','Phone Number','administrator','mega-page','settings_page_test');

}


function settings_page_test(){

$phonenumber = get_option('phonenumber');

    ?>

<div class="wrap">

            <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>

    <form method="post" action="<?php echo admin_url('options.php'); ?>">

        <?php

        settings_fields('local-settings');

        do_settings_sections('local-settings');

        ?>

<input type="text" name="phonenumber" value="<?php echo $phonenumber; ?>" />

        <?php submit_button(); ?>

    </form>

</div>

    <?php

}


add_action('admin_action_trotbgo','save_value_here');


function save_value_here(){

    update_option();

    exit;

}


function admin_reg_settings(){

    register_setting('local-settings','phonenumber');

}

Friday 20 January 2023

Remove headers already sent error in Wordpress

 for this open wp-config file. remove any space before <?php or after ?>


then open page in notepad++ select encoding ansi first option save. uplaod errors will be removed

How to create Multipurpose Plugin Add Edit Function.

 <?php

ob_start();
/*
Plugin Name:Manjeet Kashyap
Plugin URI: localhost
Description: Declares a plugin that will create a custom post type displaying movie reviews.
Version: 1.0
Author: a1
Author URI:Localhost
License: GPLv2
*/
?>
<?php
function create_menu() {

add_menu_page('cm panel', 'Resigistration', '',  __FILE__, 'settings_page');

add_submenu_page(  __FILE__, 'New_Resigistration', 'New_Resigistration', 'manage_options', 'my-submenu-handle1','settings_page');

add_submenu_page(  __FILE__, 'User_Details', 'User_Details', 'manage_options', 'my-submenu-handle2','section_1');

add_submenu_page(  __FILE__, '', '', 'manage_options', 'my-submenu-handle3','section_2');

}


function settings_page()
{
include('upload1.php');
}

function section_1()
{
include('floor_image.php');
}


function section_2()
{

   $gid=$_GET['id'];

$a="select * from wp_usersinfo where id=$gid";
$res=mysql_query($a);
?>
<form action="" method="post" class="regty" enctype="multipart/form-data">
<?php
while($row=mysql_fetch_array($res)){
?>
<div class="nn1"><span class="lab1">Name</span> <input type="text" name="name_2" value="<?php echo $row['name'];?>"/></div>
<div class="nn1"><span class="lab1">About us</span><textarea cols="59" rows="5" name="about_us_2"><?php echo $row['aboutus'];?></textarea></div>
<div class="nn1"><span class="lab1">Upload Profile image</span><input type="file" name="Photo2" />
<img src="<?php echo bloginfo('template_url').'/images/'.$row['image_name']; ?>" width="125" height="100">
</div>
<div class="nn1"><input type="submit" name="update" value="Update" class="subtn"></div>
<?php
}
?>
</form>

<?php


if(isset($_POST['update'])){
$uploadDir = get_template_directory().'/images/';
$fileName = $_FILES['Photo2']['name'];
$tmpName = $_FILES['Photo2']['tmp_name'];
$fileSize = $_FILES['Photo2']['size'];
$fileType = $_FILES['Photo2']['type'];
$filePath = $uploadDir.$fileName;
$livepath=bloginfo('template_url').'/images/'.$fileName;
$result = move_uploaded_file($tmpName, $filePath);
$a="UPDATE wp_usersinfo SET name='".$_POST['name_2']."'
,image_name='".$fileName."',
image_path='".$filePath."',
aboutus='".$_POST['about_us_2']."'
where id='$gid'";
mysql_query($a) or die(mysql_error());
$admin = admin_url();
header('location:'.$admin.'admin.php?page=my-submenu-handle2');
         }
    }
?>
<?php

/*
function myplugin_activate()
{
global $wpdb;

global $usersinfo_table;

$usersinfo_table = 'wp_usersinfo';

$sql= "CREATE TABLE $table
(id INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
name VARCHAR(250),
image_name VARCHAR( 250 ) NULL ,
image_path VARCHAR( 250 ) NULL ,
aboutus MEDIUMTEXT NULL ,
 )";

require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);

} */

register_activation_hook( __FILE__, 'myplugin_activate' );
add_action('admin_menu','create_menu');

?>

=============================================================

<style>
.nn1{ float: left;padding: 7px 0; width: 100%;}.nn1 span.lab1 {float: left;width: 14%;}.nn1 input, .nn1 textarea {float: right;margin-right: 2%;width: 80%;}.lab1 input[type="radio"] {float: right; width: auto;}selectorSavingError {
}
</style>
<div class="wrap">
<h2>Registration Form</h2>
</div>
<form action="" method="post" class="regty" enctype="multipart/form-data">
<div class="nn1"><span class="lab1">Name</span> <input type="text" name="name_1" /></div>
<div class="nn1"><span class="lab1">About us</span><textarea cols="59" rows="5" name="about_us_1"></textarea></div>
<div class="nn1"><span class="lab1">Upload Profile image</span><input type="file" name="Photo" /></div>
<div class="nn1"><input type="submit" name="submit" value="submit" class="subtn"></div>
</form>
<?php        
$_POST['Photo'];
$about=$_POST['about_us_1'];
    $name=$_POST['name_1'];

if(isset($_POST['submit']))
{
$imgp=$_POST['Photo'];
$name=$_POST['name_1'];
$url=bloginfo('template_url');
$uploadDir = get_template_directory().'/images/';
$fileName = $_FILES['Photo']['name'];
$tmpName = $_FILES['Photo']['tmp_name'];
$fileSize = $_FILES['Photo']['size'];
$fileType = $_FILES['Photo']['type'];
$filePath = $uploadDir.$fileName;
$livepath=bloginfo('template_url').'/images/'.$fileName;
$result = move_uploaded_file($tmpName, $filePath);


if (!$result) {
echo "Error uploading file";
//exit;
}

if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}

$table="wp_usersinfo";
 echo $a="insert into wp_usersinfo set name='".$name."' ,
 image_name='".$fileName."',
 image_path='".$filePath."',
 aboutus='".$about."'";
mysql_query($a) or die(mysql_error());
$admin = admin_url();

header('location:'.$admin.'admin.php?page=my-submenu-handle2');
}

================================================================

<?php

include('../../../wp-config.php');
$admin = admin_url();
$uid=$_GET['id'];
$table = 'wp_usersinfo';
$del=mysql_query("DELETE FROM $table WHERE id=$uid");
header('location:'.$admin.'admin.php?page=my-submenu-handle2');
?>

====================================================================

<table border="2">
<tr><th>Id</th>
<th>Name</th>
<th>About us</th>
<th>Image</th>
</tr>
<?php
$admin = admin_url();
$url = plugins_url();
$s="select * from wp_usersinfo";
$result=mysql_query($s);
while($row=mysql_fetch_array($result))
{
echo '<tr><td>'.$row['id'].'</td><td>'.$row['name'].'</td><td>'.$row['aboutus'].'</td><td><img  width="100px" height="100px" src="http://localhost:90/wordpress/wp-content/themes/twentyfourteen/images/'.$row['image_name'].'"/>';
?>
<td>
<a href="<?php echo $admin.'admin.php?page=my-submenu-handle3&id='.$row['id'];?>"><input type="button" name="edit" value="Edit"><a></td>
<td>
<a href="<?php echo $url.'/madhukar/delete.php?id='.$row['id'];?>"><input type="button" name="Delete" value="Delete" ></a>
</td>

</tr>
<?php
}
?>
</table>

Set applying captcha anywhere in form google captcha.

 add_action( 'wp_login_failed', 'pippin_login_fail' );  // hook failed login


function pippin_login_fail( $username ) {
      
        global $wbdb;
   
     $userdata = get_user_by( 'login', $username );
   
     $meta = get_user_meta($userdata->ID, 'theme_my_login_security', true );
  
   if ( ! is_array( $meta ) )
           $meta = array();
   
    if(sizeof($meta['failed_login_attempts'] ) > 1){
       
       
    ?>
         <script src="https://www.google.com/recaptcha/api.js" async defer></script>
           <script type="text/javascript">
            jQuery('.g-recaptcha').show();

           </script>
    <?php
         
    }

   
}
add_filter('wp_authenticate_user', 'verify_login_captcha', 10, 2);
       
function verify_login_captcha($user, $password) {

    if (isset($_POST['g-recaptcha-response'])) {
        $recaptcha_secret = '6LfkBpNteuL6rHOViv9';
        echo $_POST['g-recaptcha-response'];
        echo "<br/>";
        $response = wp_remote_get("https://www.google.com/recaptcha/api/siteverify?secret=". $recaptcha_secret ."&response=". $_POST['g-recaptcha-response']);
        print_r($response);
        $response = json_decode($response["body"], true);
       
       
       
       
        if (true == $response["success"]) {
            return $user;
        } else {
            return new WP_Error("Captcha Invalid", __("You are required to check security verification"));
        }
       
    } else {
       
        return $user;
        //return new WP_Error("Captcha Invalid", __("<strong>ERROR</strong>: You are a bot. If not then enable JavaScript"));
    }  
}
---------------------------------------------------------------------
 <div class="clear"></div>
        <div class="g-recaptcha" data-sitekey="6LfkKwoTAAA1r7mO3d67rZnJu3"></div>

How we can get pdf to text conversion code

 $text = pdf2text("sample.pdf");

 
  echo $text;


function decodeAsciiHex($input) {
    $output = "";

    $isOdd = true;
    $isComment = false;

    for($i = 0, $codeHigh = -1; $i < strlen($input) && $input[$i] != '>'; $i++) {
        $c = $input[$i];

        if($isComment) {
            if ($c == '\r' || $c == '\n')
                $isComment = false;
            continue;
        }

        switch($c) {
            case '\0': case '\t': case '\r': case '\f': case '\n': case ' ': break;
            case '%':
                $isComment = true;
            break;

            default:
                $code = hexdec($c);
                if($code === 0 && $c != '0')
                    return "";

                if($isOdd)
                    $codeHigh = $code;
                else
                    $output .= chr($codeHigh * 16 + $code);

                $isOdd = !$isOdd;
            break;
        }
    }

    if($input[$i] != '>')
        return "";

    if($isOdd)
        $output .= chr($codeHigh * 16);

    return $output;
}
function decodeAscii85($input) {
    $output = "";

    $isComment = false;
    $ords = array();
   
    for($i = 0, $state = 0; $i < strlen($input) && $input[$i] != '~'; $i++) {
        $c = $input[$i];

        if($isComment) {
            if ($c == '\r' || $c == '\n')
                $isComment = false;
            continue;
        }

        if ($c == '\0' || $c == '\t' || $c == '\r' || $c == '\f' || $c == '\n' || $c == ' ')
            continue;
        if ($c == '%') {
            $isComment = true;
            continue;
        }
        if ($c == 'z' && $state === 0) {
            $output .= str_repeat(chr(0), 4);
            continue;
        }
        if ($c < '!' || $c > 'u')
            return "";

        $code = ord($input[$i]) & 0xff;
        $ords[$state++] = $code - ord('!');

        if ($state == 5) {
            $state = 0;
            for ($sum = 0, $j = 0; $j < 5; $j++)
                $sum = $sum * 85 + $ords[$j];
            for ($j = 3; $j >= 0; $j--)
                $output .= chr($sum >> ($j * 8));
        }
    }
    if ($state === 1)
        return "";
    elseif ($state > 1) {
        for ($i = 0, $sum = 0; $i < $state; $i++)
            $sum += ($ords[$i] + ($i == $state - 1)) * pow(85, 4 - $i);
        for ($i = 0; $i < $state - 1; $i++)
            $ouput .= chr($sum >> ((3 - $i) * 8));
    }

    return $output;
}
function decodeFlate($input) {
    return @gzuncompress($input);
}

function getObjectOptions($object) {
    $options = array();
    if (preg_match("#<<(.*)>>#ismU", $object, $options)) {
        $options = explode("/", $options[1]);
        @array_shift($options);

        $o = array();
        for ($j = 0; $j < @count($options); $j++) {
            $options[$j] = preg_replace("#\s+#", " ", trim($options[$j]));
            if (strpos($options[$j], " ") !== false) {
                $parts = explode(" ", $options[$j]);
                $o[$parts[0]] = $parts[1];
            } else
                $o[$options[$j]] = true;
        }
        $options = $o;
        unset($o);
    }

    return $options;
}
function getDecodedStream($stream, $options) {
    $data = "";
    if (empty($options["Filter"]))
        $data = $stream;
    else {
        $length = !empty($options["Length"]) ? $options["Length"] : strlen($stream);
        $_stream = substr($stream, 0, $length);

        foreach ($options as $key => $value) {
            if ($key == "ASCIIHexDecode")
                $_stream = decodeAsciiHex($_stream);
            if ($key == "ASCII85Decode")
                $_stream = decodeAscii85($_stream);
            if ($key == "FlateDecode")
                $_stream = decodeFlate($_stream);
        }
        $data = $_stream;
    }
    return $data;
}
function getDirtyTexts(&$texts, $textContainers) {
    for ($j = 0; $j < count($textContainers); $j++) {
        if (preg_match_all("#\[(.*)\]\s*TJ#ismU", $textContainers[$j], $parts))
            $texts = array_merge($texts, @$parts[1]);
        elseif(preg_match_all("#Td\s*(\(.*\))\s*Tj#ismU", $textContainers[$j], $parts))
            $texts = array_merge($texts, @$parts[1]);
    }
}
function getCharTransformations(&$transformations, $stream) {
    preg_match_all("#([0-9]+)\s+beginbfchar(.*)endbfchar#ismU", $stream, $chars, PREG_SET_ORDER);
    preg_match_all("#([0-9]+)\s+beginbfrange(.*)endbfrange#ismU", $stream, $ranges, PREG_SET_ORDER);

    for ($j = 0; $j < count($chars); $j++) {
        $count = $chars[$j][1];
        $current = explode("\n", trim($chars[$j][2]));
        for ($k = 0; $k < $count && $k < count($current); $k++) {
            if (preg_match("#<([0-9a-f]{2,4})>\s+<([0-9a-f]{4,512})>#is", trim($current[$k]), $map))
                $transformations[str_pad($map[1], 4, "0")] = $map[2];
        }
    }
    for ($j = 0; $j < count($ranges); $j++) {
        $count = $ranges[$j][1];
        $current = explode("\n", trim($ranges[$j][2]));
        for ($k = 0; $k < $count && $k < count($current); $k++) {
            if (preg_match("#<([0-9a-f]{4})>\s+<([0-9a-f]{4})>\s+<([0-9a-f]{4})>#is", trim($current[$k]), $map)) {
                $from = hexdec($map[1]);
                $to = hexdec($map[2]);
                $_from = hexdec($map[3]);

                for ($m = $from, $n = 0; $m <= $to; $m++, $n++)
                    $transformations[sprintf("%04X", $m)] = sprintf("%04X", $_from + $n);
            } elseif (preg_match("#<([0-9a-f]{4})>\s+<([0-9a-f]{4})>\s+\[(.*)\]#ismU", trim($current[$k]), $map)) {
                $from = hexdec($map[1]);
                $to = hexdec($map[2]);
                $parts = preg_split("#\s+#", trim($map[3]));
               
                for ($m = $from, $n = 0; $m <= $to && $n < count($parts); $m++, $n++)
                    $transformations[sprintf("%04X", $m)] = sprintf("%04X", hexdec($parts[$n]));
            }
        }
    }
}
function getTextUsingTransformations($texts, $transformations) {
    $document = "";
    for ($i = 0; $i < count($texts); $i++) {
        $isHex = false;
        $isPlain = false;

        $hex = "";
        $plain = "";
        for ($j = 0; $j < strlen($texts[$i]); $j++) {
            $c = $texts[$i][$j];
            switch($c) {
                case "<":
                    $hex = "";
                    $isHex = true;
                break;
                case ">":
                    $hexs = str_split($hex, 4);
                    for ($k = 0; $k < count($hexs); $k++) {
                        $chex = str_pad($hexs[$k], 4, "0");
                        if (isset($transformations[$chex]))
                            $chex = $transformations[$chex];
                        $document .= html_entity_decode("&#x".$chex.";");
                    }
                    $isHex = false;
                break;
                case "(":
                    $plain = "";
                    $isPlain = true;
                break;
                case ")":
                    $document .= $plain;
                    $isPlain = false;
                break;
                case "\\":
                    $c2 = $texts[$i][$j + 1];
                    if (in_array($c2, array("\\", "(", ")"))) $plain .= $c2;
                    elseif ($c2 == "n") $plain .= '\n';
                    elseif ($c2 == "r") $plain .= '\r';
                    elseif ($c2 == "t") $plain .= '\t';
                    elseif ($c2 == "b") $plain .= '\b';
                    elseif ($c2 == "f") $plain .= '\f';
                    elseif ($c2 >= '0' && $c2 <= '9') {
                        $oct = preg_replace("#[^0-9]#", "", substr($texts[$i], $j + 1, 3));
                        $j += strlen($oct) - 1;
                        $plain .= html_entity_decode("&#".octdec($oct).";");
                    }
                    $j++;
                break;

                default:
                    if ($isHex)
                        $hex .= $c;
                    if ($isPlain)
                        $plain .= $c;
                break;
            }
        }
        $document .= "\n";
    }

    return $document;
}

function pdf2text($filename) {
    $infile = @file_get_contents($filename, FILE_BINARY);
    if (empty($infile))
        return "";

    $transformations = array();
    $texts = array();

    preg_match_all("#obj(.*)endobj#ismU", $infile, $objects);
    $objects = @$objects[1];

    for ($i = 0; $i < count($objects); $i++) {
        $currentObject = $objects[$i];

        if (preg_match("#stream(.*)endstream#ismU", $currentObject, $stream)) {
            $stream = ltrim($stream[1]);

            $options = getObjectOptions($currentObject);
            if (!(empty($options["Length1"]) && empty($options["Type"]) && empty($options["Subtype"])))
                continue;

            $data = getDecodedStream($stream, $options);
            if (strlen($data)) {
                if (preg_match_all("#BT(.*)ET#ismU", $data, $textContainers)) {
                    $textContainers = @$textContainers[1];
                    getDirtyTexts($texts, $textContainers);
                } else
                    getCharTransformations($transformations, $data);
            }
        }
    }

    return getTextUsingTransformations($texts, $transformations);
}