Why are my codes of Code Snippets not working? - code-snippets

I have recently downloaded bbpress but when users log in on the front end they can access the admin area and have the bar across the top which contains a link to remove it. I know nothing about code at all, I've only been blogging a few weeks so after doing a bit of reading I decided to download the plugin Code Snippets and add the following codes.
function annointed_admin_bar_remove() {
global $wp_admin_bar;
/* Remove their stuff */
$wp_admin_bar->remove_menu('wp-logo');
}
add_action('wp_before_admin_bar_render', 'annointed_admin_bar_remove', 0);
and
// disable access to wp-admin for non-administrators
function block_wp_admin_access() {
if ( is_admin() && ! current_user_can( 'administrator' ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
wp_redirect( home_url() );
exit;
}
}
add_action( 'init', 'block_wp_admin_access' );
Neither of these has worked and since I don't know anything about code, I don't know why they aren't working. I can't seem to find a plugin that does this for you either.

Related

Is it possible to reverse javascript code with symbolic tools

Look at this very basic javascript code:
function check(a,b,c)
{
if (a[0]==a[1] && a[1]=='A' && a[2]=='C' && a.length==3)
{
console.log('Good !');
}
else
{
console.log('Wrong !');
}
}
It is easy to see the good value for 'a' parameter is 'AAC'.
Let's imagine a more complex javascript code.
What i want to do is to ask a tool to automatically resolve this kind of function.
I want to say: give me the a, b and c value that runs "Good !" Line code.
I know angr for binaries. But i am looking for a tool which works with javascript code
Thanks
I've never used it myself, but a quick google suggests this: https://github.com/ExpoSEJS/ExpoSE
I'm not sure if it does everything you need, but being open-source, it might be a good place to start. Would be great if you try it out and write up your experiences!

ItemAdd Event on Redemption Folder - how to use properly with Console Application

I have a .Net Console Application that emails documents using Redemption with Outlook. I attach the "Items.ItemAdd" event to the relevant folder. The event never fires.
But in my test harness which is a WPF application, using the same method and the same references etc, it does work.
Does the event actually work in a console app? Is there an example of the correct way, or of an alternate way?
Your app needs to run the Windows message loop for the events to work.
OK thanks for that hint. I tried various things and eventually it seems to work as below:
DispatcherOperation op = System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvoke((Action)(() => { SomeMethod(someArgs); }));
DispatcherOperationStatus status = op.Status;
while (status != DispatcherOperationStatus.Completed && status != DispatcherOperationStatus.Aborted)
{
status = op.Wait(TimeSpan.FromMilliseconds(10000));
if (status == DispatcherOperationStatus.Completed || status == DispatcherOperationStatus.Aborted)
{
// do your final code
}
}

Gulp Graphicsmagick - setting a background image(composite)

How can I add a background image to a partially transparent png using Graphicsmagick Gulp module? (https://www.npmjs.com/package/gulp-gm)
Here is my gulp task:
gulp.task("addBackground", function () {
gulp.src('input/*.png')
.pipe(gm(function (gmfile) {
return gmfile.composite('background.jpg');
}))
.pipe(gulp.dest('output/'));
});
However when I try to run this my tasks all finish and then it throws the following error:
Any insight on how to fix this or what is going on here is appreciated.
I also ran into the same error and finally found a solution; it may not work for what you are planning since you're trying to add a background, but it does result in a solution to combine 2 images. Hopefully, this can give you a starting point to find a better solution.
gulp.task( 'composite', function () {
gulp.src('path/image.png')
.pipe( gm( function ( gmfile ) {
return gmfile
.draw('image Over 2,2 0,0 path/overlay.png')
} ) )
.pipe( gulp.dest( 'newpath/' ) );
} );
The first set of numbers "2,2" are for the x,y start. I'm not sure what the second set does yet.
I found the solution based on this github disscusion about watermarks: https://github.com/aheckmann/gm/issues/276

Twitter Module - Drupal 7

Twitter Module is working finde with my Drupal 7 site. I wanted to make a tweek so that nodes that are not hidden get tweeted, I was able to do this by altering twitter_post_node_insert in twitter/twitter_post . All I did was add a new condition of !$node->hidden . It works great.
function twitter_post_node_insert($node) {
if (!empty($node->status) && !empty($node->twitter) && !empty($node->twitter['post'])
&& !$node->hidden) { ......
My problem is that this code in the Twitter Module only gets called when I directly edit a node and save it. Now, I would like to have said code called also when I edit my node programmatically, where I save it with $node_wrapper->save(); . The twitter code won't get called. I've also tried with node_save($node); , instead of using my $node_wrapper. Nothing.
I also tried including the file twitter_post.module located in twitter/twitter_post, and then calling the function in charge of posting the tweet :
module_load_include('module', 'twitter', '../twitter/twitter_post/twitter_post');
twitter_post_node_update($node);
Nothing happens and no errors are shown. What I'd like is to know what Drupal 7 function gets called in its core when you edit a node through its interface and then save it. That way I can just put that function in the code where I edit my node programmatically so that the Twitter code will also get called. Or, does anyone have a better approach?
Thanks.
After looking into the Twitter module this is what I have done in order to have the nodes published programmatically.
I added the following function to twitter/twitter_post/twitter_post.module . It's a copy of the function function twitter_post_node_insert($node), found on the same file. I made a copy so that it would not print out the message of "tweet posted succesfully". That way I call the copied function from another place to post the tweet.
/**
* Function called from custom .module to insert tweets from "Editar Pesos" tab
*/
function twitter_post_node_custom_insert($node) {
if (!empty($node->status) && !empty($node->twitter) && !empty($node->twitter['post']) && !$node->hidden ) {
module_load_include('inc', 'twitter');
$twitter_account = twitter_account_load($node->twitter['account']);
$replacements = array(
'!title' => truncate_utf8($node->title, 90, false, true),
'!url' => url('node/' . $node->nid, array('absolute' => TRUE, 'alias' => TRUE)),
'!url-alias' => url('node/' . $node->nid, array('absolute' => TRUE))
);
// Only generate the shortened URL if it's going to be used. No sense
// burning through TinyURLs without a good reason.
if (strstr($node->twitter['status'], '!tinyurl') !== FALSE) {
$replacements['!tinyurl'] = twitter_shorten_url(url('node/' . $node->nid,
array('absolute'=> TRUE)));
}
$status = strtr($node->twitter['status'], $replacements);
return twitter_set_status($twitter_account, $status);
}
}
And following is the "magic", which gets called whenever I want the node posted as a tweet.
function post_to_twitter($node){
module_load_include('module', 'twitter', '../twitter/twitter_post/twitter_post');
$twitter = array(
'account' => getTwitterUid(),
'post' => 'POST',
'status' => "!title !tinyurl"
);
$node->twitter = $twitter;
return twitter_post_node_custom_insert($node);
}
function getTwitterUid(){
return db_query("select twitter_uid from {twitter_account} where screen_name = :screen_name
limit 1", array(":screen_name" => 'YOUR_TwitterScreenName'))->fetchField();
}
Hope this can help anyone who was looking for the same thing as I.

What does an identifier followed by a colon mean in Objective-C?

bail:
if ( err && image ) {
CGImageRelease( image );
image = NULL;
}
if ( provider ) CGDataProviderRelease( provider );
if ( colorspace ) CGColorSpaceRelease( colorspace );
*imageOut = image;
return err;
I looked at some code and found this. I have never seen this before. What does bail: mean?
It comes from here.
It's a label that the goto statement jumps to.
The code you're looking at, SquareCamViewController.m, uses a macro named require, like this:
require( error == nil, bail );
This macro is defined in the AssertMacros.h header file. It takes a label as its second argument, and uses goto if the first argument evaluates to false.
Using goto to jump to cleanup code at the end of a function is the most common use of goto and labels in C.
bail: is a label. This is standard C syntax. It's not used very often in properly written code. It's most common use is with goto. Please avoid using goto. In the code you referenced it is used by the require function. If the require fails, the code will jump ahead to the bail label, skipping all of the other code in between.

Resources