public function tst()
{
require_once( 'c:/xampp/htdocs/2/wordpress/wp-load.php' );
$this->load->view('tst');
}
And this is the tst.php view content:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<?php
// Register the script
wp_register_script( 'wp-api', 'c:/xampp/htdocs/2/wordpress/wp-includes/js/wp-api.js' );
wp_localize_script( 'wp-api', 'wpApiSettings', array(
'root' => esc_url_raw( rest_url() ),
'nonce' => wp_create_nonce( 'wp_rest' )
) );
// Enqueued script with localized data.
wp_enqueue_script( 'wp-api' );
print_r( array(
'root' => esc_url_raw( rest_url() ),
'nonce' => wp_create_nonce( 'wp_rest' )
) );
?>
<button type="button" onclick="myFunction()">Retrieve</button>
<script>
function myFunction() {
$.ajax( {
url: wpApiSettings.root + 'wp/v2/posts/1',
method: 'POST',
beforeSend: function ( xhr ) {
xhr.setRequestHeader( 'X-WP-Nonce', wpApiSettings.nonce );
},
data:{
'title' : 'Hello Moon'
}
} ).done( function ( response ) {
alert( response );
} );
}
</script>
</body>
</html>
This is the output for
print_r( array(
'root' => esc_url_raw( rest_url() ),
'nonce' => wp_create_nonce( 'wp_rest' )
) );
Array ( [root] => https://localhost/2/wordpress/wp-json/ [nonce] => 04864b371a )
The error I get is ReferenceError: wpApiSettings is not defined, for this line of code:
url: wpApiSettings.root + ‘wp/v2/posts/1’,
If wpApiSettings gets a value in the php section code , why isn’t it defined in the javascript section ?
]]>https://www.thecustomboxes.com/bakery-boxes/
https://www.thecustomboxes.com/invitation-boxes/
The problem I’m having is when I hit submit and it sends the form $_POST variables to “check_login” the variables don’t come through. I added:
var_dump($_REQUEST);
exit();
And nothing is being sent over. The plugin code is as follows:
<?php
/*
Plugin Name: ABE-app-integration
Description: Integrates registration and login with the ABE insurance app
Version: 1.0
Author: Eric Hylland
License: GPL
*/
/* Runs when plugin is activated */
register_activation_hook(__FILE__,'ABE_integrator_install');
/* Runs on plugin deactivation*/
register_deactivation_hook( __FILE__, 'ABE_integrator_remove' );
function ABE_integrator_install() {
/* Creates new database field */
add_option("ABE_integrator_data", 'Default', '', 'yes');
}
function ABE_integrator_remove() {
/* Deletes the database field */
delete_option('ABE_integrator_data');
}
/*Setup the admins page */
if ( is_admin() ){
/* Call the html code */
add_action('admin_menu', 'ABE_integrator_admin_menu');
function ABE_integrator_admin_menu() {
add_options_page('ABE Integrator', 'ABE Integrator', 'administrator',
'abe-integrator', 'ABE_integrator_html_page');
}
}
/*Admin page layout*/
function ABE_integrator_html_page(){
?>
<div>
<h2>ABE Integrator</h2>
</div>
<?php
}
function ABE_loginlogo() {
echo '<style type="text/css">
h1 a {
background-image: url("https://dev.alliedbeautyexperts.net/wp-content/uploads/2013/03/ABEWebsiteLogo.png") !important;
}
.login h1 a {
background-size: 300px auto !important;
width: 300px !important;
height: 65px !important;
}
</style>';
}
add_action('login_head', 'ABE_loginlogo');
function programmatic_login() {
if(isset($_SESSION['AbeUser'])){
if ( is_user_logged_in() ) {
wp_logout();
}
$username = $_SESSION['AbeUser'];
$password = $_SESSION['AbePass'];
add_filter( 'authenticate', 'allow_programmatic_login', 10, 3 ); // hook in earlier than other callbacks to short-circuit them
$user = wp_signon( array( 'user_login' => $username, 'user_password' =>$password ) );
remove_filter( 'authenticate', 'allow_programmatic_login', 10, 3 );
if ( is_a( $user, 'WP_User' ) ) {
wp_set_current_user( $user->ID, $user->user_login );
wp_set_auth_cookie( $user->ID );
if ( is_user_logged_in() ) {
return true;
unset($_SESSION['AbeUser']);
unset($_SESSION['AbePass']);
wp_redirect($_SERVER['REQUEST_URI']);
exit;
}
}
return false;
}
}
function allow_programmatic_login( $user, $username, $password ) {
return get_user_by( 'login', $username );
}
add_action( 'wp_head', 'programmatic_login' );
function ABE_login_form(){
$logForm = "
<div style='display: inline-block; margin: 0 auto; width: 250px;'>
<form action='/insuranceapp/index.php/common/login/check_login' method='post'>
<input type='hidden' name='wp-submit' value='Login'>
<input type='text' id='email' autocomplete='off' name='logemail' padding='12px' required pattern='[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-z]{2,3}$'>Username(Email)</input></br></br>
<input type='password' id='password' name='logpassword' autocomplete='off' padding='12px' required>Password</input></br>
</br><input type='submit'></input>
</form>
</div>
</br>
";
return $logForm;
}
add_shortcode( 'ABElog', 'ABE_login_form' );
/*Add a shortcode to embed registration form*/
function ABE_reg_form(){
$regform = "
<div style='margin: 0 auto;'>
<form action='/insuranceapp/index.php/common/registration/ABE_add_new_customer' method='post'>
<div style='display: inline-block'><input type='text' id='first_name' value='Reg' name='first_name' autocomplete='on' padding='12px' required pattern='^[a-zA-Z]+$'>First Name</input></div>
<div style='display: inline-block'><input type='text' id='last_name' value='test' name='last_name' autocomplete='on' padding='12px' required pattern='^[a-zA-Z]+$'>Last Name</input></div>
<input type='text' id='contact_no' name='contact_no' padding='12px' autocomplete='on' value='3333333333' required pattern='(?:\(\d{3}\)|\d{3})[- ]?\d{3}[- ]?\d{4}'>Phone</input><hr>
<div style='display: inline-block'><input type='text' id='business_contact_no' value='9999999999' autocomplete='off' name='business_contact_no' padding='12px' required pattern='(?:\(\d{3}\)|\d{3})[- ]?\d{3}[- ]?\d{4}'>Company Phone</input></div>
<hr>
<div style='display: inline-block'><input type='text' id='email' autocomplete='on' name='regemail' onchange='matchem()' padding='12px' required pattern='[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-z]{2,3}$'>Username (Email)</input></div>
<div style='display: inline-block'><input type='text' id='conname' autocomplete='on' name='conname' onchange='matchem()' padding='12px' required pattern='[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-z]{2,3}$'>Confirm Username (Email)</input></div><div id='mismatch' style='display: none; margin: 10px;'><font color='red'>Usernames Must Match</font></div>
<input type='password' id='password' name='regpassword' value='test' autocomplete='on' padding='12px' required>Password</input>
<input type='hidden' name='city' value='Denver'></input>
<input type='hidden' name='zip' value='000000'></input>
<input type='hidden' name='state' value='CO'></input>
<input type='hidden' name='security_question' value='What's your dogs name'></input>
<input type='hidden' name='security_answer' value='Spot'></input>
<input type='hidden' name='address' value='On Your Way'></input>
</br></br><input type='submit'></input>
</form>
</br></br>
<div>
<font color='#6a6d6f' face='Arial, Verdana, Helvetica, sans-serif'><span style='font-size: 11.111111640930176px; line-height: 14px;'><a class='linkUtility' href='/terms-use/' target='_blank' style='margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: rgb(255, 255, 255); color: rgb(35, 112, 169);' title='terms of use'>Terms of Use</a><span style='background-color: rgb(255, 255, 255);'> and </span><a class='linkUtility' href='/privacy-policy/' target='_blank' style='margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: rgb(255, 255, 255); color: rgb(35, 112, 169);' title='privacy policy'>Privacy Policy</a><span style='background-color: rgb(255, 255, 255);'>.</span></span></font>
</div>
<script>
function matchem(){
if(document.getElementById('conname').value != '' && document.getElementById('conname').value !== document.getElementById('usename').value){
document.getElementById('mismatch').style.display = 'inline-block';
}else{
document.getElementById('mismatch').style.display = 'none';
}
}
</script>
</div>
";
return $regform;
}
add_shortcode( 'ABEreg', 'ABE_reg_form' );
function ABE_complete_registration() {
if(isset($_SESSION['ABE_Reg_email'])){
$userdata = array(
'user_login' => $_SESSION['ABE_Reg_email'],
'user_email' => $_SESSION['ABE_Reg_email'],
'user_pass' => $_SESSION['ABE_Reg_pass'],
'first_name' => $_SESSION['ABE_Reg_fname'],
'last_name' => $_SESSION['ABE_Reg_lname'],
'nickname' => $_SESSION['ABE_Reg_fname'],
'phone' => $_SESSION['ABE_Reg_phone'],
'description' => $_SESSION['ABE_Reg_bphone']
);
$user = wp_insert_user( $userdata );
unset($_SESSION['ABE_Reg_email']);
unset($_SESSION['ABE_Reg_pass']);
unset($_SESSION['ABE_Reg_fname']);
unset($_SESSION['ABE_Reg_lname']);
unset($_SESSION['ABE_Reg_phone']);
unset($_SESSION['ABE_Reg_bphone']);
echo 'Registration complete. Goto <a href="' . get_site_url() . '/wp-login.php">login page</a>.';
}
}
add_action( 'wp_head', 'ABE_complete_registration' );
?>
And below is the login controller of the codeigniter app. I can provide the registration code as well but I think I will solve both problems if I figure out one. When I started writing the plugin I did the login first, and it worked for a bit, until I started writing the registration portion.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* This class is used for user home page purpose\
* @author tudip
*/
class login extends app_controller {
/**
* This constructor overrides the parent constructor
*/
function __construct(){
parent::__construct();
$this->load->model('common/user_model');
$this->set_page_title("User Dashboard");
$this->set_active_menus(array('login'));
}
/**
* This index is used to load home page of user
*/
public function index(){
redirect('../../login/');
//$this->parser->parse("common/login.tpl", $this->data);
}
/**
* This function call the validate_user_login of user_model to check login
*/
public function check_login(){
var_dump($_REQUEST);
exit();
try{
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$this->set_page_message("Invalid username or password", "error");
$val = $this->user_model->validate_user_login($_REQUEST);
if($val){
$this->data['page_data']['user_id'] = $this->session->userdata('user_id');
$this->data['page_data']['email'] = $this->session->userdata('email');
$this->data['page_data']['user_name'] = $this->session->userdata('user_name');
$this->data['page_data']['username'] = $this->session->userdata('username');
$this->data['page_data']['first_name'] = $this->session->userdata('first_name');
$this->data['page_data']['last_name'] = $this->session->userdata('last_name');
$this->data['page_data']['parent_id'] = $this->session->userdata('parent_id');
$result = $this->user_model->count_parent_ids();
if($this->session->userdata('renew_parent_id')){
$this->data['page_data']['from_renew'] = ACTIVE;
}
$this->set_page_message("User login successfully done", "success");
$this->check_session_user();
//Added this to log into wordpress after authenticating with the insurance app"
if (!session_id()) {
session_start();
}
$_SESSION['AbeUser'] = $this->session->userdata('email');
$_SESSION['AbePass'] = $_REQUEST['password'];
redirect('/membership-resources');
}else{
$this->parser->parse("common/login.tpl", $this->data);
}
}else{
$this->set_page_message("Illegal Operation - Not allowed", "error");
redirect('../../login/');
//show_404('page',false);
}
}catch (Exception $e){
$this->handle_controller_exception($e);
$this->parser->parse("common/login.tpl", $this->data);
}
}
I need some more eyes on this. It is getting incredibly frustrating. Currently the htaccess file in the base folder contains the standard WordPress rewrite rule. I can include the validate_user_login function as well, but I don’t think there is anything making it that far. Is WordPress somehow blocking the $_POST variables?
EDIT- I just talked to our hosting provider and they passed me these errors:
[Mon Mar 28 14:20:57 2016] [error] [client 50.243.152.182] exec used but not allowed in /home/alliedp5/public_html/development/500.shtml, referer: https://dev.alliedbeautyexperts.net/login/
[Mon Mar 28 14:20:57 2016] [error] [client 50.243.152.182] SoftException in Application.cpp:256: File "/home/alliedp5/public_html/development/wp-content/plugins/mimetypes-link-icons/css/style.php" is writeable by group, referer: https://dev.alliedbeautyexperts.net/login/
]]>My problem now is that no WordPress pages render. All I get is a blank page. I was thinking that I could create a Codeigniter controller that would render a WordPress page. All I would need is the call that, given a page ID, would render the page. Does anyone know of such a render call?
]]>I have my CI main page – https://www.edutrics.com/main/edu/index
This page is opening properly in browser and everything is working fine.
However, Google Webmasters and other link checker like – https://www.deadlinkchecker.com/ shows 404 error for all my Codeigniter pages like https://www.edutrics.com/main/edu/index https://www.edutrics.com/main/edu/signupstudent
Please help
]]>Let me know your thoughts on integration or thoughts on codeigniter.
Needs a front end for sails and backend for paid user management controls.
]]>Though I put I’m using the 4.1.2 version, I’m actually running the 4.2 development version on local, but that was not an option to mark.
Is there any way to avoid this replacement? Thanks.
]]>