Redux Framework Custom Rest Api / Export - php

I want to learn how I can change this export link to custom?
wp-admin/admin-ajax.php?action=redux_download_options-custom&secret=c232a146b76ca2976c6a7a345f3c7432
Like :
wp-admin/admin-ajax.php?action=redux_download_options-custom&secret=custom_export
I need to see what they change something for mobile apps.
Thanks for helping me ;)

extentions_import_export.php line 136
change md5 checks to "custom_export_uri"
function link_options() {
if ( ! isset( $_GET['secret'] ) || $_GET['secret'] != 'custom_export_uri' ) {
wp_die( 'Invalid Secret for options use' );
exit;
}
$var = $this->parent->options;
$var['redux-backup'] = '1';
if ( isset( $var['REDUX_imported'] ) ) {
unset( $var['REDUX_imported'] );
}
echo json_encode( $var );
die();
}
public function download_options() {
if ( ! isset( $_GET['secret'] ) || $_GET['secret'] != 'custom_export_uri' ) {
wp_die( 'Invalid Secret for options use' );
exit;
}
Then "field_import_export.php" line 74
public function render() {
$secret = 'custom_export_uri';
admin-ajax.php?action=redux_download_options-port&secret=custom_export_uri

Related

Wordpress - change wp_redirect url to dynamic link

I have the following code that checks if a user is logged in and then redirects them to a particular static page -
add_action('wp', 'add_login_check');
function add_login_check()
{
if ( is_user_logged_in() && is_page( [153] ) ) {
wp_redirect('https://my.thinkingmachine.co/vallis');
exit;
}
}
I want to change it so that instead of going to "https://my.thinkingmachine.co/vallis" they are directed to a dynamic url containing their user name, like this -
$username = $user->user_login;
return ( '//my.thinkingmachine.co/' . $username . '/' );
How do I change the code so that it redirects to this dynamic url instead?
I tried this but it doesn't work -
add_action('wp', 'add_login_check');
function add_login_check()
{
if ( is_user_logged_in() && is_page( [153] ) ) {
$username = $user->user_login;
return ( '//my.thinkingmachine.co/' . $username . '/' );
exit;
}
}
Thanks
The whole code is -
add_action('wp', 'add_login_check');
function add_login_check()
{
if ( is_user_logged_in() && is_page( [153] ) ) {
$username = $user->user_login;
wp_redirect("https://my.thinkingmachine.co/{$username}");
exit;
}
}
add_action('wp', 'add_not_login_check');
function add_not_login_check()
{
if ( !is_user_logged_in() && !is_page( [153] ) ) {
wp_redirect('https://my.thinkingmachine.co/');
exit;
}
}
Presuming that the username is correctly get with this line of code:
$username = $user->user_login;
You can use this code:
function add_login_check()
{
if ( is_user_logged_in() && is_page( [153] ) ) {
$username = $user->user_login;
wp_redirect("https://my.thinkingmachine.co/{$username}");
exit;
}
}
If you want to use a PHP variable inside a string, you have to use double quotes for the string and single braces around the variable.
Try code below:
function add_login_check() {
if ( is_user_logged_in() && is_page( [153] ) ) {
$username = wp_get_current_user()->user_login;
$url = 'https://my.thinkingmachine.co/'. $username . '/';
wp_redirect($url);
exit;
}
}
add_action('wp', 'add_login_check');
Hope help you.

Call to a member function wp_rewrite_rules()

I'm getting an error on my landing page plugin:
2018/05/17 16:25:00 [error] 16590#16590: *61429 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught Error: Call to a member function wp_rewrite_rules() on null in /var/www/vhosts/xxxxxx/httpdocs/wp-includes/rewrite.php:518
Stack trace:
#0 /var/www/vhosts/xxxxxxxxx/httpdocs/wp-content/plugins/xxxxxxxx/includes/functions.php(125): url_to_postid('/go/woocommerce...')
#1 /var/www/vhosts/xxxxxxxxxx/httpdocs/wp-content/plugins/xxxxxxxxx/includes/functions.php(97): lsx_check_landing_page()
#2 /var/www/vhosts/xxxxxxxxx/httpdocs/wp-includes/class-wp-hook.php(288): lsx_landing_page_style_check('/var/www/vhosts...')
And this is the code calling that in the plugin:
function lsx_landing_page_style_check( $dir ){
$url = $_SERVER['REQUEST_URI'];
if( lsx_check_landing_page() ){
add_filter( 'customize_loaded_components', 'lsx_setup_components', 100 );
return LSXLDPG_PATH . 'framework';
}
return $dir;
}
function lsx_check_landing_page(){
$url = $_SERVER['REQUEST_URI'];
if( basename( $_SERVER['SCRIPT_FILENAME'] ) === 'customize.php' ){
parse_str( $_SERVER['QUERY_STRING'], $query );
if( !empty( $query['url'] ) ){
$url = $query['url'];
}
// if saving
}
if( !empty( $_POST['action'] ) && $_POST['action'] == 'customize_save' ){
$url = wp_get_referer();
$parsed = parse_url( $url );
if( 'customize.php' == basename( $parsed['path'] ) && !empty( $parsed['query'] ) ){
$query = urldecode( $parsed['query'] );
parse_str( $query, $ref );
if( !empty( $ref['url'] ) ){
$url = $ref['url'];
}
}
}
if( false !== strpos( $url, '/go/' ) ){
$landing_page = url_to_postid( $url );
if( !empty( $landing_page ) ){
return $landing_page;
}
return true;
}
return false;
}
I'm loading all this in my main plugin file with add_action( 'plugins_loaded', function(){ ....
But I don't know why is causing these issues. Please give me some advice.
The problem should get from url_to_postid() in your code. Maybe the var $url is empty or wrong. This function checks that you use permalinks and use the function wp_rewrite_rules().
As hint, you should use xDebug to get better error messages include a stacktrace so that you see the source of the error, not only the result of the error.

Redux WP Framework. Cannot disable 'dev_mode' with if statment

I have a problem.
I want to disable 'dev_mode' if 'opt_name' not redux_demo, using the if statment, but it did not work ... where does the fault ??
I found the code on Here
and I turn it into like this
if ( ! function_exists( 'redux_disable_dev_mode_plugin' ) ) {
function redux_disable_dev_mode_plugin( $redux ) {
if ( $redux->args['opt_name'] != 'redux_demo' ) {
if ( $redux->args['dev_mode'] == true ) {
$redux->args['dev_mode'] = false;
}
} else {
if ( $redux->args['dev_mode'] == false ) {
$redux->args['dev_mode'] = true;
}
}
}
add_action( 'redux/construct', 'redux_disable_dev_mode_plugin' );
}
the above code, I input in config.php
Thanks B4 and sorry my english is not good. :D
You can also filter the args JUST for your opt_name using this:
apply_filters( "redux/args/{$this->args['opt_name']}", $this->args );
if ( ! function_exists( 'redux_disable_dev_mode_plugin' ) ) {
function redux_disable_dev_mode_plugin( $redux ) {
if ( $redux->args['opt_name'] != 'redux_demo' ) {
$redux->args['dev_mode'] = false;
}
}
add_action( 'redux/construct', 'redux_disable_dev_mode_plugin' );
}
In framework.php (for me it's from line 1281). It worked for me after making those two attr false.
// Force dev_mode on WP_DEBUG = true and if it's a local server
if ( Redux_Helpers::isLocalHost() || ( Redux_Helpers::isWpDebug() ) ) {
if ( $this->args['dev_mode'] != true ) {
$this->args['update_notice'] = false;
}
$this->dev_mode_forced = true; // make it false
$this->args['dev_mode'] = true; //make it false
}

Redirect if Wordpress query string is empty

I've added a query string to my Wordpress installation using the following code in my functions.php file:
function add_query_vars($aVars) {
$aVars[] = "username";
return $aVars;
}
add_filter('query_vars', 'add_query_vars');
function add_rewrite_rules($aRules) {
$aNewRules = array(
'([^/]+)/manage' => 'index.php?pagename=manage&username=$matches[1]',
'([^/]+)/settings' => 'index.php?pagename=settings&username=$matches[1]',
);
$aRules = $aNewRules + $aRules;
return $aRules;
}
add_filter('rewrite_rules_array', 'add_rewrite_rules');
However, I don't want to load the page template if the username query string is empty, rather I'd like to redirect to the homepage. For instance:
website.com/myusername/manage
... would load a page template
website.com/manage
... would redirect home.
Can I do this using Wordpress' rewrite engine or should I take another approach?
Well, I would use this code:
function redirect_to_homepage( $query ) {
//page manage and settings does NOT exits
if ( $query->is_main_query() && ( $query->query_vars['name'] == 'manage' || $query->query_vars['name'] == 'settings' ) ){
if( ( !array_key_exists( 'username', $query->query_vars ) || ( array_key_exists( 'username', $query->query_vars ) && trim($query->query_vars['username']) == '' ) ) ) {
wp_redirect( get_bloginfo('url') );
exit;
}
}
//page manage and settings does exits
if ( $query->is_main_query() && ( $query->is_page('manage') || $query->is_page('settings') ) ){
if( ( !array_key_exists( 'username', $query->query_vars ) || ( array_key_exists( 'username', $query->query_vars ) && trim($query->query_vars['username']) == '' ) ) ) {
wp_redirect( get_bloginfo('url') );
exit;
}
}
}
add_action( 'parse_query', 'redirect_to_homepage' );

How to add Remember me function at custom login box?

In my theme, there's custom page for the login. Login function at functions.php is like this
function log_in($username, $password) {
$user = parse_user($username);
$username = $username;
$password = $password;
if(isEmptyString($username)) return new WP_Error('username', 'required');
if(isEmptyString($password)) return new WP_Error('password', "required");
if(!wp_check_password( $password, $user->user_pass ) ) return new WP_Error('wrong_password', "wrong");
wp_set_auth_cookie($user->ID, $remember);
wp_login($username, $password);
redirect_profile();
}
function parse_user($info = null, $return = 'object') {
if ( is_null( $info ) ) {
global $current_user;
if ( empty( $current_user->ID ) ) return null;
$info = get_userdata( $current_user->ID );
}
elseif ( empty( $info ) ) {
return null;
}
if( $return == 'ID' ) {
if ( is_object( $info ) ) return $info->ID;
if ( is_numeric( $info ) ) return $info;
}
elseif( $return == 'object' ) {
if ( is_object( $info ) && $info->ID) return $info;
if ( is_object( $info )) return get_userdata( $info->ID );
if ( is_numeric( $info ) ) return get_userdata( $info );
if ( is_string( $info ) ) return get_userdatabylogin( $info );
}
else {
return null;
}
}
I want to add remember me checkbox for user to logged in all the time until they logout. How can i add this ? Please kindly help me out. Thank you.
"remember me" buttons are generally just a simple tweak to the cookie settings internally. Instead of a session cookie that gets deleted when the browser is exitted, a "remember me" login cookie gets some future expiration point (a day, a month, a year, etc...) so it'll persist after the browser's closed.
In pseudo-code, you'd have:
if (form_value('remember_me') == 'yes) {
set_long_term_cookie();
} else {
set_session_cookie();
}
"Add a login form on your WordPress Theme" (including remember me functionality):
http://www.wprecipes.com/add-a-login-form-on-your-wordpress-theme
Also: http://www.problogdesign.com/how-to/how-to-create-a-wordpress-login-form-overlay/
etc...

Categories