Overview:
I have a single Joomla website that have various copies of the database tables all in the same database, but with different table prefixes.
Depending on which user is accessing the site, i need to alter which joomla table prefix is used in order to display the relevant tables.
This has to be site wide.
Problem:
with a core code hack i can alter the prefix as needed, but would prefer this as a plugin.
With the plugin i can get the prefix, using $db->getPrefix(), and i can set an immediate instance of the connection using $db = JDatabaseDriver::getInstance( $option ). But this is not site wide and is overwritten by the standard $db = JFactory::getDbo().
So i need a system plugin that will repalce every instance of a table prefix as it is run.
Any ideas?
Sorry but if you install a new component or module you have many problem to synchronize this changes on all DB. I think the best for you is to redirect each user to his real site (many joomla file with many db).
Otherwise you can create a personal component and read table prefix of that user and display only date that you want, in this way just duplicate the tables you need and not all the joomla structure.
Related
I want to run 2 wordpress sites, one.site.com and two.site.com from the same database. Everything remains the same except for the theme.
one.site.com - Existing site
two.site.com - Should use one.site.com's database except for the
theme
Is there any way this can be done ?
Since theme details are stored in wp_options table is it possible for two.site.com to use it to display a different theme ? Say duplicating that table and making two.site.com use it ?
I appreciate any help.
EDIT:
Both the sites do not have any plugins.
The solution below did the job for me,
Install 2 WordPress sites on a single database.
Create new table in your database. Call it wp_options2 and copy everything from wp_options into this new table
In second install go to wp-config.php, and before if (!defined('ABSPATH')) add define( 'M7_OPTIONS_TABLE', 'wp_options2');
In second install go to wp-includes/wp-db.php on line 1009 and add code:
if (isset( $tables['options'] ) && defined('M7_OPTIONS_TABLE')) $tables['options'] = M7_OPTIONS_TABLE;
These codes should be added in public function tables function, before if (isset( $tables['users']) && defined('CUSTOM_USER_TABLE')))
I found this solution here, https://wordpress.stackexchange.com/questions/84313/how-to-run-two-wordpress-blogs-with-different-themes-and-with-single-database-an#answer-175494
Since we use the same database, links will be same on both the sites. I had a lot of images linked and I removed them using
.single a[href$=".jpg"] {
pointer-events: none;
cursor: default;
}
You can run two sites from a single database but not from the same set of database tables as the stored data includes the site's domain name.
There are two values in the options table: siteurl and home which are used. Using the same options table won't work, even if you update options forcefully for each php run.
So you would need to use two databases.
EDIT:
My advice is to replicate base and run both sites on different databases.
This could probably be accomplished by using wildcard subdomains (https://codex.wordpress.org/Configuring_Wildcard_Subdomains).
It may be a little hacky, but you'd have to test the condition of your subdomain (maybe in wp-config.php?) and set the theme in the database (http://www.inmotionhosting.com/support/edu/wordpress/change-theme-in-db).
The only problem I could see with this is that your functions.php can change WP functionality, so a Parent theme with two Child Themes is probably a good idea(https://codex.wordpress.org/Child_Themes).
There is a lot of jiggery hackery regarding this question, but I think there's a fairly simple solution. First, ensure that both of your 2 sites have these hardcoded in wp-config.php:
define('WP_HOME', 'https://example.com');
define('WP_SITEURL', 'https://example.com');
These will help each site "override" whatever the database setting is for the URLs.
Next, decide which site is the MASTER site where you are going to be publishing new blog posts, making edits to site data, and such. On that site, activate the theme you want to use.
Now, go to your SLAVE site (I'm using these terms loosely) and delete that theme via SFTP, and upload whichever other theme you want to use on that site. Then, hardcode it like this:
define('WP_DEFAULT_THEME', 'twentytwenty');
In this way, the SLAVE site tries to find the correct theme from wp_options that is activated on the MASTER site but you deleted it already, so it reverts to using the default theme as defined in wp-config.php
Going forward, do not mess with site settings/plugins/etc on the SLAVE site, and make any changes to the design of your SLAVE site using the theme files only (like a static theme). Obviously if you are using a bloated theme and page builder type of situation that need MySQL, this isn't going to work...
Note: you may need to visit /wp-admin/themes.php on your SLAVE site at least once, to "force" WordPress to load the hardcoded theme.
If anyone is interested, SlickStack supports this approach.
Duplicate of https://wordpress.stackexchange.com/q/65560/wp-multisite-load-content-from-site-x-on-site-y
One might argue that using WP multisite-network functionality and adding a couple of documented API calls to ones theme could be a cleaner solution than manually modifying the database schema and messing with how WP access it.
I want to use another Wordpress installation that gets it's tables from my original Wordpress prefix. I installed both WP installations in the same database with another prefix. I use WP Event Manager and the original prefix is like this:
wp_em_events
I want the same plugin at my new installation to automatically get it's tables from the orginal one, like the following code already does for the users at my wp-config.php:
define('CUSTOM_USER_TABLE', 'wp_users');
Is there a rule I can use at my wp-config.php file like the one that gets the users? or is there another way to get the data from the orginal table to the new one?
Eventually it worked using the following code in wp-config.php:
define('EM_EVENTS_TABLE', 'wp_em_events');
It also works with other (Wordpress) tables:
define('POSTS_TABLE', 'wp_posts');
Pages are also seen as posts. Be sure to get al tables for a plugin, pages, users etc. . In some cases you also have to get the table with the meta information.
I'm making a plugin for WordPress and it requires some custom tables of mine (or the data in them, to be specific). These tables are simple. They only contain an id and a varchar field. Do not mention meta fields. I am using custom tables for a reason. The problem is, I need to allow the user to edit the data in these tables. To insert, update and delete rows in the tables. How do I handle this in WordPress?
I can make my own custom pages and create a whole system for editing, inserting and updating them but that's a workaround since none of that would be native to WordPress.
The only thing I came up with is making them into custom post types and having WordPress let me use its native adding, editing and deleting menu (the same one used in posts, pages, etc.). Though then new problems would arise. I need to connect the post ids to the rows in the custom tables and be very careful when editing, updating and deleting to make sure that both the posts and my custom table data remain consistent with each other. And that's a whole new layer of complexity.
So I was wondering if there's an elegant way to handle these sorts of simple tables. If there isn't I'll find my own workaround.
EDIT:
The plugin I'm making is supposed to turn your WordPress site into a kind of an ad posting site. And I need the custom tables to provide details about the ads.
refer this codex Wp_list_table. you can play with custom table data. for more you can go through an example plugin.
In Joomla 3 I have a need to specify different admin templates for K2 articles based on category to be able to specify different extra fields and make it easier for content contributors to add items.
I thought I'd found the perfect solution, but it was written several years ago for older versions of Joomla. I did contact the author and he admitted writing it several years ago, has since quit using Joomla and was not able to advise me.
It is very similar to overriding front-end k2 templates. Here is the article describing it:
http://getk2.org/documentation/tips-a-tricks/221-custom-admin-templates-and-calling-specific-extra-field-data
However when I do this and modify a category's admin template, there is no change from the default. My thought is that something in this code which modifies the file administrator/components/com_k2/views/item/view.html.php is not compatible with Joomla v.3:
//Look for specific admin template file
jimport('joomla.filesystem.folder');
$componentPath = JPATH_SITE.DS.'components'.DS.'com_k2'.DS.'templates';
$componentFolders = JFolder::folders($componentPath);
$db =& JFactory::getDBO();
$query = "SELECT template FROM #__templates_menu WHERE client_id = 0 AND menuid = 0";
$db->setQuery($query);
$defaultemplate = $db->loadResult();
if (JFolder::exists(JPATH_SITE.DS.'templates'.DS.$defaultemplate.DS.'html'.DS.'com_k2'.DS.'templates'.DS.'admin'.DS.$item->catid))
{
$this->_addPath('template',
JPATH_SITE.DS.'templates'.DS.$defaultemplate.DS.'html'.DS.'com_k2'.DS.'templates'.DS.'admin'.DS.$item->catid);
}
Already, I know there is no table in my db with the name "templates_menu". That threw an error immediately. I believe it should template_styles", and most likely the columns should be client_id and id. Making those changes eliminated the error at least.
Further, I believe the path is incorrect in the "if" statement. The second "templates" directory is not needed.
However, even after making these changes, I do not seem to be pulling in my new template on the admin side.
I am hoping a Joomla/PHP expert (which I am not) can weigh in here. I could be entirely wrong in my assumptions about the pathing and table name.
Edit: In researching this further, I decided to go ahead and CREATE the table that was indicated in the original poster's code. I now have a table in my database called e758z_templates_menu.
However, I still get nothing when trying to make Joomla use a custom admin template connected to a category ID. It continues to use the default one.
Can you not just create different extra filed groups and then assign the right ones to the right category?
If you modify the k2 core files then any changes will be wiped on an update, which, with the new 1-click updates would be quite likely.
You should be able to override the standard admin view with a standard template override, ie
copy
/administrator/components/com_k2/views/category/default.php
to
/administrator/templates/YOUR_ADMIN_TEMPLATE/html/com_k2/category/default.php
If you want them to be different for different categories then why don't you create a frontend login and then use different templates for different categories and override them in the standard way.
I wrote a plugin for WordPress which has a few user-configurable settings that are stored using WordPress's suggested method. I know they are saved in the wp_options table, but that is abstracted by the WordPress options API.
Now I'm trying to add a "global override" of the settings that can be configured in the Network Admin section of a multi-site installation. I found the appropriate hooks to design my settings page, however I can't find any info about where to save the data.
If I save it using the normal options API, then the settings get saved individually for each site. I'm looking for a place to save them globally for all sites, so the plugin can first look to see if the settings have been globally overridden by the server admin.
I can just write some code to write directly to the wp_options table of one of the sites (for example site #1) or even create my own table. I know how to do all of these things, but I don't want to do that if there's a preferred way to write mult-site plugins.
Thanks for any advice.
As you know the main deference between developing a single WordPress plugin vs. a multisite plugin is where data is written. According to this article since plugins normally have complete reign over one database, and in some cases the plugins local pages files you must be sure to only call the $wpdb global object instead of a hard-coded reference to a table.
For example, if you need to execute an SQL command on the posts table, then do not use wp_posts as the table name $post_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM wp_posts"));
use this
$post_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts"));
Please see the article for further info.