| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Gutentools |
| 4 |
* Description: Gutentools is a powerful block editor plugin designed for seamless full-site editing. It offers a range of customizable blocks, including page and post sliders, containers, and more, all with flexible responsive controls. With an intuitive drag-and-drop visual editor, you can easily create engaging layouts and dynamic content for any device. Unlock the full potential of WordPress with blocks that are tailored for a smooth design experience. |
| 5 |
* Version: 1.1.5 |
| 6 |
* Author: Gutentools |
| 7 |
* Author URI: https://gutentools.com/ |
| 8 |
* License: GPLv3 or later |
| 9 |
* License URI: https://opensource.org/licenses/GPL-3.0 |
| 10 |
* Text Domain: gutentools |
| 11 |
*/ |
| 12 |
|
| 13 |
// Exit if accessed directly. |
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
if ( ! function_exists( 'gutentools_get_version' ) ) { |
| 19 |
/** |
| 20 |
* Get Plugin Version |
| 21 |
* |
| 22 |
* @return string |
| 23 |
*/ |
| 24 |
function gutentools_get_version() { |
| 25 |
$data = get_file_data( __FILE__, array( 'version' => 'Version' ) ); |
| 26 |
return $data['version']; |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
add_action( 'plugins_loaded', 'gutentools_load' ) ; |
| 31 |
|
| 32 |
function gutentools_load(){ |
| 33 |
define( 'Gutentools_File', __FILE__ ); |
| 34 |
define( 'Gutentools_Url', plugin_dir_url( Gutentools_File ) ); |
| 35 |
define( 'Gutentools_Path', plugin_dir_path( Gutentools_File ) ); |
| 36 |
define( 'Gutentools_Version', gutentools_get_version() ); |
| 37 |
|
| 38 |
require_once Gutentools_Path . "core/class_block_helper.php"; |
| 39 |
require_once Gutentools_Path . "core/block_configuration.php"; |
| 40 |
require_once Gutentools_Path . "inc/svg.php"; |
| 41 |
require_once Gutentools_Path . "inc/plugin-page.php"; |
| 42 |
require_once Gutentools_Path . "inc/script_loader.php"; |
| 43 |
if ( ! function_exists( 'gutentools_pro_get_version' ) ) |
| 44 |
require_once Gutentools_Path . "inc/admin-notice.php"; |
| 45 |
|
| 46 |
do_action( 'after_gutentools_gutentools_load' ); |
| 47 |
} |
| 48 |
|
| 49 |
function gutentools_register_plugin_image() { |
| 50 |
$existing_attachment_id = get_option( 'gutentools_image_id' ); |
| 51 |
$source_file = plugin_dir_path( __FILE__ ) . 'img/default.png'; |
| 52 |
$upload_dir = wp_upload_dir(); |
| 53 |
$dest_file = $upload_dir['path'] . '/default.png'; |
| 54 |
|
| 55 |
if ( $existing_attachment_id ) { |
| 56 |
$existing_file = get_attached_file( $existing_attachment_id ); |
| 57 |
|
| 58 |
if ( $existing_file !== $dest_file || !file_exists( $existing_file ) ) { |
| 59 |
wp_delete_attachment( $existing_attachment_id, true ); |
| 60 |
update_option( 'gutentools_image_id', '' ); |
| 61 |
} else { |
| 62 |
return; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
if ( file_exists( $source_file ) ) { |
| 67 |
if ( ! copy( $source_file, $dest_file ) ) { |
| 68 |
return new WP_Error( |
| 69 |
'file_copy_failed', |
| 70 |
__( 'Failed to copy file to uploads directory.', 'gutentools' ) |
| 71 |
); |
| 72 |
} |
| 73 |
|
| 74 |
$filetype = wp_check_filetype( $dest_file, null ); |
| 75 |
|
| 76 |
$attachment = [ |
| 77 |
'post_mime_type' => $filetype['type'], |
| 78 |
'post_title' => sanitize_file_name( basename( $dest_file ) ), |
| 79 |
'post_content' => '', |
| 80 |
'post_status' => 'inherit', |
| 81 |
]; |
| 82 |
|
| 83 |
$attachment_id = wp_insert_attachment( $attachment, $dest_file ); |
| 84 |
|
| 85 |
require_once( ABSPATH . 'wp-admin/includes/image.php' ); |
| 86 |
$attach_data = wp_generate_attachment_metadata( $attachment_id, $dest_file ); |
| 87 |
wp_update_attachment_metadata( $attachment_id, $attach_data ); |
| 88 |
|
| 89 |
update_option( 'gutentools_image_id', $attachment_id ); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
add_action( 'init', 'gutentools_register_plugin_image' ); |
| 94 |
register_activation_hook( __FILE__, 'gutentools_register_plugin_image' ); |
| 95 |
|
| 96 |
|