WordPress Multi-site Plugin and Manage galleries.

Published on : April 27, 2026

Author:

Category: Uncategorized


A plug-in (or plugin, add-on, Module, or extension) is a software component that adds or removes or modify a specific feature to an existing computer program.

WordPress has single and multi-site installation feature and also it’s plugin has both site installation features.

WordPress single site plugin:

  1. Create a folder. Like – our_first_wp_plugin
  2. Into this folder create a PHP file with exactly same name. Like – our_first_wp_plugin.php
  3. Open this php file with an editor. Add some code as below –

Plugin Name: Name of your plugin. Like- Example

Plugin URI: Plugin URL. Like – http://example.com

Description: Plugin Description. Like – This is my extremely awesome WordPress plugin

Version: Plugin version. Like – 1.0

Author: Developer Name. Like – CyberNetikz

Author URI: http://https://dev.cybernetikz.com

Final Code:

Plugin Name: Example

Plugin URI: http://example.com

Description: This is my extremely awesome WordPress plugin

Version: 1.0

Author: CyberNetikz

Author URI: http://https://dev.cybernetikz.com

So, our single site plugin is ready.

 

WordPress Multi-site site plugin:

Just add another option to plugin description section-

Network: True

Final Code:

Plugin Name: Example

Plugin URI: http://example.com

Description: This is my extremely awesome WordPress plugin

Version: 1.0

Author: CyberNetikz

Author URI: http://https://dev.cybernetikz.com

Network: True

 

Now need to create a function that automatically runs after installation. For this see below code –


register_activation_hook(__FILE__, ‘default_function _install'); //  default_function _install is a php function name.

function default_function _install{

// Write something that you want or develop.

}

Also need to create a function that automatically runs during deactivation this plugin. For this see below code –


register_deactivation_hook( __FILE__, ‘default_function _uninstall ' ); // default_function _uninstall is a php function name.

function default_function _uninstall {

// Write something that you want or develop.

}


Get all data from gallery:


function get_all_data_from_gallery()
{
	$taxonomies = array(
		'gallery' // Taxonomi name
	);
	
	$args = array(
		'orderby'                => 'name',
		'order'                  => 'ASC',
		'hide_empty'             => false,
	); 
	
	$terms = get_terms($taxonomies, $args);	
	print_r($terms);
}

 

Full gallery private to public:


function gallary_private_to_publish($gallery_name){

	$ca_name_args = array(
		'post_type'     => 'phts',
		'post_status'   => array('pending', 'draft'),
		'showposts'     => -1,
		'tax_query' => array(
					array(
						'taxonomy' => 'gallery',
						'field'    => 'slug',
						'terms' => $gallery_name
					),
				),
	);
	$ca_name_query = new WP_Query( $ca_name_args );
	
	while( $ca_name_query->have_posts() ): $ca_name_query->the_post();
		$c_post_id = get_the_ID();
		
		$my_post = array(
			'ID'           => $c_post_id,
			'post_status'   => 'publish'
		);
		
		wp_update_post( $my_post );
			
	endwhile; wp_reset_postdata(); wp_reset_query();	
}

 

Full gallery public to Private:


function gallary_public_to_private($gallery_name){

	$ca_name_args = array(
		'post_type'     => 'phts',
		'post_status'   => array('publish'),
		'showposts'     => -1,
		'tax_query' => array(
					array(
						'taxonomy' => 'gallery',
						'field'    => 'slug',
						'terms' => $gallery_name
					),
				),
	);
	$ca_name_query = new WP_Query( $ca_name_args );
	
	while( $ca_name_query->have_posts() ): $ca_name_query->the_post();
		$c_post_id = get_the_ID();
		
		$my_post = array(
			'ID'           => $c_post_id,
			'post_status'   => 'pending'
		);
		
		wp_update_post( $my_post );
			
	endwhile; wp_reset_postdata(); wp_reset_query();	
}

 

Download Full gallery as zip:


function download_gallery($category_name){
	
	$ca_name_args = array(
		'post_type'     => 'phts', // Change post Type
		'post_status'   => array('publish'),
		'showposts'     => -1,
		'tax_query' => array(
					array(
						'taxonomy' => 'gallery', // Change texonomi name
						'field'    => 'slug',
						'terms' => $category_name // Dynamic cat name - slug
					),
				),
	);
	$ca_name_query = new WP_Query( $ca_name_args );	
	
	$dir_name = 'download_images_'.time();
	$plugin_dir = plugin_dir_path( __FILE__ ).$dir_name;					
	if ( ! file_exists( $plugin_dir ) ) {wp_mkdir_p( $plugin_dir, 0775, true);}
	
	$zip = new ZipArchive;					
	$zip_file_name = plugin_dir_path( __FILE__ ).$dir_name.'.zip';
	
	if ($zip->open($zip_file_name, ZipArchive::CREATE) === TRUE)
	{	
		while( $ca_name_query->have_posts() ): $ca_name_query->the_post();
			$c_post_id = get_the_ID();
			$full_size_thum = wp_get_attachment_image_src(get_post_thumbnail_id($c_post_id), 'full', false );
			
			if(!empty($full_size_thum[0]))
			{
				$image_name = basename($full_size_thum[0]);
				copy($full_size_thum[0], $plugin_dir.'/'.$image_name);
				chmod($plugin_dir.'/'.$image_name, 0775);
				
				$zip->addFile($plugin_dir.'/'.$image_name, $dir_name.'/'.$image_name);
			}
				
		endwhile; $zip->close(); wp_reset_postdata(); wp_reset_query();
		
		$ab = Delete($plugin_dir);
		
		$zi_link =  plugins_url( 'plugin_folder_name/'.$dir_name.'.zip', dirname(__FILE__) ); // plugin folder name
		header('Location: '.$zi_link);	
	}
	
}