Wordpress admin plugin to save hidden input data to database - php

I am creating a Wordpress plugin for the admin area. It needs to set options and write to a file and database based on the options that are saved.
I have tried creating a "Create File" button which sends POST data back to itself. I now need to create a file and add a column to the database based on a hidden boolean filed.
I'm struggling because I can't do what I want because the form needs to have a different action. Any advice on how to so this?

What a different action? Without any code examples that show what you're doing and what exactly is not working, we only can imagine and give you general info. In Wordpress, you don't have to care about naked url options cause the core will do this for you. Its enough to register the required hooks, read the passed data here and do what is required with them. Simple storing settings wouldn't require to extend the database scheme, since Wordpress already have a table for this. You could use the Wordpress functions here.
See the article of the Wordpress developers page: https://codex.wordpress.org/Creating_Options_Pages
Using the hooks, its no big deal to create a file too. Simple write your PHP code after saving the settings in the database. How you concretely do this depends on the requirements: Is the data passed as form field? Is it fetched from an external source (like api)? Depending on the requirements this should be done with relatively less work using a search engine, cause enough sample codes exists for those scenarios.

Related

Change Post Id in wordpress post

I have to add the custom Post id for the custom post type. can anyone help me?
Check screen short for more details. http://prntscr.com/mo3eyu
This is a work around that works.
Background info:
We maintain a few almost identical web pages with different branding. The code repo is shared across these. The developers hard coded page IDs into the PHP in the past. I was asked to add new pages. After adding new pages on each website, I noticed the IDs were all randomly generated. This was breaking PHP code's logic. So, I needed to edit these IDs just like OP.
The work around:
In WP web admin page, there's an export / import functionality under tools menu. The new pages should be created in one site, then exported / imported onto other websites. This way, page IDs don't get created randomly. It copies the IDs from the exported page. So you can have same IDs on all pages.
PS:
Not sure why the past developers decided to hard-code page IDs in the code. This shouldn't have been the case to start with. When you don't have much time to refactor everything, stack overflow always comes to help.
IDs determine post record storage in database, changing them directly would be highly prone to breaking things. For example extensions often store IDs as a way to refer to specific post and do something with it.
The simple way to change to some ID would be to just create a new post and copy data over (through admin or with code either).
Post ID of a post also reflect in tables other than Post table, like post comments table. Changing post ID will disturb the relationship of post table with other tables, so it is not advisable.

WordPress Login System (with the loop?)

I currently have a MySQL database from my old site that used to have a basic PHP log-in form and it would query a table containing the user information to log them in. Basic stuff. However I've recently moved to WordPress and it appears to be quite overwhelming at first, so I'm struggling to understand how to integrate my old log-in form with a WordPress site.
I have tried looking at this post:
Wordpress login system and I am still confused. I understand the 'loop' is responsible for displaying multiple 'Posts' on a single page. But to integrate my own PHP code or more specifically; a log-in page, would I make a logged-in 'Post' and a not-logged-in 'Post', and perhaps use a template to display one or the other for a single page via a 'Loop' that uses an if statement to check if the user is logged in?
Or is there some easier method that I'm completely missing?
Thanks!
EDIT: I've thought about creating two pages, both using a template to check if the user is logged in at the top, and display relevant content if they are, or redirect to the log-in page if they aren't. Would this work?
The other possible method I could think of is creating two Posts and displaying the relevant one on a single Page via The Loop. Would this be possible? Are there any security concerns?
EDIT2: I'm going to try the Members plugin and see if I can modify the WordPress MySQL tables to allow room for my previous data.
EDIT3: I need to sync my user logins to our external database as it contains flags to check whether my members are able to access our 'support' pages. I'm not sure how this would be viable while relying on the normal WordPress login system and tables.
Keep it simple stupid.
The point of WordPress is to make things easier. So if you want to go with WP, you should adopt the WP way of doing things.
As comments has suggested, import your current user table into WP. Should be simple enough to change the columns around to get a working import directly into the WP users table.
If there is extra information in your current user table, simple create new fields in the User Profile section of WP. There should be plugins for this (although I have not tried any), but it is quite simple to add these fields yourself, just google for it, there are many tutorials.
For a frontend page to be accessed by only logged in users, simple create a page template and check if user is logged in with is_user_logged_in().
For the access part (Support Pages), either create different user roles and check that the currently logged in user is of the correct role. Or you could also add a custom user capability and validate it on your support pages.
Based on the very general details you have given there is no 'easier method' you are missing. We can't help you form the requirements of your application, but we can help with code if you paste examples of the code you are using, what you are trying to achieve, and what is going wrong with it. Pick one thing, try it out, and if it doesn't work and you get stuck then post it here.

PHP Widget layout grid

I'm building a webapp which main purpose is displaying widgets on a display. These widgets have an variable size, so not every widget is even high or wide (But they are using standards like for example a grid system). Now I'm looking for the best way to save which widgets are used, and where they are placed. For example by using something like Gridstack the user can drag and place the widgets in an admin panel, but how should I save this? And how can I recall this and put in a empty Bootstrap page for example. Working with the Bootstrap Grid system would be great aswell.
I did some research on Google and here but didn't find any plugins or ways to do this.
I'm using 'Gridster' at the moment which this Gridstack is built off of/inspired by, so it probably won't be able to save for you.
You'll need to do that, either by sending it back via AJAX or storing in local storage. As it looks similar, you should be able to find a 'serialization' function which should wrap it up ready for you to send to your PHP via AJAX.
You may need to scan through the widgets and wrap them up in your own JSON string, such as the row/column/sizex/sizey which is all the grid system really needs to "add" a widget when its first loaded up, so as long as you can feed that back in you should be good to go.

Migrating custom database pages to Wordpress

I've been toying with the idea of using Wordpress as a CMS to replace the various database-driven pages I've kludged together over the years. I'm wondering though if there's a seamless way to grab info from a database based on the URL.
e.g. I have pages that serve up info on awards
/academy-awards grabs the intro info from the database
/academy-awards/32 grabs the intro info about the 32nd edition
/academy-awards/32/winners grabs the results and commentary for that ceremony
Now, academy-awards is actually an extensionless php file and depending on what comes after it (nothing, a number, a number and word) it serves up the various pages.
How would/could I translate that work into Wordpress? I'm a complete WP noob, so I'm hoping your initial answers can help me dig a little more.
Unless there is already an import filter or plugin, there's no easy way to import post/page data into Wordpress posts/pages without making and using a custom database query that will insert what you want into the correct spots in the WP database schema.
That said, you can export tables out of phpmyadmin into CSV or plain text and then manipulate that data into a a file that when imported will generate WordPress posts/pages. See http://codex.wordpress.org/Database_Description
Also think about setting set up a demo WordPress site, enter some posts/pages and then Export from Dashboard>>Tools>Export and see how a WordPress WXR file is constructed. That is a good format to arrange your data for import. See http://codex.wordpress.org/Tools_Export_Screen
If you simply want to display data from another database, use the wpdb Class. See https://codex.wordpress.org/Class_Reference/wpdb
After digging around some more it appears I can access info from other databases by using Custom Queries (http://codex.wordpress.org/Custom_Queries) and combining them with page templates.

Notify web page about a plugin new version php

I'm developing a web application where users can upload multiple plugins. I want to give an extra value to my app with a feature like wordpress plugin version adviser. I don't know how to deep in this area in order to investigate. I hear someting like "pingtracks", but not sure if this the correct way. Well, that's my doubt, how can I determinate if there is a new plugin version to uptade?
Thanks in advance.
PS: There is a table in my db with all plugins relevent data like url, author, current version, etc.
Each plugin should have a URL for some sort of update manifest. The resource at that URL should contain information such as currently available versions, and the URLs of files that need to be updated. This file could be as simple as static JSON data.
Please remember to use HTTPS, so that it is harder to spoof your update site.
Every time that user uploads a new plugin, check the "current version" in your DB and compare it with the last same-named plugin uploaded. (create another table for saving needed data for example)

Categories