How can I display multiple lines of version.php? - php

I'm new to PHP code and am trying to find a way to display 3 lines from the version.php file within WordPress without having to download the file; look into it and move on - this is what I have come up with so far, but does not seem to be working. I'm sure I'm doing something wrong here and would greatly appreciate some help.
<?php
$version = "wp-includes/version.php";
$all_lines = file($version);
echo $all_lines[16];
echo $all_lines[23];
echo $all_lines[37];
?>

To be able to see specific version numbers on your frontend its best to create a shortcode and use that shortcode to output.
Add the below code in functions.php file.
function bks_show_versions( $atts ) {
global $wpdb;
$wordpress = $GLOBALS['wp_version'];
$php_version = phpversion();
$mysql_version = $wpdb->db_server_info();
return sprintf("<pre> wordpress version : %s | php version: %s | mysql version : %s </pre>", $wordpress, $php_version, $mysql_version);
}
add_shortcode( 'show_versions', 'bks_show_versions' );
This basically will fetch all the values and print them on the screen.
<pre> wordpress version : 5.7 | php version: 7.4.16 | mysql version : 5.7.24 </pre>
Now, at whichever page you want it to print,edit that page and add [show_versions] on that page. Now view that page. You should be able to see.
WordPress Version
PHP Version
MySql Version
You can use this article to understand how to add shortcode to a page.
The shortcode you have to add is : [show_versions]

Related

How do I properly add a theme region to a views-view--page.tpl.php in Drupal 7

OK, so here is what I have and found (which works - however it produces a log Notice) "Only variables should be passed by reference in eval()" which is driving me absolutely crazy!
Initially like any theme region I added the regions I wanted for views use to the theme.info file.
; View Regions
regions[view_header] = View Header
regions[view_content] = View Content
regions[view_footer] = View Footer
In the views-view--page.tpl.php I placed these (where I wanted the region to render)
<?php print render(block_get_blocks_by_region('view_header')); ?>
<?php print render(block_get_blocks_by_region('view_content')); ?>
<?php print render(block_get_blocks_by_region('view_footer')); ?>
This produces a notice for each entry in the tpl yet it works as expected 100%
I then tried adding a hook in the themes template.php (in an attempt to make variables out of them) so I can just use <?php print $view_header; ?> like so:
function theme_preprocess_views_view(&$variables){
$variables['view_header'] = render(block_get_blocks_by_region('view_header'));
$variables['view_content'] = render(block_get_blocks_by_region('view_content'));
$variables['view_footer'] = render(block_get_blocks_by_region('view_footer'));
Again this works - and again this produces log notices.. this time 3 for each region on all page loads, so 9 instead of 3 (not just when the views-view--page.tpl.php loads) which traced back to theme template.php (same notice as listed above this time but no notice from the $variables used in the views template when that page loads).
Obviously I'm missing something here! Maybe this is entirely the wrong way to do this...
How do I make the theme regions usable variables in tpl's?
I'm under the impression everything I've found is years old (3 to 10) and likely worked fine for php 5.x - this site is currently using php 7.2.x (should that make a difference in how this needs to be done)
Any help here would be greatly appreciated, thank you!
This is because the function render() expects a reference, and only variables should be passed by reference :
function render(&$element) {
# code need to be able to modify $element
}
render('value'); # throws notice
render(block_get_blocks_by_region('view_header')); # throws notice
$value = 'value';
$build = block_get_blocks_by_region('view_header');
render($value); # Ok
render($build); # Ok
Also, I think the way to go should be to assign the renderable arrays to $variables in the preprocess hook :
function theme_preprocess_views_view(&$variables){
$variables['view_header'] = block_get_blocks_by_region('view_header');
$variables['view_content'] = block_get_blocks_by_region('view_content');
$variables['view_footer'] = block_get_blocks_by_region('view_footer');
# ...
}
... and let the template call render() :
<?php print render($view_header); ?>
<?php print render($view_content); ?>
<?php print render($view_footer); ?>

WP v-5.5 $_GET parameter does not work in my plugin

I have developed a wordpress plugin. In my plugin I manage all pages by get parameters like (http://example.com/client-portal/?page=dashboard) and it was working till wordpress version 5.4
But new version of wordpress version 5.5 in automatically redirect http://example.com/client-portal/?page=dashboard to http://example.com/client-portal/. Get parameter vanished automatically.
I have added shortcode by this way -
//page short code for user page
add_shortcode( 'ccgclient_portal', array($this,'ccgclient_portal_shortcode_func') );
This is my shortcode function -
function ccgclient_portal_shortcode_func()
{
ob_start();
include_once 'pages/user/index.php';
return ob_get_clean();
}
And catch get parameters by -
if(isset($_GET['page']) && $_GET['page'] == 'dashboard'){
include_once 'dashboard.php';
}
I don't know what's wrong with the new version of wordpress (5.5).
Please can you help me ?
Thanks in advance.
I believe your issue is with the 'page' key, this is a post type slug and it's creating a conflict with WP in this version. This is the same as configuring the permalink to work with '?post=98979' or a similar format.
My suggestion is to try and use a different get key and see what happens.
Let me know what you get.
I have the same issue with my plugin.
My problem was not using a new key. My client defined "page" here. It is about all the old links around in the world.
Im my case I solved it like this:
add_action( 'parse_request', 'ai_parse_request', 1);
and in
function ai_parse_request( $query ) {
unset( $query->query_vars['page']);
return $query;
}
I remove the "page" parameter from the $query to avoid the 301 redirect.
I have made this "workaround" configurable as the page parameter is used actually for pagination in the blog. In you case you should only apply this if e.g. the parameter is not a number to make sure you don't break pagination globally!

Check module position in OpenCart 2.0

I was using following code for Check module position. So, It is working fine in OpenCart 1.5.6. When module Enabled in Content left & right panel so I want to hide javascript code in OpenCart
but, it is not working in Opencart 2.0
How can be achieved in Opencart 2.0?
in .tpl file
<?php if ($module['position'] == 'content_bottom' || $module['position'] == 'content_top') { ?>
//add your code Here
<?php } ?>
add in .php file
$this->data['module'] = $setting;
I have found simple solution. This is working like charm.
Step 1
in .tpl file. (You want to that module. featured.tpl etc...)
<?php if ($module['position'] == 'content_bottom' || $module['position'] == 'content_top') { ?>
//add your code Here
<?php } ?>
Step 2
add in .php file (You want to that module. featured.php etc...)
$data['module'] = $setting;
Step 3 (if, You are used OpenCart 2.0.0.0 version)
catalog/controller/common/{content_top, content_bottom, content_right, content_left}.php,
Find the below code
if (isset($part[1]) && isset($setting[$part[1]])) {
and add the below code after
$setting[$part[1]]['position'] = basename(__FILE__, '.php');
Step 3 (if, You are used OpenCart 2.0.1.x. version)
catalog/controller/common/{content_top, content_bottom, content_right, content_left}.php,
Find the below code
$setting_info = $this->model_extension_module->getModule($part[1]);
and add the below code after
$setting_info['position'] = basename(__FILE__, '.php');
OC 2.0 is a major update so lots of things working on OC 1.5.X might not work on OC 2.X
Eg OC 1.5.x we used to add layout to module now in OC 2.0 we add Modules to layout So In 1.5.x we used to find Module and it's associated positions, Now we find
Positions and it's associated Modules.
Suppose you are working on \catalog\controller\common\content_top.php
After
$modules = $this->model_design_layout->getLayoutModules($layout_id, 'content_top');
Which fetches all the modules set on content_top of the particular layout
Add
$search_text = 'featured'; // name of the module you want to find
$matched_top = array_filter($modules, function($el) use ($search_text) {
return ( strpos($el['code'], $search_text) !== false );
});
if(!empty($matched_top)){
$data['truevalue'] = 1;
}
Now in content_top.tpl you can write script
if(isset($truevalue)){
//here goes script code
}
Similarly You can do the same for content_bottom as well

Connecting to Wordpress Database

I have a problem with my custom theme for wordpress. I made a custom theme locally on my PC where I installed Wordpress. Now inside my theme is another folder let's say php, and inside this folder is a php file that will fetch data from the database which I want to run later on. The code in this php file is as follows:
<?php
define('WP_USE_THEMES', false);
require('/wp-blog-header.php');
header('HTTP/1.1 200 OK');
global $wpdb;
$rs = $wpdb->get_results("select * from wp_users");
$user_db=$rs[0]->user_nicename;
echo $user_db;
?>
The codes above works on my local machine, where it prints out the user_nicename field from my local database (phpMyAdmin). Now when I upload and install the custom theme I made and access this php file the browser displays nothing. Is something missing in define or require so I can successfully connect to the Wordpress database? Any help help would be much appreciated.
Please note that theme is located at C:\wamp\www\wordpress\wp-content\themes\custom_theme and the php file to connect to database is here: C:\wamp\www\wordpress\wp-content\themes\custom_theme\php\connect.php
Instead of using the above code, why not just the function get_userdata on your template where you want to display the user nicename.
<?php
$user = get_userdata( $userid );
echo $user->user_nicename;
?>
See http://codex.wordpress.org/Function_Reference/get_userdata for details and look at the "Related" section at the bottom for other related uses.

Wordpress: How to set default (active) theme via script

I need to assign the "active" theme via script. Anyone know the API call needed to do this? Also, how do I retrieve the current theme via script (PHP)?
Update current_theme option:
update_option('current_theme', '[theme name]');
To get the theme's name use:
$themes = get_themes();
In current Wordpress version 3.4.2 you need to update 3 options to switch to another theme(minihyper - in my case)
update_option('template', 'minihyper');
update_option('stylesheet', 'minihyper');
update_option('current_theme', 'Mini Hyper');
The first two options are key, the third really does nothing except maybe you can use this option somewhere in code to display current theme name.
Update:
Here is a true way:
<?php switch_theme( $template, $stylesheet ) ?>
Example with minihyper:
<?php switch_theme( 'minihyper', 'minihyper' ) ?>

Categories