Auto add content such as pages upon plugin activation?

You can add those without a button: register_activation_hook( __FILE__, ‘my_plugin_install_function’); function my_plugin_install_function() { //post status and options $post = array( ‘comment_status’ => ‘closed’, ‘ping_status’ => ‘closed’ , ‘post_author’ => 1, ‘post_date’ => date(‘Y-m-d H:i:s’), ‘post_name’ => ‘Checklists’, ‘post_status’ => ‘publish’ , ‘post_title’ => ‘Checklists’, ‘post_type’ => ‘page’, ); //insert page and save the id $newvalue … Read more

Unexpected Output: register_activation_hook with namespace

When we are outside the Sample namespace, we should call the function by \Sample\sp_activate(), so please try the following: <?php /** * Plugin Name: Sample Plugin * Version: 0.0.2 */ namespace Sample; \register_activation_hook( __FILE__, ‘\Sample\sp_activate’ ); function sp_activate() { } If something is printed out during the plugin activation it will result in unexpected output … Read more

How to include plugin without activation?

WP_PLUGIN_DIR.’/pluginName/’ will give you the absolute path to the directory of the plugin. EDIT After comment Plugins are plugins, theme files are theme files. Lets not confuse the two. You cannot copy a plugin in the theme directory – because stuff does not work like that. After careful editing you can include the plugin as … Read more

How to create a page when a theme is activated?

There is a hook specifically for this purpose, called after_switch_theme. You can hook into it and create your personal page after theme activation. Have a look at this: add_action( ‘after_switch_theme’, ‘create_page_on_theme_activation’ ); function create_page_on_theme_activation(){ // Set the title, template, etc $new_page_title = __(‘About Us’,’text-domain’); // Page’s title $new_page_content=””; // Content goes here $new_page_template=”page-custom-page.php”; // The … Read more

Cannot run the code after I activate the plugin

you can not, and should not be able to write to files directly. You need to use the wordpress filesystem api https://codex.wordpress.org/Filesystem_API which either requires a pre configuration on the site or user manual control. In addition it is just wrong to automatically write anything into wp-config.php as any mistake will bring down the site … Read more

Correct way to use register_activation_hook

This quotation from The Codex clearly states what does this function do: The register_activation_hook function registers a plugin function to be run when the plugin is activated. This means, this function works similar as a class’s __construct() method. You can use it to set initial options, update database, and more. It doesn’t run every time … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)