nomatteus
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: another “can WordPress do this?” threadYou can do this with filters and/or actions.
You have to hook into “the_content()” function, and depending what exactly you want to do, use a filter or action.
If you want to replace the entire content, or just append/prepend your HTML snippet, then you would want to use an action.
If you want to do something like replace “[foobar]” in your post with your HTML snippet, then you’d use a filter.
The following would add “<p>Hello There!</p>” to the end of each post/page content:
function add_html_snip($content) { $html_snip = "<p>Hello There!</p>"; return $content . $html_snip; } add_action ( 'the_content', 'add_html_snip');This code would go into your plugin. Visit this codex page for more info on plugin structure and actions/filters:
http://codex.ww.wp.xz.cn/Plugin_APIForum: Requests and Feedback
In reply to: One thing that is annoying…Hey,
If you want to also supress the plugin upgrade notices you can change the CSS to the following (I just FireBugged the page to find the classes for the plugin nags):
supress_nag.css:
#update-nag, #update-nag a, span.update-plugins, td.plugin-update { display: none; }I am doing this since I have modified some plugins’ code and don’t want any other admins to auto-upgrade and overwrite my changes. To find out if there are any plugins that need updating just deactivate the ‘supress nag’ plugin to see the notices, and then re-activate it again when you’re done.
Matt
Forum: Fixing WordPress
In reply to: Quickest way to add some html to multiple posts ?Are you looking to do this as a one-time thing, or do you want a block of HTML added to all your current AND future posts?
This could be along the lines of what you’re looking for:
http://ww.wp.xz.cn/extend/plugins/custom-post-text/This could also work too:
http://ww.wp.xz.cn/extend/plugins/add-post-footer/Matt
Forum: Plugins
In reply to: [Plugin: Customize Your Community] Error on the profile page shows backendI ran into the exact same problem, and it’s pretty much a dealbreaker if it can’t be fixed. So I played around with the code and managed to put together a fix. (I haven’t tried the alternative plugin mentioned above–it may be better, but regardless this is a fix for anyone that wants to keep using the CYC plugin!)
Nothing elegant, but prevents users seeing the admin screen!
This involves editing the following two files:
- /wp-admin/user-edit.php — CORE WordPress file
- /wp-content/plugins/customize-your-community/cyc.php — Main Plugin File
As you should always do, be sure to make a backup to these files before going in and editing them!
In /wp-admin/user-edit.php, find the following (~line 143):
if ( !is_wp_error( $errors ) ) { $redirect = ($is_profile_page? "profile.php?" : "user-edit.php?user_id=$user_id&"). "updated=true"; $redirect = add_query_arg('wp_http_referer', urlencode($wp_http_referer), $redirect); wp_redirect($redirect); exit; }and change it to (adding an elseif statment):
if ( !is_wp_error( $errors ) ) { $redirect = ($is_profile_page? "profile.php?" : "user-edit.php?user_id=$user_id&"). "updated=true"; $redirect = add_query_arg('wp_http_referer', urlencode($wp_http_referer), $redirect); wp_redirect($redirect); exit; } elseif ($is_profile_page) { $redirect = "profile.php?" . "errors=" . urlencode(implode('||',$errors->get_error_messages())); wp_redirect($redirect); exit; }What this does it redirects back to the profile.php page (which will be the non-admin styled one), and sends a get variable with the output text of the errors. It’s sent as a “piped” array.
Second, open up /wp-content/plugins/customize-your-community/cyc.php, and find the following (~line 275):
if ($_GET['updated'] == true) { echo '<p class="message">Your profile has been updated.</p>'; }and change it to (again adding an elseif statment):
if ($_GET['updated'] == true) { echo '<p class="message">Your profile has been updated.</p>'; } elseif ($_GET['errors'] != "") { $error_messages = explode("||", $_GET['errors']); echo '<p class="message">'; foreach ($error_messages as $the_msg) { echo "$the_msg<br />"; } echo '</p>'; }This looks for the errors GET variable and if found, prints out each error message. This code can be changed to display the errors however you like, for example in a red box, etc.
This should solve the problem. If anyone tries this out let me know if it works for you!
An important note: Since you’ve changed a core WordPress file and also the plugin code, you’ll have to be careful when upgrading both the WordPress core and the plugin. You either will have to upgrade manually, or make the above changes again after doing an automatic upgrade.
That should be it! Hopefully a real fix will make it into a future CYC version…
Matt