├── .distignore
├── .editorconfig
├── .gitignore
├── Gruntfile.js
├── README.md
├── assets
├── banner-1544x500.png
├── banner-772x250.png
├── icon-128x128.png
├── icon-256x256.png
├── screenshot-1.png
├── screenshot-2.gif
├── screenshot-3.gif
└── screenshot-4.gif
├── languages
└── createwithrani-quickpost.pot
├── license.txt
├── package-lock.json
├── package.json
├── quickpost.php
├── readme.txt
└── src
├── add-button.js
├── duplicate-menu-item.js
├── editor.scss
├── index.js
├── kebab-menu.js
├── quick-post.js
└── utils.js
/.distignore:
--------------------------------------------------------------------------------
1 | # A set of files you probably don't want in your WordPress.org distribution
2 | .babelrc
3 | .deployignore
4 | .distignore
5 | .editorconfig
6 | .eslintignore
7 | .eslintrc
8 | .git
9 | .gitignore
10 | .github
11 | .gitlab-ci.yml
12 | .travis.yml
13 | .DS_Store
14 | Thumbs.db
15 | behat.yml
16 | bitbucket-pipelines.yml
17 | bin
18 | .circleci/config.yml
19 | composer.json
20 | composer.lock
21 | dependencies.yml
22 | Gruntfile.js
23 | package.json
24 | package-lock.json
25 | phpunit.xml
26 | phpunit.xml.dist
27 | multisite.xml
28 | multisite.xml.dist
29 | .phpcs.xml
30 | phpcs.xml
31 | .phpcs.xml.dist
32 | phpcs.xml.dist
33 | README.md
34 | webpack.config.js
35 | wp-cli.local.yml
36 | yarn.lock
37 | tests
38 | vendor
39 | node_modules
40 | *.sql
41 | *.tar.gz
42 | *.zip
43 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # This file is for unifying the coding style for different editors and IDEs
2 | # editorconfig.org
3 |
4 | # WordPress Coding Standards
5 | # https://make.wordpress.org/core/handbook/coding-standards/
6 |
7 | root = true
8 |
9 | [*]
10 | charset = utf-8
11 | end_of_line = lf
12 | insert_final_newline = true
13 | trim_trailing_whitespace = true
14 | indent_style = tab
15 | indent_size = 4
16 |
17 | [{.jshintrc,*.json,*.yml}]
18 | indent_style = space
19 | indent_size = 2
20 |
21 | [{*.txt,wp-config-sample.php}]
22 | end_of_line = crlf
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | phpcs.xml
3 | phpunit.xml
4 | Thumbs.db
5 | wp-cli.local.yml
6 | node_modules/
7 | *.sql
8 | *.tar.gz
9 | *.zip
10 | build/
11 |
--------------------------------------------------------------------------------
/Gruntfile.js:
--------------------------------------------------------------------------------
1 | module.exports = function (grunt) {
2 | "use strict";
3 |
4 | // Project configuration
5 | grunt.initConfig({
6 | pkg: grunt.file.readJSON("package.json"),
7 |
8 | addtextdomain: {
9 | options: {
10 | textdomain: "quickpost",
11 | },
12 | update_all_domains: {
13 | options: {
14 | updateDomains: true,
15 | },
16 | src: [
17 | "*.php",
18 | "**/*.php",
19 | "!.git/**/*",
20 | "!bin/**/*",
21 | "!node_modules/**/*",
22 | "!tests/**/*",
23 | ],
24 | },
25 | },
26 |
27 | wp_readme_to_markdown: {
28 | your_target: {
29 | files: {
30 | "README.md": "readme.txt",
31 | },
32 | },
33 | },
34 |
35 | makepot: {
36 | target: {
37 | options: {
38 | domainPath: "/languages",
39 | exclude: [".git/*", "bin/*", "node_modules/*", "tests/*"],
40 | mainFile: "quickpost.php",
41 | potFilename: "quickpost.pot",
42 | potHeaders: {
43 | poedit: true,
44 | "x-poedit-keywordslist": true,
45 | },
46 | type: "wp-plugin",
47 | updateTimestamp: true,
48 | },
49 | },
50 | },
51 | });
52 |
53 | grunt.loadNpmTasks("grunt-wp-i18n");
54 | grunt.loadNpmTasks("grunt-wp-readme-to-markdown");
55 | grunt.registerTask("default", ["i18n", "readme"]);
56 | grunt.registerTask("i18n", ["addtextdomain", "makepot"]);
57 | grunt.registerTask("readme", ["wp_readme_to_markdown"]);
58 |
59 | grunt.util.linefeed = "\n";
60 | };
61 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # QuickPost - Add New Posts & Duplicate from the Block Editor
2 |
3 | [](https://github.com/createwithrani/add-new-post/blob/main/license.txt)
4 |
5 | 
6 |
7 | Adds an "Add New" button to the Block Editor (Gutenberg) toolbar, so you can easily create new posts/pages/custom post types without leaving Fullscreen Mode in the editor. A kebab menu on the button allows you to duplicate the current post as well.
8 |
9 | ## About
10 |
11 | Download the latest version of the plugin from [WordPress.org](https://wordpress.org/plugins/quickpost/) or from the [Latest Release area](https://github.com/createwithrani/quickpost/releases/).
12 |
13 | A razor sharp plugin that does just one thing: allow you to quickly create new posts from the Block Editor toolbar. You can create new posts in one of two ways:
14 |
15 | 1. Create a brand new empty post.
16 | 2. Duplicate the current post.
17 |
18 | This brings back the ability to create new posts, pages, custom post types quickly and easily even when you're in Fullscreen Mode in the Editor.
19 |
20 | If you enjoy the plugin, please leave a review! ⭐
21 |
22 | If you have a feature request, please create an issue in the [GitHub repository](https://github.com/createwithrani/quickpost). ➕
23 |
24 | If you need support, please use the support forum to reach out. 🆘
25 |
26 | ### Key Features
27 |
28 | - A disabled button is available in the toolbar in brand new posts
29 | - The "Add New" button becomes clickable once your post's status is auto-draft, draft, pending, published, or any other state except new.
30 | - You can duplicate the current post with two clicks.
31 | - A keyboard shortcut to create a new post directly from your keyboard (Ctrl + Option + N on Mac or Alt + Shift + N on Windows)
32 |
33 | ### Requirements
34 |
35 | - WordPress 5.8+
36 | - PHP 7.0+
37 |
38 | ## Filtering QuickPost Visibility
39 |
40 | As of v0.1.2, you can filter the visibilty of the entire QuickPost button using the filter `QuickPost.Display`. QuickPost has a property called `visibility`, which you can set to `true` or `false` depending on a condition of your choosing.
41 |
42 | ### Example: Only allow Administrators to see the button
43 |
44 | ```js
45 | import { addFilter } from "@wordpress/hooks";
46 | import { useSelect } from "@wordpress/data";
47 | import { store as coreStore } from "@wordpress/core-data";
48 |
49 | function onlyAdmins(FilteredComponent) {
50 | const adminUser = () => {
51 | const { isAdmin } = useSelect((select) => {
52 | const { canUser } = select(coreStore);
53 | // check if current user can create users, because only admins can do that
54 | const isAdmin = canUser("create", "users"); // returns undefined, true, or false
55 | return {
56 | isAdmin: isAdmin,
57 | };
58 | });
59 | return isAdmin;
60 | };
61 | return (props) => (
62 | <>
63 |
64 | >
65 | );
66 | }
67 |
68 | addFilter(
69 | "QuickPost.Display",
70 | "my-plugin/only-admins-quickpost",
71 | onlyAdmins
72 | );
73 | ```
74 |
75 | ## Thanks these lovely humans
76 |
77 | This was an odd duck, although relatively easy to make. I truly appreciate people taking time out of their day to test and give me feedback so I could make this tiny but handy plugin great. Major props to @sc0ttkclark, @treadlightly, and @christinaworkman for all their help! 💟
78 |
79 | ## Contributors
80 |
81 | @aurooba, @pixolin, @kkoppenhaver
82 |
--------------------------------------------------------------------------------
/assets/banner-1544x500.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/createwithrani/quickpost/06c150b01a83ff41788052c1817361f4bd037605/assets/banner-1544x500.png
--------------------------------------------------------------------------------
/assets/banner-772x250.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/createwithrani/quickpost/06c150b01a83ff41788052c1817361f4bd037605/assets/banner-772x250.png
--------------------------------------------------------------------------------
/assets/icon-128x128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/createwithrani/quickpost/06c150b01a83ff41788052c1817361f4bd037605/assets/icon-128x128.png
--------------------------------------------------------------------------------
/assets/icon-256x256.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/createwithrani/quickpost/06c150b01a83ff41788052c1817361f4bd037605/assets/icon-256x256.png
--------------------------------------------------------------------------------
/assets/screenshot-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/createwithrani/quickpost/06c150b01a83ff41788052c1817361f4bd037605/assets/screenshot-1.png
--------------------------------------------------------------------------------
/assets/screenshot-2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/createwithrani/quickpost/06c150b01a83ff41788052c1817361f4bd037605/assets/screenshot-2.gif
--------------------------------------------------------------------------------
/assets/screenshot-3.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/createwithrani/quickpost/06c150b01a83ff41788052c1817361f4bd037605/assets/screenshot-3.gif
--------------------------------------------------------------------------------
/assets/screenshot-4.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/createwithrani/quickpost/06c150b01a83ff41788052c1817361f4bd037605/assets/screenshot-4.gif
--------------------------------------------------------------------------------
/languages/createwithrani-quickpost.pot:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2023 Aurooba Ahmed
2 | # This file is distributed under the same license as the QuickPost plugin.
3 | msgid ""
4 | msgstr ""
5 | "Project-Id-Version: QuickPost 0.1.5\n"
6 | "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/quickpost\n"
7 | "Last-Translator: FULL NAME \n"
8 | "Language-Team: LANGUAGE \n"
9 | "MIME-Version: 1.0\n"
10 | "Content-Type: text/plain; charset=UTF-8\n"
11 | "Content-Transfer-Encoding: 8bit\n"
12 | "POT-Creation-Date: 2023-02-27T15:43:27+00:00\n"
13 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
14 | "X-Generator: WP-CLI 2.7.1\n"
15 | "X-Domain: createwithrani-quickpost\n"
16 |
17 | #. Plugin Name of the plugin
18 | msgid "QuickPost"
19 | msgstr ""
20 |
21 | #. Plugin URI of the plugin
22 | msgid "https://createwithrani.com"
23 | msgstr ""
24 |
25 | #. Description of the plugin
26 | msgid "Adds an \"Add New\" button to the Block Editor toolbar, so you can easily create new posts/pages/custom post types, as well as duplicate them."
27 | msgstr ""
28 |
29 | #. Author of the plugin
30 | msgid "Aurooba Ahmed"
31 | msgstr ""
32 |
33 | #. Author URI of the plugin
34 | msgid "https://aurooba.com"
35 | msgstr ""
36 |
37 | #: build/index.js:80
38 | #: src/add-button.js:25
39 | #: build/index.js:39
40 | msgid "Ctrl + Option + N"
41 | msgstr ""
42 |
43 | #: build/index.js:82
44 | #: build/index.js:84
45 | #: src/add-button.js:27
46 | #: src/add-button.js:29
47 | #: build/index.js:41
48 | #: build/index.js:43
49 | msgid "Alt + Shift + N"
50 | msgstr ""
51 |
52 | #. translators: %1$s: Name of current post type.
53 | #: build/index.js:113
54 | #: src/add-button.js:60
55 | #: build/index.js:74
56 | msgid "Add new %1$s"
57 | msgstr ""
58 |
59 | #. translators: %s: singular label of current post type i.e Page, Post
60 | #: build/index.js:214
61 | #: src/duplicate-menu-item.js:65
62 | #: build/index.js:150
63 | msgid "Edit duplicated %s"
64 | msgstr ""
65 |
66 | #. translators: %s: singular label of current post type i.e Page, Post
67 | #: build/index.js:224
68 | #: src/duplicate-menu-item.js:80
69 | #: build/index.js:165
70 | msgid "Duplicate %s"
71 | msgstr ""
72 |
--------------------------------------------------------------------------------
/license.txt:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5 | 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
6 |
7 | Everyone is permitted to copy and distribute verbatim copies
8 | of this license document, but changing it is not allowed.
9 |
10 | Preamble
11 |
12 | The licenses for most software are designed to take away your
13 | freedom to share and change it. By contrast, the GNU General Public
14 | License is intended to guarantee your freedom to share and change free
15 | software--to make sure the software is free for all its users. This
16 | General Public License applies to most of the Free Software
17 | Foundation's software and to any other program whose authors commit to
18 | using it. (Some other Free Software Foundation software is covered by
19 | the GNU Library General Public License instead.) You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | this service if you wish), that you receive source code or can get it
26 | if you want it, that you can change the software or use pieces of it
27 | in new free programs; and that you know you can do these things.
28 |
29 | To protect your rights, we need to make restrictions that forbid
30 | anyone to deny you these rights or to ask you to surrender the rights.
31 | These restrictions translate to certain responsibilities for you if you
32 | distribute copies of the software, or if you modify it.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must give the recipients all the rights that
36 | you have. You must make sure that they, too, receive or can get the
37 | source code. And you must show them these terms so they know their
38 | rights.
39 |
40 | We protect your rights with two steps: (1) copyright the software, and
41 | (2) offer you this license which gives you legal permission to copy,
42 | distribute and/or modify the software.
43 |
44 | Also, for each author's protection and ours, we want to make certain
45 | that everyone understands that there is no warranty for this free
46 | software. If the software is modified by someone else and passed on, we
47 | want its recipients to know that what they have is not the original, so
48 | that any problems introduced by others will not reflect on the original
49 | authors' reputations.
50 |
51 | Finally, any free program is threatened constantly by software
52 | patents. We wish to avoid the danger that redistributors of a free
53 | program will individually obtain patent licenses, in effect making the
54 | program proprietary. To prevent this, we have made it clear that any
55 | patent must be licensed for everyone's free use or not licensed at all.
56 |
57 | The precise terms and conditions for copying, distribution and
58 | modification follow.
59 |
60 | GNU GENERAL PUBLIC LICENSE
61 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
62 |
63 | 0. This License applies to any program or other work which contains
64 | a notice placed by the copyright holder saying it may be distributed
65 | under the terms of this General Public License. The "Program", below,
66 | refers to any such program or work, and a "work based on the Program"
67 | means either the Program or any derivative work under copyright law:
68 | that is to say, a work containing the Program or a portion of it,
69 | either verbatim or with modifications and/or translated into another
70 | language. (Hereinafter, translation is included without limitation in
71 | the term "modification".) Each licensee is addressed as "you".
72 |
73 | Activities other than copying, distribution and modification are not
74 | covered by this License; they are outside its scope. The act of
75 | running the Program is not restricted, and the output from the Program
76 | is covered only if its contents constitute a work based on the
77 | Program (independent of having been made by running the Program).
78 | Whether that is true depends on what the Program does.
79 |
80 | 1. You may copy and distribute verbatim copies of the Program's
81 | source code as you receive it, in any medium, provided that you
82 | conspicuously and appropriately publish on each copy an appropriate
83 | copyright notice and disclaimer of warranty; keep intact all the
84 | notices that refer to this License and to the absence of any warranty;
85 | and give any other recipients of the Program a copy of this License
86 | along with the Program.
87 |
88 | You may charge a fee for the physical act of transferring a copy, and
89 | you may at your option offer warranty protection in exchange for a fee.
90 |
91 | 2. You may modify your copy or copies of the Program or any portion
92 | of it, thus forming a work based on the Program, and copy and
93 | distribute such modifications or work under the terms of Section 1
94 | above, provided that you also meet all of these conditions:
95 |
96 | a) You must cause the modified files to carry prominent notices
97 | stating that you changed the files and the date of any change.
98 |
99 | b) You must cause any work that you distribute or publish, that in
100 | whole or in part contains or is derived from the Program or any
101 | part thereof, to be licensed as a whole at no charge to all third
102 | parties under the terms of this License.
103 |
104 | c) If the modified program normally reads commands interactively
105 | when run, you must cause it, when started running for such
106 | interactive use in the most ordinary way, to print or display an
107 | announcement including an appropriate copyright notice and a
108 | notice that there is no warranty (or else, saying that you provide
109 | a warranty) and that users may redistribute the program under
110 | these conditions, and telling the user how to view a copy of this
111 | License. (Exception: if the Program itself is interactive but
112 | does not normally print such an announcement, your work based on
113 | the Program is not required to print an announcement.)
114 |
115 | These requirements apply to the modified work as a whole. If
116 | identifiable sections of that work are not derived from the Program,
117 | and can be reasonably considered independent and separate works in
118 | themselves, then this License, and its terms, do not apply to those
119 | sections when you distribute them as separate works. But when you
120 | distribute the same sections as part of a whole which is a work based
121 | on the Program, the distribution of the whole must be on the terms of
122 | this License, whose permissions for other licensees extend to the
123 | entire whole, and thus to each and every part regardless of who wrote it.
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "quickpost",
3 | "version": "0.1.5",
4 | "main": "index.js",
5 | "author": "Aurooba Ahmed",
6 | "scripts": {
7 | "start": "wp-scripts start",
8 | "readme": "grunt readme",
9 | "i18n": "grunt i18n",
10 | "build": "wp-scripts build",
11 | "check-engines": "wp-scripts check-engines",
12 | "check-licenses": "wp-scripts check-licenses",
13 | "format": "wp-scripts format",
14 | "lint:css": "wp-scripts lint-style",
15 | "lint:js": "wp-scripts lint-js",
16 | "lint:md:docs": "wp-scripts lint-md-docs",
17 | "lint:md:js": "wp-scripts lint-md-js",
18 | "lint:pkg-json": "wp-scripts lint-pkg-json",
19 | "packages-update": "wp-scripts packages-update",
20 | "plugin-zip": "wp-scripts plugin-zip"
21 | },
22 | "dependencies": {
23 | "@wordpress/block-editor": "^8.0.11",
24 | "@wordpress/blocks": "^11.1.4",
25 | "@wordpress/i18n": "^4.2.4",
26 | "@wordpress/element": "^4.1.0"
27 | },
28 | "devDependencies": {
29 | "@wordpress/scripts": "^20.0.2",
30 | "grunt": "^0.4.5",
31 | "grunt-wp-i18n": "~0.5.0",
32 | "grunt-wp-readme-to-markdown": "~1.0.0"
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/quickpost.php:
--------------------------------------------------------------------------------
1 | -1;
20 | const isWindows = platform.indexOf("Win") > -1;
21 | const isLinux = platform.indexOf("Linux") > -1;
22 |
23 | function getAriaLabel() {
24 | if (isMac) {
25 | return __("Ctrl + Option + N", "createwithrani-quickpost");
26 | } else if (isWindows || isLinux) {
27 | return __("Alt + Shift + N", "createwithrani-quickpost");
28 | } else if (isLinux) {
29 | return __("Alt + Shift + N", "createwithrani-quickpost");
30 | }
31 | }
32 |
33 | return (
34 |
35 | setClick(true)}
56 | >
57 |
58 | {sprintf(
59 | /* translators: %1$s: Name of current post type. */
60 | __("Add new %1$s", "createwithrani-quickpost"),
61 | singleLabel
62 | )}
63 |
64 | {click && }
65 |
66 |
67 | );
68 | }
69 |
70 | export default AddNewPostButton;
71 |
--------------------------------------------------------------------------------
/src/duplicate-menu-item.js:
--------------------------------------------------------------------------------
1 | /**
2 | * WordPress dependencies.
3 | */
4 | import apiFetch from "@wordpress/api-fetch";
5 | import { __ } from "@wordpress/i18n";
6 | import { MenuItem, ToolbarItem } from "@wordpress/components";
7 | import { useSelect } from "@wordpress/data";
8 | import { useState } from "@wordpress/element";
9 | import { Spinner } from "@wordpress/components";
10 | import { addQueryArgs } from "@wordpress/url";
11 |
12 | /**
13 | * Internal dependencies.
14 | */
15 | import "./editor.scss";
16 |
17 | export function DuplicateMenuItem({ singleLabel, restBase }) {
18 | const [postId, setPostId] = useState(0);
19 | const [duplicationStatus, setDuplicationStatus] = useState(false);
20 | const { currentPostData } = useSelect((select) => {
21 | return {
22 | currentPostData: select("core/editor").getCurrentPost(),
23 | };
24 | });
25 | const DuplicatePost = {
26 | author: currentPostData.author,
27 | content: currentPostData.content,
28 | title: "Copy of " + currentPostData.title,
29 | excerpt: currentPostData.excerpt,
30 | comment_status: currentPostData.comment_status,
31 | ping_status: currentPostData.ping_status,
32 | password: currentPostData.password,
33 | parent: currentPostData.parent,
34 | menu_order: currentPostData.menu_order,
35 | meta: currentPostData.meta,
36 | template: currentPostData.template,
37 | };
38 |
39 | const fetchData = async () => {
40 | const response = await apiFetch({
41 | path: `wp/v2/${restBase}`,
42 | method: "POST",
43 | data: DuplicatePost,
44 | });
45 | setPostId(response.id);
46 | setDuplicationStatus(false);
47 | };
48 | function DuplicateThePost() {
49 | setDuplicationStatus(true);
50 | fetchData();
51 | }
52 |
53 | const ViewDuplicatedPost = () => {
54 | return (
55 |
63 | {sprintf(
64 | /* translators: %s: singular label of current post type i.e Page, Post */
65 | __("Edit duplicated %s", "createwithrani-quickpost"),
66 | singleLabel
67 | )}
68 |
69 | );
70 | };
71 | const DuplicatePostButton = () => {
72 | return (
73 |
78 | {sprintf(
79 | /* translators: %s: singular label of current post type i.e Page, Post */
80 | __("Duplicate %s", "createwithrani-quickpost"),
81 | singleLabel
82 | )}
83 |
84 | {duplicationStatus && }
85 |
86 | );
87 | };
88 | return (
89 | <>
90 | {0 === postId && }
91 | {0 !== postId && }
92 | >
93 | );
94 | }
95 |
--------------------------------------------------------------------------------
/src/editor.scss:
--------------------------------------------------------------------------------
1 | .createwithrani-quick-post-duplicate-menu-item {
2 | .components-menu-item__item {
3 | justify-content: space-between;
4 | .components-spinner {
5 | margin: 0;
6 | }
7 | }
8 | }
9 |
10 | .edit-post-header__toolbar .edit-post-header-toolbar {
11 | flex-grow: 0;
12 | }
13 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * WordPress dependencies.
3 | */
4 | import { render } from "@wordpress/element";
5 | import { subscribe } from "@wordpress/data";
6 | import domReady from "@wordpress/dom-ready";
7 |
8 | /**
9 | * Internal dependencies.
10 | */
11 | import QuickPostButton from "./quick-post";
12 | import { listenForKeyboardShortcut } from "./utils";
13 |
14 | /**
15 | * Let's subscribe (because I finally understand what this does better)
16 | * and add the component to the toolbar!
17 | */
18 | subscribe(() => {
19 | const quickpostbutton = document.querySelector(
20 | "#createwithrani-quick-post-button-wrapper"
21 | );
22 |
23 | // If the Quick Post Button already exists, skip render
24 | if (quickpostbutton) {
25 | return;
26 | }
27 |
28 | domReady(() => {
29 | const editorToolbar = document.querySelector(
30 | ".edit-post-header__toolbar"
31 | );
32 |
33 | // If toolbar doesn't exist, we can't continue
34 | if (!editorToolbar) {
35 | return;
36 | }
37 |
38 | // So turns out you can't append to an existing container without
39 | // using dangerouslySetInnerHTML, which..I don't want to use.
40 | const buttonWrapper = document.createElement("div");
41 | buttonWrapper.id = "createwithrani-quick-post-button-wrapper";
42 | buttonWrapper.style.cssText = "display:flex;";
43 |
44 | // add empty div to the toolbar so we can fill it.
45 | editorToolbar.appendChild(buttonWrapper);
46 |
47 | render(
48 | ,
49 | document.getElementById("createwithrani-quick-post-button-wrapper")
50 | );
51 | });
52 | });
53 |
54 | document.addEventListener('keydown', listenForKeyboardShortcut);
55 |
--------------------------------------------------------------------------------
/src/kebab-menu.js:
--------------------------------------------------------------------------------
1 | /**
2 | * External dependencies
3 | */
4 | import classnames from "classnames";
5 |
6 | /**
7 | * WordPress dependencies.
8 | */
9 | import { DropdownMenu } from "@wordpress/components";
10 | import { moreVertical } from "@wordpress/icons";
11 |
12 | /**
13 | * Internal dependencies.
14 | */
15 | import { DuplicateMenuItem } from "./duplicate-menu-item";
16 | import "./editor.scss";
17 |
18 | const POPOVER_PROPS = {
19 | className: classnames("createwithrani-quick-post-button-popover"),
20 | position: "bottom left",
21 | };
22 |
23 | /**
24 | * Create the kebab menu for the Quick Post Button
25 | *
26 | * @since 0.1.0
27 | * @return {string} Return the rendered Quick Post Button kebab menu
28 | */
29 | function QuickPostKebabMenu({ newPost, restBase, singleLabel }) {
30 | const toggleProps = {
31 | isSecondary: true,
32 | disabled: !newPost,
33 | style: {
34 | borderTopLeftRadius: "0px",
35 | borderBottomLeftRadius: "0px",
36 | marginLeft: "-1px",
37 | maxHeight: "36px",
38 | minHeight: "36px",
39 | maxWidth: "36px",
40 | minWidth: "36px",
41 | display: "block",
42 | padding: "0px",
43 | },
44 | };
45 |
46 | return (
47 | <>
48 |
54 | {() => (
55 |
59 | )}
60 |
61 | >
62 | );
63 | }
64 | export default QuickPostKebabMenu;
65 |
--------------------------------------------------------------------------------
/src/quick-post.js:
--------------------------------------------------------------------------------
1 | /**
2 | * WordPress dependencies
3 | */
4 | import { withFilters } from "@wordpress/components";
5 |
6 | /**
7 | * Internal dependencies.
8 | */
9 | import { getPostInfo, getPostLabels, getPostTypeRestBase } from "./utils";
10 | import AddNewPostButton from "./add-button";
11 | import QuickPostKebabMenu from "./kebab-menu";
12 |
13 | /**
14 | * Create the Quick Post button
15 | *
16 | * @since 0.1.0
17 | * @return {string} Return the rendered Quick Post Button
18 | */
19 | function QuickPostButton({ visibility }) {
20 | const { postType, newPost } = getPostInfo();
21 | if (!postType) {
22 | return null;
23 | }
24 | const { addNewLabel, singleLabel } = getPostLabels(postType);
25 | const restBase = getPostTypeRestBase(postType);
26 | // Until we get the label info back, we don't want to render the button.
27 | if (undefined !== addNewLabel && undefined !== restBase && visibility) {
28 | return (
29 | <>
30 |
36 |
41 | >
42 | );
43 | }
44 | return null;
45 | }
46 | const QuickPostButtoWithFilters = withFilters("QuickPost.Display")(
47 | QuickPostButton
48 | );
49 | export default QuickPostButtoWithFilters;
50 |
--------------------------------------------------------------------------------
/src/utils.js:
--------------------------------------------------------------------------------
1 | /**
2 | * WordPress dependencies.
3 | */
4 | import { __ } from "@wordpress/i18n";
5 | import { useSelect } from "@wordpress/data";
6 | import { store as coreStore } from "@wordpress/core-data";
7 |
8 | /**
9 | * We need to know two things:
10 | * 1. What post type are we in – so we can set up the URL to create a new post of the same type
11 | * 2. Is this a new post? – because if it's brand new, we don't want our button to be active, yer already in a new post, bud.
12 | */
13 | export function getPostInfo() {
14 | const { postType } = useSelect((select) => {
15 | return {
16 | postType: select("core/editor").getCurrentPostType(),
17 | };
18 | });
19 | const { newPost } = useSelect((select) => {
20 | const newPost = select("core/editor").isEditedPostSaveable();
21 |
22 | return {
23 | newPost: newPost,
24 | };
25 | });
26 | return { postType, newPost };
27 | }
28 |
29 | export function getPostLabels(postType) {
30 | const { singleLabel, addNewLabel } = useSelect((select) => {
31 | const { getPostTypes } = select(coreStore);
32 | const includedPostType = [postType];
33 | const filteredPostTypes = getPostTypes({
34 | per_page: -1,
35 | })?.filter(({ slug }) => includedPostType.includes(slug));
36 |
37 | if (undefined !== filteredPostTypes && filteredPostTypes.length) {
38 | return {
39 | addNewLabel: filteredPostTypes[0].labels.add_new,
40 | singleLabel: filteredPostTypes[0].labels.singular_name,
41 | };
42 | }
43 |
44 | return {
45 | addNewLabel: undefined,
46 | singleLabel: undefined,
47 | };
48 | });
49 | return { addNewLabel, singleLabel };
50 | }
51 |
52 | export function getPostTypeRestBase(postType) {
53 | const { rest_base } = useSelect((select) => {
54 | const { getPostTypes } = select(coreStore);
55 | const includedPostType = [postType];
56 | const filteredPostTypes = getPostTypes({
57 | per_page: -1,
58 | })?.filter(({ slug }) => includedPostType.includes(slug));
59 |
60 | if (undefined !== filteredPostTypes && filteredPostTypes.length) {
61 | return {
62 | rest_base: filteredPostTypes[0].rest_base,
63 | };
64 | }
65 |
66 | return {
67 | rest_base: undefined,
68 | };
69 | });
70 | return rest_base;
71 | }
72 |
73 | export function listenForKeyboardShortcut(event) {
74 | if (
75 | // Shortcut for Mac (Ctrl + Option + N)
76 | (event.ctrlKey && event.altKey && 78 === event.keyCode) ||
77 | // Shortcut for Windows (Alt + Shift + N)
78 | (event.altKey && event.shiftKey && 78 === event.keyCode)
79 | ) {
80 | event.preventDefault();
81 | document.querySelector("#createwithrani-quick-post-button").click();
82 | }
83 | }
84 |
--------------------------------------------------------------------------------