Skip to content

Commit

Permalink
import from v1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
5um17 committed Feb 7, 2023
1 parent c2364ef commit d803529
Show file tree
Hide file tree
Showing 9 changed files with 2,874 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/node_modules
/languages
/build
/vendor
54 changes: 54 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Gruntfile
*/

module.exports = function (grunt) {

// Grunt configuration
var config = {
pkg: grunt.file.readJSON('package.json'),

makepot: {
target: {
options: {
type: 'wp-plugin',
domainPath: '/languages'
}
}
},

copy: {
main: {
expand: true,
src: [
'**',
'!.*',
'!.git/**',
'!README.md',
'!node_modules/**',
'!package.json',
'!package-lock.json',
'!Gruntfile.js',
'!composer.json',
'!composer.lock',
'!vendor/**',
],
dest: './build'
}
},

clean: ['./build']
};

//init grunt
grunt.initConfig(config);

//Load Tasks
grunt.loadNpmTasks('grunt-wp-i18n');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');

//Register Tasks
grunt.registerTask('default', ['makepot']);
grunt.registerTask('build', ['default', 'clean', 'copy']);
};
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
# classic-widgets-with-block-based-widgets
Restore the classic widgets screen as a new menu item without replacing new block-based widgets.
# Classic Widgets with Block-based Widgets

<p align="center"><a href="https://wordpress.org/plugins/classic-widgets-with-block-based-widgets/"><img alt="Classic Widgets with Block-based Widgets" src="https://ps.w.org/classic-widgets-with-block-based-widgets/assets/banner-1544x500.png?rev=2861054" /></a></p>

*Classic Widgets with Block-based Widgets* allows you to use both widgets screens at the same time.
Sometimes, you need to use the classic widget screen for some of the widgets without permanently disabling the block-based widgets. With this plugin, you can access the Classic Widgets screen in `Appearance > Classic Widgets` and the block-based screen at the usual place in `Appearance > Widgets`.

>This plugin uses WordPress filters to create a new classic widget screen. That means it will work as long as WordPress supports the Classic Widgets screen.
## Contributing
If you have spotted an issue or want to suggest a new feature then please submit a new issue or if you want to submit a patch then please send a pull request.

## Useful Links
* [Latest Release](https://github.com/5um17/classic-widgets-with-block-based-widgets/releases/latest)
* [WP Plugin Page](https://wordpress.org/plugins/classic-widgets-with-block-based-widgets/)
* [Support](https://wordpress.org/support/plugin/classic-widgets-with-block-based-widgets/)
104 changes: 104 additions & 0 deletions classic-and-block-widgets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
/**
* Plugin Name: Classic Widgets with Block-based Widgets
* Plugin URI: https://www.secretsofgeeks.com/
* Description: Restore the classic widgets screen as a new menu item without replacing new block-based widgets.
* Version: 1.0.1
* Author: 5um17
* Author URI: https://www.secretsofgeeks.com
* Text Domain: classic-widgets-with-block-based-widgets
*
* @package CBW
*/

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}

if ( ! defined( 'CLASSIC_AND_BLOCK_WIDGETS_FILENAME' ) ) {
define( 'CLASSIC_AND_BLOCK_WIDGETS_FILENAME', plugin_basename( __FILE__ ) );
}

add_action(
'plugins_loaded',
function () {
if ( cbw_request_uri_contain( '/wp-admin/widgets.php' ) ) {
// If this is widget.php screen, set or delete transient based on cw query string.
! empty( $_GET['cw'] ) ? set_transient( 'classic_and_block_widgets', true, HOUR_IN_SECONDS ) : delete_transient( 'classic_and_block_widgets' );
}

// Add actual filters to disable block based widgets based on transients.
if ( get_transient( 'classic_and_block_widgets' ) ) {
add_filter( 'gutenberg_use_widgets_block_editor', '__return_false' );
add_filter( 'use_widgets_block_editor', '__return_false' );
}

// Add the new menu under appearance.
add_action(
'admin_menu',
function() {
add_submenu_page( 'themes.php', __( 'Classic Widgets', 'classic-widgets-with-block-based-widgets' ), __( 'Classic Widgets', 'classic-widgets-with-block-based-widgets' ), 'edit_theme_options', 'widgets.php?cw=1', null, 3 );

// Handle current menu class.
add_filter(
'submenu_file',
function( $submenu_file ) {
if ( cbw_request_uri_contain( 'widgets.php?cw=1' ) ) {
global $self;
$self = 'widgets.php?cw=1';
}
return $submenu_file;
}
);
}
);

// Plugin row meta data.
add_filter(
'plugin_row_meta',
function ( $links, $file ) {
if ( CLASSIC_AND_BLOCK_WIDGETS_FILENAME !== $file ) {
return $links;
}

if ( is_array( $links ) ) {
$links[] = '<a href="https://wordpress.org/plugins/search/5um17/" target="_blank">'
. __( 'More Plugins', 'classic-widgets-with-block-based-widgets' )
. '</a>';
}
return $links;
},
10,
2
);

// Classic widgets link in plugin row actions.
add_filter(
'plugin_action_links_' . CLASSIC_AND_BLOCK_WIDGETS_FILENAME,
function ( $links ) {
if ( is_array( $links ) ) {
$links[] = '<a href="' . admin_url( 'widgets.php?cw=1' ) . '">'
. __( 'Classic Widgets', 'classic-widgets-with-block-based-widgets' )
. '</a>';
}

return $links;
}
);
}
);

/**
* Check if REQUEST_URI exist and contains the given value.
*
* @since 1.0
* @param string $needle Needle to search.
* @return boolean true if needle found else false.
*/
function cbw_request_uri_contain( $needle ) {
if ( ! empty( $_SERVER['REQUEST_URI'] ) && false !== strpos( $_SERVER['REQUEST_URI'], $needle ) ) {
return true;
}

return false;
}
28 changes: 28 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "5um17/classic-widgets-with-block-based-widgets",
"description": "Restore the classic widgets screen as a new menu item without replacing new block-based widgets.",
"type": "wordpress-plugin",
"license": "GPL-3.0+",
"authors": [
{
"name": "5um17",
"email": "5um17@secretsofgeeks.com"
}
],
"scripts": {
"wpcs" : ".\\vendor\\bin\\phpcs --colors --standard=WordPress-Core,WordPress-Docs",
"wpcb" : ".\\vendor\\bin\\phpcbf --standard=WordPress-Core,WordPress-Docs"
},
"require": {
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"wp-coding-standards/wpcs": "^2.3",
"squizlabs/php_codesniffer": "^3.5"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
Loading

0 comments on commit d803529

Please sign in to comment.