Exclude a function in PHP (Wordpress) - php

I recently purchased a Wordpress theme and having some problems with importing a feature from another theme (from the same author).
The author of the themes helped me a lot with importing some stuff to the new theme. While both themes share many similarities, there's still some tweaking that needs to be done.
One of the issues I'm currently facing is with a PHP file I imported from the original theme to the new one. Both Wordpress themes work with minisites, but the author coded them differently for each Wordpress.
When I copy/paste boxes.php from the old theme to the new theme, I get this error message:
Fatal error: Call to undefined function it_get_minisite() in /home/vincevc73/domains/quirk.be/public_html/wp-content/themes/explicit/inc/boxes.php on line 13
The author told me I had to exclude this, but I have no idea how to do this. I read I had to put /*-*/ around the functions to exclude it, but I'm not sure where to put these marks exactly
The it_get_minisite function appears three times in the file
$minisite = it_get_minisite($post->ID);
if($minisite)
{
#override general theme options with minisite-specific options
$boxes_layout = $minisite->boxes_layout;
}
#get the current minisite $minisite = it_get_minisite($post->ID);
if($minisite)
{
#add post type to query args
if(it_targeted('boxes', $minisite))
$boxesargs['post_type'] = $minisite->id;
}
$minisite = it_get_minisite(get_the_ID(), true);

I think he meant that you should remove all the code which requires this function. But then you will also have to remove the code which requires "$minisite" too. But that's only a guess based on the information you posted.

Related

My php code is keep getting disable in wordpress editor after upgraded into latest version

My website had a older version of wordpress. Recently I upgraded it to the latest version. After that my php code what I write in the editor is keep getting disabled.
The old page which has php code in ti still works. Although in the editor the php codes are disabled. But if I try to save that it stops working. So i cannot update those page. And also I cannot create new page with php code in it
Exec-PHP plugin is installed.
If I write
<?php echo $c; ?>
It converts into
<!--?php echo $c; ?-->
How to fix that
attached image for better understanding.
Another way, which I don't quite recommend, is to follow this direction:
https://wordpress.org/support/topic/exec-php-to-work-in-php-7-needs-this/
This is basically updating the actual plugin, which will surely be overwritten by their next update.
This plugin requires a number of changes to work with php 7.
In exec-php.php
$GLOBALS[‘g_execphp_manager’] =& new ExecPhp_Manager();
must be changed to
$GLOBALS[‘g_execphp_manager’] = new ExecPhp_Manager();
In includes/manager.php from line 36
change each =& to =
In includes/admin.php lines 53,56,57,63,64,79 change =& to =
In includes/cache.php line 22,39 change =& to =
In includes/ajax.php line 64 change =& to =
I don't know about the plugin you use for this. However, I use xyzscripts for the same cause. It creates short-codes for me to use.
Here is an example:
Create your PHP code and get a Tracking Name.
You will then get your short-code as below, note the Tracking Name.
I personally think this is the best way as it allows re-usability and centralized location to update all your scripts.
XYZ WP PHP Code Download and Documentation
Thank you all for responding.
Apparently I find the solution by installing the Classic Editor plugin
https://en-gb.wordpress.org/plugins/classic-editor/
It prevents disabling the php code.
If you are facing similar problem you can try this one

How to call TYPO3 plugin when normal page renders

Well, I am developing a plugin a and I need to display some stuff from my plugin when TYPO3 page load.
Is there some function how to hook action, like in WordPress when page loads than plugin will execute some controller method? Then this controller will produce some output a HTML, which I would like to dispaly in frontend page. Specially I would like display custom script in the head. So the script should be like this <head>...<script>my content</script>...</head>
Ok, what you probably want to do is to develop a so-called TYPO3 extension - that's what plugins/add-ons are called in TYPO3 (which is the term you will likely find google results for).
To get started fast you can try the TYPO3 extension builder (https://docs.typo3.org/typo3cms/extensions/extension_builder/) - which can generate a skeleton extension for you.
For more information you can also have a look at https://docs.typo3.org/typo3cms/CoreApiReference/latest/ExtensionArchitecture/Index.html which explains the concepts in far more detail.
Additional information is available in https://docs.typo3.org/typo3cms/ExtbaseFluidBook/Index.html
in TYPO3 there is something named plugins, but you should differ to the meaning in other context.
first TYPO3 is a CMS which content is structured in a hierarchical tree of pages. These pages are the basis for navigation. and each page contains individual contentelmenents (CE).
As Susi already told: add ons to TYPO3 are in general 'extensions' which could extend(!) the functinality of TYPO3 in different ways. one way is the definition of (TYPO3-)Plugins. These are special ContentElements which enable to show special information.
While normal CEs have all the information what to show in the record (e.g. Text & Image), plugins can be more flexible.
typical examples are: show a list of records OR one record in detail.
These Plugins can be controlled with typoscript or the plugin-CE could have additional fields to hold information what to display.
For detailed information how a plugin is defined consult the links given by Susi.
And be aware: for security reasons it is not possible to just execute a plain PHP file to echo any output. You need to register your plugin using the API, build your output as string and return the generated HTML as string to the calling function. For beginners the ExtensionBuilder will help you to generate a well formed extension which uses the API to register and output your data.
OK guys, thanks for your answers, but it was not very concrete. I found this solution, is not the best one, but it works! If anybody has better please share.
At first, you have to make a file for the class which will be called from the hook at location /your-plugin-name/Classes/class.tx_contenthook.php. Filename have to have this pattern class.tx_yourname.php Inside we will have a code with one method which will be called by the hook.
class tx_contenthook {
function displayContent(&$params, &$that){
//content of page from param
$content = $params['pObj']->content;
//your content
$inject = '4747474747';
// inject content on
$content = str_replace('</body>', $inject. '</body>', $content);
// save
$params['pObj']->content = $content;
}
}
And next, we have to call it on the hook. So Let's go to /your-plugin-name/ext_localconf.php and add there these two lines, which makes a magic and handles also caching.
// hook is called after caching
$TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['contentPostProc-output'][] = 'EXT:' . $_EXTKEY . '/Classes/class.tx_contenthook.php:&tx_contenthook->displayContent';
// hook is called before caching
$TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['contentPostProc-all'][] = 'EXT:'. $_EXTKEY .'/Classes/class.tx_contenthook.php:&tx_contenthook->displayContent';
I hope this will help those who struggling with typo3.

Error: Call to undefined function get_meta() in functions.php

I have inherited a custom wordpress theme and am doing a few changes to it (all cosmetics of changing city names, etc) , but at the bottom of a post I get the error : "Fatal error: Call to undefined function get_meta()"
In my functions.php I have this:
function bardetails(){
$web = get_meta('web');
$email = get_meta('email');
//...
}
I have a Java background but am new to php and wordpress. I dont see anywhere else this function is called, but must be tied to a post.
Have looked and can find a lot of problems about "get_post_meta()" and "meta()" but nothing about this. It also seems to be working on the other site the theme is on. I used FTP to pull over everything and all the other parts of the site seem to work fine. Looked at the database for something that could help with no luck, and also have tried to find if this is some kind of library, as the intention of the function is clear and thats to grab the website/email of the post.
So is this just a straight custom function? And if so were should it be defined in a php/wordpress setup?
It was due to a plugin that was not installed. "More Fields" By Henrik Melin, Kal Ström is a seemingly defunct plugin that was needed that allows you to use "get_meta()". For now, I just copied over the plugin but seems like I need to find an alternative going forward.

WordPress - overwrite core function even after theme or site update

I have googled this, of course, but I require a solution that stays put even after I upgrade a theme AND/OR upgrade the entire WordPress site to a newer version.
Basically, before a post is shown, I want to show specific HTML. And I want it absolutely foolproof because I will be handing over the site to an old guy. I also don't want any plugins installed because I am quite sure he will be clicking on stuff randomly. -it must be seamless.
It must be an analog of what this would do like this: (post-template.php)
function the_content( $more_link_text = null, $strip_teaser = false) {
$content = get_the_content( $more_link_text, $strip_teaser );
/**
* Filter the post content.
*
* #since 0.71
*
* #param string $content Content of the current post.
*/
$content = apply_filters( 'the_content', $content );
$content = str_replace( ']]>', ']]>', $content );
$EXTRA_HTML='';
if(is_single()){$EXTRA_HTML='INSERT HTML HERE';}
echo $EXTRA_HTML.$content;
}
I cant get my head around it. What should I put and WHERE? The updates just make it all go away.
To make sure any solution you make up will not be overwritten on post and themes update, the best way around is creating a Child Theme and adding the piece of HTML you want on its proper place. Probably on a loop template or single.php depending on how the base theme is structured.
This way, even if Wordpress or the Core Theme he's using is updated, you'll have your solution online as your Child Theme will not be replaced.
Another solution for this would be using a theme and make sure it's always online by making two simple adjustments on your WP setup:
On wp-content folder create a new folder called mu-plugins and drop your custom made plugin in there. mu-plugins stands for Must Use Plugins and plugins on this folder will always be enabled and can't be turn off unless you delete it from the server folder.
Make sure the user can't edit theme and plugin files by dropping define( 'DISALLOW_FILE_MODS', true ); line on wp-config.php.
Both solutions will help you achieve this customization without a regular user being able to break it by simple button clicking around. If this can still be an issue, you can also hide any admin settings that can cause trouble in the future. I use Adminimize quite often with the solutions above to make sure any user will not click and break stuff around.

Wordpress loop inside of function = fatal error

I have my Wordpress blog on blog.mysite.com, and a totally different site (built in my framework) at www.mysite.com.
I know if the blog and another site are on the same server, and have correct permissions, I can use the following to "syndicate" my blogs to the non-blog site with:
define('WP_USE_THEMES', false);
require('/var/www/vhosts/mysite/subdomains/blog/httpdocs/wp-config.php');
query_posts('showposts=5');
...and then run a loop on the page.
The problem is that since my non-blog site is a framework, everything except for my front controller lives in a function - and this is creating the following error for me:
Fatal error: Call to undefined method
stdClass::set_prefix()
(btw, I'm fairly certain the fact that this code is called within a function that is causing the error...when I put the code on the front controller (not in function), the error disappears)
I would REALLY like to have recent blog listings on my non-blog site to spruce it up. Any ideas on how to do this?
Well I guess you forgot to write
global $wpdb
inside the function

Categories