Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add Check For Theme Activation Constant #950

Closed
wants to merge 10 commits into from

8 participants

@willthemoor

Allows a developer to skip Roots' Theme Activation step by setting a constant:

define('ROOTS_ACTIVATION', FALSE);

From discussion at http://discourse.roots.io/t/disable-activation-page-when-switching-themes/917/

@swalkinshaw
Owner

Looks great! Sorry to be picky but can you remove the surrounding spaces in the conditional?

@willthemoor

Whitespace fixed.

Couldn't figure out how to squash the two commits and push up to github so sorry for this history noise. Do I need to close and do a new pull request or does the auto added comment above with the fixed commit represent the same?

@retlehs
Owner

try git rebase -i HEAD~2 and choose to squash them - if you can't figure it out, no worries we can just merge

@willthemoor

that's exactly what I did but when finished I got this:

# On branch theme-activation
# Your branch and 'origin/theme-activation' have diverged,
# and have 1 and 2 different commits each, respectively.

can't push...

$ git push origin theme-activation
To https://github.com/willthemoor/roots
 ! [rejected]        theme-activation -> theme-activation (non-fast-forward)
error: failed to push some refs to 'https://github.com/willthemoor/roots'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

and it seems to me that pull/merge/push adds similar history noise. Happy to do it though.

@swalkinshaw
Owner
@willthemoor

Cheers for the git lesson @swalkinshaw. :) I'll give it another go.

@willthemoor

Looks like that did the trick. Thanks!

@retlehs
Owner

@Foxaii brought up something in our chat earlier this evening.. @willthemoor is there any reason why we couldn't add another add_theme_support that's toggled in lib/config.php to enable/disable activation, rather than using a constant in wp-config.php?

@willthemoor

@retlehs Yes and no. Doing it via add_theme_support is a great idea and feels much cleaner as it keeps roots concerns within roots. But it also means that someone spinning up multiple sites with roots can't set a constant outside of roots (which would presumably be pulled in via git/composer). I'm in middle of rebuilding my WP boilerplate project so I may be overly concerned with that use case. Happy to let it go.

I can see three ways, you can prolly see more!

1) Affirmative

add_theme_support('allow-activation'); 
  if (current_theme_supports('allow-activation')) {
    wp_redirect(admin_url('themes.php?page=theme_activation_options'));
    exit;
  }

2) Negative

add_theme_support('disallow-activation'); 
  if (!current_theme_supports('disallow-activation')) {
    wp_redirect(admin_url('themes.php?page=theme_activation_options'));
    exit;
  }

Negative, I believe, has the benefit of not needing to be present at all in lib/config.php. Putting a negative into add_theme_support() just feels weird though. But...

3) Negative + Constant

Perhaps too messy but might something like this work? Where like is in italics because I've been staring at a screen too long to know if this logic would even work. :)

  if (!current_theme_supports('disallow-activation') || (defined('ROOTS_ACTIVATION') && ROOTS_ACTIVATION)) {
    wp_redirect(admin_url('themes.php?page=theme_activation_options'));
    exit;
  }

I'd appreciate something like 3) for the use case mentioned above but I might have edge case on my forehead.

@Foxaii
Collaborator

I would keep the affirmative case, but change how you add theme support to honour the constant if set. Can you test this:

add_theme_support('roots-activation', (defined('ROOTS_ACTIVATION') ? ROOTS_ACTIVATION : true )); // Enable activation options

I would also name the support feature the same as the constant, but that's more of a personal preference.

@willthemoor

@Foxali That looks great. I'll give it a shot.

@ajmalafif

what's the status of the Add Check For Theme Activation Constant feature?

Will it be merged for the next release?

leoj3n and others added some commits
@leoj3n leoj3n Fix gallery link option
Galleries should support three link types:

* Attachment Page (default): [gallery ids="1,2,3"]
* Media File: [gallery link="file" ids="1,2,3"]
* None: [gallery link="none" ids="1,2,3"]
a8eadbb
@willthemoor willthemoor Add Check For Theme Activation Constant
Allows a developer to skip Roots' Theme Activation step by setting a constant:

define('ROOTS_ACTIVATION', FALSE);
8d52542
@retlehs retlehs Remove changing media folder from theme activation 3827134
@retlehs retlehs screen_icon has been deprecated with WP 3.8 c1815c9
@retlehs retlehs Add notice to theme activation, tidy activation table markup 4dd31ab
@retlehs retlehs Generate new roots.pot 73a8b47
@retlehs retlehs Add analytics 36f02b7
@retlehs retlehs Ignore LESS source map cfd32e6
@roscius roscius Match wp_register_script function signature
Although the third parameter currently works when false to indicate
no dependancies, it works by side-effect, the function signature uses
an empty array to indicate no dependancies.
1118bec
@retlehs retlehs Remove analytics 0dbd226
@willthemoor

Well, that's neat. #gitfail. Think I'll close this, fork, add the three lines and submit a new pull request.

@willthemoor willthemoor closed this
@willthemoor

Well, just as well. I ran my test incorrectly anyway. :)

@Foxaii

add_theme_support('roots-activation', (defined('ROOTS_ACTIVATION') ? ROOTS_ACTIVATION : true )); 

doesn't work. It always returns true (even if I set the final true to false manually.

Other ideas?

@willthemoor willthemoor reopened this
@Foxaii
Collaborator

Did you try:

define("ROOTS_ACTIVATION", false);

Edit:
You're correct. It looks like the "current_theme_supports" argument isn't being passed. I'll look into this over the weekend.

@Foxaii
Collaborator

A weekend late...

One fix would be to directly reference the global variable $_wp_theme_features but it's seems too hacky for my liking. The other option is something like:

if (is_admin() && isset($_GET['activated']) && 'themes.php' == $GLOBALS['pagenow']) {
  if (defined('ROOTS_ACTIVATION') && ROOTS_ACTIVATION == false) { 
    return remove_theme_support('roots-activation'); 
  } elseif (current_theme_supports('roots-activation' || defined('ROOTS_ACTIVATION') && ROOTS_ACTIVATION)) {
    wp_redirect(admin_url('themes.php?page=theme_activation_options'));
    exit;
  }
}

Could you give it a try please @willthemoor?

Edit: Updated example thanks to @swalkinshaw

@QWp6t
Collaborator

How come it can't be done through an event?

add_filter('roots-activation', [...]);

[...]

apply_filters('roots-activation', [...]);

Then to disable...

add_filter('roots-activation', '__return_false');

Or if you want to use actions, we could rely on remove_action() to disable activation.

Are there any pitfalls to this approach?

@Foxaii
Collaborator

There are lots of different ways to do it but it should be in keeping with the other functions (i.e. enabled through add_theme_support in lib/config.php) and if you can force it off, you should be able to force it on (meaning the same kind of logic would need to be applied, no matter how the feature is structured).

@retlehs retlehs added the feature label
@retlehs retlehs added this to the 7.0.0 milestone
@retlehs retlehs referenced this pull request
Merged

Roots 7.0.0 #982

11 of 13 tasks complete
@retlehs retlehs removed this from the 7.0.0 milestone
@swalkinshaw
Owner

@willthemoor if you're interested in this could do a new or cleaned up PR with just the activation changes? We'll give you a bit to respond but if not we'll probably do a version of this ourselves as @Foxaii last suggested.

@willthemoor

Sorry for falling off the map. @Foxaii's way looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 9, 2014
  1. @leoj3n @willthemoor

    Fix gallery link option

    leoj3n authored willthemoor committed
    Galleries should support three link types:
    
    * Attachment Page (default): [gallery ids="1,2,3"]
    * Media File: [gallery link="file" ids="1,2,3"]
    * None: [gallery link="none" ids="1,2,3"]
  2. @willthemoor

    Add Check For Theme Activation Constant

    willthemoor authored
    Allows a developer to skip Roots' Theme Activation step by setting a constant:
    
    define('ROOTS_ACTIVATION', FALSE);
  3. @retlehs @willthemoor

    Remove changing media folder from theme activation

    retlehs authored willthemoor committed
  4. @retlehs @willthemoor

    screen_icon has been deprecated with WP 3.8

    retlehs authored willthemoor committed
  5. @retlehs @willthemoor
  6. @retlehs @willthemoor

    Generate new roots.pot

    retlehs authored willthemoor committed
  7. @retlehs @willthemoor

    Add analytics

    retlehs authored willthemoor committed
  8. @retlehs @willthemoor

    Ignore LESS source map

    retlehs authored willthemoor committed
  9. @roscius @willthemoor

    Match wp_register_script function signature

    roscius authored willthemoor committed
    Although the third parameter currently works when false to indicate
    no dependancies, it works by side-effect, the function signature uses
    an empty array to indicate no dependancies.
  10. @retlehs @willthemoor

    Remove analytics

    retlehs authored willthemoor committed
This page is out of date. Refresh to see the latest.
View
1  .gitignore
@@ -1,3 +1,4 @@
# Include your project-specific ignores in this file
# Read about how to use .gitignore: https://help.github.com/articles/ignoring-files
node_modules
+assets/css/main.min.css.map
View
2  CHANGELOG.md
@@ -1,4 +1,6 @@
### HEAD
+* Add notice to theme activation, tidy activation table markup
+* Remove changing media folder from theme activation (use [Bedrock](https://github.com/roots/bedrock) for clean URLs out of the box)
* Update to Bootstrap 3.0.3
* Switch `div.main` to `main` element now that Modernizr uses the latest HTML5 Shiv
* Update to Modernizr 2.7.0
View
70 lang/roots.pot
@@ -1,6 +1,6 @@
msgid ""
msgstr ""
-"Content-Type: text/plain; charset=utf-8\n"
+"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: 404.php:4
@@ -19,7 +19,7 @@ msgstr ""
msgid "an out-of-date link"
msgstr ""
-#: base.php:4
+#: base.php:6
msgid "You are using an <strong>outdated</strong> browser. Please <a href=\"http://browsehappy.com/\">upgrade your browser</a> to improve your experience."
msgstr ""
@@ -39,69 +39,61 @@ msgstr ""
msgid "Theme Activation"
msgstr ""
-#: lib/activation.php:51
+#: lib/activation.php:50
msgid "%s Theme Activation"
msgstr ""
-#: lib/activation.php:62 lib/activation.php:64
+#: lib/activation.php:52
+msgid "These settings are optional and should usually be used only on a fresh installation"
+msgstr ""
+
+#: lib/activation.php:59 lib/activation.php:62
msgid "Create static front page?"
msgstr ""
-#: lib/activation.php:66 lib/activation.php:79 lib/activation.php:92
-#: lib/activation.php:105 lib/activation.php:118
+#: lib/activation.php:64 lib/activation.php:76 lib/activation.php:88
+#: lib/activation.php:100
msgid "Yes"
msgstr ""
-#: lib/activation.php:67 lib/activation.php:80 lib/activation.php:93
-#: lib/activation.php:106 lib/activation.php:119
+#: lib/activation.php:65 lib/activation.php:77 lib/activation.php:89
+#: lib/activation.php:101
msgid "No"
msgstr ""
-#: lib/activation.php:70
+#: lib/activation.php:67
msgid "Create a page called Home and set it to be the static front page"
msgstr ""
-#: lib/activation.php:75
+#: lib/activation.php:71
msgid "Change permalink structure?"
msgstr ""
-#: lib/activation.php:77
+#: lib/activation.php:74
msgid "Update permalink structure?"
msgstr ""
-#: lib/activation.php:83
+#: lib/activation.php:79
msgid "Change permalink structure to /&#37;postname&#37;/"
msgstr ""
-#: lib/activation.php:88
-msgid "Change uploads folder?"
-msgstr ""
-
-#: lib/activation.php:90
-msgid "Update uploads folder?"
-msgstr ""
-
-#: lib/activation.php:96
-msgid "Change uploads folder to /media/ instead of /wp-content/uploads/"
-msgstr ""
-
-#: lib/activation.php:101 lib/activation.php:103
+#: lib/activation.php:83 lib/activation.php:86
msgid "Create navigation menu?"
msgstr ""
-#: lib/activation.php:109
+#: lib/activation.php:91
msgid "Create the Primary Navigation menu and set the location"
msgstr ""
-#: lib/activation.php:114 lib/activation.php:116
+#: lib/activation.php:95 lib/activation.php:98
msgid "Add pages to menu?"
msgstr ""
-#: lib/activation.php:122
+#: lib/activation.php:103
msgid "Add all current published pages to the Primary Navigation"
msgstr ""
-#: lib/cleanup.php:210
+#: lib/cleanup.php:193
msgid "Continued"
msgstr ""
@@ -211,27 +203,27 @@ msgstr ""
msgid "Log out &raquo;"
msgstr ""
-#: templates/comments.php:57
+#: templates/comments.php:58
msgid "Name"
msgstr ""
-#: templates/comments.php:57 templates/comments.php:59
+#: templates/comments.php:58 templates/comments.php:62
msgid " (required)"
msgstr ""
-#: templates/comments.php:59
+#: templates/comments.php:62
msgid "Email (will not be published)"
msgstr ""
-#: templates/comments.php:61
+#: templates/comments.php:66
msgid "Website"
msgstr ""
-#: templates/comments.php:64
+#: templates/comments.php:71
msgid "Comment"
msgstr ""
-#: templates/comments.php:66
+#: templates/comments.php:74
msgid "Submit Comment"
msgstr ""
@@ -243,10 +235,10 @@ msgstr ""
msgid "By"
msgstr ""
-#: templates/searchform.php:2
-msgid "Search for:"
+#: templates/searchform.php:3 templates/searchform.php:6
+msgid "Search"
msgstr ""
-#: templates/searchform.php:3 templates/searchform.php:4
-msgid "Search"
+#: templates/searchform.php:4
+msgid "Search for:"
msgstr ""
View
70 lib/activation.php
@@ -3,8 +3,10 @@
* Theme activation
*/
if (is_admin() && isset($_GET['activated']) && 'themes.php' == $GLOBALS['pagenow']) {
- wp_redirect(admin_url('themes.php?page=theme_activation_options'));
- exit;
+ if (current_theme_supports('roots-activation')) {
+ wp_redirect(admin_url('themes.php?page=theme_activation_options'));
+ exit;
+ }
}
function roots_theme_activation_options_init() {
@@ -47,85 +49,64 @@ function roots_get_theme_activation_options() {
function roots_theme_activation_options_render_page() { ?>
<div class="wrap">
- <?php screen_icon(); ?>
<h2><?php printf(__('%s Theme Activation', 'roots'), wp_get_theme()); ?></h2>
+ <div class="update-nag">
+ <?php _e('These settings are optional and should usually be used only on a fresh installation', 'roots'); ?>
+ </div>
<?php settings_errors(); ?>
<form method="post" action="options.php">
-
- <?php
- settings_fields('roots_activation_options');
- ?>
-
+ <?php settings_fields('roots_activation_options'); ?>
<table class="form-table">
-
<tr valign="top"><th scope="row"><?php _e('Create static front page?', 'roots'); ?></th>
<td>
- <fieldset><legend class="screen-reader-text"><span><?php _e('Create static front page?', 'roots'); ?></span></legend>
+ <fieldset>
+ <legend class="screen-reader-text"><span><?php _e('Create static front page?', 'roots'); ?></span></legend>
<select name="roots_theme_activation_options[create_front_page]" id="create_front_page">
<option selected="selected" value="true"><?php echo _e('Yes', 'roots'); ?></option>
<option value="false"><?php echo _e('No', 'roots'); ?></option>
</select>
- <br>
- <small class="description"><?php printf(__('Create a page called Home and set it to be the static front page', 'roots')); ?></small>
+ <p class="description"><?php printf(__('Create a page called Home and set it to be the static front page', 'roots')); ?></p>
</fieldset>
</td>
</tr>
-
<tr valign="top"><th scope="row"><?php _e('Change permalink structure?', 'roots'); ?></th>
<td>
- <fieldset><legend class="screen-reader-text"><span><?php _e('Update permalink structure?', 'roots'); ?></span></legend>
+ <fieldset>
+ <legend class="screen-reader-text"><span><?php _e('Update permalink structure?', 'roots'); ?></span></legend>
<select name="roots_theme_activation_options[change_permalink_structure]" id="change_permalink_structure">
<option selected="selected" value="true"><?php echo _e('Yes', 'roots'); ?></option>
<option value="false"><?php echo _e('No', 'roots'); ?></option>
</select>
- <br>
- <small class="description"><?php printf(__('Change permalink structure to /&#37;postname&#37;/', 'roots')); ?></small>
- </fieldset>
- </td>
- </tr>
-
- <tr valign="top"><th scope="row"><?php _e('Change uploads folder?', 'roots'); ?></th>
- <td>
- <fieldset><legend class="screen-reader-text"><span><?php _e('Update uploads folder?', 'roots'); ?></span></legend>
- <select name="roots_theme_activation_options[change_uploads_folder]" id="change_uploads_folder">
- <option selected="selected" value="true"><?php echo _e('Yes', 'roots'); ?></option>
- <option value="false"><?php echo _e('No', 'roots'); ?></option>
- </select>
- <br>
- <small class="description"><?php printf(__('Change uploads folder to /media/ instead of /wp-content/uploads/', 'roots')); ?></small>
+ <p class="description"><?php printf(__('Change permalink structure to /&#37;postname&#37;/', 'roots')); ?></p>
</fieldset>
</td>
</tr>
-
<tr valign="top"><th scope="row"><?php _e('Create navigation menu?', 'roots'); ?></th>
<td>
- <fieldset><legend class="screen-reader-text"><span><?php _e('Create navigation menu?', 'roots'); ?></span></legend>
+ <fieldset>
+ <legend class="screen-reader-text"><span><?php _e('Create navigation menu?', 'roots'); ?></span></legend>
<select name="roots_theme_activation_options[create_navigation_menus]" id="create_navigation_menus">
<option selected="selected" value="true"><?php echo _e('Yes', 'roots'); ?></option>
<option value="false"><?php echo _e('No', 'roots'); ?></option>
</select>
- <br>
- <small class="description"><?php printf(__('Create the Primary Navigation menu and set the location', 'roots')); ?></small>
+ <p class="description"><?php printf(__('Create the Primary Navigation menu and set the location', 'roots')); ?></p>
</fieldset>
</td>
</tr>
-
<tr valign="top"><th scope="row"><?php _e('Add pages to menu?', 'roots'); ?></th>
<td>
- <fieldset><legend class="screen-reader-text"><span><?php _e('Add pages to menu?', 'roots'); ?></span></legend>
+ <fieldset>
+ <legend class="screen-reader-text"><span><?php _e('Add pages to menu?', 'roots'); ?></span></legend>
<select name="roots_theme_activation_options[add_pages_to_primary_navigation]" id="add_pages_to_primary_navigation">
<option selected="selected" value="true"><?php echo _e('Yes', 'roots'); ?></option>
<option value="false"><?php echo _e('No', 'roots'); ?></option>
</select>
- <br>
- <small class="description"><?php printf(__('Add all current published pages to the Primary Navigation', 'roots')); ?></small>
+ <p class="description"><?php printf(__('Add all current published pages to the Primary Navigation', 'roots')); ?></p>
</fieldset>
</td>
</tr>
-
</table>
-
<?php submit_button(); ?>
</form>
</div>
@@ -186,17 +167,6 @@ function roots_theme_activation_action() {
}
}
- if ($roots_theme_activation_options['change_uploads_folder'] === 'true') {
- $roots_theme_activation_options['change_uploads_folder'] = false;
-
- update_option('uploads_use_yearmonth_folders', 0);
- if (!is_multisite()) {
- update_option('upload_path', 'media');
- } else {
- update_option('upload_path', '');
- }
- }
-
if ($roots_theme_activation_options['create_navigation_menus'] === 'true') {
$roots_theme_activation_options['create_navigation_menus'] = false;
View
1  lib/config.php
@@ -7,6 +7,7 @@
add_theme_support('bootstrap-gallery'); // Enable Bootstrap's thumbnails component on [gallery]
add_theme_support('nice-search'); // Enable /?s= to /search/ redirect
add_theme_support('jquery-cdn'); // Enable to load jQuery from the Google CDN
+add_theme_support('roots-activation', (defined('ROOTS-ACTIVATION') ? ROOTS-ACTIVATION : true )); // Enable activation options
/**
* Configuration values
View
14 lib/gallery.php
@@ -44,7 +44,7 @@ function roots_gallery($attr) {
'size' => 'thumbnail',
'include' => '',
'exclude' => '',
- 'link' => 'file'
+ 'link' => ''
), $attr));
$id = intval($id);
@@ -85,7 +85,17 @@ function roots_gallery($attr) {
$i = 0;
foreach ($attachments as $id => $attachment) {
- $image = ('file' == $link) ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);
+ switch($link) {
+ case 'file':
+ $image = wp_get_attachment_link($id, $size, false, false);
+ break;
+ case 'none':
+ $image = wp_get_attachment_image($id, $size, false, array('class' => 'thumbnail img-thumbnail'));
+ break;
+ default:
+ $image = wp_get_attachment_link($id, $size, true, false);
+ break;
+ }
$output .= ($i % $columns == 0) ? '<div class="row gallery-row">': '';
$output .= '<div class="' . $grid .'">' . $image;
View
6 lib/scripts.php
@@ -18,7 +18,7 @@ function roots_scripts() {
// It's kept in the header instead of footer to avoid conflicts with plugins.
if (!is_admin() && current_theme_supports('jquery-cdn')) {
wp_deregister_script('jquery');
- wp_register_script('jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js', false, null, false);
+ wp_register_script('jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js', array(), null, false);
add_filter('script_loader_src', 'roots_jquery_local_fallback', 10, 2);
}
@@ -26,8 +26,8 @@ function roots_scripts() {
wp_enqueue_script('comment-reply');
}
- wp_register_script('modernizr', get_template_directory_uri() . '/assets/js/vendor/modernizr-2.7.0.min.js', false, null, false);
- wp_register_script('roots_scripts', get_template_directory_uri() . '/assets/js/scripts.min.js', false, '01d073428e4e54f227f8a0a3bad4b804', true);
+ wp_register_script('modernizr', get_template_directory_uri() . '/assets/js/vendor/modernizr-2.7.0.min.js', array(), null, false);
+ wp_register_script('roots_scripts', get_template_directory_uri() . '/assets/js/scripts.min.js', array(), '01d073428e4e54f227f8a0a3bad4b804', true);
wp_enqueue_script('modernizr');
wp_enqueue_script('jquery');
wp_enqueue_script('roots_scripts');
Something went wrong with that request. Please try again.