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
Related
I have a cf7 form that is connected to multiple pages on the site. How do I allow these pages to have access to one thank you page? I tried this code below but it doesnt work.
It doesnt work as in, only array[0] is getting redirected. Not the others.
I am still a noob with PHP so do pardon the logic
add_action('template_redirect', function() {
$theOrigins = array(
'https://web1',
'https://web2',
'https://web3',
'https://web4',
);
$ref = wp_get_referer();
// ID of the thank you page
if (!is_page(1234)) {
return;
}
// coming from the form, so all is fine
if (in_array($ref, $theOrigins)) {
return;
}
// we are on thank you page
// visitor is not coming from form
// so redirect to home
wp_redirect(get_home_url());
exit;
} );
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.
I would like to bypass core and plugin functions to customize them.
I didn't succeed to do it from template.
I try to add into my tpl_functions.php something like:
if (!function_exists('html_buildlist')) {
function html_buildlist($data,$class,$func,$lifunc='html_li_default',$forcewrapper=false){
// etc.
}
}
My first idea is to check if the page has been visited and then customize the indexmenu plugin.
For example, i make this function to check if a page has been visited:
function wt__pagevisited($id){
if ($id == null) {
global $INFO;
$id = $INFO['id'];
}
// get cookie session info
$crumbs = isset($_SESSION[DOKU_COOKIE]['bc']) ? $_SESSION[DOKU_COOKIE]['bc'] : array();
// check ID into breadcrumb
if( array_key_exists($id,$crumbs) ) {
return true;
}
return false;
}
Any help will be appreciated.
Thank you in advance.
Jean-baptiste
What you're asking has nothing to do with DokuWiki. You want to replace PHP functions. That's not possible without the help of certain PHP extensions. See Is it possible to replace a function in php (such as mail) and make it do something else? for more info.
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
I'm creating a mediawiki theme for my wiki. It is more than just css, I'm changing the layout too, as described in the mediawiki docs.
I would like to make the interface very simple, so I want to only show certain sidebars and other content if a user is logged in or is an "admin" user (or whatever they are called in mediawiki).
Changing the layout is done via php functions that I create in my skins php to output various page elements.
How do you check if a user is logged in? Or what rights/role they have? Is there some kind of function I can check, or constant set by mediawiki?
I have found the answer, incase anyone else needs it, it is:
$this->getSkin()->getUser()->isLoggedIn()
and with this function you can check if the user is admin:
/**
* Returns true if user is admin.
*/
protected function userIsAdmin() {
$isAdmin = FALSE;
if ($this->getSkin()->getUser()->isLoggedIn() === TRUE) {
foreach ($this->getSkin()->getUser()->getGroups() as $key => $group) {
if ($group == 'sysop') {
$isAdmin = TRUE;
break;
}
}
}
return $isAdmin;
}