How to open new page with wordpress hook in function.php? - php

I'm am creating a new function on my WordPress theme: I want to open a new page if the options that I insert inside my form correct.
This is what i wrote inside my functions.php:
function form_action_filter() {
if($_POST['name'] == "Emanuele" && $_POST['nascita'] == "Loreto"){
header('Location: https://www.youtube.com/watch?v=HBBIXeosabg');
} else {
echo "Compila il form";
}
}
add_action('myAction', 'form_action_filter');
do_action('myAction');
At the moment, if I write my function directly inside the layout, the function works, but, if I write my function inside functions.php when i push "Invia", the code doesn't work.
Thank's to everyone that will help me to understand how to fix this error.

Related

Wordpress echo link to .php, page not found

First, I use shortcode API and put these codes inside wp function.php and it works normally. Here the code;
function example() {
include('index.php' );
}
function examp_func() {
ob_start();
example();
$output = ob_get_contents();
ob_end_clean();
return $output;
}
add_shortcode( 'example', 'examp_func' );
Next, for my index.php file. i created code for a link(i need this hyperlink to execute my create.php file on my index.php page) like this..
echo "<a href= 'create.php' class='examplecss'>Create New</a>";
and when i click on a hyperlink i got page not found.
I checked url and it's correct. I searched all over the internet and it has yet not found. Any suggestions is really appreciate, thanks in advance.

How to target specific options pages in WordPress

I'm trying to remove screen options from a specific page and I've got something that removes screen options from all pages so I just need to check for "when page == {x}" How do I check what page I'm on in wordpress though?
function remove_screen_options(){
return false;
}
add_filter('screen_options_show_screen', 'remove_screen_options');
Thought it would be as easy as:
function remove_screen_options(){
global $pagename;
if( $pagename == "admin_faucet_settings") {
return false;
}
}
add_filter('screen_options_show_screen', 'remove_screen_options');
But that is not working - seems to fire all the time too which is strange and off...any ideas?
So, if you need to target any particular page of wordpress admin area, such as plugin page then you can use admin enqueue script hook like this:
function my_admin_enqueue($hook_suffix) {
if($hook_suffix == 'faucet_admin_settings') {
// your code that should be executed if we are on the right page.
}
}
add_action('admin_enqueue_scripts', 'my_admin_enqueue');
Reference: https://wordpress.stackexchange.com/questions/7278/how-can-you-check-if-you-are-in-a-particular-page-in-the-wp-admin-section-for-e

Get current page type in wordpress

I need to get cuurent page type.
Whene I use this func out of any other function it works !
function get_current_page_name(){
if (is_home() || is_front_page())
return 'is_home';
else
return 'is_page';
}
But whene I use it like this in home page
function my_function(){
echo get_current_page_name(); /// returns 'is_page'
}
This functions calls with ajax
I checked it and it seems to work for me.
Can you specify what version of WordPress you are using? Are there any plugins installed? And where exactly do you put this code.
In my test case I added this to my functions.php file.
function get_current_page_name(){
if (is_home() || is_front_page())
return 'is_home';
else
return 'is_page';
}
function my_function(){
echo get_current_page_name();
}
And this to my index.php file.
<?php
my_function();
?>
This works.
If I will choose home page to some static page in WordPress settings, and put the same but in page.php file it still works and returns is_home

How to create a Layout for a custom view in SugarCRM

I have created a fully custom view, I want this view to only show certain fields in an editview format so I can update records. But this view is to be different from the normal editview. How do I add a custom metadata file to this view that will allow me to define the form and fields that I need? The view is tied to a custom button and currently just shows "works". This is working so far just need to understand how to define the layout.
the controller:
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class CustomCasesController extends SugarController {
function action_resolve_Case() {
$this->view = 'resolve_case';
}
}
The view :
if (!defined('sugarEntry') || !sugarEntry)
die('Not A Valid Entry Point');
require_once('include/MVC/View/SugarView.php');
class CasesViewresolve_case extends SugarView {
public function CasesViewresolve_case() {
parent::SugarView();
}
function preDisplay() {
parent::preDisplay();
}
public function display() {
// include ('test.php');
echo "works";
}
}
Old, but still may help someone...
You can :
work inside the display function. Everything you do or echo here will be shown inside the main Sugar app screen (navbar, footer, etc) so it will look native.
Work directly inside the controller and echo everything out.
Build your form with the fields you want to edit and have as action a function in controller where you can use the bean->save() method for the POST results.
<form name="whatever" method="POST" action="index.php?module=Contacts&action=yourcustomaction">
ex:
`$contact = new Contact();
$contact->retrieve("{$_REQUEST['contactId']}");
//be sure to send the id in the button/link to the view
$contact->first_name =$_POST['first_name'];
$contact->last_name =$_POST['last_name'];
.....
$contact->save();`
Not very elegant but the only other option I know of is working with smarty templates which I'm not familiar with.
If anybody has a better solution, please post it.

PHP + Wordpress: getting a session variable on wp-login.php template

I am editing wp-login.php to create a custom login screen. Maybe there's a better way to do this, so if anyone has experience with that any comments are welcome.
Within my theme's functions.php I start a session:
function init_sessions() {
if (!session_id()) {
session_start();
}
}
add_action('init', 'init_sessions');
Within my theme file I set a session variable:
// Check if we've submitted a language
if($_GET['id'] == 'en') {
$_SESSION['bam_lan'] = 'en';
}
if(!isset($_SESSION['bam_lan'])) {
$_SESSION['bam_lan'] = 'es';
}
// Set language
$bam_lan = $_SESSION['bam_lan'];
Within wp-login.php, echo $_SESSION['bam_lan']; doesn't echo anything.
How do I get a global session variable which is set in my theme's functions.php from wp-login.php??
Thanks!
wp-login.php executes before functions.php and before 'init' action.

Categories